Skip to content

Commit f357f26

Browse files
Wunkologibbed
authored andcommitted
[Build] Add parallel PPC test generation
Utilizes `multiprocessing` to allow for multiple power-pc assembly tests to be generated in parallel. Some results on my i9-11900k(8c/16t): Before: ``` Measure-Command {.\xb gentests} Days : 0 Hours : 0 Minutes : 0 Seconds : 11 Milliseconds : 200 Ticks : 112007585 TotalDays : 0.000129638408564815 TotalHours : 0.00311132180555556 TotalMinutes : 0.186679308333333 TotalSeconds : 11.2007585 TotalMilliseconds : 11200.7585 ``` After: ``` Measure-Command {.\xb gentests} Days : 0 Hours : 0 Minutes : 0 Seconds : 5 Milliseconds : 426 Ticks : 54265895 TotalDays : 6.28077488425926E-05 TotalHours : 0.00150738597222222 TotalMinutes : 0.0904431583333333 TotalSeconds : 5.4265895 TotalMilliseconds : 5426.5895 ``` This is an over **x2** speedup!
1 parent 4a2f4d9 commit f357f26

File tree

1 file changed

+63
-54
lines changed

1 file changed

+63
-54
lines changed

xenia-build

Lines changed: 63 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Run with --help or no arguments for possible commands.
88
"""
99
from __future__ import print_function
1010
from datetime import datetime
11+
from multiprocessing import Pool
12+
from functools import partial
1113
import argparse
1214
import json
1315
import os
@@ -1206,6 +1208,62 @@ class GenTestsCommand(Command):
12061208
''',
12071209
*args, **kwargs)
12081210

1211+
def process_src_file(test_bin, ppc_as, ppc_objdump, ppc_ld, ppc_nm, src_file):
1212+
print('- %s' % src_file)
1213+
1214+
def make_unix_path(p):
1215+
"""Forces a unix path separator style, as required by binutils.
1216+
"""
1217+
return p.replace(os.sep, '/')
1218+
1219+
src_name = os.path.splitext(os.path.basename(src_file))[0]
1220+
obj_file = os.path.join(test_bin, src_name) + '.o'
1221+
shell_call([
1222+
ppc_as,
1223+
'-a32',
1224+
'-be',
1225+
'-mregnames',
1226+
'-mpower7',
1227+
'-maltivec',
1228+
'-mvsx',
1229+
'-mvmx128',
1230+
'-R',
1231+
'-o%s' % (make_unix_path(obj_file)),
1232+
make_unix_path(src_file),
1233+
])
1234+
dis_file = os.path.join(test_bin, src_name) + '.dis'
1235+
shell_call([
1236+
ppc_objdump,
1237+
'--adjust-vma=0x100000',
1238+
'-Mpower7',
1239+
'-Mvmx128',
1240+
'-D',
1241+
'-EB',
1242+
make_unix_path(obj_file),
1243+
], stdout_path=dis_file)
1244+
# Eat the first 4 lines to kill the file path that'll differ across machines.
1245+
with open(dis_file) as f:
1246+
dis_file_lines = f.readlines()
1247+
with open(dis_file, 'w') as f:
1248+
f.writelines(dis_file_lines[4:])
1249+
shell_call([
1250+
ppc_ld,
1251+
'-A powerpc:common32',
1252+
'-melf32ppc',
1253+
'-EB',
1254+
'-nostdlib',
1255+
'--oformat=binary',
1256+
'-Ttext=0x80000000',
1257+
'-e0x80000000',
1258+
'-o%s' % (make_unix_path(os.path.join(test_bin, src_name) + '.bin')),
1259+
make_unix_path(obj_file),
1260+
])
1261+
shell_call([
1262+
ppc_nm,
1263+
'--numeric-sort',
1264+
make_unix_path(obj_file),
1265+
], stdout_path=os.path.join(test_bin, src_name) + '.map')
1266+
12091267
def execute(self, args, pass_args, cwd):
12101268
print('Generating test binaries...')
12111269
print('')
@@ -1229,61 +1287,12 @@ class GenTestsCommand(Command):
12291287
if (name.startswith('instr_') or name.startswith('seq_'))
12301288
and name.endswith(('.s'))]
12311289

1232-
def make_unix_path(p):
1233-
"""Forces a unix path separator style, as required by binutils.
1234-
"""
1235-
return p.replace(os.sep, '/')
1236-
12371290
any_errors = False
1238-
for src_file in src_files:
1239-
print('- %s' % src_file)
1240-
src_name = os.path.splitext(os.path.basename(src_file))[0]
1241-
obj_file = os.path.join(test_bin, src_name) + '.o'
1242-
shell_call([
1243-
ppc_as,
1244-
'-a32',
1245-
'-be',
1246-
'-mregnames',
1247-
'-mpower7',
1248-
'-maltivec',
1249-
'-mvsx',
1250-
'-mvmx128',
1251-
'-R',
1252-
'-o%s' % (make_unix_path(obj_file)),
1253-
make_unix_path(src_file),
1254-
])
1255-
dis_file = os.path.join(test_bin, src_name) + '.dis'
1256-
shell_call([
1257-
ppc_objdump,
1258-
'--adjust-vma=0x100000',
1259-
'-Mpower7',
1260-
'-Mvmx128',
1261-
'-D',
1262-
'-EB',
1263-
make_unix_path(obj_file),
1264-
], stdout_path=dis_file)
1265-
# Eat the first 4 lines to kill the file path that'll differ across machines.
1266-
with open(dis_file) as f:
1267-
dis_file_lines = f.readlines()
1268-
with open(dis_file, 'w') as f:
1269-
f.writelines(dis_file_lines[4:])
1270-
shell_call([
1271-
ppc_ld,
1272-
'-A powerpc:common32',
1273-
'-melf32ppc',
1274-
'-EB',
1275-
'-nostdlib',
1276-
'--oformat=binary',
1277-
'-Ttext=0x80000000',
1278-
'-e0x80000000',
1279-
'-o%s' % (make_unix_path(os.path.join(test_bin, src_name) + '.bin')),
1280-
make_unix_path(obj_file),
1281-
])
1282-
shell_call([
1283-
ppc_nm,
1284-
'--numeric-sort',
1285-
make_unix_path(obj_file),
1286-
], stdout_path=os.path.join(test_bin, src_name) + '.map')
1291+
1292+
pool_func = partial(GenTestsCommand.process_src_file, test_bin, ppc_as, ppc_objdump, ppc_ld, ppc_nm)
1293+
with Pool() as pool:
1294+
pool.map(pool_func, src_files)
1295+
12871296

12881297
if any_errors:
12891298
print('ERROR: failed to build one or more tests.')

0 commit comments

Comments
 (0)