Skip to content

Commit 90a41d1

Browse files
committed
SIMD-302: implement alt_bn128 G2 syscalls
1 parent f5599b7 commit 90a41d1

File tree

6 files changed

+464
-220
lines changed

6 files changed

+464
-220
lines changed

src/core/features.zon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,5 @@
253253
.{ .name = "increase_cpi_account_info_limit", .pubkey = "H6iVbVaDZgDphcPbcZwc5LoznMPWQfnJ1AM7L1xzqvt5" },
254254
.{ .name = "vote_state_v4", .pubkey = "Gx4XFcrVMt4HUvPzTpTSVkdDVgcDSjKhDN1RqRS6KDuZ" },
255255
.{ .name = "alt_bn128_little_endian", .pubkey = "bnS3pWfLrxHRJvMyLm6EaYQkP7A2Fe9DxoKv4aGA8YM" },
256+
.{ .name = "enable_alt_bn128_g2_syscalls", .pubkey = "bn1hKNURMGQaQoEVxahcEAcqiX3NwRs6hgKKNSLeKxH" },
256257
}

src/crypto/bn254/fields.zig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ pub const Fp = struct {
122122
}
123123

124124
pub fn byteSwap(a: [32]u8) [32]u8 {
125+
// NOTE: This compiles down into a single ymm vpshufb, which is nice
126+
// however it has a high latency (10 cycles on tigerlake), so I'm not
127+
// sure if this is better than just 4 mov + 4 movbe instructions, which
128+
// could be trivially executed in parallel.
129+
//
130+
// Alternative:
131+
// const x: u256 = @bitCast(a);
132+
// return @bitCast(@byteSwap(x));
133+
125134
const limbs: [4]u64 = @bitCast(a);
126135
const array: [4]u64 = .{
127136
@byteSwap(limbs[3]),
@@ -565,7 +574,7 @@ pub const Fp2 = struct {
565574
}
566575

567576
/// https://eprint.iacr.org/2010/354.pdf, Alg. 8
568-
fn inverse(a: Fp2) Fp2 {
577+
pub fn inverse(a: Fp2) Fp2 {
569578
// t0 ← a0^2
570579
var t0 = a.c0.sq();
571580
// t1 ← a1^2

0 commit comments

Comments
 (0)