From d1daa0f3bf32263c05bb88cfdf624e6ea3973cf8 Mon Sep 17 00:00:00 2001 From: Mike Xu Date: Mon, 19 Aug 2024 11:26:49 -0700 Subject: [PATCH] Fix std pub functions. Precursor to https://github.com/google/xls/pull/1546. PiperOrigin-RevId: 664897978 --- xls/dslx/stdlib/std.x | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/xls/dslx/stdlib/std.x b/xls/dslx/stdlib/std.x index 06a2e0ca6c..61af63bc05 100644 --- a/xls/dslx/stdlib/std.x +++ b/xls/dslx/stdlib/std.x @@ -204,7 +204,7 @@ fn smul_test() { // If dividing by `0`, returns all `1`s for quotient and `n` for remainder. // Implements binary long division; should be expected to use a large number of gates and have a slow // critical path when using combinational codegen. -fn iterative_div_mod(n: uN[N], d: uN[M]) -> (uN[N], uN[M]) { +pub fn iterative_div_mod(n: uN[N], d: uN[M]) -> (uN[N], uN[M]) { // Zero extend divisor by 1 bit. let divisor = d as uN[M + u32:1]; @@ -223,7 +223,7 @@ fn iterative_div_mod(n: uN[N], d: uN[M]) -> (uN[N], uN[M]) { // Returns unsigned division of `n` (N bits) and `d` (M bits) as quotient (N bits). // If dividing by `0`, returns all `1`s for quotient. -fn iterative_div(n: uN[N], d: uN[M]) -> uN[N] { +pub fn iterative_div(n: uN[N], d: uN[M]) -> uN[N] { let (q, r) = iterative_div_mod(n, d); q } @@ -440,7 +440,9 @@ fn round_up_to_nearest_test() { // Returns `x` rounded up to the nearest multiple of `y`, where `y` is a known positive power of 2. // This functionality is the same as `round_up_to_nearest` but optimized when `y` is a power of 2. -fn round_up_to_nearest_pow2_unsigned(x: uN[N], y: uN[N]) -> uN[N] { (x + y - uN[N]:1) & -y } +pub fn round_up_to_nearest_pow2_unsigned(x: uN[N], y: uN[N]) -> uN[N] { + (x + y - uN[N]:1) & -y +} #[test] fn test_round_up_to_nearest_pow2_unsigned() { @@ -455,7 +457,7 @@ fn test_round_up_to_nearest_pow2_unsigned() { // Returns `x` rounded up to the nearest multiple of `y`, where `y` is a known positive power of 2. // This functionality is the same as `round_up_to_nearest` but optimized when `y` is a power of 2. -fn round_up_to_nearest_pow2_signed(x: sN[N], y: uN[N]) -> sN[N] { +pub fn round_up_to_nearest_pow2_signed(x: sN[N], y: uN[N]) -> sN[N] { (x + y as sN[N] - sN[N]:1) & -(y as sN[N]) } @@ -999,7 +1001,8 @@ fn is_unsigned_msb_set_test() { // // This is given for help in porting code from Verilog to DSLX, e.g. if a user // wants a more direct transcription. -fn vslice(x: bits[IN]) -> bits[OUT] { +pub fn vslice + (x: bits[IN]) -> bits[OUT] { // This will help flag if the MSB and LSB are given out of order const_assert!(MSB >= LSB); x[LSB+:bits[OUT]] @@ -1166,7 +1169,7 @@ fn clzt_pow2_512(value: bits[512]) -> uN[10] { // Count leading zeroes for power of 2 numbers. // Since we can't have recursion, manually expand this here up to 64 bits -fn clzt_pow2(value: bits[N]) -> uN[RESULT_BITS] { +pub fn clzt_pow2(value: bits[N]) -> uN[RESULT_BITS] { const_assert!(is_pow2(N)); match N { // These casts for the arguments and return types should not be needed. @@ -1216,7 +1219,7 @@ fn clzt_pow2_test() { } // Given a number, what is the next power of two. E.g. 5 -> 8; 8 -> 8; 20 -> 32 -fn next_pow2(n: u32) -> u32 { upow(2, clog2(n)) } +pub fn next_pow2(n: u32) -> u32 { upow(2, clog2(n)) } #[test] fn test_next_pow2() {