Skip to content

Commit 0de3c0a

Browse files
authored
feat: unify one/ones (#160)
* feat: unify one/ones * opti * opti
1 parent 4b9d8d8 commit 0de3c0a

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

starky/src/f3g.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ impl FieldExtension for F3G {
6161
dim: 1,
6262
};
6363

64+
const ZEROS: Self = F3G {
65+
cube: [Fr::ZERO, Fr::ZERO, Fr::ZERO],
66+
dim: 3,
67+
};
68+
const ONES: Self = F3G {
69+
cube: [Fr::ONE, Fr::ZERO, Fr::ZERO],
70+
dim: 3,
71+
};
6472
#[inline(always)]
6573
fn dim(&self) -> usize {
6674
self.dim
@@ -256,18 +264,12 @@ impl ::rand::Rand for F3G {
256264
impl plonky::Field for F3G {
257265
#[inline(always)]
258266
fn zero() -> Self {
259-
F3G {
260-
cube: [Fr::ZERO, Fr::ZERO, Fr::ZERO],
261-
dim: 3,
262-
}
267+
Self::ZEROS
263268
}
264269

265270
#[inline(always)]
266271
fn one() -> Self {
267-
F3G {
268-
cube: [Fr::ONE, Fr::ZERO, Fr::ZERO],
269-
dim: 3,
270-
}
272+
Self::ONES
271273
}
272274

273275
#[inline(always)]
@@ -730,7 +732,7 @@ pub mod tests {
730732

731733
let b = a.inv();
732734
let c = a.mul(b);
733-
assert_eq!(c, F3G::one());
735+
assert_eq!(c, F3G::ONES);
734736
}
735737

736738
#[test]

starky/src/f5g.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::hash::{Hash, Hasher};
77
use std::slice;
88

99
use core::fmt::{Display, Formatter};
10+
1011
/// Prime: 0xFFFFFFFF00000001
1112
/// Irreducible polynomial: x^5-3
1213
#[repr(C)]
@@ -47,7 +48,14 @@ impl FieldExtension for F5G {
4748
cube: [Fr::ONE, Fr::ZERO, Fr::ZERO, Fr::ZERO, Fr::ZERO],
4849
dim: 1,
4950
};
50-
51+
const ZEROS: Self = F5G {
52+
cube: [Fr::ZERO, Fr::ZERO, Fr::ZERO, Fr::ZERO, Fr::ZERO],
53+
dim: 5,
54+
};
55+
const ONES: Self = F5G {
56+
cube: [Fr::ONE, Fr::ZERO, Fr::ZERO, Fr::ZERO, Fr::ZERO],
57+
dim: 5,
58+
};
5159
#[inline(always)]
5260
fn dim(&self) -> usize {
5361
self.dim
@@ -229,18 +237,12 @@ impl ::rand::Rand for F5G {
229237
impl plonky::Field for F5G {
230238
#[inline(always)]
231239
fn zero() -> Self {
232-
F5G {
233-
cube: [Fr::ZERO, Fr::ZERO, Fr::ZERO, Fr::ZERO, Fr::ZERO],
234-
dim: 1,
235-
}
240+
Self::ZEROS
236241
}
237242

238243
#[inline(always)]
239244
fn one() -> Self {
240-
F5G {
241-
cube: [Fr::ONE, Fr::ZERO, Fr::ZERO, Fr::ZERO, Fr::ZERO],
242-
dim: 1,
243-
}
245+
Self::ONES
244246
}
245247

246248
#[inline(always)]

starky/src/traits.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ pub trait FieldExtension:
8181
const IS_CANONICAL: bool = false;
8282
const ZERO: Self;
8383
const ONE: Self;
84+
85+
const ZEROS: Self;
86+
const ONES: Self;
8487
const NEW_SIZE: u64 = 0;
8588
fn dim(&self) -> usize;
8689
fn from_vec(values: Vec<Fr>) -> Self;

0 commit comments

Comments
 (0)