Commit 5876e035 authored by Adam P. Goucher's avatar Adam P. Goucher

LtL Generations

parent 3e02afed
#ifndef LIFELIB_VERSION /*
__version__=[x.replace('"', '') for x in '''
*/
#define LIFELIB_VERSION "ll1.4"
#define LIFELIB_VERSION "ll1.5"
// '''.split() if ('ll' in x)][0]
#endif
......@@ -97,6 +97,12 @@ def gwrite_leaf_iterator(f, nstates):
gwli_bsi(f, 'sse2', 'ssse3')
f.write(' }\n')
postprocess(f, nstates)
f.write(' return false;\n')
f.write(' }\n\n')
def postprocess(f, nstates):
br = '' if (nstates == 3) else (bin(nstates - 3)[2:])[::-1]
# We run 256 parallel binary counters in outleaf:
......@@ -112,7 +118,3 @@ def gwrite_leaf_iterator(f, nstates):
f.write(' outleaf[%d+i] ^= carry;\n' % (4 * i + 8))
f.write(' outleaf[4+i] |= outleaf2[i];\n')
f.write(' }\n')
f.write(' return false;\n')
f.write(' }\n\n')
......@@ -8,3 +8,4 @@ genus_list.append({'name': 'lifelike', 'regex': 'b0?1?2?3?4?5?6?7?8?s0?1?2?3?4?5
genus_list.append({'name': 'generations', 'regex': 'g[1-9][0-9]*b1?2?3?4?5?6?7?8?s0?1?2?3?4?5?6?7?8?'})
genus_list.append({'name': 'isotropic', 'regex': 'b[1-9ceaiknjqrytwz-]*s[0-9ceaiknjqrytwz-]*'})
genus_list.append({'name': 'ltl', 'regex': 'r[234567]b[1-9][0-9]*t[1-9][0-9]*s[1-9][0-9]*t[1-9][0-9]*'})
genus_list.append({'name': 'gltl', 'regex': 'g[1-9][0-9]*r[234567]b[1-9][0-9]*t[1-9][0-9]*s[1-9][0-9]*t[1-9][0-9]*'})
'''
In this file, we demonstrate the usability of genera by implementing the
Generations variant of Larger than Life, reusing much of the existing code
from both Generations and Larger than Life.
'''
from generations import family, mantissa, postprocess
from ltl import get_ltl_params
def number_of_states(rulestring):
return int(rulestring[1:rulestring.index('r')])
def bitplanes(rulestring):
nstates = number_of_states(rulestring)
return (2 if (nstates == 3) else len(bin(nstates - 3)))
def create_rule(rulestring):
nstates = number_of_states(rulestring)
if (nstates < 3):
raise ValueError("Number of states must be at least 3")
logstring = rulestring[rulestring.index('r'):]
gparams = get_ltl_params(logstring)
with open('iterators_%s.h' % rulestring, 'w') as f:
f.write('#pragma once\n')
f.write('#include <stdint.h>\n')
f.write('#include "../ltl.h"\n')
f.write('namespace %s {\n\n' % rulestring.replace('-', '_'))
f.write(' bool iterate_var_leaf(uint64_t *inleaves, uint64_t *hleaves, uint64_t *outleaf) {\n\n')
f.write(' apg::ltl_kernel(inleaves, outleaf')
for g in gparams:
f.write(', %d' % g)
f.write(');\n')
f.write(' outleaf[0] &= (~hleaves[3]); outleaf[1] &= (~hleaves[6]); outleaf[2] &= (~hleaves[9]); outleaf[3] &= (~hleaves[12]);\n')
f.write(' uint64_t outleaf2[4] = {inleaves[3] & (~outleaf[0]), inleaves[6] & (~outleaf[1]), inleaves[9] & (~outleaf[2]), inleaves[12] & (~outleaf[3])};\n')
postprocess(f, nstates)
f.write(' return false;\n')
f.write(' }\n')
f.write('}\n')
......@@ -2,7 +2,7 @@ family = 4
bitplanes = 1
mantissa = {0, 1}
def create_rule(rulestring):
def get_ltl_params(rulestring):
gparams = rulestring[1:].replace('b', 't').replace('s', 't').split('t')
gparams = tuple(map(int, gparams))
......@@ -15,6 +15,12 @@ def create_rule(rulestring):
if (gparams[4] > ((2 * gparams[0] + 1) ** 2)):
raise ValueError("Maximum survival count cannot exceed neighbourhood area")
return gparams
def create_rule(rulestring):
gparams = get_ltl_params(rulestring)
with open('iterators_%s.h' % rulestring, 'w') as f:
f.write('#pragma once\n')
f.write('#include <stdint.h>\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