inline-assembly

How to specify an individual register as constraint in ARM GCC inline assembly?

倖福魔咒の 提交于 2019-11-26 18:37:05
问题 in x86 inline assembly i can write something like this: asm ("cpuid" : "=a" (_eax), "=b" (_ebx), "=c" (_ecx), "=d" (_edx) : "a" (op)); so in the matchin constraints instead of just writing "=r" and let the compiler chose the register, I can say which particular register i want to use (=a for example to use %eax) how can I do this for ARM assembly? the ARM GCC assembly cookbook http://www.ethernut.de/en/documents/arm-inline-asm.html states that i can for example use the constraints "r" for one

The difference between asm, asm volatile and clobbering memory

佐手、 提交于 2019-11-26 17:56:40
问题 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

How can I accurately benchmark unaligned access speed on x86_64

情到浓时终转凉″ 提交于 2019-11-26 17:48:51
In an answer , I've stated that unaligned access has almost the same speed as aligned access a long time (on x86/x86_64). I didn't have any numbers to back up this statement, so I've created a benchmark for it. Do you see any flaws in this benchmark? Can you improve on it (I mean, to increase GB/sec, so it reflects the truth better)? #include <sys/time.h> #include <stdio.h> template <int N> __attribute__((noinline)) void loop32(const char *v) { for (int i=0; i<N; i+=160) { __asm__ ("mov (%0), %%eax" : : "r"(v) :"eax"); __asm__ ("mov 0x04(%0), %%eax" : : "r"(v) :"eax"); __asm__ ("mov 0x08(%0),

Looping over arrays with inline assembly

自闭症网瘾萝莉.ら 提交于 2019-11-26 16:45:51
When looping over an array with inline assembly should I use the register modifier "r" or he memory modifier "m"? Let's consider an example which adds two float arrays x , and y and writes the results to z . Normally I would use intrinsics to do this like this for(int i=0; i<n/4; i++) { __m128 x4 = _mm_load_ps(&x[4*i]); __m128 y4 = _mm_load_ps(&y[4*i]); __m128 s = _mm_add_ps(x4,y4); _mm_store_ps(&z[4*i], s); } Here is the inline assembly solution I have come up with using the register modifier "r" void add_asm1(float *x, float *y, float *z, unsigned n) { for(int i=0; i<n; i+=4) { __asm__ _

How do I do inline assembly on the IPhone?

烂漫一生 提交于 2019-11-26 15:28:14
问题 How is it done? What steps do I need to take and what pitfalls and gotchas are there to consider? 回答1: 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

Convert inline assembly code to C++

假如想象 提交于 2019-11-26 14:52:23
问题 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

How to represent hex value such as FFFFFFBB in x86 assembly programming?

孤街浪徒 提交于 2019-11-26 14:45:15
I'm learning about x86 inline assembly programming. I wanted to write mov ecx, FFFFFFBB , however the compiler isn’t recognizing it. How should hex numbers like that be written in inline assembler code? It depends on the flavour of your assembler. AT&T: movl $0xFFFFFFBB, %ecx Intel: mov ecx, 0FFFFFFBBh FYI, AT&T syntax is used by assemblers such as the GNU Assembler , whereas NASM and most of others use Intel's one. See the x86 tag wiki for links to assembler manuals, and lots of other stuff. Different x86 assemblers support one or both of these syntaxes for hex constants: 0xDEADBEEF : NASM

Which inline assembly code is correct for rdtscp?

♀尐吖头ヾ 提交于 2019-11-26 14:17:48
问题 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

Writing a Linux int 80h system-call wrapper in GNU C inline assembly [duplicate]

一曲冷凌霜 提交于 2019-11-26 14:09:16
问题 This question already has an answer here: How to invoke a system call via sysenter in inline assembly? 2 answers I'm trying to use inline assembly... I read this page http://www.codeproject.com/KB/cpp/edujini_inline_asm.aspx but I can't understand the parameters passing to my function. I'm writing a C write example.. this is my function header: write2(char *str, int len){ } And this is my assembly code: global write2 write2: push ebp mov ebp, esp mov eax, 4 ;sys_write mov ebx, 1 ;stdout mov

Can I use Intel syntax of x86 assembly with GCC?

℡╲_俬逩灬. 提交于 2019-11-26 11:19:03
I want to write a small low level program. For some parts of it I will need to use assembly language, but the rest of the code will be written on C/C++. So, if I will use GCC to mix C/C++ with assembly code, do I need to use AT&T syntax or can I use Intel syntax? Or how do you mix C/C++ and asm (intel syntax) in some other way? I realize that maybe I don't have a choice and must use AT&T syntax, but I want to be sure.. And if there turns out to be no choice, where I can find full/official documentation about the AT&T syntax? Thanks! ninjalj If you are using separate assembly files, gas has a