Skip to content

Commit 4422340

Browse files
committed
intrinsic-test: move/rename rust_vals_array_name
Move this function to the `values` module alongside the other functions related to generation of the test value arrays and rename with a similar name.
1 parent 9b642a5 commit 4422340

3 files changed

Lines changed: 21 additions & 19 deletions

File tree

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use itertools::Itertools;
22

33
use crate::common::intrinsic_helpers::TypeKind;
4-
use crate::common::values::{test_values_array, test_values_array_length};
4+
use crate::common::values::{test_values_array, test_values_array_length, test_values_array_name};
55

66
use super::constraint::Constraint;
77
use super::gen_rust::PASSES;
@@ -53,17 +53,6 @@ where
5353
self.constraint.is_some()
5454
}
5555

56-
/// Returns a string with the name of the static variable containing test values for intrinsic
57-
/// arguments of this type.
58-
pub(crate) fn rust_vals_array_name(&self) -> impl std::fmt::Display {
59-
let loads = crate::common::gen_rust::PASSES;
60-
format!(
61-
"{ty}_{load_size}",
62-
ty = self.ty.rust_scalar_type().to_uppercase(),
63-
load_size = test_values_array_length(&self.ty, loads),
64-
)
65-
}
66-
6756
/// Should this argument be passed by reference in C wrapper function declarations?
6857
///
6958
/// SIMD types and `f16` are currently passed by reference.
@@ -184,7 +173,7 @@ where
184173
writeln!(
185174
w,
186175
"static {name}: [{ty}; {load_size}] = {values};\n",
187-
name = arg.rust_vals_array_name(),
176+
name = test_values_array_name(&arg.ty, loads),
188177
ty = arg.ty.rust_scalar_type(),
189178
load_size = test_values_array_length(&arg.ty, loads),
190179
values = test_values_array(&arg.ty, loads)
@@ -208,7 +197,7 @@ where
208197
///
209198
/// Each subsequent argument's first window is started one element further into the array
210199
/// then the previous.
211-
pub fn load_values_rust(&self) -> String {
200+
pub fn load_values_rust(&self, loads: u32) -> String {
212201
self.iter()
213202
.filter(|&arg| !arg.has_constraint())
214203
.enumerate()
@@ -217,14 +206,14 @@ where
217206
format!(
218207
"let {name} = {load}({vals_name}.as_ptr().add((i+{idx}) % {PASSES}) as _);\n",
219208
name = arg.generate_name(),
220-
vals_name = arg.rust_vals_array_name(),
209+
vals_name = test_values_array_name(&arg.ty, loads),
221210
load = arg.ty.get_load_function(),
222211
)
223212
} else {
224213
format!(
225214
"let {name} = {vals_name}[(i+{idx}) % {PASSES}];\n",
226215
name = arg.generate_name(),
227-
vals_name = arg.rust_vals_array_name(),
216+
vals_name = test_values_array_name(&arg.ty, loads),
228217
)
229218
}
230219
})

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::common::argument::ArgumentList;
77
use crate::common::cli::{CcArgStyle, ProcessedCli};
88
use crate::common::intrinsic::Intrinsic;
99
use crate::common::intrinsic_helpers::TypeKind;
10+
use crate::common::values::test_values_array_name;
1011

1112
// The number of times each intrinsic will be called - influences the generation of the
1213
// test arrays to minimise repeated testing of the same test values.
@@ -135,7 +136,7 @@ pub fn write_lib_rs<T: IntrinsicTypeDefinition>(
135136
for intrinsic in intrinsics {
136137
for arg in &intrinsic.arguments.args {
137138
if !arg.has_constraint() {
138-
let name = arg.rust_vals_array_name().to_string();
139+
let name = test_values_array_name(&arg.ty, PASSES);
139140

140141
if seen.insert(name) {
141142
ArgumentList::gen_arg_rust(arg, w, PASSES)?;
@@ -244,7 +245,7 @@ fn generate_rust_test_loop<T: IntrinsicTypeDefinition>(
244245
" }}",
245246
" }}",
246247
),
247-
loaded_args = intrinsic.arguments.load_values_rust(),
248+
loaded_args = intrinsic.arguments.load_values_rust(passes),
248249
rust_args = intrinsic.arguments.as_call_param_rust(),
249250
c_args = intrinsic.arguments.as_c_call_param_rust(),
250251
passes = passes,

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
use itertools::Itertools as _;
22

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

57
/// Maximum size of a SVE vector
68
pub const MAX_SVE_BITS: u32 = 2048;
79

10+
/// Returns a string with the name of the static variable containing test values for intrinsic
11+
/// arguments of this type.
12+
pub fn test_values_array_name<T: IntrinsicTypeDefinition>(ty: &T, num_loads: u32) -> String {
13+
format!(
14+
"{ty}_{load_size}",
15+
ty = ty.rust_scalar_type().to_uppercase(),
16+
load_size = test_values_array_length(&ty, num_loads),
17+
)
18+
}
19+
820
/// Returns the elements used in the test value arrays in `gen_arg_rust`. Uses the
921
/// `test_values_array_length` fn to determine the number of values that
1022
/// `ArgumentList::gen_arg_rust` expects and `ArgumentList::load_values_rust` needs.

0 commit comments

Comments
 (0)