Skip to content

Commit 4311578

Browse files
committed
Add the intrinsic test tool to the CI
1 parent 4520108 commit 4311578

File tree

7 files changed

+4402
-24
lines changed

7 files changed

+4402
-24
lines changed

ci/docker/aarch64-unknown-linux-gnu/Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
FROM ubuntu:20.04
22
RUN apt-get update && apt-get install -y --no-install-recommends \
33
gcc \
4+
g++ \
45
ca-certificates \
56
libc6-dev \
67
gcc-aarch64-linux-gnu \
8+
g++-aarch64-linux-gnu \
79
libc6-dev-arm64-cross \
810
qemu-user \
911
make \
10-
file
12+
file \
13+
clang-9 \
14+
lld
1115

1216
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
1317
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="qemu-aarch64 -L /usr/aarch64-linux-gnu" \

ci/run-docker.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ run() {
99
target=$(echo "${1}" | sed 's/-emulated//')
1010
echo "Building docker container for TARGET=${1}"
1111
docker build -t stdarch -f "ci/docker/${1}/Dockerfile" ci/
12-
mkdir -p target
12+
mkdir -p target c_programs rust_programs
1313
echo "Running docker"
1414
# shellcheck disable=SC2016
1515
docker run \
@@ -29,6 +29,8 @@ run() {
2929
--volume "$(rustc --print sysroot)":/rust:ro \
3030
--volume "$(pwd)":/checkout:ro \
3131
--volume "$(pwd)"/target:/checkout/target \
32+
--volume "$(pwd)"/c_programs:/checkout/c_programs \
33+
--volume "$(pwd)"/rust_programs:/checkout/rust_programs \
3234
--init \
3335
--workdir /checkout \
3436
--privileged \

ci/run.sh

+7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ cargo_test() {
6565
CORE_ARCH="--manifest-path=crates/core_arch/Cargo.toml"
6666
STD_DETECT="--manifest-path=crates/std_detect/Cargo.toml"
6767
STDARCH_EXAMPLES="--manifest-path=examples/Cargo.toml"
68+
INTRINSIC_TEST="--manifest-path=crates/intrinsic-test/Cargo.toml"
69+
6870
cargo_test "${CORE_ARCH} --release"
6971

7072
if [ "$NOSTD" != "1" ]; then
@@ -111,6 +113,11 @@ case ${TARGET} in
111113

112114
esac
113115

116+
if [ "${TARGET}" = "aarch64-unknown-linux-gnu" ]; then
117+
export CPPFLAGS="-fuse-ld=lld -I/usr/aarch64-linux-gnu/include/ -I/usr/aarch64-linux-gnu/include/c++/9/aarch64-linux-gnu/"
118+
cargo run ${INTRINSIC_TEST} --release --bin intrinsic-test -- crates/intrinsic-test/neon-intrinsics.csv --runner "${CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER}" --cppcompiler "clang++-9"
119+
fi
120+
114121
if [ "$NORUN" != "1" ] && [ "$NOSTD" != 1 ]; then
115122
# Test examples
116123
(

crates/intrinsic-test/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ FLAGS:
1212
1313
OPTIONS:
1414
--cppcompiler <CPPCOMPILER> The C++ compiler to use for compiling the c++ code [default: clang++]
15-
--toolchain <TOOLCHAIN> The rust toolchain to use for building the rust code [default: nightly]
15+
--runner <RUNNER> Run the C programs under emulation with this command
16+
--toolchain <TOOLCHAIN> The rust toolchain to use for building the rust code
1617
1718
ARGS:
1819
<INPUT> The input file containing the intrinsics

crates/intrinsic-test/neon-intrinsics.csv

+4,356
Large diffs are not rendered by default.

crates/intrinsic-test/src/main.rs

+23-15
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ fn generate_rust_program(intrinsic: &Intrinsic) -> String {
6767
#![feature(stdsimd)]
6868
#![allow(overflowing_literals)]
6969
use core::arch::aarch64::*;
70-
#[allow(unused_macros)]
71-
macro_rules! bits_to_float(
72-
($t:ty, $bits:expr) => (
73-
{{ let x: $t = ::std::mem::transmute($bits); x }}
74-
)
75-
);
7670
7771
fn main() {{
7872
{passes}
@@ -86,14 +80,17 @@ fn main() {{
8680
}
8781

8882
fn compile_c(c_filename: &str, intrinsic: &Intrinsic, compiler: &str) -> bool {
83+
let flags = std::env::var("CPPFLAGS").unwrap_or("".into());
84+
8985
let output = Command::new("sh")
9086
.arg("-c")
9187
.arg(format!(
92-
"{cpp} -Wno-narrowing -O2 -target {target} -o c_programs/{intrinsic} {filename}",
88+
"{cpp} {cppflags} -Wno-narrowing -O2 -target {target} -o c_programs/{intrinsic} {filename}",
9389
target = "aarch64-unknown-linux-gnu",
9490
filename = c_filename,
9591
intrinsic = intrinsic.name,
9692
cpp = compiler,
93+
cppflags = flags,
9794
))
9895
.output();
9996
if let Ok(output) = output {
@@ -182,8 +179,9 @@ path = "{intrinsic}/main.rs""#,
182179
.current_dir("rust_programs")
183180
.arg("-c")
184181
.arg(format!(
185-
"cargo +{toolchain} build --release",
182+
"cargo {toolchain} build --release --target {target}",
186183
toolchain = toolchain,
184+
target = "aarch64-unknown-linux-gnu",
187185
))
188186
.output();
189187
if let Ok(output) = output {
@@ -217,7 +215,6 @@ fn main() {
217215
.arg(
218216
Arg::with_name("TOOLCHAIN")
219217
.takes_value(true)
220-
.default_value("nightly")
221218
.long("toolchain")
222219
.help("The rust toolchain to use for building the rust code"),
223220
)
@@ -228,12 +225,21 @@ fn main() {
228225
.long("cppcompiler")
229226
.help("The C++ compiler to use for compiling the c++ code"),
230227
)
228+
.arg(
229+
Arg::with_name("RUNNER")
230+
.takes_value(true)
231+
.long("runner")
232+
.help("Run the C programs under emulation with this command"),
233+
)
231234
.get_matches();
232235

233236
let filename = matches.value_of("INPUT").unwrap();
234-
let toolchain = matches.value_of("TOOLCHAIN").unwrap();
235-
let cpp_compiler = matches.value_of("CPPCOMPILER").unwrap();
237+
let toolchain = matches
238+
.value_of("TOOLCHAIN")
239+
.map_or("".into(), |t| format!("+{}", t));
236240

241+
let cpp_compiler = matches.value_of("CPPCOMPILER").unwrap();
242+
let c_runner = matches.value_of("RUNNER").unwrap_or("");
237243
let mut csv_reader = csv::Reader::from_reader(std::fs::File::open(filename).unwrap());
238244

239245
let mut intrinsics = csv_reader
@@ -288,7 +294,7 @@ fn main() {
288294
std::process::exit(3);
289295
}
290296

291-
if !compare_outputs(&intrinsics, &toolchain) {
297+
if !compare_outputs(&intrinsics, &toolchain, &c_runner) {
292298
std::process::exit(1)
293299
}
294300
}
@@ -299,24 +305,26 @@ enum FailureReason {
299305
Difference(String, String, String),
300306
}
301307

302-
fn compare_outputs(intrinsics: &Vec<Intrinsic>, toolchain: &str) -> bool {
308+
fn compare_outputs(intrinsics: &Vec<Intrinsic>, toolchain: &str, runner: &str) -> bool {
303309
let intrinsics = intrinsics
304310
.par_iter()
305311
.filter_map(|intrinsic| {
306312
let c = Command::new("sh")
307313
.arg("-c")
308314
.arg(format!(
309-
"./c_programs/{intrinsic}",
315+
"{runner} ./c_programs/{intrinsic}",
316+
runner = runner,
310317
intrinsic = intrinsic.name,
311318
))
312319
.output();
313320
let rust = Command::new("sh")
314321
.current_dir("rust_programs")
315322
.arg("-c")
316323
.arg(format!(
317-
"cargo +{toolchain} run --release --bin {intrinsic}",
324+
"cargo {toolchain} run --release --target {target} --bin {intrinsic}",
318325
intrinsic = intrinsic.name,
319326
toolchain = toolchain,
327+
target = "aarch64-unknown-linux-gnu",
320328
))
321329
.output();
322330

crates/intrinsic-test/src/types.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,10 @@ impl IntrinsicType {
366366
} => (0..(simd_len.unwrap_or(1) * vec_len.unwrap_or(1)))
367367
.map(|i| {
368368
format!(
369-
"{}{})",
369+
"{}({})",
370370
match language {
371-
&Language::Rust => "bits_to_float!(f32, ",
372-
&Language::C => "cast<float, uint32_t>(",
371+
&Language::Rust => "f32::from_bits",
372+
&Language::C => "cast<float, uint32_t>",
373373
},
374374
values_for_pass(32, i, pass),
375375
)
@@ -385,10 +385,10 @@ impl IntrinsicType {
385385
} => (0..(simd_len.unwrap_or(1) * vec_len.unwrap_or(1)))
386386
.map(|i| {
387387
format!(
388-
"{}{}{})",
388+
"{}({}{})",
389389
match language {
390-
&Language::Rust => "bits_to_float!(f64,",
391-
&Language::C => "cast<double, uint64_t>(",
390+
&Language::Rust => "f64::from_bits",
391+
&Language::C => "cast<double, uint64_t>",
392392
},
393393
values_for_pass(64, i, pass),
394394
match language {

0 commit comments

Comments
 (0)