Newer
Older
#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;
asm(
"Loop:t\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"
"addi 1, %[i] \t\n" //循环末尾部分
"cmpl $64, %[i] \t\n"
"blt Loop \n"
:[s] "+r" (s), [i] "+r" (i), [x] "+r" (x), [temp]"+r"(temp)
);
/*int asm_popcnt(uint64_t x) {
int s = 0;
for (int i = 0; i < 64; i++) {
if ((x >> i) & 1) s++;
}
return s;
}*/