小编Ada*_*nko的帖子

这如何更快?使用“FPU 技巧”的 52 位模乘法比 x64 上的内联 ASM 更快

我发现这个:

#define mulmod52(a,b,m) (((a * b) - (((uint64_t)(((double)a * (double)b) / (double)m) - 1ULL) * m)) % m)
Run Code Online (Sandbox Code Playgroud)

... 比:

static inline uint64_t _mulmod(uint64_t a, uint64_t b, uint64_t n) {
    uint64_t d, dummy;                    /* d will get a*b mod c */
    asm ("mulq %3\n\t"              /* mul a*b -> rdx:rax */
         "divq %4\n\t"              /* (a*b)/c -> quot in rax remainder in rdx */
         :"=a"(dummy), "=&d"(d)     /* output */
         :"a"(a), "rm"(b), "rm"(n)  /* input */
         :"cc"                      /* mulq and divq can set …
Run Code Online (Sandbox Code Playgroud)

optimization performance assembly x86-64

1
推荐指数
1
解决办法
99
查看次数

标签 统计

assembly ×1

optimization ×1

performance ×1

x86-64 ×1