permutations.h 2.55 KB
Newer Older
Martin Schläffer committed
1 2 3
#ifndef PERMUTATIONS_H_
#define PERMUTATIONS_H_

Enrico Pozzobon committed
4 5 6
#include <stdint.h>

#include "api.h"
Martin Schläffer committed
7 8
#include "ascon.h"
#include "config.h"
Martin Schläffer committed
9
#include "constants.h"
Enrico Pozzobon committed
10
#include "printstate.h"
Martin Schläffer committed
11
#include "round.h"
Martin Schläffer committed
12

Enrico Pozzobon committed
13
const uint64_t C[12] = {
Martin Schläffer committed
14 15 16 17 18 19
    0xffffffffffffff0full, 0xffffffffffffff1eull, 0xffffffffffffff2dull,
    0xffffffffffffff3cull, 0xffffffffffffff4bull, 0xffffffffffffff5aull,
    0xffffffffffffff69ull, 0xffffffffffffff78ull, 0xffffffffffffff87ull,
    0xffffffffffffff96ull, 0xffffffffffffffa5ull, 0xffffffffffffffb4ull,
};

Enrico Pozzobon committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#define P12ROUNDS(s) \
  ROUND(0)           \
  ROUND(8)           \
  ROUND(16)          \
  ROUND(24)          \
  ROUND(32)          \
  ROUND(40)          \
  ROUND(48)          \
  ROUND(56)          \
  ROUND(64)          \
  ROUND(72)          \
  ROUND(80)          \
  ROUND(88)

#define P8ROUNDS(s) \
  ROUND(32)         \
  ROUND(40)         \
  ROUND(48)         \
  ROUND(56)         \
  ROUND(64)         \
  ROUND(72)         \
  ROUND(80)         \
  ROUND(88)

#define P6ROUNDS(s) \
  ROUND(48)         \
  ROUND(56)         \
  ROUND(64)         \
  ROUND(72)         \
  ROUND(80)         \
  ROUND(88)

forceinline void P12(state_t* s) {
Martin Schläffer committed
53 54 55 56 57
  __asm__ __volatile__ ( \
      ".arm \n\t" \
      ".fpu neon \n\t" \
      "vldm %[s], {d0-d4} \n\t" \
      "vmvn d2, d2 \n\t" \
Enrico Pozzobon committed
58
      P12ROUNDS(s) \
Martin Schläffer committed
59 60
      "vmvn d2, d2 \n\t" \
      "vstm %[s], {d0-d4} \n\t" \
Enrico Pozzobon committed
61
      :: [s] "r" (s), [C] "r" (C) \
Martin Schläffer committed
62 63 64
      : "d0", "d1", "d2", "d3", "d4", \
        "d10", "d11", "d12", "d13", "d14", \
        "d20", "d21", "d22", "d23", "d24", \
Enrico Pozzobon committed
65 66
        "d31", "memory");
}
Martin Schläffer committed
67

Enrico Pozzobon committed
68
forceinline void P8(state_t* s) {
Martin Schläffer committed
69 70 71 72 73
  __asm__ __volatile__ ( \
      ".arm \n\t" \
      ".fpu neon \n\t" \
      "vldm %[s], {d0-d4} \n\t" \
      "vmvn d2, d2 \n\t" \
Enrico Pozzobon committed
74
      P8ROUNDS(s) \
Martin Schläffer committed
75 76
      "vmvn d2, d2 \n\t" \
      "vstm %[s], {d0-d4} \n\t" \
Enrico Pozzobon committed
77
      :: [s] "r" (s), [C] "r" (C) \
Martin Schläffer committed
78 79 80
      : "d0", "d1", "d2", "d3", "d4", \
        "d10", "d11", "d12", "d13", "d14", \
        "d20", "d21", "d22", "d23", "d24", \
Enrico Pozzobon committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
        "d31", "memory");
}

forceinline void P6(state_t* s) {
  __asm__ __volatile__ ( \
      ".arm \n\t" \
      ".fpu neon \n\t" \
      "vldm %[s], {d0-d4} \n\t" \
      "vmvn d2, d2 \n\t" \
      P6ROUNDS(s) \
      "vmvn d2, d2 \n\t" \
      "vstm %[s], {d0-d4} \n\t" \
      :: [s] "r" (s), [C] "r" (C) \
      : "d0", "d1", "d2", "d3", "d4", \
        "d10", "d11", "d12", "d13", "d14", \
        "d20", "d21", "d22", "d23", "d24", \
        "d31", "memory");
}

forceinline void P(state_t* s, int nr) {
  if (nr == 12) P12(s);
  if (nr == 8) P8(s);
  if (nr == 6) P6(s);
}
Martin Schläffer committed
105 106

#endif /* PERMUTATIONS_H_ */