|
发表于 2023-10-15 13:25:35
|
显示全部楼层
先寫這麼多- typedef unsigned long long u64;template<int N>struct divHelper { static void shl(u64* dst, const u64* src, int d) { asm("shldq %1, %%cl, %0": "=r"(dst[N]): "g"(src[N-1]), "0"(src[N]), "c"(d)); } static void div(u64* ret, u64* mod, const u64* dive, const u64* divo) { int cnt; bool zf; asm("bsrq %1, %q0": "=@ccz"(zf), "=r"(cnt): "g"(divo[N-1])); if (zf) return divHelper<N-1>::div(ret, mod, dive, divo); cnt ^= 63; u64 divo2[N]; divHelper<N-1>::shl(divo2, divo, cnt); }};template<>struct divHelper<0> { static void shl(u64* dst, const u64* src, int d) { *dst = *src << d; } static void div(u64* ret, u64* mod, const u64* dive, const u64* divo) { __builtin_unreachable(); }};
复制代码 |
|