#include "asm.h" #include <string.h> int64_t asm_add(int64_t a, int64_t b) { asm( "add %[b], %[a] \t" :[a] "+r" (a) :[b] "r" (b) ); return a; } int asm_popcnt(uint64_t x) { int s = 0; int i = 0; uint64_t temp = 0; asm( ".Loop: \n" "shrq %[i], %[x] \t\n" //x >>= i "movq %[x], %[temp] \t\n" //x -> tempx "andq $1, %[temp] \t\n" "addl %[temp], %[s] \t\n" //s+=?1 "shlq %[i], %[x] \t\n" "addl $1, %[i] \t\n" //循环末尾部分 "cmpl $64, %[i] \t\n" "jlt .Loop \n" :[s] "+r" (s), [i] "+r" (i), [x] "+r" (x), [temp]"+r"(temp) ); return s; } /*int asm_popcnt(uint64_t x) { int s = 0; for (int i = 0; i < 64; i++) { if ((x >> i) & 1) s++; } return s; }*/ void *asm_memcpy(void *dest, const void *src, size_t n) { return memcpy(dest, src, n); } int asm_setjmp(asm_jmp_buf env) { return setjmp(env); } void asm_longjmp(asm_jmp_buf env, int val) { longjmp(env, val); }