From 69d59be8fbea73bde4ea47ffe8d61423f057f13e Mon Sep 17 00:00:00 2001 From: Jason Gross Date: Thu, 2 Nov 2017 03:54:58 -0400 Subject: Update fibe --- generate_parameters.py | 26 +++++++++++++++++--------- src/Specific/Framework/bench/fibe.c | 26 ++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/generate_parameters.py b/generate_parameters.py index bb47f638c..ba6ab9cdf 100644 --- a/generate_parameters.py +++ b/generate_parameters.py @@ -142,13 +142,21 @@ def eval_numexpr(numexpr): numexpr = re.sub(r"\.(?![0-9])", "", numexpr) # purge any instance of '.' not followed by a number return eval(numexpr, {'__builtins__':None}) -def get_extra_compiler_params(q, base): - q_mpz = repr(re.sub(r'2(\s*)\^(\s*)([0-9]+)', r'(1_mpz\1<<\2\3)', str(q))) - modulus_bytes_val = repr(str(base)) +def get_extra_compiler_params(q, base, bitwidth, sz): + def log_wt(i): + return 2 ** int(math.ceil(base * i)) q_hex_stripped = hex(eval_numexpr(q.replace('^', '**')))[2:].strip('L') q_hex_padded = q_hex_stripped.rjust(2 * int((len(q_hex_stripped) + 1) / 2), '0') - modulus_array = repr('{%s}' % ','.join('0x%s' % s for s in textwrap.wrap(q_hex_padded, 2))) - return ' -Dq_mpz=%(q_mpz)s -Dmodulus_bytes_val=%(modulus_bytes_val)s -Dmodulus_array=%(modulus_array)s' % locals() + limb_widths = repr('{%s}' % ','.join(str(int(log_wt(i + 1) - log_wt(i))) for i in range(sz))) + defs = { + 'q_mpz' : repr(re.sub(r'2(\s*)\^(\s*)([0-9]+)', r'(1_mpz\1<<\2\3)', str(q))), + 'modulus_bytes_val' : repr(str(base)), + 'modulus_array' : repr('{%s}' % ','.join('0x%s' % s for s in textwrap.wrap(q_hex_padded, 2))), + 'limb_t' : 'uint%d_t' % bitwidth, + 'modulus_limbs' : repr(str(sz)), + 'limb_weight_gaps_array' : limb_widths + } + return ' ' + ' '.join('-D%s=%s' % (k, v) for k, v in defs.items()) def num_bits(p): return p[0][1] @@ -163,8 +171,8 @@ def get_params_montgomery(prime, bitwidth): "sz" : str(sz), "montgomery" : True, "operations" : ["fenz", "feadd", "femul", "feopp", "fesub"], - "compiler" : COMPILER_MONT + get_extra_compiler_params(prime, bitwidth), - "compilerxx" : COMPILERXX_MONT + get_extra_compiler_params(prime, bitwidth) + "compiler" : COMPILER_MONT + get_extra_compiler_params(prime, bitwidth, bitwidth, sz), + "compilerxx" : COMPILERXX_MONT + get_extra_compiler_params(prime, bitwidth, bitwidth, sz) } # given a parsed prime, pick a number of (unsaturated) limbs @@ -240,8 +248,8 @@ def get_params_solinas(prime, bitwidth): "carry_chains" : carry_chains, "coef_div_modulus" : str(2), "operations" : ["femul", "fesquare", "freeze"], - "compiler" : COMPILER_SOLI + get_extra_compiler_params(prime, base), - "compilerxx" : COMPILERXX_SOLI + get_extra_compiler_params(prime, base) + "compiler" : COMPILER_SOLI + get_extra_compiler_params(prime, base, bitwidth, sz), + "compilerxx" : COMPILERXX_SOLI + get_extra_compiler_params(prime, base, bitwidth, sz) } if is_goldilocks(p): output["goldilocks"] = True diff --git a/src/Specific/Framework/bench/fibe.c b/src/Specific/Framework/bench/fibe.c index 4ff9f0c9e..ab577cf63 100644 --- a/src/Specific/Framework/bench/fibe.c +++ b/src/Specific/Framework/bench/fibe.c @@ -3,12 +3,30 @@ #include typedef unsigned int uint128_t __attribute__((mode(TI))); -#define modulus_bytes 32 -#define modulus_limbs 5 +#ifndef modulus_bytes_val +#define modulus_bytes_val 32 +#endif + +#ifndef limb_t #define limb_t uint64_t +#endif + +#ifndef a24_val +#define a24_val 121665 +#endif + +#ifndef modulus_limbs +#define modulus_limbs 5 +#endif + +#ifndef limb_weight_gaps_array +#define limb_weight_gaps_array {51,51,51,51,51} +#endif + +#define modulus_bytes modulus_bytes_val -static const limb_t a24[modulus_limbs] = {121665}; -static const limb_t limb_weight_gaps[modulus_limbs] = {51,51,51,51,51}; +static const limb_t a24[modulus_limbs] = {a24_val}; +static const limb_t limb_weight_gaps[modulus_limbs] = limb_weight_gaps_array; static void fe_add(uint64_t out[5], const uint64_t in1[5], const uint64_t in2[5]) { { const uint64_t x10 = in1[4]; -- cgit v1.2.3