Skip to main content

binius_field/underlier/
underlier_impls.rs

1// Copyright 2024-2025 Irreducible Inc.
2// Copyright 2026 The Binius Developers
3
4use super::underlier_type::UnderlierType;
5use crate::arch::{interleave_mask_even, interleave_with_mask};
6
7macro_rules! impl_underlier_type {
8	($name:ty, $($mask_idx:literal),+) => {
9		impl UnderlierType for $name {
10			const LOG_BITS: usize =
11				binius_utils::checked_arithmetics::checked_log_2(Self::BITS as _);
12
13			const ZERO: Self = 0;
14			const ONE: Self = 1;
15			const ONES: Self = Self::MAX;
16
17			fn interleave(self, other: Self, log_block_len: usize) -> (Self, Self) {
18				const MASKS: &[$name] = &[
19					$(interleave_mask_even!($name, $mask_idx)),+
20				];
21				interleave_with_mask(self, other, log_block_len, MASKS)
22			}
23		}
24	};
25}
26
27impl_underlier_type!(u8, 0, 1, 2);
28impl_underlier_type!(u16, 0, 1, 2, 3);
29impl_underlier_type!(u32, 0, 1, 2, 3, 4);
30impl_underlier_type!(u64, 0, 1, 2, 3, 4, 5);
31impl_underlier_type!(u128, 0, 1, 2, 3, 4, 5, 6);