Commit 9540f87d authored by Adam P. Goucher's avatar Adam P. Goucher

Refactoring

parent d3b47cde
......@@ -33,10 +33,8 @@
if (bis >= 9) {
apg::z64_to_r32_centre_avx(inleaf, d);
// displaycentre(d);
iterate_avx_16_12(d, e, 0, 0, 0, false);
iterate_avx_12_8(d+2, e+2, 0, 0, 0, false);
// displaycentre(d);
} else {
apg::z64_to_r32_centre_ssse3(inleaf, d);
iterate_sse2_16_12(d, e, 0, 0, 0, false);
......@@ -44,8 +42,42 @@
}
centres[0] = r32_centre_to_u64(d, 0, 0);
// std::cerr << inleaf[0] << " " << inleaf[1] << " " << inleaf[2] << " " << inleaf[3] << ": " << centres[0] << std::endl;
}
int iterate_var_32_28(uint32_t* d, uint32_t* diffs) {
uint32_t e[32];
int bis = apg::best_instruction_set();
if (bis >= 10) {
return iterate_avx2_32_28(d, e, 0, 0, diffs, false);
} else if (bis >= 9) {
return iterate_avx_32_28(d, e, 0, 0, diffs, false);
} else {
return iterate_sse2_32_28(d, e, 0, 0, diffs, false);
}
}
int iterate_var_32_28(uint32_t* d, uint32_t* h, uint32_t* diffs) {
uint32_t e[32];
int bis = apg::best_instruction_set();
if (bis >= 10) {
return iterate_avx2_32_28(d, e, h, 0, diffs, false);
} else if (bis >= 9) {
return iterate_avx_32_28(d, e, h, 0, diffs, false);
} else {
return iterate_sse2_32_28(d, e, h, 0, diffs, false);
}
}
int iterate_var_32_28(uint32_t* d, uint32_t* h, uint32_t* j, uint32_t* diffs) {
uint32_t e[32];
int bis = apg::best_instruction_set();
if (bis >= 10) {
return iterate_avx2_32_28(d, e, h, j, diffs, false);
} else if (bis >= 9) {
return iterate_avx_32_28(d, e, h, j, diffs, false);
} else {
return iterate_sse2_32_28(d, e, h, j, diffs, false);
}
}
bool iterate_var_leaf(int n, uint64_t * inleaves, uint64_t * outleaf) {
......
......@@ -6,21 +6,77 @@ import sys
def get_script_path():
return os.path.dirname(os.path.realpath(sys.argv[0]))
def main():
os.chdir(get_script_path())
import genera
try:
os.makedirs('avxlife/lifelogic')
except OSError as e:
print(repr(e))
os.chdir('avxlife/lifelogic')
def write_all_iterators(f, hist, rules, families):
params = 'int n, uint64_t * inleaves'
params2 = 'uint32_t* d'
xparams = 'n, inleaves'
xparams2 = 'd'
if (hist):
params += ', uint64_t * hleaves'
xparams += ', hleaves'
params2 += ', uint32_t* h'
xparams2 += ', h'
if (hist >= 2):
params += ', uint64_t * jleaves'
xparams += ', jleaves'
params2 += ', uint32_t* j'
xparams2 += ', j'
params += ', uint64_t * outleaf'
params2 += ', uint32_t * diffs'
xparams += ', outleaf'
xparams2 += ', diffs'
f.write(' int iterate_var_leaf(int rule, %s) {\n' % params)
f.write(' switch(rule) {\n')
not_used = True
for (i, (runsafe, family)) in enumerate(zip(rules, families)):
r = runsafe.replace('-', '_')
if (family == 0):
not_used = False
f.write(' case %d :\n' % i)
f.write(' return %s::iterate_var_leaf(%s);\n' % (r, xparams))
elif ((family == 2) and (hist == 1)):
not_used = False
f.write(' case %d :\n' % i)
f.write(' return %s::iterate_var_leaf(inleaves, hleaves, outleaf);\n' % r)
elif ((family != 2) and (hist == 0)):
not_used = False
f.write(' case %d :\n' % i)
f.write(' return %s::iterate_var_leaf(inleaves, outleaf);\n' % r)
f.write(' }\n')
if not_used:
f.write(' (void) %s;\n' % (xparams.replace(',', '; (void)')))
f.write(' return -1;\n')
f.write(' }\n\n')
f.write(' int iterate_var_32_28(int rule, %s) {\n' % params2)
f.write(' switch(rule) {\n')
not_used = True
for (i, (runsafe, family)) in enumerate(zip(rules, families)):
r = runsafe.replace('-', '_')
if (family == 0):
not_used = False
f.write(' case %d :\n' % i)
f.write(' return %s::iterate_var_32_28(%s);\n' % (r, xparams2))
f.write(' }\n')
if not_used:
f.write(' (void) %s;\n' % (xparams2.replace(',', '; (void)')))
f.write(' return -1;\n')
f.write(' }\n\n')
def main(logic_directory='avxlife/lifelogic'):
# Check command-line arguments:
rules = list(sys.argv)[1:]
if (len(rules) == 0):
print("Usage:")
print("python rule2asm.py b3s23 b38s23 g4b2s345")
......@@ -29,6 +85,13 @@ def main():
print("lifelib supports a maximum of 8 different rules")
exit(1)
# Setup directories and import genera:
os.chdir(get_script_path())
import genera
if not os.path.exists(logic_directory):
os.makedirs(logic_directory)
os.chdir(logic_directory)
# Determine rule families from genera:
families = [genera.rule_property(r, 'family') for r in rules]
......@@ -76,10 +139,8 @@ def main():
f.write(' return 3;\n')
f.write(' }\n\n')
'''
for hist in xrange(3):
write_all_iterators(f, hist, rules)
'''
write_all_iterators(f, hist, rules, families)
f.write('}\n')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment