Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tin-z/babd0ca6fa768038abeae5cc1b6d5939 to your computer and use it in GitHub Desktop.
Save tin-z/babd0ca6fa768038abeae5cc1b6d5939 to your computer and use it in GitHub Desktop.
c-c++ assembly inline x86-64 128-bit SIMD - brief summary

C/C++ and inline assembly

128-bit stuff

SIMD

int check_sse2(void){
  int test;
  __asm__ ( 
    "mov $0, %%rax      \n\t"
    "cpuid              \n\t" 
    "xor %%rax, %%rax   \n\t"
    "mov %%edx, %%eax   \n\t"
    "mov %%eax, %0  \n\t"

    : "=r" (test)
  );
  if (!(test & 0x4000000))
    return -1;
  return 0;
}

other

  • get stack pointer
static void* get_sp(void) {
  void* sp;
  __asm__ volatile("mov %0, sp" : "=r"(sp));
  return sp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment