Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
broadcast.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <cstddef>
7
8namespace bb {
9
10// Adapts a scalar Fr into the token-dispatched operator[] protocol used by
11// Polynomial / PolynomialSpan in vectorized_for<N> kernels. For ScalarIndex
12// it yields the scalar; for ContiguousVectorIndex<N> it yields a VectorField
13// holding the same scalar broadcast across all lanes. A kernel can then read
14//
15// vectorized_for<5>(0, n, [&](auto ctx) {
16// self[ctx] = self[ctx] + other[ctx] * scaling[ctx];
17// });
18//
19// without an `if constexpr` branch on the token type: `scaling[ctx]` returns
20// Fr in the tail and VectorField in the bulk, matching the type the
21// surrounding arithmetic expects.
22//
23// Both forms are materialized once in the constructor (the VectorField
24// broadcast does a one-time splat of `s` into all lanes), and both operator[]
25// overloads return by const-reference so iterating callers do not pay a copy
26// per loop block.
27template <typename Fr> struct Broadcast {
29
32
33 explicit Broadcast(const Fr& s)
34 : scalar(s)
35 , vector(Vec::broadcast(s))
36 {}
37
38 [[gnu::always_inline]] const Fr& operator[](ScalarIndex) const { return scalar; }
39
40 template <size_t N> [[gnu::always_inline]] const Vec& operator[](ContiguousVectorIndex<N>) const { return vector; }
41};
42
43} // namespace bb
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
const Vec & operator[](ContiguousVectorIndex< N >) const
Definition broadcast.hpp:40
Broadcast(const Fr &s)
Definition broadcast.hpp:33
const Fr & operator[](ScalarIndex) const
Definition broadcast.hpp:38