forked from slothy-optimizer/slothy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slothy_x25519.sh
executable file
·209 lines (191 loc) · 12.2 KB
/
slothy_x25519.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env sh
# X25519 scalar multiplication on Cortex-A55
#
# Supporting material for
#
# "Fast and Clean: Auditable high-performance assembly via constraint solving"
# https://eprint.iacr.org/2022/1303.pdf
set -e
SLOTHY_DIR=../../
CLEAN_DIR=../clean
OPT_DIR=../opt
LOG_DIR=logs
mkdir -p $LOG_DIR
REDIRECT_OUTPUT="--log --logdir=${LOG_DIR}"
if [ "$NO_LOG" = "Y" ]; then
REDIRECT_OUTPUT=""
fi
if [ "$SILENT" = "Y" ]; then
REDIRECT_OUTPUT="${REDIRECT_OUTPUT} --silent"
fi
echo "* X25519, Cortex-A55"
echo "** Step 0: Resolve symbolic registers"
${SLOTHY_DIR}/slothy-cli Arm_AArch64 Arm_Cortex_A55 \
${CLEAN_DIR}/neon/X25519-AArch64-simple.s \
-o ${OPT_DIR}/neon/X25519-AArch64-simple_nosymvars.s \
-c inputs_are_outputs -c outputs="[x0]" \
-s mainloop -e end_label \
-c constraints.allow_reordering=False \
-c constraints.functional_only=True \
$SLOTHY_FLAGS $REDIRECT_OUTPUT
echo "** Step 1: Preprocessing"
${SLOTHY_DIR}/slothy-cli Arm_AArch64 Arm_Cortex_A55 \
${OPT_DIR}/neon/X25519-AArch64-simple_nosymvars.s \
-o ${OPT_DIR}/neon/X25519-AArch64-simple_unfold_process0.s \
-r x25519_scalarmult_alt_orig,x25519_scalarmult_alt_unfold_process0 \
-c inputs_are_outputs -c outputs="[x0]" \
-s mainloop -e end_label \
-c split_heuristic -c split_heuristic_repeat=0 \
-c split_heuristic_preprocess_naive_interleaving \
$SLOTHY_FLAGS $REDIRECT_OUTPUT
echo "** Steps 2-6: Stepwise optimization, ignoring latencies"
# The goal here is to get a good amount of interleaving
# The best order of subregions is still TBD, but presently we 'comb' all stalls
# towards the middle of the code and repeat the process. The idea/hope is that
# by doing this multiple times, the stalls will eventually be absorbed.
echo "*** Step 2"
i=0
${SLOTHY_DIR}/slothy-cli Arm_AArch64 Arm_Cortex_A55 \
${OPT_DIR}/neon/X25519-AArch64-simple_unfold_process${i}.s \
-o ${OPT_DIR}/neon/X25519-AArch64-simple_unfold_process$((${i}+1)).s \
-r x25519_scalarmult_alt_unfold_process${i},x25519_scalarmult_alt_unfold_process$((${i}+1)) \
-c inputs_are_outputs -c outputs="[x0]" \
-s mainloop -e end_label \
-c variable_size \
-c max_solutions=512 \
-c timeout=300 \
-c constraints.stalls_first_attempt=32 \
-c split_heuristic \
-c split_heuristic_region="[0,1]" \
-c objective_precision=0.1 \
-c split_heuristic_stepsize=0.1 \
-c split_heuristic_factor=6 \
-c constraints.model_latencies=False \
$SLOTHY_FLAGS $REDIRECT_OUTPUT
echo "*** Step 3"
i=1
${SLOTHY_DIR}/slothy-cli Arm_AArch64 Arm_Cortex_A55 \
${OPT_DIR}/neon/X25519-AArch64-simple_unfold_process${i}.s \
-o ${OPT_DIR}/neon/X25519-AArch64-simple_unfold_process$((${i}+1)).s \
-r x25519_scalarmult_alt_unfold_process${i},x25519_scalarmult_alt_unfold_process$((${i}+1)) \
-c inputs_are_outputs -c outputs="[x0]" \
-s mainloop -e end_label \
-c variable_size \
-c max_solutions=512 \
-c timeout=180 \
-c constraints.stalls_first_attempt=32 \
-c split_heuristic \
-c split_heuristic_region="[0,0.6]" \
-c objective_precision=0.1 \
-c constraints.move_stalls_to_bottom \
-c split_heuristic_stepsize=0.1 \
-c split_heuristic_factor=4 \
-c constraints.model_latencies=False \
$SLOTHY_FLAGS $REDIRECT_OUTPUT
echo "*** Step 4"
i=2
${SLOTHY_DIR}/slothy-cli Arm_AArch64 Arm_Cortex_A55 \
${OPT_DIR}/neon/X25519-AArch64-simple_unfold_process${i}.s \
-o ${OPT_DIR}/neon/X25519-AArch64-simple_unfold_process$((${i}+1)).s \
-r x25519_scalarmult_alt_unfold_process${i},x25519_scalarmult_alt_unfold_process$((${i}+1)) \
-c inputs_are_outputs -c outputs="[x0]" \
-s mainloop -e end_label \
-c variable_size \
-c max_solutions=512 \
-c timeout=240 \
-c constraints.stalls_first_attempt=32 \
-c split_heuristic \
-c split_heuristic_region="[0.3,1]" \
-c objective_precision=0.1 \
-c constraints.move_stalls_to_top \
-c split_heuristic_bottom_to_top \
-c split_heuristic_stepsize=0.2 \
-c split_heuristic_factor=6 \
-c split_heuristic_repeat=1 \
-c constraints.model_latencies=False \
$SLOTHY_FLAGS $REDIRECT_OUTPUT
echo "*** Step 5"
i=3
${SLOTHY_DIR}/slothy-cli Arm_AArch64 Arm_Cortex_A55 \
${OPT_DIR}/neon/X25519-AArch64-simple_unfold_process${i}.s \
-o ${OPT_DIR}/neon/X25519-AArch64-simple_unfold_process$((${i}+1)).s \
-r x25519_scalarmult_alt_unfold_process${i},x25519_scalarmult_alt_unfold_process$((${i}+1)) \
-c inputs_are_outputs -c outputs="[x0]" \
-s mainloop -e end_label \
-c variable_size \
-c max_solutions=512 \
-c timeout=240 \
-c constraints.stalls_first_attempt=32 \
-c split_heuristic \
-c split_heuristic_region="[0.3,1]" \
-c objective_precision=0.1 \
-c constraints.move_stalls_to_top \
-c split_heuristic_stepsize=0.2 \
-c split_heuristic_factor=6 \
-c split_heuristic_repeat=1 \
-c constraints.model_latencies=False \
$SLOTHY_FLAGS $REDIRECT_OUTPUT
# Finally, also consider latencies
echo "*** Step 6"
i=4
${SLOTHY_DIR}/slothy-cli Arm_AArch64 Arm_Cortex_A55 \
${OPT_DIR}/neon/X25519-AArch64-simple_unfold_process${i}.s \
-o ${OPT_DIR}/neon/X25519-AArch64-simple_unfold_process$((${i}+1)).s \
-r x25519_scalarmult_alt_unfold_process${i},x25519_scalarmult_alt_unfold_process$((${i}+1)) \
-c inputs_are_outputs -c outputs="[x0]" \
-s mainloop -e end_label \
-c variable_size \
-c max_solutions=512 \
-c timeout=300 \
-c constraints.stalls_first_attempt=32 \
-c split_heuristic \
-c split_heuristic_region="[0,1]" \
-c objective_precision=0.1 \
-c split_heuristic_stepsize=0.05 \
-c split_heuristic_optimize_seam=10 \
-c split_heuristic_factor=8 \
-c split_heuristic_repeat=1 \
$SLOTHY_FLAGS $REDIRECT_OUTPUT
echo "*** Step 7"
i=5
${SLOTHY_DIR}/slothy-cli Arm_AArch64 Arm_Cortex_A55 \
${OPT_DIR}/neon/X25519-AArch64-simple_unfold_process${i}.s \
-o ${OPT_DIR}/neon/X25519-AArch64-simple_unfold_process$((${i}+1)).s \
-r x25519_scalarmult_alt_unfold_process${i},x25519_scalarmult_alt_unfold_process$((${i}+1)) \
-c inputs_are_outputs -c outputs="[x0]" \
-s mainloop -e end_label \
-c variable_size \
-c max_solutions=512 \
-c timeout=300 \
-c constraints.stalls_first_attempt=32 \
-c split_heuristic \
-c split_heuristic_region="[0,1]" \
-c split_heuristic_bottom_to_top=True \
-c objective_precision=0.1 \
-c split_heuristic_stepsize=0.05 \
-c split_heuristic_optimize_seam=10 \
-c constraints.move_stalls_to_top \
-c split_heuristic_factor=8 \
-c split_heuristic_repeat=2 \
$SLOTHY_FLAGS $REDIRECT_OUTPUT
echo "*** Step 8"
i=6
${SLOTHY_DIR}/slothy-cli Arm_AArch64 Arm_Cortex_A55 \
${OPT_DIR}/neon/X25519-AArch64-simple_unfold_process${i}.s \
-o ${OPT_DIR}/neon/X25519-AArch64-simple_opt.s \
-r x25519_scalarmult_alt_unfold_process${i},x25519_scalarmult_opt \
-c inputs_are_outputs -c outputs="[x0]" \
-s mainloop -e end_label \
-c variable_size \
-c max_solutions=512 \
-c timeout=300 \
-c constraints.stalls_first_attempt=32 \
-c split_heuristic \
-c split_heuristic_region="[0,1]" \
-c objective_precision=0.1 \
-c split_heuristic_stepsize=0.05 \
-c split_heuristic_optimize_seam=10 \
-c constraints.move_stalls_to_top \
-c split_heuristic_factor=8 \
$SLOTHY_FLAGS $REDIRECT_OUTPUT
cd "${0%/*}"