Skip to main content

binius_field/arch/portable/
reuse_multiply_arithmetic.rs

1// Copyright 2024-2025 Irreducible Inc.
2
3use std::ops::Mul;
4
5use bytemuck::TransparentWrapper;
6
7use crate::arithmetic_traits::Square;
8
9/// Square wrapper that reuses the type's own multiplication: `square(x) = x * x`.
10#[repr(transparent)]
11#[derive(TransparentWrapper)]
12pub struct ReuseMultiply<T>(T);
13
14impl<T> Square for ReuseMultiply<T>
15where
16	T: Mul<T, Output = T> + Copy,
17{
18	#[inline]
19	fn square(self) -> Self {
20		let val = Self::peel(self);
21		Self::wrap(val * val)
22	}
23}