def __init__(self, p): """Create instance for modulus p with p + 1 a power of two""" self.p = p self.directives = { "MMV_ROTL": UserDirective(self.gen_mmv_rotl, "sis"), "MMV_UINT_SPREAD": UserDirective(self.gen_mmv_uint_spread, "ss"), } self.tables = self.sizes(p).copy()
def __init__(self): new_tables = { self.T_NAME: self.table, "P_LIST": config.PRIMES, "MMV_CONST": UserFormat(self.f, "ss"), "smask": UserFormat(smask, fmt=c_hex), } self.tables = self.tables.copy() self.tables.update(new_tables) self.directives = { "MMV_LOAD_CONST": UserDirective(self.gen_get_const_table, "ss", "NAMES"), } for name in [ "P", "P_BITS", "FIELD_BITS", "LOG_FIELD_BITS", "INT_FIELDS", "LOG_INT_FIELDS", "V24_INTS", "LOG_V24_INTS", "V24_INTS_USED", "V64_INTS", "LOG_V64_INTS", ]: f = partial(_attr_from_table, name) setattr(self, name, f) self.tables[name] = UserFormat(f, "i")
class Mockup_MM_TablesXi: directives = { "CODE_XI_POINTERS": UserDirective(code_pointers, "ss"), } TABLES = {} for k in product([1, 2], range(1, 6)): TABLES["MM_TABLE_PERM_XI_%d%d" % k] = [0] TABLES["MM_TABLE_SIGN_XI_%d%d" % k] = [0] tables = TABLES
class Mockup_MonomialOp_xi: def __init__(srlf, *args): pass tables = {"OP_XI_TABLE_INFO": [], "OP_XI_TABLE_DIFF": 0} def op(self, *args): return "\n" directives = {"OP_XI": UserDirective(op, "ssssi")}
def make_directives(self): d = { "PERM24_BENES_PREPARE": UserDirective(self.prepare, "ss"), "PERM24_BENES_DECLARE": UserDirective(self.declare, "s"), "PERM24_BENES_LOAD": UserDirective(self.load, "ss"), "PERM24_BENES_COPY": UserDirective(self.copy, "ss"), "PERM24_BENES_PERMUTE": UserDirective(self.permute, "sss"), "PERM24_BENES_STORE": UserDirective(self.store, "ss"), } if len(self.prep_table): return d else: d0 = {} for key_ in d: d0[key_] = self.not_supported return d0
def directives(self): """Code generation function has name "MAT24_MATRIX_TO_PERM". """ return { "MAT24_MATRIX_TO_PERM": UserDirective(self.generate, "ssss", 1), }
def directives(self): """Code generation directive has name "BITVMULTRANSP". """ return { "BITVMULTRANSP": UserDirective(self.generate_c_mul_transp, "ss"), }
def directives(self): """Code generation directive has name "BITMATMUL". """ return { "BITMATMUL": UserDirective(self.generate_c_bitmatmul, "psss"), }
def make_directives(self): return { "LOAD_PERM64": UserDirective(self.generate_load_perm64, "ssss"), "STORE_PERM64": UserDirective(self.generate_store_perm64, "sss"), "INVERT_PERM64": UserDirective(self.generate_invert_perm64, "s"), }
def make_directives(self): return { "SCALAR_PROD_2048_UNROLL": UserDirective(self.scalar_prod_2048_unroll, "sss") }
class MM_TablesXi: done_ = False directives = { "CODE_XI_POINTERS": UserDirective(code_pointers, "ss"), } def __init__(self): cls = self.__class__ if cls.done_: return Pre_Tables = Pre_MM_TablesXi() cls.TAG_NAMES = Pre_Tables.TAG_NAMES cls.PERM_TABLES = {} cls.SIGN_TABLES = {} for i in range(1, 3): for j in range(1, 6): i1, j1 = map_table(i, j) cls.PERM_TABLES[i, j] = Pre_Tables.PERM_TABLES[i1, j1] cls.SIGN_TABLES[i, j] = Pre_Tables.SIGN_TABLES[i1, j1] cls.SOURCE_SHAPES = {} cls.DEST_SHAPES = {} cls.SOURCE_START_1 = {} cls.SOURCE_START_DIFF = {} cls.SOURCE_OP_DIFF = {} cls.DEST_START_1 = {} cls.DEST_START_DIFF = {} cls.DEST_OP_DIFF = {} cls.SOURCE_TAGS = {} cls.DEST_TAGS = {} cls.MAX_ABS_START_DIFF = MDIFF = 32768 REV = Pre_Tables.REVERSE_TABLE_INDICES for j in range(1, 6): source_start1 = REV[map_table(1, j)][1] source_start2 = REV[map_table(2, j)][1] dest_start1 = Pre_Tables.MAP_XI[1, source_start1] dest_start2 = Pre_Tables.MAP_XI[2, source_start2] SHAPES = Pre_Tables.SHAPES assert SHAPES[source_start1] == SHAPES[source_start2] assert SHAPES[dest_start1] == SHAPES[dest_start2] cls.SOURCE_SHAPES[j] = SHAPES[source_start1] cls.DEST_SHAPES[j] = SHAPES[dest_start1] cls.SOURCE_START_1[j] = source_start1 cls.SOURCE_START_DIFF[j] = source_start2 - source_start1 cls.DEST_START_1[j] = dest_start1 cls.DEST_START_DIFF[j] = dest_start2 - dest_start1 assert abs(cls.SOURCE_START_DIFF[j]) in [0, MDIFF] assert abs(cls.DEST_START_DIFF[j]) in [0, MDIFF] cls.SOURCE_OP_DIFF[j] = operator_(cls.SOURCE_START_DIFF[j]) cls.DEST_OP_DIFF[j] = operator_(cls.DEST_START_DIFF[j]) cls.SOURCE_TAGS[j] = (cls.TAG_NAMES[source_start1], cls.TAG_NAMES[source_start2]) cls.DEST_TAGS[j] = (cls.TAG_NAMES[dest_start1], cls.TAG_NAMES[dest_start2]) del SHAPES del REV TABLES = {} for k in product([1, 2], range(1, 6)): TABLES["MM_TABLE_PERM_XI_%d%d" % k] = cls.PERM_TABLES[k] TABLES["MM_TABLE_SIGN_XI_%d%d" % k] = cls.SIGN_TABLES[k] cls.tables = TABLES cls.done_ = True @classmethod def display_config(cls): cls.__init__() print("source:") print(" shapes:", cls.SOURCE_SHAPES) print(" start: ", cls.SOURCE_START_1) print(" diff: ", cls.SOURCE_OP_DIFF) print(" tags: ", cls.SOURCE_TAGS) print("destination:") print(" shapes:", cls.DEST_SHAPES) print(" start: ", cls.DEST_START_1) print(" diff: ", cls.DEST_OP_DIFF) print(" tags: ", cls.DEST_TAGS)
def make_directives(self): return { "MUL_MATRIX_T3A": UserDirective(self.make_code, "sss"), }
def make_directives(self): return { "OP_XI": UserDirective(self.op, "ssssi"), }
def make_directives(self): return { "OP_XI_LOAD": UserDirective(self.load_bytes, "ssis"), "OP_XI_STORE": UserDirective(self.store_bytes, "ssssi"), }