ff-cl-gen

Crates.ioff-cl-gen
lib.rsff-cl-gen
version0.3.0
sourcesrc
created_at2020-06-09 09:33:17.801735
updated_at2021-06-01 19:42:57.321871
descriptionOpenCL code generator for prime-fields
homepagehttps://github.com/filecoin-project/ff-cl-gen
repositoryhttps://github.com/filecoin-project/ff-cl-gen
max_upload_size
id251833
size40,663
porcuquine (porcuquine)

documentation

https://docs.rs/ff-cl-gen

README

ff-cl-gen Crates.io

OpenCL code generator for finite-field arithmetic over prime fields constructed with Rust ff library.

Notes:

  • Limbs are 32/64-bit long, by your choice.
  • The library assumes that the most significant bit of your prime-field is unset. This allows for cheap reductions.

Usage

Generating OpenCL codes for Bls12-381 Fr elements:

use paired::bls12_381::Fr;
let src = ff_cl_gen::field::<Fr, Limb64>("Fr");

Generated interface (FIELD is substituted with Fr):

#define FIELD_LIMB_BITS ... // 32/64
#define FIELD_limb ... // uint/ulong, based on FIELD_LIMB_BITS
#define FIELD_LIMBS ... // Number of limbs for this field
#define FIELD_P ... // Normal form of field modulus
#define FIELD_ONE ... // Montomery form of one
#define FIELD_ZERO ... // Montomery/normal form of zero
#define FIELD_BITS (FIELD_LIMBS * FIELD_LIMB_BITS)

typedef struct { FIELD_limb val[FIELD_LIMBS]; } FIELD;

bool FIELD_gte(FIELD a, FIELD b); // Greater than or equal
bool FIELD_eq(FIELD a, FIELD b); // Equal
FIELD FIELD_sub(FIELD a, FIELD b); // Modular subtraction
FIELD FIELD_add(FIELD a, FIELD b); // Modular addition
FIELD FIELD_mul(FIELD a, FIELD b); // Modular multiplication
FIELD FIELD_sqr(FIELD a); // Modular squaring
FIELD FIELD_double(FIELD a); // Modular doubling
FIELD FIELD_pow(FIELD base, uint exponent); // Modular power
FIELD FIELD_pow_lookup(global FIELD *bases, uint exponent); // Modular power with lookup table for bases
FIELD FIELD_mont(FIELD a); // To montgomery form
FIELD FIELD_unmont(FIELD a); // To regular form
bool FIELD_get_bit(FIELD l, uint i); // Get `i`th bit (From most significant digit)
uint FIELD_get_bits(FIELD l, uint skip, uint window); // Get `window` consecutive bits, (Starting from `skip`th bit from most significant digit)

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 85

cargo fmt