Skip to content

Commit 11bafe2

Browse files
committed
intrinsic-test: uses PASSES consistently
`PASSES` is a constant accessible to all of the `common` module but is sometimes used directly and sometimes threaded through functions as an argument - this commit eliminates the inconsistency and just uses the constant everywhere.
1 parent 4422340 commit 11bafe2

4 files changed

Lines changed: 27 additions & 30 deletions

File tree

crates/intrinsic-test/src/common/argument.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use itertools::Itertools;
33
use crate::common::intrinsic_helpers::TypeKind;
44
use crate::common::values::{test_values_array, test_values_array_length, test_values_array_name};
55

6+
use super::PASSES;
67
use super::constraint::Constraint;
7-
use super::gen_rust::PASSES;
88
use super::intrinsic_helpers::IntrinsicTypeDefinition;
99

1010
/// An argument for the intrinsic.
@@ -165,18 +165,14 @@ where
165165
/// 0x80, 0x3b, 0xff,
166166
/// ];
167167
/// ```
168-
pub fn gen_arg_rust(
169-
arg: &Argument<T>,
170-
w: &mut impl std::io::Write,
171-
loads: u32,
172-
) -> std::io::Result<()> {
168+
pub fn gen_arg_rust(arg: &Argument<T>, w: &mut impl std::io::Write) -> std::io::Result<()> {
173169
writeln!(
174170
w,
175171
"static {name}: [{ty}; {load_size}] = {values};\n",
176-
name = test_values_array_name(&arg.ty, loads),
172+
name = test_values_array_name(&arg.ty),
177173
ty = arg.ty.rust_scalar_type(),
178-
load_size = test_values_array_length(&arg.ty, loads),
179-
values = test_values_array(&arg.ty, loads)
174+
load_size = test_values_array_length(&arg.ty),
175+
values = test_values_array(&arg.ty)
180176
)
181177
}
182178

@@ -197,7 +193,7 @@ where
197193
///
198194
/// Each subsequent argument's first window is started one element further into the array
199195
/// then the previous.
200-
pub fn load_values_rust(&self, loads: u32) -> String {
196+
pub fn load_values_rust(&self) -> String {
201197
self.iter()
202198
.filter(|&arg| !arg.has_constraint())
203199
.enumerate()
@@ -206,14 +202,14 @@ where
206202
format!(
207203
"let {name} = {load}({vals_name}.as_ptr().add((i+{idx}) % {PASSES}) as _);\n",
208204
name = arg.generate_name(),
209-
vals_name = test_values_array_name(&arg.ty, loads),
205+
vals_name = test_values_array_name(&arg.ty),
210206
load = arg.ty.get_load_function(),
211207
)
212208
} else {
213209
format!(
214210
"let {name} = {vals_name}[(i+{idx}) % {PASSES}];\n",
215211
name = arg.generate_name(),
216-
vals_name = test_values_array_name(&arg.ty, loads),
212+
vals_name = test_values_array_name(&arg.ty),
217213
)
218214
}
219215
})

crates/intrinsic-test/src/common/gen_rust.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ use std::process::Command;
33
use itertools::Itertools;
44

55
use super::intrinsic_helpers::IntrinsicTypeDefinition;
6+
use crate::common::PASSES;
67
use crate::common::argument::ArgumentList;
78
use crate::common::cli::{CcArgStyle, ProcessedCli};
89
use crate::common::intrinsic::Intrinsic;
910
use crate::common::intrinsic_helpers::TypeKind;
1011
use crate::common::values::test_values_array_name;
1112

12-
// The number of times each intrinsic will be called - influences the generation of the
13-
// test arrays to minimise repeated testing of the same test values.
14-
pub(crate) const PASSES: u32 = 20;
15-
1613
/// Rust definitions that are included verbatim in the generated source. In particular, defines
1714
/// a wrapper around float types that defines `NaN`s to be equal reflexively to enable
1815
/// comparison of results that use floats types.
@@ -136,10 +133,10 @@ pub fn write_lib_rs<T: IntrinsicTypeDefinition>(
136133
for intrinsic in intrinsics {
137134
for arg in &intrinsic.arguments.args {
138135
if !arg.has_constraint() {
139-
let name = test_values_array_name(&arg.ty, PASSES);
136+
let name = test_values_array_name(&arg.ty);
140137

141138
if seen.insert(name) {
142-
ArgumentList::gen_arg_rust(arg, w, PASSES)?;
139+
ArgumentList::gen_arg_rust(arg, w)?;
143140
}
144141
}
145142
}
@@ -164,7 +161,6 @@ pub fn write_lib_rs<T: IntrinsicTypeDefinition>(
164161
fn generate_rust_test_loop<T: IntrinsicTypeDefinition>(
165162
w: &mut impl std::io::Write,
166163
intrinsic: &Intrinsic<T>,
167-
passes: u32,
168164
) -> std::io::Result<()> {
169165
let intrinsic_name = &intrinsic.name;
170166

@@ -245,10 +241,10 @@ fn generate_rust_test_loop<T: IntrinsicTypeDefinition>(
245241
" }}",
246242
" }}",
247243
),
248-
loaded_args = intrinsic.arguments.load_values_rust(passes),
244+
loaded_args = intrinsic.arguments.load_values_rust(),
249245
rust_args = intrinsic.arguments.as_call_param_rust(),
250246
c_args = intrinsic.arguments.as_c_call_param_rust(),
251-
passes = passes,
247+
passes = PASSES,
252248
cast_prefix = cast_prefix,
253249
cast_suffix = cast_suffix,
254250
)
@@ -268,7 +264,7 @@ fn create_rust_test<T: IntrinsicTypeDefinition>(
268264
intrinsic_name = intrinsic.name,
269265
)?;
270266

271-
generate_rust_test_loop(w, intrinsic, PASSES)?;
267+
generate_rust_test_loop(w, intrinsic)?;
272268

273269
writeln!(w, "}}")?;
274270

crates/intrinsic-test/src/common/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ mod gen_c;
2323
mod gen_rust;
2424
mod values;
2525

26+
// The number of times each intrinsic will be called - influences the generation of the
27+
// test arrays to minimise repeated testing of the same test values.
28+
pub(crate) const PASSES: u32 = 20;
29+
2630
/// Architectures must support this trait
2731
/// to be successfully tested.
2832
pub trait SupportedArchitectureTest {

crates/intrinsic-test/src/common/values.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
use itertools::Itertools as _;
22

3-
use crate::common::intrinsic_helpers::{
4-
IntrinsicType, IntrinsicTypeDefinition, Sign, SimdLen, TypeKind,
3+
use crate::common::{
4+
PASSES,
5+
intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, Sign, SimdLen, TypeKind},
56
};
67

78
/// Maximum size of a SVE vector
89
pub const MAX_SVE_BITS: u32 = 2048;
910

1011
/// Returns a string with the name of the static variable containing test values for intrinsic
1112
/// arguments of this type.
12-
pub fn test_values_array_name<T: IntrinsicTypeDefinition>(ty: &T, num_loads: u32) -> String {
13+
pub fn test_values_array_name<T: IntrinsicTypeDefinition>(ty: &T) -> String {
1314
format!(
1415
"{ty}_{load_size}",
1516
ty = ty.rust_scalar_type().to_uppercase(),
16-
load_size = test_values_array_length(&ty, num_loads),
17+
load_size = test_values_array_length(&ty),
1718
)
1819
}
1920

@@ -25,7 +26,7 @@ pub fn test_values_array_name<T: IntrinsicTypeDefinition>(ty: &T, num_loads: u32
2526
/// which is then printed as a hex value in the generated code (and if identified as a negative
2627
/// value, with the appropriate minus and corrected hex pattern). Calls to `fN::from_bits` are
2728
/// generated for floats.
28-
pub fn test_values_array(ty: &IntrinsicType, num_loads: u32) -> String {
29+
pub fn test_values_array(ty: &IntrinsicType) -> String {
2930
let (bit_len, kind) = match ty {
3031
IntrinsicType {
3132
kind: TypeKind::Float,
@@ -46,7 +47,7 @@ pub fn test_values_array(ty: &IntrinsicType, num_loads: u32) -> String {
4647

4748
format!(
4849
"[{}]",
49-
(0..test_values_array_length(ty, num_loads)).format_with(",", |i, fmt| {
50+
(0..test_values_array_length(ty)).format_with(",", |i, fmt| {
5051
let src = bit_pattern_for_test_values_array(bit_len, i);
5152
assert!(src == 0 || src.ilog2() < bit_len);
5253
match kind {
@@ -80,7 +81,7 @@ pub fn test_values_array(ty: &IntrinsicType, num_loads: u32) -> String {
8081
///
8182
/// For scalable vectors (only SVE is currently supported), assume that the length of the vector is
8283
/// the maximum supported by the architecture.
83-
pub fn test_values_array_length(ty: &IntrinsicType, num_loads: u32) -> u32 {
84+
pub fn test_values_array_length(ty: &IntrinsicType) -> u32 {
8485
let IntrinsicType {
8586
simd_len, vec_len, ..
8687
} = ty;
@@ -94,7 +95,7 @@ pub fn test_values_array_length(ty: &IntrinsicType, num_loads: u32) -> u32 {
9495
});
9596
let vec_len = vec_len.unwrap_or(1);
9697

97-
(simd_len * vec_len) + num_loads - 1
98+
(simd_len * vec_len) + PASSES - 1
9899
}
99100

100101
/// Returns a bit pattern for a value being output into a array of test values. Bit patterns come

0 commit comments

Comments
 (0)