Skip to content

Commit a5d092c

Browse files
committed
intrinsic-test: move/rename gen_arg_rust
This function doesn't really generate an argument at all, it writes a static that is eventually loaded from to become the argument.
1 parent bd48fd6 commit a5d092c

3 files changed

Lines changed: 28 additions & 26 deletions

File tree

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

Lines changed: 1 addition & 22 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, test_values_array_name};
4+
use crate::common::values::test_values_array_name;
55

66
use super::PASSES;
77
use super::constraint::Constraint;
@@ -155,27 +155,6 @@ where
155155
.join("")
156156
}
157157

158-
/// Returns a string defining a static variable with test values used for all intrinsics with
159-
/// arguments of `arg`'s type.
160-
///
161-
/// e.g.
162-
/// ```rust,ignore
163-
/// static U8_20: [u8; 20] = [
164-
/// 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0xf0,
165-
/// 0x80, 0x3b, 0xff,
166-
/// ];
167-
/// ```
168-
pub fn gen_arg_rust(arg: &Argument<T>, w: &mut impl std::io::Write) -> std::io::Result<()> {
169-
writeln!(
170-
w,
171-
"static {name}: [{ty}; {load_size}] = {values};\n",
172-
name = test_values_array_name(&arg.ty),
173-
ty = arg.ty.rust_scalar_type(),
174-
load_size = test_values_array_length(&arg.ty),
175-
values = test_values_array(&arg.ty)
176-
)
177-
}
178-
179158
/// Returns a string defining a local variable for each argument and loading a value into each
180159
/// using a load intrinsic.
181160
///

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ use itertools::Itertools;
44

55
use super::intrinsic_helpers::IntrinsicTypeDefinition;
66
use crate::common::PASSES;
7-
use crate::common::argument::ArgumentList;
87
use crate::common::cli::{CcArgStyle, ProcessedCli};
98
use crate::common::intrinsic::Intrinsic;
109
use crate::common::intrinsic_helpers::TypeKind;
11-
use crate::common::values::test_values_array_name;
10+
use crate::common::values::{test_values_array_name, test_values_array_static};
1211

1312
/// Rust definitions that are included verbatim in the generated source. In particular, defines
1413
/// a wrapper around float types that defines `NaN`s to be equal reflexively to enable
@@ -136,7 +135,7 @@ pub fn write_lib_rs<T: IntrinsicTypeDefinition>(
136135
let name = test_values_array_name(&arg.ty);
137136

138137
if seen.insert(name) {
139-
ArgumentList::gen_arg_rust(arg, w)?;
138+
test_values_array_static(w, &arg.ty)?;
140139
}
141140
}
142141
}

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,30 @@ use crate::common::{
88
/// Maximum size of a SVE vector
99
pub const MAX_SVE_BITS: u32 = 2048;
1010

11+
/// Writes a string defining a static variable with test values used for all intrinsics with
12+
/// arguments of type `ty` to `w`.
13+
///
14+
/// e.g.
15+
/// ```rust,ignore
16+
/// static U8_20: [u8; 20] = [
17+
/// 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0xf0,
18+
/// 0x80, 0x3b, 0xff,
19+
/// ];
20+
/// ```
21+
pub fn test_values_array_static<T: IntrinsicTypeDefinition>(
22+
w: &mut impl std::io::Write,
23+
ty: &T,
24+
) -> std::io::Result<()> {
25+
writeln!(
26+
w,
27+
"static {name}: [{ty}; {load_size}] = {values};\n",
28+
name = test_values_array_name(ty),
29+
ty = ty.rust_scalar_type(),
30+
load_size = test_values_array_length(&ty),
31+
values = test_values_array(&ty)
32+
)
33+
}
34+
1135
/// Returns a string with the name of the static variable containing test values for intrinsic
1236
/// arguments of this type.
1337
pub fn test_values_array_name<T: IntrinsicTypeDefinition>(ty: &T) -> String {
@@ -20,7 +44,7 @@ pub fn test_values_array_name<T: IntrinsicTypeDefinition>(ty: &T) -> String {
2044

2145
/// Returns the elements used in the test value arrays in `gen_arg_rust`. Uses the
2246
/// `test_values_array_length` fn to determine the number of values that
23-
/// `ArgumentList::gen_arg_rust` expects and `ArgumentList::load_values_rust` needs.
47+
/// `test_values_array_static` expects and `ArgumentList::load_values_rust` needs.
2448
///
2549
/// Each value in the array starts as a bit pattern from `bit_pattern_for_test_values_array`
2650
/// which is then printed as a hex value in the generated code (and if identified as a negative

0 commit comments

Comments
 (0)