inline-assembly

llvm reports: unsupported inline asm: input with type 'void *' matching output with type 'int'

拜拜、爱过 提交于 2019-11-28 12:56:50
问题 I have the below inline assembly code: int get_year(int a, int *b, char * c) { int ret, t1, t2; asm ( "addl %3, %[a] \n\t" "movl %[a], %[t1] \n\t" "movl $58, %%edx \n\t" "movb %%dl, 0x04(%1) \n\t" : [t1] "=r" (t1), "=&D" (t2) : [a] "r" (a), "rm" (*b), "1" (c) : "edx", "memory" ); ret = t1; return ret; } When I compile this via llvm, error dumps: error: unsupported inline asm: input with type 'char *' matching output with type 'int' : [a] "r" (a), "rm" (*b), "1" (c) ^ However, the memcpy

How can I indicate that the memory *pointed* to by an inline ASM argument may be used?

不羁岁月 提交于 2019-11-28 11:34:02
Consider the following small function: void foo(int* iptr) { iptr[10] = 1; __asm__ volatile ("nop"::"r"(iptr):); iptr[10] = 2; } Using gcc, this compiles to : foo: nop mov DWORD PTR [rdi+40], 2 ret Note in particular, that the first write to iptr , iptr[10] = 1 doesn't occur at all: the inline asm nop is the first thing in the function, and only the final write of 2 appears (after the ASM call). Apparently the compiler decides that it only needs to provide an up-to-date version of the value of iptr itself , but not the memory it points to. I can tell the compiler that memory must be up to date

gcc inline assembly error “operand type mismatch for mov”

99封情书 提交于 2019-11-28 11:28:08
问题 //quick inline asm statements performing the swap_byte for key_scheduling inline void swap_byte(unsigned char *x, unsigned char *y) { unsigned char t; asm("movl %1, %%eax;" "movl %%eax, %0;" :"=r"(t) :"r"(*x) :"%eax"); asm("movl %1, %%eax;" "movl %%eax, %0;" :"=r"(*x) :"r"(*y) :"%eax"); asm("movl %1, %%eax;" "movl %%eax, %0;" :"=r"(*y) :"r"(t) :"%eax"); } Here I am trying to swap the char from x and store in y , and the same for y to x . I have compiled these instructions by changing movl to

How do I specify immediate floating point numbers with inline assembly?

半世苍凉 提交于 2019-11-28 11:11:28
When I try to compile this code: #include <stdio.h> main(int argc, char *argv[]) { double y = 0; __asm__ ("fldl $150;" "fsqrt;" "fstl %0;" : : "g" (y) ); printf("%f\n", y); return 0; } I get this error: sqrt.c: Assembler messages: sqrt.c:6: Error: suffix or operands invalid for `fld' Why doesn't this work? Why can't I push the number "150" onto the stack for floating point operations? I do not know of an assembly language which supports literal floating point constants for immediate use. The usual means is to declare initialized storage containing the floating point constant and referencing it

syscall from within GCC inline assembly [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-11-28 10:28:30
This question already has an answer here: How to invoke a system call via sysenter in inline assembly? 2 answers is it possible to write a single character using a syscall from within an inline assembly block? if so, how? it should look "something" like this: __asm__ __volatile__ ( " movl $1, %%edx \n\t" " movl $80, %%ecx \n\t" " movl $0, %%ebx \n\t" " movl $4, %%eax \n\t" " int $0x80 \n\t" ::: "%eax", "%ebx", "%ecx", "%edx" ); $80 is 'P' in ascii, but that returns nothing. any suggestions much appreciated! Something like char p = 'P'; int main() { __asm__ __volatile__ ( " movl $1, %%edx \n\t"

GCC inline assembly with stack operation

徘徊边缘 提交于 2019-11-28 10:27:40
问题 I am in need of such a inline assembly code: I have a pair (so, it is balanced) of push/pop operation inside the assembly I also have a variable in memory (so, not register) as input like this: __asm__ __volatile__ ("push %%eax\n\t" // ... some operations that use ECX as a temporary "mov %0, %%ecx\n\t" // ... some other operation "pop %%eax" : : "m"(foo)); // foo is my local variable, that is to say, on stack When disassembling the compiled code, the compiler give the memory address like 0xc(

Is Intel's timestamp reading asm code example using two more registers than are necessary?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 10:11:40
I'm looking into measuring benchmark performance using the time-stamp register (TSR) found in x86 CPUs. It's a useful register, since it measures in a monotonic unit of time which is immune to the clock speed changing. Very cool. Here is an Intel document showing asm snippets for reliably benchmarking using the TSR, including using cpuid for pipeline synchronisation. See page 16: http://www.intel.com/content/www/us/en/embedded/training/ia-32-ia-64-benchmark-code-execution-paper.html To read the start time, it says (I annotated a bit): __asm volatile ( "cpuid\n\t" // writes e[abcd]x "rdtsc\n\t"

Is it possible to write inline assembly in Swift?

坚强是说给别人听的谎言 提交于 2019-11-28 09:44:32
I was wondering if you can write inline assembly in Swift. I know that in Objective-C you could use something like this: inline void assemblyFunc() { __asm__(/*Assembly*/); } But in Swift it seems that you can't use __asm__(/*Assembly*/) . Does anyone know how to use __asm__() if its even possible. I haven't found anything about it, so I thought it would be a good question to ask. To expand on what Robert Levy said, you can just use the Swift/Obj-C interop feature, and write an Obj-C class that does the ASM stuff, which you can then call from Swift. It's an annoying workaround, but it should

Visual C++ x64 add with carry

被刻印的时光 ゝ 提交于 2019-11-28 09:23:50
Since there doesn't seem to be an intrinsic for ADC and I can't use inline assembler for x64 architecture with Visual C++, what should I do if I want to write a function using add with carry but include it in a C++ namespace? (Emulating with comparison operators is not an option. This 256 megabit add is performance critical.) There is now an instrinsic for ADC in MSVC: _addcarry_u64 . The following code #include <inttypes.h> #include <intrin.h> #include <stdio.h> typedef struct { uint64_t x1; uint64_t x2; uint64_t x3; uint64_t x4; } uint256; void add256(uint256 *x, uint256 *y) { unsigned char

Direct C function call using GCC's inline assembly

南楼画角 提交于 2019-11-28 09:14:07
If you want to call a C/C++ function from inline assembly, you can do something like this: void callee() {} void caller() { asm("call *%0" : : "r"(callee)); } GCC will then emit code which looks like this: movl $callee, %eax call *%eax This can be problematic since the indirect call will destroy the pipeline on older CPUs. Since the address of callee is eventually a constant, one can imagine that it would be possible to use the i constraint. Quoting from the GCC online docs : `i' An immediate integer operand (one with constant value) is allowed. This includes symbolic constants whose values