| 1 |
#!/usr/bin/env perl |
| 2 |
# Copyright 2017-2025 The OpenSSL Project Authors. All Rights Reserved. |
| 3 |
# |
| 4 |
# Licensed under the Apache License 2.0 (the "License"). You may not use |
| 5 |
# this file except in compliance with the License. You can obtain a copy |
| 6 |
# in the file LICENSE in the source distribution or at |
| 7 |
# https://www.openssl.org/source/license.html |
| 8 |
# |
| 9 |
# ==================================================================== |
| 10 |
# Written by Andy Polyakov, @dot-asm, initially for use in the OpenSSL |
| 11 |
# project. The module is, however, dual licensed under OpenSSL and |
| 12 |
# CRYPTOGAMS licenses depending on where you obtain it. For further |
| 13 |
# details see https://github.com/dot-asm/cryptogams/. |
| 14 |
# ==================================================================== |
| 15 |
# |
| 16 |
# Keccak-1600 for ARMv8. |
| 17 |
# |
| 18 |
# June 2017. |
| 19 |
# |
| 20 |
# This is straightforward KECCAK_1X_ALT implementation. It makes no |
| 21 |
# sense to attempt SIMD/NEON implementation for following reason. |
| 22 |
# 64-bit lanes of vector registers can't be addressed as easily as in |
| 23 |
# 32-bit mode. This means that 64-bit NEON is bound to be slower than |
| 24 |
# 32-bit NEON, and this implementation is faster than 32-bit NEON on |
| 25 |
# same processor. Even though it takes more scalar xor's and andn's, |
| 26 |
# it gets compensated by availability of rotate. Not to forget that |
| 27 |
# most processors achieve higher issue rate with scalar instructions. |
| 28 |
# |
| 29 |
# February 2018. |
| 30 |
# |
| 31 |
# Add hardware-assisted ARMv8.2 implementation. It's KECCAK_1X_ALT |
| 32 |
# variant with register permutation/rotation twist that allows to |
| 33 |
# eliminate copies to temporary registers. If you look closely you'll |
| 34 |
# notice that it uses only one lane of vector registers. The new |
| 35 |
# instructions effectively facilitate parallel hashing, which we don't |
| 36 |
# support [yet?]. But lowest-level core procedure is prepared for it. |
| 37 |
# The inner round is 67 [vector] instructions, so it's not actually |
| 38 |
# obvious that it will provide performance improvement [in serial |
| 39 |
# hash] as long as vector instructions issue rate is limited to 1 per |
| 40 |
# cycle... |
| 41 |
# |
| 42 |
###################################################################### |
| 43 |
# Numbers are cycles per processed byte. |
| 44 |
# |
| 45 |
# r=1088(*) |
| 46 |
# |
| 47 |
# Cortex-A53 13 |
| 48 |
# Cortex-A57 12 |
| 49 |
# X-Gene 14 |
| 50 |
# Mongoose 10 |
| 51 |
# Kryo 12 |
| 52 |
# Denver 7.8 |
| 53 |
# Apple A7 7.2 |
| 54 |
# ThunderX2 9.7 |
| 55 |
# |
| 56 |
# (*) Corresponds to SHA3-256. No improvement coefficients are listed |
| 57 |
# because they vary too much from compiler to compiler. Newer |
| 58 |
# compiler does much better and improvement varies from 5% on |
| 59 |
# Cortex-A57 to 25% on Cortex-A53. While in comparison to older |
| 60 |
# compiler this code is at least 2x faster... |
| 61 |
|
| 62 |
# $output is the last argument if it looks like a file (it has an extension) |
| 63 |
# $flavour is the first argument if it doesn't look like a file |
| 64 |
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef; |
| 65 |
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef; |
| 66 |
|
| 67 |
$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; |
| 68 |
( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or |
| 69 |
( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or |
| 70 |
die "can't locate arm-xlate.pl"; |
| 71 |
|
| 72 |
open OUT,"| \"$^X\" $xlate $flavour \"$output\"" |
| 73 |
or die "can't call $xlate: $!"; |
| 74 |
*STDOUT=*OUT; |
| 75 |
|
| 76 |
my @rhotates = ([ 0, 1, 62, 28, 27 ], |
| 77 |
[ 36, 44, 6, 55, 20 ], |
| 78 |
[ 3, 10, 43, 25, 39 ], |
| 79 |
[ 41, 45, 15, 21, 8 ], |
| 80 |
[ 18, 2, 61, 56, 14 ]); |
| 81 |
|
| 82 |
$code.=<<___; |
| 83 |
#include "arm_arch.h" |
| 84 |
|
| 85 |
.rodata |
| 86 |
|
| 87 |
.align 8 // strategic alignment and padding that allows to use |
| 88 |
// address value as loop termination condition... |
| 89 |
.quad 0,0,0,0,0,0,0,0 |
| 90 |
.type iotas,%object |
| 91 |
iotas: |
| 92 |
.quad 0x0000000000000001 |
| 93 |
.quad 0x0000000000008082 |
| 94 |
.quad 0x800000000000808a |
| 95 |
.quad 0x8000000080008000 |
| 96 |
.quad 0x000000000000808b |
| 97 |
.quad 0x0000000080000001 |
| 98 |
.quad 0x8000000080008081 |
| 99 |
.quad 0x8000000000008009 |
| 100 |
.quad 0x000000000000008a |
| 101 |
.quad 0x0000000000000088 |
| 102 |
.quad 0x0000000080008009 |
| 103 |
.quad 0x000000008000000a |
| 104 |
.quad 0x000000008000808b |
| 105 |
.quad 0x800000000000008b |
| 106 |
.quad 0x8000000000008089 |
| 107 |
.quad 0x8000000000008003 |
| 108 |
.quad 0x8000000000008002 |
| 109 |
.quad 0x8000000000000080 |
| 110 |
.quad 0x000000000000800a |
| 111 |
.quad 0x800000008000000a |
| 112 |
.quad 0x8000000080008081 |
| 113 |
.quad 0x8000000000008080 |
| 114 |
.quad 0x0000000080000001 |
| 115 |
.quad 0x8000000080008008 |
| 116 |
.size iotas,.-iotas |
| 117 |
___ |
| 118 |
{{{ |
| 119 |
my @A = map([ "x$_", "x".($_+1), "x".($_+2), "x".($_+3), "x".($_+4) ], |
| 120 |
(0, 5, 10, 15, 20)); |
| 121 |
$A[3][3] = "x25"; # x18 is reserved |
| 122 |
|
| 123 |
my @C = map("x$_", (26,27,28,30)); |
| 124 |
|
| 125 |
$code.=<<___; |
| 126 |
.text |
| 127 |
|
| 128 |
.type KeccakF1600_int,%function |
| 129 |
.align 5 |
| 130 |
KeccakF1600_int: |
| 131 |
AARCH64_SIGN_LINK_REGISTER |
| 132 |
adrp $C[2],iotas |
| 133 |
add $C[2],$C[2],:lo12:iotas |
| 134 |
stp $C[2],x30,[sp,#16] // 32 bytes on top are mine |
| 135 |
b .Loop |
| 136 |
.align 4 |
| 137 |
.Loop: |
| 138 |
////////////////////////////////////////// Theta |
| 139 |
eor $C[0],$A[0][0],$A[1][0] |
| 140 |
stp $A[0][4],$A[1][4],[sp,#0] // offload pair... |
| 141 |
eor $C[1],$A[0][1],$A[1][1] |
| 142 |
eor $C[2],$A[0][2],$A[1][2] |
| 143 |
eor $C[3],$A[0][3],$A[1][3] |
| 144 |
___ |
| 145 |
$C[4]=$A[0][4]; |
| 146 |
$C[5]=$A[1][4]; |
| 147 |
$code.=<<___; |
| 148 |
eor $C[4],$A[0][4],$A[1][4] |
| 149 |
eor $C[0],$C[0],$A[2][0] |
| 150 |
eor $C[1],$C[1],$A[2][1] |
| 151 |
eor $C[2],$C[2],$A[2][2] |
| 152 |
eor $C[3],$C[3],$A[2][3] |
| 153 |
eor $C[4],$C[4],$A[2][4] |
| 154 |
eor $C[0],$C[0],$A[3][0] |
| 155 |
eor $C[1],$C[1],$A[3][1] |
| 156 |
eor $C[2],$C[2],$A[3][2] |
| 157 |
eor $C[3],$C[3],$A[3][3] |
| 158 |
eor $C[4],$C[4],$A[3][4] |
| 159 |
eor $C[0],$C[0],$A[4][0] |
| 160 |
eor $C[2],$C[2],$A[4][2] |
| 161 |
eor $C[1],$C[1],$A[4][1] |
| 162 |
eor $C[3],$C[3],$A[4][3] |
| 163 |
eor $C[4],$C[4],$A[4][4] |
| 164 |
|
| 165 |
eor $C[5],$C[0],$C[2],ror#63 |
| 166 |
|
| 167 |
eor $A[0][1],$A[0][1],$C[5] |
| 168 |
eor $A[1][1],$A[1][1],$C[5] |
| 169 |
eor $A[2][1],$A[2][1],$C[5] |
| 170 |
eor $A[3][1],$A[3][1],$C[5] |
| 171 |
eor $A[4][1],$A[4][1],$C[5] |
| 172 |
|
| 173 |
eor $C[5],$C[1],$C[3],ror#63 |
| 174 |
eor $C[2],$C[2],$C[4],ror#63 |
| 175 |
eor $C[3],$C[3],$C[0],ror#63 |
| 176 |
eor $C[4],$C[4],$C[1],ror#63 |
| 177 |
|
| 178 |
eor $C[1], $A[0][2],$C[5] // mov $C[1],$A[0][2] |
| 179 |
eor $A[1][2],$A[1][2],$C[5] |
| 180 |
eor $A[2][2],$A[2][2],$C[5] |
| 181 |
eor $A[3][2],$A[3][2],$C[5] |
| 182 |
eor $A[4][2],$A[4][2],$C[5] |
| 183 |
|
| 184 |
eor $A[0][0],$A[0][0],$C[4] |
| 185 |
eor $A[1][0],$A[1][0],$C[4] |
| 186 |
eor $A[2][0],$A[2][0],$C[4] |
| 187 |
eor $A[3][0],$A[3][0],$C[4] |
| 188 |
eor $A[4][0],$A[4][0],$C[4] |
| 189 |
___ |
| 190 |
$C[4]=undef; |
| 191 |
$C[5]=undef; |
| 192 |
$code.=<<___; |
| 193 |
ldp $A[0][4],$A[1][4],[sp,#0] // re-load offloaded data |
| 194 |
eor $C[0], $A[0][3],$C[2] // mov $C[0],$A[0][3] |
| 195 |
eor $A[1][3],$A[1][3],$C[2] |
| 196 |
eor $A[2][3],$A[2][3],$C[2] |
| 197 |
eor $A[3][3],$A[3][3],$C[2] |
| 198 |
eor $A[4][3],$A[4][3],$C[2] |
| 199 |
|
| 200 |
eor $C[2], $A[0][4],$C[3] // mov $C[2],$A[0][4] |
| 201 |
eor $A[1][4],$A[1][4],$C[3] |
| 202 |
eor $A[2][4],$A[2][4],$C[3] |
| 203 |
eor $A[3][4],$A[3][4],$C[3] |
| 204 |
eor $A[4][4],$A[4][4],$C[3] |
| 205 |
|
| 206 |
////////////////////////////////////////// Rho+Pi |
| 207 |
mov $C[3],$A[0][1] |
| 208 |
ror $A[0][1],$A[1][1],#64-$rhotates[1][1] |
| 209 |
//mov $C[1],$A[0][2] |
| 210 |
ror $A[0][2],$A[2][2],#64-$rhotates[2][2] |
| 211 |
//mov $C[0],$A[0][3] |
| 212 |
ror $A[0][3],$A[3][3],#64-$rhotates[3][3] |
| 213 |
//mov $C[2],$A[0][4] |
| 214 |
ror $A[0][4],$A[4][4],#64-$rhotates[4][4] |
| 215 |
|
| 216 |
ror $A[1][1],$A[1][4],#64-$rhotates[1][4] |
| 217 |
ror $A[2][2],$A[2][3],#64-$rhotates[2][3] |
| 218 |
ror $A[3][3],$A[3][2],#64-$rhotates[3][2] |
| 219 |
ror $A[4][4],$A[4][1],#64-$rhotates[4][1] |
| 220 |
|
| 221 |
ror $A[1][4],$A[4][2],#64-$rhotates[4][2] |
| 222 |
ror $A[2][3],$A[3][4],#64-$rhotates[3][4] |
| 223 |
ror $A[3][2],$A[2][1],#64-$rhotates[2][1] |
| 224 |
ror $A[4][1],$A[1][3],#64-$rhotates[1][3] |
| 225 |
|
| 226 |
ror $A[4][2],$A[2][4],#64-$rhotates[2][4] |
| 227 |
ror $A[3][4],$A[4][3],#64-$rhotates[4][3] |
| 228 |
ror $A[2][1],$A[1][2],#64-$rhotates[1][2] |
| 229 |
ror $A[1][3],$A[3][1],#64-$rhotates[3][1] |
| 230 |
|
| 231 |
ror $A[2][4],$A[4][0],#64-$rhotates[4][0] |
| 232 |
ror $A[4][3],$A[3][0],#64-$rhotates[3][0] |
| 233 |
ror $A[1][2],$A[2][0],#64-$rhotates[2][0] |
| 234 |
ror $A[3][1],$A[1][0],#64-$rhotates[1][0] |
| 235 |
|
| 236 |
ror $A[1][0],$C[0],#64-$rhotates[0][3] |
| 237 |
ror $A[2][0],$C[3],#64-$rhotates[0][1] |
| 238 |
ror $A[3][0],$C[2],#64-$rhotates[0][4] |
| 239 |
ror $A[4][0],$C[1],#64-$rhotates[0][2] |
| 240 |
|
| 241 |
////////////////////////////////////////// Chi+Iota |
| 242 |
bic $C[0],$A[0][2],$A[0][1] |
| 243 |
bic $C[1],$A[0][3],$A[0][2] |
| 244 |
bic $C[2],$A[0][0],$A[0][4] |
| 245 |
bic $C[3],$A[0][1],$A[0][0] |
| 246 |
eor $A[0][0],$A[0][0],$C[0] |
| 247 |
bic $C[0],$A[0][4],$A[0][3] |
| 248 |
eor $A[0][1],$A[0][1],$C[1] |
| 249 |
ldr $C[1],[sp,#16] |
| 250 |
eor $A[0][3],$A[0][3],$C[2] |
| 251 |
eor $A[0][4],$A[0][4],$C[3] |
| 252 |
eor $A[0][2],$A[0][2],$C[0] |
| 253 |
ldr $C[3],[$C[1]],#8 // Iota[i++] |
| 254 |
|
| 255 |
bic $C[0],$A[1][2],$A[1][1] |
| 256 |
tst $C[1],#255 // are we done? |
| 257 |
str $C[1],[sp,#16] |
| 258 |
bic $C[1],$A[1][3],$A[1][2] |
| 259 |
bic $C[2],$A[1][0],$A[1][4] |
| 260 |
eor $A[0][0],$A[0][0],$C[3] // A[0][0] ^= Iota |
| 261 |
bic $C[3],$A[1][1],$A[1][0] |
| 262 |
eor $A[1][0],$A[1][0],$C[0] |
| 263 |
bic $C[0],$A[1][4],$A[1][3] |
| 264 |
eor $A[1][1],$A[1][1],$C[1] |
| 265 |
eor $A[1][3],$A[1][3],$C[2] |
| 266 |
eor $A[1][4],$A[1][4],$C[3] |
| 267 |
eor $A[1][2],$A[1][2],$C[0] |
| 268 |
|
| 269 |
bic $C[0],$A[2][2],$A[2][1] |
| 270 |
bic $C[1],$A[2][3],$A[2][2] |
| 271 |
bic $C[2],$A[2][0],$A[2][4] |
| 272 |
bic $C[3],$A[2][1],$A[2][0] |
| 273 |
eor $A[2][0],$A[2][0],$C[0] |
| 274 |
bic $C[0],$A[2][4],$A[2][3] |
| 275 |
eor $A[2][1],$A[2][1],$C[1] |
| 276 |
eor $A[2][3],$A[2][3],$C[2] |
| 277 |
eor $A[2][4],$A[2][4],$C[3] |
| 278 |
eor $A[2][2],$A[2][2],$C[0] |
| 279 |
|
| 280 |
bic $C[0],$A[3][2],$A[3][1] |
| 281 |
bic $C[1],$A[3][3],$A[3][2] |
| 282 |
bic $C[2],$A[3][0],$A[3][4] |
| 283 |
bic $C[3],$A[3][1],$A[3][0] |
| 284 |
eor $A[3][0],$A[3][0],$C[0] |
| 285 |
bic $C[0],$A[3][4],$A[3][3] |
| 286 |
eor $A[3][1],$A[3][1],$C[1] |
| 287 |
eor $A[3][3],$A[3][3],$C[2] |
| 288 |
eor $A[3][4],$A[3][4],$C[3] |
| 289 |
eor $A[3][2],$A[3][2],$C[0] |
| 290 |
|
| 291 |
bic $C[0],$A[4][2],$A[4][1] |
| 292 |
bic $C[1],$A[4][3],$A[4][2] |
| 293 |
bic $C[2],$A[4][0],$A[4][4] |
| 294 |
bic $C[3],$A[4][1],$A[4][0] |
| 295 |
eor $A[4][0],$A[4][0],$C[0] |
| 296 |
bic $C[0],$A[4][4],$A[4][3] |
| 297 |
eor $A[4][1],$A[4][1],$C[1] |
| 298 |
eor $A[4][3],$A[4][3],$C[2] |
| 299 |
eor $A[4][4],$A[4][4],$C[3] |
| 300 |
eor $A[4][2],$A[4][2],$C[0] |
| 301 |
|
| 302 |
bne .Loop |
| 303 |
|
| 304 |
ldr x30,[sp,#24] |
| 305 |
AARCH64_VALIDATE_LINK_REGISTER |
| 306 |
ret |
| 307 |
.size KeccakF1600_int,.-KeccakF1600_int |
| 308 |
|
| 309 |
.type KeccakF1600,%function |
| 310 |
.align 5 |
| 311 |
KeccakF1600: |
| 312 |
AARCH64_SIGN_LINK_REGISTER |
| 313 |
stp x29,x30,[sp,#-128]! |
| 314 |
add x29,sp,#0 |
| 315 |
stp x19,x20,[sp,#16] |
| 316 |
stp x21,x22,[sp,#32] |
| 317 |
stp x23,x24,[sp,#48] |
| 318 |
stp x25,x26,[sp,#64] |
| 319 |
stp x27,x28,[sp,#80] |
| 320 |
sub sp,sp,#48 |
| 321 |
|
| 322 |
str x0,[sp,#32] // offload argument |
| 323 |
mov $C[0],x0 |
| 324 |
ldp $A[0][0],$A[0][1],[x0,#16*0] |
| 325 |
ldp $A[0][2],$A[0][3],[$C[0],#16*1] |
| 326 |
ldp $A[0][4],$A[1][0],[$C[0],#16*2] |
| 327 |
ldp $A[1][1],$A[1][2],[$C[0],#16*3] |
| 328 |
ldp $A[1][3],$A[1][4],[$C[0],#16*4] |
| 329 |
ldp $A[2][0],$A[2][1],[$C[0],#16*5] |
| 330 |
ldp $A[2][2],$A[2][3],[$C[0],#16*6] |
| 331 |
ldp $A[2][4],$A[3][0],[$C[0],#16*7] |
| 332 |
ldp $A[3][1],$A[3][2],[$C[0],#16*8] |
| 333 |
ldp $A[3][3],$A[3][4],[$C[0],#16*9] |
| 334 |
ldp $A[4][0],$A[4][1],[$C[0],#16*10] |
| 335 |
ldp $A[4][2],$A[4][3],[$C[0],#16*11] |
| 336 |
ldr $A[4][4],[$C[0],#16*12] |
| 337 |
|
| 338 |
bl KeccakF1600_int |
| 339 |
|
| 340 |
ldr $C[0],[sp,#32] |
| 341 |
stp $A[0][0],$A[0][1],[$C[0],#16*0] |
| 342 |
stp $A[0][2],$A[0][3],[$C[0],#16*1] |
| 343 |
stp $A[0][4],$A[1][0],[$C[0],#16*2] |
| 344 |
stp $A[1][1],$A[1][2],[$C[0],#16*3] |
| 345 |
stp $A[1][3],$A[1][4],[$C[0],#16*4] |
| 346 |
stp $A[2][0],$A[2][1],[$C[0],#16*5] |
| 347 |
stp $A[2][2],$A[2][3],[$C[0],#16*6] |
| 348 |
stp $A[2][4],$A[3][0],[$C[0],#16*7] |
| 349 |
stp $A[3][1],$A[3][2],[$C[0],#16*8] |
| 350 |
stp $A[3][3],$A[3][4],[$C[0],#16*9] |
| 351 |
stp $A[4][0],$A[4][1],[$C[0],#16*10] |
| 352 |
stp $A[4][2],$A[4][3],[$C[0],#16*11] |
| 353 |
str $A[4][4],[$C[0],#16*12] |
| 354 |
|
| 355 |
ldp x19,x20,[x29,#16] |
| 356 |
add sp,sp,#48 |
| 357 |
ldp x21,x22,[x29,#32] |
| 358 |
ldp x23,x24,[x29,#48] |
| 359 |
ldp x25,x26,[x29,#64] |
| 360 |
ldp x27,x28,[x29,#80] |
| 361 |
ldp x29,x30,[sp],#128 |
| 362 |
AARCH64_VALIDATE_LINK_REGISTER |
| 363 |
ret |
| 364 |
.size KeccakF1600,.-KeccakF1600 |
| 365 |
|
| 366 |
.globl SHA3_absorb |
| 367 |
.type SHA3_absorb,%function |
| 368 |
.align 5 |
| 369 |
SHA3_absorb: |
| 370 |
AARCH64_SIGN_LINK_REGISTER |
| 371 |
stp x29,x30,[sp,#-128]! |
| 372 |
add x29,sp,#0 |
| 373 |
stp x19,x20,[sp,#16] |
| 374 |
stp x21,x22,[sp,#32] |
| 375 |
stp x23,x24,[sp,#48] |
| 376 |
stp x25,x26,[sp,#64] |
| 377 |
stp x27,x28,[sp,#80] |
| 378 |
sub sp,sp,#64 |
| 379 |
|
| 380 |
stp x0,x1,[sp,#32] // offload arguments |
| 381 |
stp x2,x3,[sp,#48] |
| 382 |
|
| 383 |
mov $C[0],x0 // uint64_t A[5][5] |
| 384 |
mov $C[1],x1 // const void *inp |
| 385 |
mov $C[2],x2 // size_t len |
| 386 |
mov $C[3],x3 // size_t bsz |
| 387 |
ldp $A[0][0],$A[0][1],[$C[0],#16*0] |
| 388 |
ldp $A[0][2],$A[0][3],[$C[0],#16*1] |
| 389 |
ldp $A[0][4],$A[1][0],[$C[0],#16*2] |
| 390 |
ldp $A[1][1],$A[1][2],[$C[0],#16*3] |
| 391 |
ldp $A[1][3],$A[1][4],[$C[0],#16*4] |
| 392 |
ldp $A[2][0],$A[2][1],[$C[0],#16*5] |
| 393 |
ldp $A[2][2],$A[2][3],[$C[0],#16*6] |
| 394 |
ldp $A[2][4],$A[3][0],[$C[0],#16*7] |
| 395 |
ldp $A[3][1],$A[3][2],[$C[0],#16*8] |
| 396 |
ldp $A[3][3],$A[3][4],[$C[0],#16*9] |
| 397 |
ldp $A[4][0],$A[4][1],[$C[0],#16*10] |
| 398 |
ldp $A[4][2],$A[4][3],[$C[0],#16*11] |
| 399 |
ldr $A[4][4],[$C[0],#16*12] |
| 400 |
b .Loop_absorb |
| 401 |
|
| 402 |
.align 4 |
| 403 |
.Loop_absorb: |
| 404 |
subs $C[0],$C[2],$C[3] // len - bsz |
| 405 |
blo .Labsorbed |
| 406 |
|
| 407 |
str $C[0],[sp,#48] // save len - bsz |
| 408 |
___ |
| 409 |
for (my $i=0; $i<24; $i+=2) { |
| 410 |
my $j = $i+1; |
| 411 |
$code.=<<___; |
| 412 |
ldr $C[0],[$C[1]],#8 // *inp++ |
| 413 |
#ifdef __AARCH64EB__ |
| 414 |
rev $C[0],$C[0] |
| 415 |
#endif |
| 416 |
eor $A[$i/5][$i%5],$A[$i/5][$i%5],$C[0] |
| 417 |
cmp $C[3],#8*($i+2) |
| 418 |
blo .Lprocess_block |
| 419 |
ldr $C[0],[$C[1]],#8 // *inp++ |
| 420 |
#ifdef __AARCH64EB__ |
| 421 |
rev $C[0],$C[0] |
| 422 |
#endif |
| 423 |
eor $A[$j/5][$j%5],$A[$j/5][$j%5],$C[0] |
| 424 |
beq .Lprocess_block |
| 425 |
___ |
| 426 |
} |
| 427 |
$code.=<<___; |
| 428 |
ldr $C[0],[$C[1]],#8 // *inp++ |
| 429 |
#ifdef __AARCH64EB__ |
| 430 |
rev $C[0],$C[0] |
| 431 |
#endif |
| 432 |
eor $A[4][4],$A[4][4],$C[0] |
| 433 |
|
| 434 |
.Lprocess_block: |
| 435 |
str $C[1],[sp,#40] // save inp |
| 436 |
|
| 437 |
bl KeccakF1600_int |
| 438 |
|
| 439 |
ldr $C[1],[sp,#40] // restore arguments |
| 440 |
ldp $C[2],$C[3],[sp,#48] |
| 441 |
b .Loop_absorb |
| 442 |
|
| 443 |
.align 4 |
| 444 |
.Labsorbed: |
| 445 |
ldr $C[1],[sp,#32] |
| 446 |
stp $A[0][0],$A[0][1],[$C[1],#16*0] |
| 447 |
stp $A[0][2],$A[0][3],[$C[1],#16*1] |
| 448 |
stp $A[0][4],$A[1][0],[$C[1],#16*2] |
| 449 |
stp $A[1][1],$A[1][2],[$C[1],#16*3] |
| 450 |
stp $A[1][3],$A[1][4],[$C[1],#16*4] |
| 451 |
stp $A[2][0],$A[2][1],[$C[1],#16*5] |
| 452 |
stp $A[2][2],$A[2][3],[$C[1],#16*6] |
| 453 |
stp $A[2][4],$A[3][0],[$C[1],#16*7] |
| 454 |
stp $A[3][1],$A[3][2],[$C[1],#16*8] |
| 455 |
stp $A[3][3],$A[3][4],[$C[1],#16*9] |
| 456 |
stp $A[4][0],$A[4][1],[$C[1],#16*10] |
| 457 |
stp $A[4][2],$A[4][3],[$C[1],#16*11] |
| 458 |
str $A[4][4],[$C[1],#16*12] |
| 459 |
|
| 460 |
mov x0,$C[2] // return value |
| 461 |
ldp x19,x20,[x29,#16] |
| 462 |
add sp,sp,#64 |
| 463 |
ldp x21,x22,[x29,#32] |
| 464 |
ldp x23,x24,[x29,#48] |
| 465 |
ldp x25,x26,[x29,#64] |
| 466 |
ldp x27,x28,[x29,#80] |
| 467 |
ldp x29,x30,[sp],#128 |
| 468 |
AARCH64_VALIDATE_LINK_REGISTER |
| 469 |
ret |
| 470 |
.size SHA3_absorb,.-SHA3_absorb |
| 471 |
___ |
| 472 |
{ |
| 473 |
my ($A_flat,$out,$len,$bsz) = map("x$_",(19..22)); |
| 474 |
$code.=<<___; |
| 475 |
.globl SHA3_squeeze |
| 476 |
.type SHA3_squeeze,%function |
| 477 |
.align 5 |
| 478 |
SHA3_squeeze: |
| 479 |
AARCH64_SIGN_LINK_REGISTER |
| 480 |
stp x29,x30,[sp,#-48]! |
| 481 |
add x29,sp,#0 |
| 482 |
stp x19,x20,[sp,#16] |
| 483 |
stp x21,x22,[sp,#32] |
| 484 |
|
| 485 |
mov $A_flat,x0 // put aside arguments |
| 486 |
mov $out,x1 |
| 487 |
mov $len,x2 |
| 488 |
mov $bsz,x3 |
| 489 |
cmp w4, #0 // w4 = 'next' argument |
| 490 |
bne .Lnext_block |
| 491 |
|
| 492 |
.Loop_squeeze: |
| 493 |
ldr x4,[x0],#8 |
| 494 |
cmp $len,#8 |
| 495 |
blo .Lsqueeze_tail |
| 496 |
#ifdef __AARCH64EB__ |
| 497 |
rev x4,x4 |
| 498 |
#endif |
| 499 |
str x4,[$out],#8 |
| 500 |
subs $len,$len,#8 |
| 501 |
beq .Lsqueeze_done |
| 502 |
|
| 503 |
subs x3,x3,#8 |
| 504 |
bhi .Loop_squeeze |
| 505 |
.Lnext_block: |
| 506 |
mov x0,$A_flat |
| 507 |
bl KeccakF1600 |
| 508 |
mov x0,$A_flat |
| 509 |
mov x3,$bsz |
| 510 |
b .Loop_squeeze |
| 511 |
|
| 512 |
.align 4 |
| 513 |
.Lsqueeze_tail: |
| 514 |
strb w4,[$out],#1 |
| 515 |
lsr x4,x4,#8 |
| 516 |
subs $len,$len,#1 |
| 517 |
beq .Lsqueeze_done |
| 518 |
strb w4,[$out],#1 |
| 519 |
lsr x4,x4,#8 |
| 520 |
subs $len,$len,#1 |
| 521 |
beq .Lsqueeze_done |
| 522 |
strb w4,[$out],#1 |
| 523 |
lsr x4,x4,#8 |
| 524 |
subs $len,$len,#1 |
| 525 |
beq .Lsqueeze_done |
| 526 |
strb w4,[$out],#1 |
| 527 |
lsr x4,x4,#8 |
| 528 |
subs $len,$len,#1 |
| 529 |
beq .Lsqueeze_done |
| 530 |
strb w4,[$out],#1 |
| 531 |
lsr x4,x4,#8 |
| 532 |
subs $len,$len,#1 |
| 533 |
beq .Lsqueeze_done |
| 534 |
strb w4,[$out],#1 |
| 535 |
lsr x4,x4,#8 |
| 536 |
subs $len,$len,#1 |
| 537 |
beq .Lsqueeze_done |
| 538 |
strb w4,[$out],#1 |
| 539 |
|
| 540 |
.Lsqueeze_done: |
| 541 |
ldp x19,x20,[sp,#16] |
| 542 |
ldp x21,x22,[sp,#32] |
| 543 |
ldp x29,x30,[sp],#48 |
| 544 |
AARCH64_VALIDATE_LINK_REGISTER |
| 545 |
ret |
| 546 |
.size SHA3_squeeze,.-SHA3_squeeze |
| 547 |
___ |
| 548 |
} }}} |
| 549 |
{{{ |
| 550 |
my @A = map([ "v".$_.".16b", "v".($_+1).".16b", "v".($_+2).".16b", |
| 551 |
"v".($_+3).".16b", "v".($_+4).".16b" ], |
| 552 |
(0, 5, 10, 15, 20)); |
| 553 |
|
| 554 |
my @C = map("v$_.16b", (25..31)); |
| 555 |
my @D = @C[4,5,6,2,3]; |
| 556 |
|
| 557 |
$code.=<<___; |
| 558 |
.type KeccakF1600_ce,%function |
| 559 |
.align 5 |
| 560 |
KeccakF1600_ce: |
| 561 |
mov x9,#24 |
| 562 |
adrp x10,iotas |
| 563 |
add x10,x10,:lo12:iotas |
| 564 |
b .Loop_ce |
| 565 |
.align 4 |
| 566 |
.Loop_ce: |
| 567 |
////////////////////////////////////////////////// Theta |
| 568 |
eor3 $C[0],$A[4][0],$A[3][0],$A[2][0] |
| 569 |
eor3 $C[1],$A[4][1],$A[3][1],$A[2][1] |
| 570 |
eor3 $C[2],$A[4][2],$A[3][2],$A[2][2] |
| 571 |
eor3 $C[3],$A[4][3],$A[3][3],$A[2][3] |
| 572 |
eor3 $C[4],$A[4][4],$A[3][4],$A[2][4] |
| 573 |
eor3 $C[0],$C[0], $A[1][0],$A[0][0] |
| 574 |
eor3 $C[1],$C[1], $A[1][1],$A[0][1] |
| 575 |
eor3 $C[2],$C[2], $A[1][2],$A[0][2] |
| 576 |
eor3 $C[3],$C[3], $A[1][3],$A[0][3] |
| 577 |
eor3 $C[4],$C[4], $A[1][4],$A[0][4] |
| 578 |
|
| 579 |
rax1 $C[5],$C[0],$C[2] // D[1] |
| 580 |
rax1 $C[6],$C[1],$C[3] // D[2] |
| 581 |
rax1 $C[2],$C[2],$C[4] // D[3] |
| 582 |
rax1 $C[3],$C[3],$C[0] // D[4] |
| 583 |
rax1 $C[4],$C[4],$C[1] // D[0] |
| 584 |
|
| 585 |
////////////////////////////////////////////////// Theta+Rho+Pi |
| 586 |
xar $C[0], $A[0][1],$D[1],#64-$rhotates[0][1] // C[0]=A[2][0] |
| 587 |
|
| 588 |
xar $A[0][1],$A[1][1],$D[1],#64-$rhotates[1][1] |
| 589 |
xar $A[1][1],$A[1][4],$D[4],#64-$rhotates[1][4] |
| 590 |
xar $A[1][4],$A[4][2],$D[2],#64-$rhotates[4][2] |
| 591 |
xar $A[4][2],$A[2][4],$D[4],#64-$rhotates[2][4] |
| 592 |
xar $A[2][4],$A[4][0],$D[0],#64-$rhotates[4][0] |
| 593 |
|
| 594 |
xar $C[1], $A[0][2],$D[2],#64-$rhotates[0][2] // C[1]=A[4][0] |
| 595 |
|
| 596 |
xar $A[0][2],$A[2][2],$D[2],#64-$rhotates[2][2] |
| 597 |
xar $A[2][2],$A[2][3],$D[3],#64-$rhotates[2][3] |
| 598 |
xar $A[2][3],$A[3][4],$D[4],#64-$rhotates[3][4] |
| 599 |
xar $A[3][4],$A[4][3],$D[3],#64-$rhotates[4][3] |
| 600 |
xar $A[4][3],$A[3][0],$D[0],#64-$rhotates[3][0] |
| 601 |
|
| 602 |
xar $A[3][0],$A[0][4],$D[4],#64-$rhotates[0][4] |
| 603 |
|
| 604 |
xar $D[4], $A[4][4],$D[4],#64-$rhotates[4][4] // D[4]=A[0][4] |
| 605 |
xar $A[4][4],$A[4][1],$D[1],#64-$rhotates[4][1] |
| 606 |
xar $A[1][3],$A[1][3],$D[3],#64-$rhotates[1][3] // A[1][3]=A[4][1] |
| 607 |
xar $A[0][4],$A[3][1],$D[1],#64-$rhotates[3][1] // A[0][4]=A[1][3] |
| 608 |
xar $A[3][1],$A[1][0],$D[0],#64-$rhotates[1][0] |
| 609 |
|
| 610 |
xar $A[1][0],$A[0][3],$D[3],#64-$rhotates[0][3] |
| 611 |
|
| 612 |
eor $A[0][0],$A[0][0],$D[0] |
| 613 |
|
| 614 |
xar $D[3], $A[3][3],$D[3],#64-$rhotates[3][3] // D[3]=A[0][3] |
| 615 |
xar $A[0][3],$A[3][2],$D[2],#64-$rhotates[3][2] // A[0][3]=A[3][3] |
| 616 |
xar $D[1], $A[2][1],$D[1],#64-$rhotates[2][1] // D[1]=A[3][2] |
| 617 |
xar $D[2], $A[1][2],$D[2],#64-$rhotates[1][2] // D[2]=A[2][1] |
| 618 |
xar $D[0], $A[2][0],$D[0],#64-$rhotates[2][0] // D[0]=A[1][2] |
| 619 |
|
| 620 |
////////////////////////////////////////////////// Chi+Iota |
| 621 |
bcax $A[4][0],$C[1], $A[4][2],$A[1][3] // A[1][3]=A[4][1] |
| 622 |
bcax $A[4][1],$A[1][3],$A[4][3],$A[4][2] // A[1][3]=A[4][1] |
| 623 |
bcax $A[4][2],$A[4][2],$A[4][4],$A[4][3] |
| 624 |
bcax $A[4][3],$A[4][3],$C[1], $A[4][4] |
| 625 |
bcax $A[4][4],$A[4][4],$A[1][3],$C[1] // A[1][3]=A[4][1] |
| 626 |
|
| 627 |
ld1r {$C[1]},[x10],#8 |
| 628 |
|
| 629 |
bcax $A[3][2],$D[1], $A[3][4],$A[0][3] // A[0][3]=A[3][3] |
| 630 |
bcax $A[3][3],$A[0][3],$A[3][0],$A[3][4] // A[0][3]=A[3][3] |
| 631 |
bcax $A[3][4],$A[3][4],$A[3][1],$A[3][0] |
| 632 |
bcax $A[3][0],$A[3][0],$D[1], $A[3][1] |
| 633 |
bcax $A[3][1],$A[3][1],$A[0][3],$D[1] // A[0][3]=A[3][3] |
| 634 |
|
| 635 |
bcax $A[2][0],$C[0], $A[2][2],$D[2] |
| 636 |
bcax $A[2][1],$D[2], $A[2][3],$A[2][2] |
| 637 |
bcax $A[2][2],$A[2][2],$A[2][4],$A[2][3] |
| 638 |
bcax $A[2][3],$A[2][3],$C[0], $A[2][4] |
| 639 |
bcax $A[2][4],$A[2][4],$D[2], $C[0] |
| 640 |
|
| 641 |
bcax $A[1][2],$D[0], $A[1][4],$A[0][4] // A[0][4]=A[1][3] |
| 642 |
bcax $A[1][3],$A[0][4],$A[1][0],$A[1][4] // A[0][4]=A[1][3] |
| 643 |
bcax $A[1][4],$A[1][4],$A[1][1],$A[1][0] |
| 644 |
bcax $A[1][0],$A[1][0],$D[0], $A[1][1] |
| 645 |
bcax $A[1][1],$A[1][1],$A[0][4],$D[0] // A[0][4]=A[1][3] |
| 646 |
|
| 647 |
bcax $A[0][3],$D[3], $A[0][0],$D[4] |
| 648 |
bcax $A[0][4],$D[4], $A[0][1],$A[0][0] |
| 649 |
bcax $A[0][0],$A[0][0],$A[0][2],$A[0][1] |
| 650 |
bcax $A[0][1],$A[0][1],$D[3], $A[0][2] |
| 651 |
bcax $A[0][2],$A[0][2],$D[4], $D[3] |
| 652 |
|
| 653 |
eor $A[0][0],$A[0][0],$C[1] |
| 654 |
|
| 655 |
subs x9,x9,#1 |
| 656 |
bne .Loop_ce |
| 657 |
|
| 658 |
ret |
| 659 |
.size KeccakF1600_ce,.-KeccakF1600_ce |
| 660 |
|
| 661 |
.type KeccakF1600_cext,%function |
| 662 |
.align 5 |
| 663 |
KeccakF1600_cext: |
| 664 |
AARCH64_SIGN_LINK_REGISTER |
| 665 |
stp x29,x30,[sp,#-80]! |
| 666 |
add x29,sp,#0 |
| 667 |
stp d8,d9,[sp,#16] // per ABI requirement |
| 668 |
stp d10,d11,[sp,#32] |
| 669 |
stp d12,d13,[sp,#48] |
| 670 |
stp d14,d15,[sp,#64] |
| 671 |
___ |
| 672 |
for($i=0; $i<24; $i+=2) { # load A[5][5] |
| 673 |
my $j=$i+1; |
| 674 |
$code.=<<___; |
| 675 |
ldp d$i,d$j,[x0,#8*$i] |
| 676 |
___ |
| 677 |
} |
| 678 |
$code.=<<___; |
| 679 |
ldr d24,[x0,#8*$i] |
| 680 |
bl KeccakF1600_ce |
| 681 |
ldr x30,[sp,#8] |
| 682 |
___ |
| 683 |
for($i=0; $i<24; $i+=2) { # store A[5][5] |
| 684 |
my $j=$i+1; |
| 685 |
$code.=<<___; |
| 686 |
stp d$i,d$j,[x0,#8*$i] |
| 687 |
___ |
| 688 |
} |
| 689 |
$code.=<<___; |
| 690 |
str d24,[x0,#8*$i] |
| 691 |
|
| 692 |
ldp d8,d9,[sp,#16] |
| 693 |
ldp d10,d11,[sp,#32] |
| 694 |
ldp d12,d13,[sp,#48] |
| 695 |
ldp d14,d15,[sp,#64] |
| 696 |
ldr x29,[sp],#80 |
| 697 |
AARCH64_VALIDATE_LINK_REGISTER |
| 698 |
ret |
| 699 |
.size KeccakF1600_cext,.-KeccakF1600_cext |
| 700 |
___ |
| 701 |
|
| 702 |
{ |
| 703 |
my ($ctx,$inp,$len,$bsz) = map("x$_",(0..3)); |
| 704 |
|
| 705 |
$code.=<<___; |
| 706 |
.globl SHA3_absorb_cext |
| 707 |
.type SHA3_absorb_cext,%function |
| 708 |
.align 5 |
| 709 |
SHA3_absorb_cext: |
| 710 |
AARCH64_SIGN_LINK_REGISTER |
| 711 |
stp x29,x30,[sp,#-80]! |
| 712 |
add x29,sp,#0 |
| 713 |
stp d8,d9,[sp,#16] // per ABI requirement |
| 714 |
stp d10,d11,[sp,#32] |
| 715 |
stp d12,d13,[sp,#48] |
| 716 |
stp d14,d15,[sp,#64] |
| 717 |
___ |
| 718 |
for($i=0; $i<24; $i+=2) { # load A[5][5] |
| 719 |
my $j=$i+1; |
| 720 |
$code.=<<___; |
| 721 |
ldp d$i,d$j,[x0,#8*$i] |
| 722 |
___ |
| 723 |
} |
| 724 |
$code.=<<___; |
| 725 |
ldr d24,[x0,#8*$i] |
| 726 |
b .Loop_absorb_ce |
| 727 |
|
| 728 |
.align 4 |
| 729 |
.Loop_absorb_ce: |
| 730 |
subs $len,$len,$bsz // len - bsz |
| 731 |
blo .Labsorbed_ce |
| 732 |
___ |
| 733 |
for (my $i=0; $i<24; $i+=2) { |
| 734 |
my $j = $i+1; |
| 735 |
$code.=<<___; |
| 736 |
ldr d31,[$inp],#8 // *inp++ |
| 737 |
#ifdef __AARCH64EB__ |
| 738 |
rev64 v31.16b,v31.16b |
| 739 |
#endif |
| 740 |
eor $A[$i/5][$i%5],$A[$i/5][$i%5],v31.16b |
| 741 |
cmp $bsz,#8*($i+2) |
| 742 |
blo .Lprocess_block_ce |
| 743 |
ldr d31,[$inp],#8 // *inp++ |
| 744 |
#ifdef __AARCH64EB__ |
| 745 |
rev64 v31.16b,v31.16b |
| 746 |
#endif |
| 747 |
eor $A[$j/5][$j%5],$A[$j/5][$j%5],v31.16b |
| 748 |
beq .Lprocess_block_ce |
| 749 |
___ |
| 750 |
} |
| 751 |
$code.=<<___; |
| 752 |
ldr d31,[$inp],#8 // *inp++ |
| 753 |
#ifdef __AARCH64EB__ |
| 754 |
rev64 v31.16b,v31.16b |
| 755 |
#endif |
| 756 |
eor $A[4][4],$A[4][4],v31.16b |
| 757 |
|
| 758 |
.Lprocess_block_ce: |
| 759 |
|
| 760 |
bl KeccakF1600_ce |
| 761 |
|
| 762 |
b .Loop_absorb_ce |
| 763 |
|
| 764 |
.align 4 |
| 765 |
.Labsorbed_ce: |
| 766 |
___ |
| 767 |
for($i=0; $i<24; $i+=2) { # store A[5][5] |
| 768 |
my $j=$i+1; |
| 769 |
$code.=<<___; |
| 770 |
stp d$i,d$j,[x0,#8*$i] |
| 771 |
___ |
| 772 |
} |
| 773 |
$code.=<<___; |
| 774 |
str d24,[x0,#8*$i] |
| 775 |
add x0,$len,$bsz // return value |
| 776 |
|
| 777 |
ldp d8,d9,[sp,#16] |
| 778 |
ldp d10,d11,[sp,#32] |
| 779 |
ldp d12,d13,[sp,#48] |
| 780 |
ldp d14,d15,[sp,#64] |
| 781 |
ldp x29,x30,[sp],#80 |
| 782 |
AARCH64_VALIDATE_LINK_REGISTER |
| 783 |
ret |
| 784 |
.size SHA3_absorb_cext,.-SHA3_absorb_cext |
| 785 |
___ |
| 786 |
} |
| 787 |
{ |
| 788 |
my ($ctx,$out,$len,$bsz) = map("x$_",(0..3)); |
| 789 |
$code.=<<___; |
| 790 |
.globl SHA3_squeeze_cext |
| 791 |
.type SHA3_squeeze_cext,%function |
| 792 |
.align 5 |
| 793 |
SHA3_squeeze_cext: |
| 794 |
AARCH64_SIGN_LINK_REGISTER |
| 795 |
stp x29,x30,[sp,#-16]! |
| 796 |
add x29,sp,#0 |
| 797 |
mov x9,$ctx |
| 798 |
mov x10,$bsz |
| 799 |
|
| 800 |
.Loop_squeeze_ce: |
| 801 |
ldr x4,[x9],#8 |
| 802 |
cmp $len,#8 |
| 803 |
blo .Lsqueeze_tail_ce |
| 804 |
#ifdef __AARCH64EB__ |
| 805 |
rev x4,x4 |
| 806 |
#endif |
| 807 |
str x4,[$out],#8 |
| 808 |
beq .Lsqueeze_done_ce |
| 809 |
|
| 810 |
sub $len,$len,#8 |
| 811 |
subs x10,x10,#8 |
| 812 |
bhi .Loop_squeeze_ce |
| 813 |
|
| 814 |
bl KeccakF1600_cext |
| 815 |
ldr x30,[sp,#8] |
| 816 |
mov x9,$ctx |
| 817 |
mov x10,$bsz |
| 818 |
b .Loop_squeeze_ce |
| 819 |
|
| 820 |
.align 4 |
| 821 |
.Lsqueeze_tail_ce: |
| 822 |
strb w4,[$out],#1 |
| 823 |
lsr x4,x4,#8 |
| 824 |
subs $len,$len,#1 |
| 825 |
beq .Lsqueeze_done_ce |
| 826 |
strb w4,[$out],#1 |
| 827 |
lsr x4,x4,#8 |
| 828 |
subs $len,$len,#1 |
| 829 |
beq .Lsqueeze_done_ce |
| 830 |
strb w4,[$out],#1 |
| 831 |
lsr x4,x4,#8 |
| 832 |
subs $len,$len,#1 |
| 833 |
beq .Lsqueeze_done_ce |
| 834 |
strb w4,[$out],#1 |
| 835 |
lsr x4,x4,#8 |
| 836 |
subs $len,$len,#1 |
| 837 |
beq .Lsqueeze_done_ce |
| 838 |
strb w4,[$out],#1 |
| 839 |
lsr x4,x4,#8 |
| 840 |
subs $len,$len,#1 |
| 841 |
beq .Lsqueeze_done_ce |
| 842 |
strb w4,[$out],#1 |
| 843 |
lsr x4,x4,#8 |
| 844 |
subs $len,$len,#1 |
| 845 |
beq .Lsqueeze_done_ce |
| 846 |
strb w4,[$out],#1 |
| 847 |
|
| 848 |
.Lsqueeze_done_ce: |
| 849 |
ldr x29,[sp],#16 |
| 850 |
AARCH64_VALIDATE_LINK_REGISTER |
| 851 |
ret |
| 852 |
.size SHA3_squeeze_cext,.-SHA3_squeeze_cext |
| 853 |
___ |
| 854 |
} }}} |
| 855 |
$code.=<<___; |
| 856 |
.asciz "Keccak-1600 absorb and squeeze for ARMv8, CRYPTOGAMS by <https://github.com/dot-asm>" |
| 857 |
___ |
| 858 |
|
| 859 |
{ my %opcode = ( |
| 860 |
"rax1" => 0xce608c00, "eor3" => 0xce000000, |
| 861 |
"bcax" => 0xce200000, "xar" => 0xce800000 ); |
| 862 |
|
| 863 |
sub unsha3 { |
| 864 |
my ($mnemonic,$arg)=@_; |
| 865 |
|
| 866 |
$arg =~ m/[qv]([0-9]+)[^,]*,\s*[qv]([0-9]+)[^,]*(?:,\s*[qv]([0-9]+)[^,]*(?:,\s*[qv#]([0-9\-]+))?)?/ |
| 867 |
&& |
| 868 |
sprintf ".inst\t0x%08x\t//%s %s", |
| 869 |
$opcode{$mnemonic}|$1|($2<<5)|($3<<16)|(eval($4)<<10), |
| 870 |
$mnemonic,$arg; |
| 871 |
} |
| 872 |
} |
| 873 |
|
| 874 |
foreach(split("\n",$code)) { |
| 875 |
|
| 876 |
s/\`([^\`]*)\`/eval($1)/ge; |
| 877 |
|
| 878 |
m/\bld1r\b/ and s/\.16b/.2d/g or |
| 879 |
s/\b(eor3|rax1|xar|bcax)\s+(v.*)/unsha3($1,$2)/ge; |
| 880 |
|
| 881 |
print $_,"\n"; |
| 882 |
} |
| 883 |
|
| 884 |
close STDOUT or die "error closing STDOUT: $!"; |