Skip to content

Commit 56f7307

Browse files
author
Ariel Ben-Yehuda
committed
add script for regenerating asmMap
1 parent 16d5ac4 commit 56f7307

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

crypto/fipsmodule/aes/asm/aes-gcm-avx2-x86_64.pl

+6-1
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ sub filter_and_print {
987987
'vpclmulqdq $0x01, %ymm2, %ymm12, %ymm4' => '.byte 0xc4,0xe3,0x1d,0x44,0xe2,0x01',
988988
'vpclmulqdq $0x01, %ymm2, %ymm12, %ymm6' => '.byte 0xc4,0xe3,0x1d,0x44,0xf2,0x01',
989989
'vpclmulqdq $0x01, %ymm3, %ymm13, %ymm4' => '.byte 0xc4,0xe3,0x15,0x44,0xe3,0x01',
990-
'vpclmulqdq $0x01, %ymm5, %ymm2, %ymm3' => '.byte 0xc4,0xe3,0x6d,0x44,0xdd,0x01',
990+
'vpclmulqdq $0x01, %ymm5, %ymm2, %ymm3' => '.byte 0xc4,0xe3,0x6d,0x44,0xdd,0x01',
991991
'vpclmulqdq $0x01, %ymm5, %ymm3, %ymm1' => '.byte 0xc4,0xe3,0x65,0x44,0xcd,0x01',
992992
'vpclmulqdq $0x01, %ymm5, %ymm4, %ymm1' => '.byte 0xc4,0xe3,0x5d,0x44,0xcd,0x01',
993993
'vpclmulqdq $0x01, %ymm5, %ymm4, %ymm2' => '.byte 0xc4,0xe3,0x5d,0x44,0xd5,0x01',
@@ -1014,6 +1014,11 @@ sub filter_and_print {
10141014
$trimmed =~ s/\s+(#.*)?$//;
10151015
if (exists $asmMap{$trimmed}) {
10161016
$line = $asmMap{$trimmed};
1017+
} else {
1018+
if($trimmed =~ /(vpclmulqdq|vaes).*%[yz]mm/) {
1019+
die ("found instruction not supported under old binutils, please update asmMap with the results of running\n" .
1020+
'find target -name "*aes-gcm-avx2*.o" -exec python3 crypto/fipsmodule/aes/asm/make-avx-map-for-old-binutils.py \{\} \; | LC_ALL=C sort | uniq');
1021+
}
10171022
}
10181023
print $line,"\n";
10191024
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/python3
2+
3+
import argparse
4+
import subprocess
5+
import re
6+
import sys
7+
8+
PCLMUL_RE = re.compile(r'^\s+[0-9a-f]+:\s+(?P<disas>(?:[0-9a-f][0-9a-f] )+)\s+vpclmul(?P<type>[0-9a-z]+)dq (?P<args>.*%ymm.*)$')
9+
NON_PCLMUL_RE = re.compile(r'^\s+[0-9a-f]+:\s+(?P<disas>(?:[0-9a-f][0-9a-f] )+)\s+(?P<instruction>vaesenc|vaesenclast) (?P<args>.*%ymm.*)$')
10+
11+
TYPE_MAP = {
12+
'lqlq': 0x00,
13+
'lqhq': 0x10,
14+
'hqlq': 0x01,
15+
'hqhq': 0x11,
16+
}
17+
18+
def hexify_disas(disas):
19+
return (' '+disas.strip()).replace(' ', ',0x')[1:]
20+
21+
def main():
22+
parser = argparse.ArgumentParser(
23+
prog='make-avx-map-for-old-binutils',
24+
description='Generate a map file for old binutils from .o files'
25+
)
26+
parser.add_argument('filename', nargs='+', help='object file to generate map from')
27+
parsed = parser.parse_args()
28+
for filename in parsed.filename:
29+
for line in subprocess.check_output(['objdump', '-d', filename], stderr=sys.stderr).decode('utf-8').split('\n'):
30+
if match := PCLMUL_RE.match(line):
31+
hexified_disas = hexify_disas(match.group('disas'))
32+
ty = TYPE_MAP[match.group('type')]
33+
args = match.group('args').replace(',', ', ')
34+
print(f" 'vpclmulqdq $0x{ty:02x}, {args}' => '.byte {hexified_disas}',")
35+
elif match := NON_PCLMUL_RE.match(line):
36+
hexified_disas = hexify_disas(match.group('disas'))
37+
args = match.group('args').replace(',', ', ')
38+
print(f" '{match.group('instruction').ljust(16)}{args}' => '.byte {hexified_disas}',")
39+
40+
41+
if __name__ == '__main__':
42+
main()

0 commit comments

Comments
 (0)