Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef unsigned long u64;
- void mul(u64 f[8], const u64 a[4], const u64 b[4]) {
- u64 t0, t1, dx;
- asm(
- "movq %[A0], %[dx]; mulxq %[B0], %[s0], %[s1]; xorq %[s2], %[s2];"
- "movq %[s0], %[F0]; xorq %[s0], %[s0];"
- "mulxq %[B1], %[t0], %[t1]; addq %[t0], %[s1]; adcq %[t1], %[s2]; adcq $0, %[s0];"
- "movq %[A1], %[dx]; mulxq %[B0], %[t0], %[t1]; addq %[t0], %[s1]; adcq %[t1], %[s2]; adcq $0, %[s0];"
- "movq %[s1], %[F1]; xorq %[s1], %[s1];"
- "mulxq %[B1], %[t0], %[t1]; addq %[t0], %[s2]; adcq %[t1], %[s0]; adcq $0, %[s1];"
- "movq %[A0], %[dx]; mulxq %[B2], %[t0], %[t1]; addq %[t0], %[s2]; adcq %[t1], %[s0]; adcq $0, %[s1];"
- "movq %[A2], %[dx]; mulxq %[B0], %[t0], %[t1]; addq %[t0], %[s2]; adcq %[t1], %[s0]; adcq $0, %[s1];"
- "movq %[s2], %[F2]; xorq %[s2], %[s2];"
- "mulxq %[B1], %[t0], %[t1]; addq %[t0], %[s0]; adcq %[t1], %[s1]; adcq $0, %[s2];"
- "movq %[A1], %[dx]; mulxq %[B2], %[t0], %[t1]; addq %[t0], %[s0]; adcq %[t1], %[s1]; adcq $0, %[s2];"
- "movq %[A0], %[dx]; mulxq %[B3], %[t0], %[t1]; addq %[t0], %[s0]; adcq %[t1], %[s1]; adcq $0, %[s2];"
- "movq %[A3], %[dx]; mulxq %[B0], %[t0], %[t1]; addq %[t0], %[s0]; adcq %[t1], %[s1]; adcq $0, %[s2];"
- "movq %[s0], %[F3]; xorq %[s0], %[s0];"
- "mulxq %[B1], %[t0], %[t1]; addq %[t0], %[s1]; adcq %[t1], %[s2]; adcq $0, %[s0];"
- "movq %[A1], %[dx]; mulxq %[B3], %[t0], %[t1]; addq %[t0], %[s1]; adcq %[t1], %[s2]; adcq $0, %[s0];"
- "movq %[A2], %[dx]; mulxq %[B2], %[t0], %[t1]; addq %[t0], %[s1]; adcq %[t1], %[s2]; adcq $0, %[s0];"
- "movq %[s1], %[F4]; xorq %[s1], %[s1];"
- "mulxq %[B3], %[t0], %[t1]; addq %[t0], %[s2]; adcq %[t1], %[s0]; adcq $0, %[s1];"
- "movq %[A3], %[dx]; mulxq %[B2], %[t0], %[t1]; addq %[t0], %[s2]; adcq %[t1], %[s0]; adcq $0, %[s1];"
- "mulxq %[B3], %[t0], %[t1]; addq %[t0], %[s0]; adcq %[t1], %[s1];":
- [F0]"=&m"(f[0]), [F1]"=&m"(f[1]), [F2]"=&m"(f[2]), [F3]"=&m"(f[3]),
- [F4]"=&m"(f[4]), [s2]"=&r"(f[5]), [s0]"=&r"(f[6]), [s1]"=&r"(f[7]),
- [t0]"=&r"(t0), [t1]"=&r"(t1), [dx]"=&d"(dx):
- [A0]"m"(a[0]), [A1]"m"(a[1]), [A2]"m"(a[2]), [A3]"m"(a[3]),
- [B0]"m"(b[0]), [B1]"m"(b[1]), [B2]"m"(b[2]), [B3]"m"(b[3])
- );
- }
- int main() {
- u64 f[8], a[4]={1,2,3,4}, b[4]={1,2,3,4};
- for (unsigned i=0; ++i; ) mul(f, a, b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement