base/asm-common.h, symm/*.S: New macros for register name decoration.
[catacomb] / symm / salsa20-arm-neon.S
index f212f2f..9d553d3 100644 (file)
@@ -79,7 +79,7 @@ FUNC(salsa20_core_arm_neon)
        // We need a copy for later.  Rather than waste time copying them by
        // hand, we'll use the three-address nature of the instruction set.
        // But this means that the main loop is offset by a bit.
-       vldmia  r1, {d24-d31}
+       vldmia  r1, {QQ(q12, q15)}
 
        // Apply a column quarterround to each of the columns simultaneously,
        // moving the results to their working registers.  Alas, there
@@ -205,35 +205,36 @@ FUNC(salsa20_core_arm_neon)
 
        b       0b
 
-       // Almost there.  Firstly the feedfoward addition, and then we have
-       // to write out the result.  Here we have to undo the permutation
-       // which was already applied to the input.
-9:     vadd.u32 q8, q8, q12
-       vadd.u32 q9, q9, q13
-       vadd.u32 q10, q10, q14
-       vadd.u32 q11, q11, q15
-
-       vst1.32 {d16[0]}, [r2 :32]!
-       vst1.32 {d22[1]}, [r2 :32]!
-       vst1.32 {d21[0]}, [r2 :32]!
-       vst1.32 {d19[1]}, [r2 :32]!
-
-       vst1.32 {d18[0]}, [r2 :32]!
-       vst1.32 {d16[1]}, [r2 :32]!
-       vst1.32 {d23[0]}, [r2 :32]!
-       vst1.32 {d21[1]}, [r2 :32]!
-
-       vst1.32 {d20[0]}, [r2 :32]!
-       vst1.32 {d18[1]}, [r2 :32]!
-       vst1.32 {d17[0]}, [r2 :32]!
-       vst1.32 {d23[1]}, [r2 :32]!
-
-       vst1.32 {d22[0]}, [r2 :32]!
-       vst1.32 {d20[1]}, [r2 :32]!
-       vst1.32 {d19[0]}, [r2 :32]!
-       vst1.32 {d17[1]}, [r2 :32]!
+       // Almost there.  Firstly the feedfoward addition.
+9:     vadd.u32 q0, q8, q12                    //  0,  5, 10, 15
+       vadd.u32 q9, q9, q13                    //  4,  9, 14,  3
+       vadd.u32 q10, q10, q14                  //  8, 13,  2,  7
+       vadd.u32 q11, q11, q15                  // 12,  1,  6, 11
+
+       // Next we must undo the permutation which was already applied to the
+       // input.  This can be done juggling values in registers, with the
+       // following fancy footwork: some row rotations, a transpose, and
+       // some more rotations.
+       vext.32 q9, q9, q9, #3                  //  3,  4,  9, 14
+       vext.32 q10, q10, q10, #2               //  2,  7,  8, 13
+       vext.32 q11, q11, q11, #1               //  1,  6, 11, 12
+
+       vzip.32 q0, q10                         //  0,  2,  5,  7
+                                               // 10,  8, 15, 13
+       vzip.32 q11, q9                         //  1,  3,  6,  4
+                                               // 11,  9, 12, 14
+
+       vzip.32 q0, q11                         //  0,  1,  2,  3
+                                               //  5,  6,  7,  4
+       vzip.32 q10, q9                         // 10, 11,  8,  9
+                                               // 15, 12, 13, 14
+
+       vext.32 q1, q11, q11, #3                //  4,  5,  6,  7
+       vext.32 q2, q10, q10, #2                //  8,  9, 10, 11
+       vext.32 q3, q9, q9, #1                  // 12, 13, 14, 15
 
        // And with that, we're done.
+       vstmia  r2, {QQ(q0, q3)}
        bx      r14
 
 ENDFUNC