Skip to content

Instantly share code, notes, and snippets.

@michaeleisel
Last active January 2, 2019 22:51
Show Gist options
  • Save michaeleisel/46d9d5410be827e195b10bf222ce99af to your computer and use it in GitHub Desktop.
Save michaeleisel/46d9d5410be827e195b10bf222ce99af to your computer and use it in GitHub Desktop.
// in asm_atoi.S...
fbld (%rdi)
fstpl -8(%rbp)
movq -8(%rbp), %xmm0
// in main.c...
int main(int argc, const char * argv[]) {
const char *c = "2384";
char b[10] = {0};
for (int i = 0; i < sizeof(c); i++) {
int shift = (i & 1) ? 0 : 4;
b[i / 2] |= (c[i] - '0') << shift;
}
double z = asm_atoi(b);
printf("%lf\n", z); // should print 2384
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment