enc_reshuffle.c 975 B

1234567891011121314151617181920212223242526272829303132
  1. static inline uint8x16x4_t
  2. enc_reshuffle (const uint8x16x3_t in)
  3. {
  4. uint8x16x4_t out;
  5. // Input:
  6. // in[0] = a7 a6 a5 a4 a3 a2 a1 a0
  7. // in[1] = b7 b6 b5 b4 b3 b2 b1 b0
  8. // in[2] = c7 c6 c5 c4 c3 c2 c1 c0
  9. // Output:
  10. // out[0] = 00 00 a7 a6 a5 a4 a3 a2
  11. // out[1] = 00 00 a1 a0 b7 b6 b5 b4
  12. // out[2] = 00 00 b3 b2 b1 b0 c7 c6
  13. // out[3] = 00 00 c5 c4 c3 c2 c1 c0
  14. // Move the input bits to where they need to be in the outputs. Except
  15. // for the first output, the high two bits are not cleared.
  16. out.val[0] = vshrq_n_u8(in.val[0], 2);
  17. out.val[1] = vshrq_n_u8(in.val[1], 4);
  18. out.val[2] = vshrq_n_u8(in.val[2], 6);
  19. out.val[1] = vsliq_n_u8(out.val[1], in.val[0], 4);
  20. out.val[2] = vsliq_n_u8(out.val[2], in.val[1], 2);
  21. // Clear the high two bits in the second, third and fourth output.
  22. out.val[1] = vandq_u8(out.val[1], vdupq_n_u8(0x3F));
  23. out.val[2] = vandq_u8(out.val[2], vdupq_n_u8(0x3F));
  24. out.val[3] = vandq_u8(in.val[2], vdupq_n_u8(0x3F));
  25. return out;
  26. }