inline-assembly

Why does MSVC not support inline assembly for AMD64 and Itanium targets?

好久不见. 提交于 2019-11-29 13:17:01
Yesterday I learned that inline assembly (with the __asm keyword) is not supported under Microsoft Visual C++ when compiling for AMD64 and Itanium targets. Is that correct? And if so, does anyone know why they would not support inline assembly for those targets? It seems like a rather big feature to just drop... Correct, it still isn't supported in VS 2010 Beta 1 . My guess is that inline assembly is just too difficult to implement: the way Microsoft implemented it, it integrates with the surrounding C code so that data can flow in and out of the C code, and appropriate glue code is

clang (LLVM) inline assembly - multiple constraints with useless spills / reloads

偶尔善良 提交于 2019-11-29 13:15:03
clang / gcc : Some inline assembly operands can be satisfied with multiple constraints, e.g., "rm" , when an operand can be satisfied with a register or memory location. As an example, the 64 x 64 = 128 bit multiply: __asm__ ("mulq %q3" : "=a" (rl), "=d" (rh) : "%0" (x), "rm" (y) : "cc") The generated code appears to choose a memory constraint for argument 3 , which would be fine if we were register starved, to avoid a spill. Obviously there's less register pressure on x86-64 than on IA32. However, the assembly snippet generated (by clang ) is: movq %rcx, -8(%rbp) ## InlineAsm Start mulq -8(

Assembly code fsqrt and fmul instructions

ぐ巨炮叔叔 提交于 2019-11-29 13:06:44
I'm trying to compute 1.34 *sqrt(lght) in this function using inline assembly but I'm getting errors like: '_asm' undeclared (first use in this function) each undeclared identifier is reported only once for each func tion it appears in expected ';' before '{' token I have been researching how to solve this problem but can't find much information. Can someone suggest a way to get this to work? My code is: double hullSpeed(double lgth) { _asm { global _start fld lght; //load lght fld st(0); //duplicate lght on Top of stack fsqrt; square root of lght fld st(0); //load square result on top of

GCC: putchar(char) in inline assembly

流过昼夜 提交于 2019-11-29 12:21:24
Overflow, how can I implement the putchar(char) procedure using inline assembly only? I would like to do this in x86-64 assembly. The reason for me doing this is to implement my own standard-lib (or at least part of it). Here is what I have so far: void putchar(char c) { /* your code here: print character c on stdout */ asm(...); } void _start() { /* exit system call */ asm("mov $1,%rax;" "xor %rbx,%rbx;" "int $0x80" ); } I am compiling with: gcc -nostdlib -o putchar putchar.c Thanks for helping me! When using GNU C inline asm, use constraints to tell the compiler where you want things ,

How do you detect the CPU architecture type during run-time with GCC and inline asm?

99封情书 提交于 2019-11-29 12:18:34
I need to find the architecture type of a CPU. I do not have access to /proc/cpuinfo, as the machine is running syslinux. I know there is a way to do it with inline ASM, however I believe my syntax is incorrect as my variable iedx is not being set properly. I'm drudging along with ASM, and by no means an expert. If anyone has any tips or can point me in the right direction, I would be much obliged. static int is64Bit(void) { int iedx = 0; asm("mov %eax, 0x80000001"); asm("cpuid"); asm("mov %0, %%eax" : : "a" (iedx)); if ((iedx) && (1 << 29)) { return 1; } return 0; } tyranid How many bugs can

How do I write the following inline Assembly Code in C using GCC

こ雲淡風輕ζ 提交于 2019-11-29 12:17:29
I was reading some answers and questions on here and kept coming up with this suggestion but I noticed no one ever actually explained "exactly" what you need to do to do it, On Windows using Intel and GCC compiler. Commented below is exactly what I am trying to do. #include <stdio.h> int main() { int x = 1; int y = 2; //assembly code begin /* push x into stack; < Need Help x=y; < With This pop stack into y; < Please */ //assembly code end printf("x=%d,y=%d",x,y); getchar(); return 0; } Let the compiler choose the registers, using the k prefix to denote a 32-bit register for the int type (so it

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

别来无恙 提交于 2019-11-29 11:18:52
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

Working inline assembly in C for bit parity?

妖精的绣舞 提交于 2019-11-29 11:12:22
I'm trying to compute the bit parity of a large number of uint64's. By bit parity I mean a function that accepts a uint64 and outputs 0 if the number of set bits is even, and 1 otherwise. Currently I'm using the following function (by @Troyseph, found here ): uint parity64(uint64 n){ n ^= n >> 1; n ^= n >> 2; n = (n & 0x1111111111111111) * 0x1111111111111111; return (n >> 60) & 1; } The same SO page has the following assembly routine (by @papadp): .code ; bool CheckParity(size_t Result) CheckParity PROC mov rax, 0 add rcx, 0 jnp jmp_over mov rax, 1 jmp_over: ret CheckParity ENDP END which

How do I tell GCC asm that an input register is clobbered?

折月煮酒 提交于 2019-11-29 11:01:01
I'm trying to do a 64=32x32 multiply via the x86 mul instruction, but I only need the high dword of the result (the edx register). So naturally, I tried listing edx as an output register and eax as a clobbered register. This seems natural to me, but eax is also an input register. When I try to tell GCC that eax is clobbered, it gives an error message. __asm__("mull\t%2" : "=d"(div10) : "%a"(UINT32_C(0x1999999A)), "r"(number) : "cc", "rax"); If I try that, it throws this error message: divmod10.cpp:76:91: error: can’t find a register in class ‘AREG’ while reloading ‘asm’ divmod10.cpp:76:91:

cmpxchg example for 64 bit integer

a 夏天 提交于 2019-11-29 10:03:50
问题 I am using cmpxchg (compare-and-exchange) in i686 architecture for 32 bit compare and swap as follows. (Editor's note: the original 32-bit example was buggy, but the question isn't about it. I believe this version is safe, and as a bonus compiles correctly for x86-64 as well. Also note that inline asm isn't needed or recommended for this; __atomic_compare_exchange_n or the older __sync_bool_compare_and_swap work for int32_t or int64_t on i486 and x86-64 . But this question is about doing it