inline-assembly

The difference between asm, asm volatile and clobbering memory

 ̄綄美尐妖づ 提交于 2019-11-27 17:04:48
When implementing lock-free data structures and timing code it's often necessary to suppress the compiler's optimisations. Normally people do this using asm volatile with memory in the clobber list, but you sometimes see just asm volatile or just a plain asm clobbering memory. What impact do these different statements have on code generation (particularly in GCC, as it's unlikely to be portable)? Just for reference, these are the interesting variations: asm (""); // presumably this has no effect on code generation asm volatile (""); asm ("" ::: "memory"); asm volatile ("" ::: "memory");

How to convert Linux 32-bit gcc inline assembly to 64-bit code? [closed]

陌路散爱 提交于 2019-11-27 14:26:07
I'm attempting to convert RR0D Rasta Ring 0 Debugger from 32-bit mode to 64-bit mode (long mode) in Linux, using gcc. I'm familiar with x86 32-bit assembly (in MS-DOS environment) but I'm a beginner in x86 64-bit assembly and in Linux assembly programming in general. This project is for production use (I need a working non-source debugger), but I also attempt to learn how to do the 32-bit to 64-bit conversion. If possible, I attempt to find a universal way to do 32-bit to 64-bit conversion that could be done on any 32-bit program using regular expressions (so that it can be automatized). I'm

Is it possible to access 32-bit registers in C?

£可爱£侵袭症+ 提交于 2019-11-27 13:59:58
问题 Is it possible to access 32-bit registers in C ? If it is, how ? And if not, then is there any way to embed Assembly code in C ? I`m using the MinGW compiler, by the way. Thanks in advance! 回答1: If you want to only read the register, you can simply: register int ecx asm("ecx"); Obviously it's tied to instantiation. Another way is using inline assembly. For example: asm("movl %%ecx, %0;" : "=r" (value) : ); This stores the ecx value into the variable value . I've already posted a similar

How do I do inline assembly on the IPhone?

人走茶凉 提交于 2019-11-27 11:14:43
How is it done? What steps do I need to take and what pitfalls and gotchas are there to consider? Hans Sjunnesson I've gotten this to work, thanks to some inside help over at the Apple Devforums , you should sign up if you're a dedicated IPhone developer. First thing's first, it's __asm__() , not plain asm() . Secondly, by default, XCode generates a compilation target that compiles inline assembly against the ARM Thumb instruction set, so usat wasn't recognized as a proper instruction. To fix this, do "Get Info" on the Target. Scroll down to the section "GCC 4.0 - Code Generation" and uncheck

Reading a register value into a C variable

ぐ巨炮叔叔 提交于 2019-11-27 11:13:14
I remember seeing a way to use extended gcc inline assembly to read a register value and store it into a C variable. I cannot though for the life of me remember how to form the asm statement. ephemient Editor's note: this way of using a local register-asm variable is now documented by GCC as "not supported" . It still usually happens to work on GCC, but breaks with clang. (This wording in the documentation was added after this answer was posted, I think.) The global fixed-register variable version has a large performance cost for 32-bit x86, which only has 7 GP-integer registers (not counting

Convert inline assembly code to C++

眉间皱痕 提交于 2019-11-27 09:44:22
I am working on a cpp project. The project need to be migrated to 64 bit. It contains some Inline assembly code which cannot compile on x64. This is the Function which contain the assembly code: void ExternalFunctionCall::callFunction(ArgType resultType, void* resultBuffer) { #if defined(_NT_) || defined(__OS2__) // I386 // just copy the args buffer to the stack (it's already layed out correctly) int* begin = m_argsBegin; int* ptr = m_argsEnd; int arr[1000], i=0; while (ptr > begin) { int val = *(--ptr); __asm push val } void* functionAddress = m_functionAddress; // call the function & handle

Which inline assembly code is correct for rdtscp?

十年热恋 提交于 2019-11-27 08:55:30
Disclaimer: Words cannot describe how much I detest AT&T style syntax I have a problem that I hope is caused by register clobbering. If not, I have a much bigger problem. The first version I used was static unsigned long long rdtscp(void) { unsigned int hi, lo; __asm__ __volatile__("rdtscp" : "=a"(lo), "=d"(hi)); return (unsigned long long)lo | ((unsigned long long)hi << 32); } I notice there is no 'clobbering' stuff in this version. Whether or not this is a problem I don't know... I suppose it depends if the compiler inlines the function or not. Using this version causes me problems that aren

How to move double in %rax into particular qword position on %ymm or %zmm? (Kaby Lake or later)

假如想象 提交于 2019-11-27 08:48:08
问题 The idea is that I'd like to collect returned values of double into a vector register for processing for machine imm width at a time without storing back into memory first. The particular processing is a vfma with other two operands that are all constexpr , so that they can simply be summoned by _mm256_setr_pd or aligned/unaligned memory load from constexpr array . Is there a way to store double in %ymm at particular position directly from value in %rax for collecting purpose? The target

Merit of inline-ASM rounding via putting float into int variable

独自空忆成欢 提交于 2019-11-27 08:32:31
问题 I have inherited a pretty interesting piece of code: inline int round(float a) { int i; __asm { fld a fistp i } return i; } My first impulse was to discard it and replace calls with (int)std::round (pre-C++11, would use std::lround if it happened today), but after a while I started to wonder if it might have some merit after all... The use case for this function are all values in [-100, 100] , so even int8_t would be wide enough to hold the result. fistp requires at least a 32 bit memory

How to access C struct/variables from inline asm?

点点圈 提交于 2019-11-27 08:31:59
问题 Consider the following code: int bn_div(bn_t *bn1, bn_t *bn2, bn_t *bnr) { uint32 q, m; /* Division Result */ uint32 i; /* Loop Counter */ uint32 j; /* Loop Counter */ /* Check Input */ if (bn1 == NULL) return(EFAULT); if (bn1->dat == NULL) return(EFAULT); if (bn2 == NULL) return(EFAULT); if (bn2->dat == NULL) return(EFAULT); if (bnr == NULL) return(EFAULT); if (bnr->dat == NULL) return(EFAULT); #if defined(__i386__) || defined(__amd64__) __asm__ (".intel_syntax noprefix"); __asm__ ("pushl