Advertisement
Guest User

Untitled

a guest
May 5th, 2023
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.55 KB | None | 0 0
  1. typedef unsigned long u64;
  2. void mul(u64 f[8], const u64 a[4], const u64 b[4]) {
  3.     u64 t0, t1, dx;
  4.     asm(
  5.         "movq %[A0], %[dx]; mulxq %[B0], %[s0], %[s1]; xorq %[s2], %[s2];"
  6.         "movq %[s0], %[F0]; xorq %[s0], %[s0];"
  7.        
  8.                            "mulxq %[B1], %[t0], %[t1]; addq %[t0], %[s1]; adcq %[t1], %[s2]; adcq $0, %[s0];"
  9.         "movq %[A1], %[dx]; mulxq %[B0], %[t0], %[t1]; addq %[t0], %[s1]; adcq %[t1], %[s2]; adcq $0, %[s0];"
  10.         "movq %[s1], %[F1]; xorq %[s1], %[s1];"
  11.        
  12.                            "mulxq %[B1], %[t0], %[t1]; addq %[t0], %[s2]; adcq %[t1], %[s0]; adcq $0, %[s1];"
  13.         "movq %[A0], %[dx]; mulxq %[B2], %[t0], %[t1]; addq %[t0], %[s2]; adcq %[t1], %[s0]; adcq $0, %[s1];"
  14.         "movq %[A2], %[dx]; mulxq %[B0], %[t0], %[t1]; addq %[t0], %[s2]; adcq %[t1], %[s0]; adcq $0, %[s1];"
  15.         "movq %[s2], %[F2]; xorq %[s2], %[s2];"
  16.        
  17.                            "mulxq %[B1], %[t0], %[t1]; addq %[t0], %[s0]; adcq %[t1], %[s1]; adcq $0, %[s2];"
  18.         "movq %[A1], %[dx]; mulxq %[B2], %[t0], %[t1]; addq %[t0], %[s0]; adcq %[t1], %[s1]; adcq $0, %[s2];"
  19.         "movq %[A0], %[dx]; mulxq %[B3], %[t0], %[t1]; addq %[t0], %[s0]; adcq %[t1], %[s1]; adcq $0, %[s2];"
  20.         "movq %[A3], %[dx]; mulxq %[B0], %[t0], %[t1]; addq %[t0], %[s0]; adcq %[t1], %[s1]; adcq $0, %[s2];"
  21.         "movq %[s0], %[F3]; xorq %[s0], %[s0];"
  22.        
  23.                            "mulxq %[B1], %[t0], %[t1]; addq %[t0], %[s1]; adcq %[t1], %[s2]; adcq $0, %[s0];"
  24.         "movq %[A1], %[dx]; mulxq %[B3], %[t0], %[t1]; addq %[t0], %[s1]; adcq %[t1], %[s2]; adcq $0, %[s0];"
  25.         "movq %[A2], %[dx]; mulxq %[B2], %[t0], %[t1]; addq %[t0], %[s1]; adcq %[t1], %[s2]; adcq $0, %[s0];"
  26.         "movq %[s1], %[F4]; xorq %[s1], %[s1];"
  27.        
  28.                            "mulxq %[B3], %[t0], %[t1]; addq %[t0], %[s2]; adcq %[t1], %[s0]; adcq $0, %[s1];"
  29.         "movq %[A3], %[dx]; mulxq %[B2], %[t0], %[t1]; addq %[t0], %[s2]; adcq %[t1], %[s0]; adcq $0, %[s1];"
  30.        
  31.                            "mulxq %[B3], %[t0], %[t1]; addq %[t0], %[s0]; adcq %[t1], %[s1];":
  32.         [F0]"=&m"(f[0]), [F1]"=&m"(f[1]), [F2]"=&m"(f[2]), [F3]"=&m"(f[3]),
  33.         [F4]"=&m"(f[4]), [s2]"=&r"(f[5]), [s0]"=&r"(f[6]), [s1]"=&r"(f[7]),
  34.         [t0]"=&r"(t0), [t1]"=&r"(t1), [dx]"=&d"(dx):
  35.         [A0]"m"(a[0]), [A1]"m"(a[1]), [A2]"m"(a[2]), [A3]"m"(a[3]),
  36.         [B0]"m"(b[0]), [B1]"m"(b[1]), [B2]"m"(b[2]), [B3]"m"(b[3])
  37.     );
  38. }
  39. int main() {
  40.     u64 f[8], a[4]={1,2,3,4}, b[4]={1,2,3,4};
  41.     for (unsigned i=0; ++i; ) mul(f, a, b);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement