inline-assembly

`ldm/stm` in gcc inline ARM assembly

走远了吗. 提交于 2019-12-21 14:01:06
问题 I am trying to create an ldm (resp. stm ) instruction with inline assembly but have problems to express the operands (especially: their order). A trivial void *ptr; unsigned int a; unsigned int b; __asm__("ldm %0!,{%1,%2}" : "+&r"(ptr), "=r"(a), "=r"(b)); does not work because it might put a into r1 and b into r0 : ldm ip!, {r1, r0} ldm expects registers in ascending order (as they are encoded in a bitfield) so I need a way to say that the register used for a is lower than this of b . A

`ldm/stm` in gcc inline ARM assembly

纵饮孤独 提交于 2019-12-21 14:00:09
问题 I am trying to create an ldm (resp. stm ) instruction with inline assembly but have problems to express the operands (especially: their order). A trivial void *ptr; unsigned int a; unsigned int b; __asm__("ldm %0!,{%1,%2}" : "+&r"(ptr), "=r"(a), "=r"(b)); does not work because it might put a into r1 and b into r0 : ldm ip!, {r1, r0} ldm expects registers in ascending order (as they are encoded in a bitfield) so I need a way to say that the register used for a is lower than this of b . A

How to determine values saved on the stack?

独自空忆成欢 提交于 2019-12-21 13:26:58
问题 I'm doing some experimenting and would like to be able to see what is saved on the stack during a system call (the saved state of the user land process). According to http://lxr.linux.no/#linux+v2.6.30.1/arch/x86/kernel/entry_32.S it shows that the various values of registers are saved at those particular offsets to the stack pointer. Here is the code I have been trying to use to examine what is saved on the stack (this is in a custom system call I have created): asm("movl 0x1C(%esp), %ecx");

Is there an 8-bit atomic CAS (cmpxchg) intrinsic for X64 in Visual C++?

Deadly 提交于 2019-12-21 04:49:28
问题 The following code is possible in 32-bit Visual Studio C++. Is there a 64-bit equivalent using intrinsics since inline ASM isn't supported in the 64-bit version of Visual Studio C++? FORCEINLINE bool bAtomicCAS8(volatile UINT8 *dest, UINT8 oldval, UINT8 newval) { bool result=false; __asm { mov al,oldval mov edx,dest mov cl,newval lock cmpxchg byte ptr [edx],cl setz result } return(result); } The following instrinsics compile under Visual Studio C++ _InterlockedCompareExchange16

Accessing a register without using inline assembly with gcc

﹥>﹥吖頭↗ 提交于 2019-12-20 10:44:02
问题 I want to read the stack pointer register value without writing inline assembly.The reason I want to do this is because I want to assign the stack pointer register value to an element of an array and I find it cumbersome to access an array using inline assembly. So I would want to do something like that. register "rsp" long rsp_alias; <--- How do I achieve something like that in gcc? long current_rsp_value[NUM_OF_THREADS]; current_rsp_value[tid] = rsp_alias; Is there anything like that

How to have GCC combine “move r10, r3; store r10” into a “store r3”?

我是研究僧i 提交于 2019-12-20 07:56:56
问题 I'm working Power9 and utilizing the hardware random number generator instruction called DARN. I have the following inline assembly: uint64_t val; __asm__ __volatile__ ( "xor 3,3,3 \n" // r3 = 0 "addi 4,3,-1 \n" // r4 = -1, failure "1: \n" ".byte 0xe6, 0x05, 0x61, 0x7c \n" // r3 = darn 3, 1 "cmpd 3,4 \n" // r3 == -1? "beq 1b \n" // retry on failure "mr %0,3 \n" // val = r3 : "=g" (val) : : "r3", "r4", "cc" ); I had to add a mr %0,3 with "=g" (val) because I could not get GCC to produce

Strange 'asm' operand has impossible constraints error

蓝咒 提交于 2019-12-20 07:39:53
问题 I'm trying to compile a simple C program (Win7 32bit, Mingw32 Shell and GCC 5.3.0). The C code is like this: #include <stdio.h> #include <stdlib.h> #define _set_tssldt_desc(n,addr,type) \ __asm__ ("movw $104,%1\n\t" \ :\ :"a" (addr),\ "m" (*(n)),\ "m" (*(n+2)),\ "m" (*(n+4)),\ "m" (*(n+5)),\ "m" (*(n+6)),\ "m" (*(n+7))\ ) #define set_tss_desc(n,addr) _set_tssldt_desc(((char *) (n)),addr,"0x89") char *n; char *addr; int main(void) { char *n = (char *)malloc(100*sizeof(int)); char *addr = (char

ROL / ROR on variable using inline assembly in Objective-C

非 Y 不嫁゛ 提交于 2019-12-19 21:26:06
问题 I would like to perform ROR and ROL operations on variables in an Objective-C program. However, I can't manage it – I am not an assembly expert. Here is what I have done so far: uint8_t v1 = ....; uint8_t v2 = ....; // v2 is either 1, 2, 3, 4 or 5 asm("ROR v1, v2"); the error I get is: Unknown use of instruction mnemonic with unknown size suffix How can I fix this? Edit: The code does not need to use inline assembly. However, I haven't found a way to do this using Objective-C / C++ / C

How do I tell gcc that my inline assembly clobbers part of the stack?

别说谁变了你拦得住时间么 提交于 2019-12-19 09:03:58
问题 Consider inline assembly like this: uint64_t flags; asm ("pushf\n\tpop %0" : "=rm"(flags) : : /* ??? */); Nonwithstanding the fact that there is probably some kind of intrinsic to get the contents of RFLAGS, how do I indicate to the compiler that my inline assembly clobbers one quadword of memory at the top of stack? 回答1: As far as I am concerned, this is currently not possible. 来源: https://stackoverflow.com/questions/39160450/how-do-i-tell-gcc-that-my-inline-assembly-clobbers-part-of-the

How to use a global variable in gcc inline assembly

时光怂恿深爱的人放手 提交于 2019-12-19 00:22:52
问题 I am trying to use inline assembly like this, for a global variable, but the compiler gives an error by saying undefined reference to saved_sp . __asm__ __volatile__ ( "movq saved_sp, %rsp\n\t" ); saved_sp is declared as static long saved_sp globally (for a file that is). What mistake am I doing here? 回答1: If it fails with "undefined reference to `saved_sp' " (which is really a linker error, not a compiler error) when saved_sp is static , but works when it is not, then it seems likely that