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
3
#include "
barretenberg/ecc/fields/vector_field.hpp
"
4
#include "
barretenberg/ecc/fields/vectorized_for.hpp
"
5
6
#include <cstddef>
7
8
namespace
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.
27
template
<
typename
Fr>
struct
Broadcast
{
28
using
Vec
=
VectorField<typename Fr::Params>
;
29
30
Fr
scalar
;
31
Vec
vector
;
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
bb
Entry point for Barretenberg command-line interface.
Definition
api.hpp:5
bb::Broadcast
Definition
broadcast.hpp:27
bb::Broadcast::vector
Vec vector
Definition
broadcast.hpp:31
bb::Broadcast::operator[]
const Vec & operator[](ContiguousVectorIndex< N >) const
Definition
broadcast.hpp:40
bb::Broadcast::scalar
Fr scalar
Definition
broadcast.hpp:30
bb::Broadcast::Broadcast
Broadcast(const Fr &s)
Definition
broadcast.hpp:33
bb::Broadcast::operator[]
const Fr & operator[](ScalarIndex) const
Definition
broadcast.hpp:38
bb::ContiguousVectorIndex
Definition
vectorized_for.hpp:49
bb::ScalarIndex
Definition
vectorized_for.hpp:34
bb::VectorField< typename Fr::Params >
bb::field< Bn254FrParams >
vector_field.hpp
vectorized_for.hpp
src
barretenberg
polynomials
broadcast.hpp
Generated by
1.9.8