Vectorized Operations
Vectorized operations process multiple field elements in parallel using SIMD instructions.
Type Definition
typedef struct __vbn254fr {
uint64_t __handle;
} vbn254fr_t[1];
Memory Management
// Allocation and initialization
void vbn254fr_alloc(vbn254fr_t vfr, size_t len);
void vbn254fr_free(vbn254fr_t vfr);
Initialization
// Set all elements to scalar value
void vbn254fr_set_ui_scalar(vbn254fr_t out, uint64_t x);
Arithmetic Operations
Element-wise operations on vectors:
// Addition: out[i] = a[i] + b[i] mod p
void vbn254fr_addmod(vbn254fr_t out, const vbn254fr_t a, const vbn254fr_t b);
// Multiplication: out[i] = a[i] * b[i] mod p
void vbn254fr_mulmod(vbn254fr_t out, const vbn254fr_t a, const vbn254fr_t b);
Operations with Constants
// Add constant to all elements: out[i] = a[i] + k mod p
void vbn254fr_addmod_constant(vbn254fr_t out, const vbn254fr_t a,
const vbn254fr_constant* k);
// Multiply all elements by constant: out[i] = a[i] * k mod p
void vbn254fr_mulmod_constant(vbn254fr_t out, const vbn254fr_t a,
const vbn254fr_constant* k);
// Montgomery multiplication with constant
void vbn254fr_mont_mul_constant(vbn254fr_t out, const vbn254fr_t a,
const vbn254fr_constant* k);
Use Cases
Vectorized operations are ideal for:
- Batch Processing: Process multiple values simultaneously
- Performance: Leverage SIMD instructions for speed
- Parallel Computations: Element-wise operations on arrays
Example
#include <ligetron/vbn254fr_class.h>
// Allocate vector of 1000 field elements
vbn254fr_t vec_a, vec_b, vec_result;
vbn254fr_alloc(vec_a, 1000);
vbn254fr_alloc(vec_b, 1000);
vbn254fr_alloc(vec_result, 1000);
// Initialize all elements
vbn254fr_set_ui_scalar(vec_a, 10);
vbn254fr_set_ui_scalar(vec_b, 20);
// Vectorized addition: result[i] = a[i] + b[i]
vbn254fr_addmod(vec_result, vec_a, vec_b);
// Clean up
vbn254fr_free(vec_a);
vbn254fr_free(vec_b);
vbn254fr_free(vec_result);