Reputation: 2225
I'm trying to write a function in C/x86_64 inline assembly, but I'm not having much luck.
We can boil it all down to this:
void f(const unsigned char *a, unsigned char *b, const unsigned char *c) {
asm __volatile__ ("movdqa %0, %%xmm0" : : "m"(a) : "%xmm0");
}
(The function is called correctly, by the way; I'm trying to replace C code, and when I use the now-commented out C code, it works just fine.)
This crashes:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: 0x000000000000000d, 0x0000000000000000
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
I've tried quite a few combinations of constraints, but (as I said), I'm not having much luck.
The goal is to have access to all three of the function parameters in assembly; a
read-only, b
read-write and c
read-only.
As you can see, all three are char arrays in C; however, both a
and b
are 16 bytes long and can be stored in an XMM register each (which is one of my goals).
c
is an array of such variables, so each of those can also be stored in an XMM register.
Also, I should point out, I'd prefer if GCC didn't load things into registers (as it appears to do with the "x" constraint), but rather it left that to me.
I'd really appriciate if someone could write the constraints for me (and if you feel like it, add a short explanation.)
Upvotes: 2
Views: 1830
Reputation: 2225
The solution (as posted in the comments to the question) was to simply dereference the pointer before passing in to the asm block. Doing so made everything work as it should.
I'm only posting this as an answer because I can't mark it as answered with only comments to the question. (Also, I'm answering it a bit late because it wouldn't let me yesterday, due to my low rep.)
Upvotes: 5