Skip to content

Instantly share code, notes, and snippets.

@Fylwind
Created February 19, 2016 05:57
Show Gist options
  • Save Fylwind/43882f85092a7c510448 to your computer and use it in GitHub Desktop.
Save Fylwind/43882f85092a7c510448 to your computer and use it in GitHub Desktop.
#include <stdint.h>
#include <string.h>
struct alpha {
int8_t a;
int8_t b;
int8_t c;
int8_t d;
int8_t e;
int8_t f;
int8_t g;
int8_t h;
};
struct alpha unpack(uint64_t x)
{
struct alpha r;
memcpy(&r, &x, 8);
return r;
}
struct alpha wrapper(uint64_t y)
{
return unpack(y);
}
unpack:
mov rax, rdi
ret
wrapper:
mov rax, rdi
ret
unpack:
mov rax, rdi
ret
wrapper:
mov eax, edi
xor ecx, ecx
mov esi, edi
shr ax, 8
mov cl, dil
shr esi, 24
mov ch, al
mov rax, rdi
movzx edx, sil
and eax, 16711680
and rcx, -16711681
sal rdx, 24
movabs rsi, -4278190081
or rcx, rax
mov rax, rcx
movabs rcx, -1095216660481
and rax, rsi
or rax, rdx
movabs rdx, 1095216660480
and rdx, rdi
and rax, rcx
movabs rcx, -280375465082881
or rax, rdx
movabs rdx, 280375465082880
and rdx, rdi
and rax, rcx
movabs rcx, -71776119061217281
or rax, rdx
movabs rdx, 71776119061217280
and rdx, rdi
and rax, rcx
shr rdi, 56
or rax, rdx
sal rdi, 56
movabs rdx, 72057594037927935
and rax, rdx
or rax, rdi
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment