Skip to content

Commit 300c34b

Browse files
committed
fix(riscv): fix most of D extension in relation to NaNs
1 parent 30f72fb commit 300c34b

12 files changed

Lines changed: 257 additions & 29 deletions

File tree

test/snippy/fadd_d.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# RUN: llvm-snippy -march=rv64ifd %S/inputs/options.yaml %s %S/inputs/sections.yaml %S/inputs/callgraph.yaml -o %t.elf
2+
# RUN: riscv64-unknown-linux-gnu-clang -march=rv64ifd %t.elf %S/inputs/main.c -o %t.out
3+
# RUN: %config-gen-path/config-gen.rb --march rv64imf \
4+
# RUN: --template-dir %config-gen-path/templates -o %t.yaml
5+
# RUN: ld.lld %t.elf -T %S/inputs/entry.ld -o %t.linked.elf
6+
# RUN: %bin/llvm-bleach %t.linked.elf --instructions %t.yaml -o %t.ll \
7+
# RUN: --state-struct-file=%t.state.h --noinline-instr
8+
# RUN: sed 's|STATE|%t.state.h|g' %S/inputs/native-main.c > \
9+
# RUN: %t.native-main.c
10+
# RUN: sed -i 's/define void \@bleached_print/define weak void @bleached_print/g' %t.ll
11+
# RUN: clang %t.native-main.c %t.ll -o %t.native.out -g -fsanitize=address,undefined \
12+
# RUN: -I %S/inputs -O0
13+
# RUN: qemu-riscv64 %t.out > %t.native.log
14+
# RUN: %t.native.out > %t.log
15+
# RUN: diff %t.native.log %t.log
16+
histogram:
17+
- [FADD_D, 2.0]
18+
- [FSUB_D, 2.0]
19+
- [JAL, 1.0]
Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# RUN: llvm-snippy -march=rv64ifd %s %S/inputs/sections.yaml %S/inputs/callgraph.yaml -o %t.elf
1+
# RUN: llvm-snippy -march=rv64ifd %S/inputs/options.yaml %s %S/inputs/sections.yaml %S/inputs/callgraph.yaml -o %t.elf
22
# RUN: riscv64-unknown-linux-gnu-clang -march=rv64ifd %t.elf %S/inputs/main.c -o %t.out
33
# RUN: %config-gen-path/config-gen.rb --march rv64imf \
44
# RUN: --template-dir %config-gen-path/templates -o %t.yaml
55
# RUN: ld.lld %t.elf -T %S/inputs/entry.ld -o %t.linked.elf
66
# RUN: %bin/llvm-bleach %t.linked.elf --instructions %t.yaml -o %t.ll \
7-
# RUN: --state-struct-file=%t.state.h
7+
# RUN: --state-struct-file=%t.state.h --noinline-instr
88
# RUN: sed 's|STATE|%t.state.h|g' %S/inputs/native-main.c > \
99
# RUN: %t.native-main.c
1010
# RUN: sed -i 's/define void \@bleached_print/define weak void @bleached_print/g' %t.ll
@@ -13,23 +13,10 @@
1313
# RUN: qemu-riscv64 %t.out > %t.native.log
1414
# RUN: %t.native.out > %t.log
1515
# RUN: diff %t.native.log %t.log
16-
options:
17-
mtriple: riscv64
18-
init-regs-in-elf: true
19-
last-instr: RET
20-
num-instrs: 1000
21-
model-plugin: None
22-
honor-target-abi: on
23-
external-stack: on
24-
preserve-caller-saved-regs: [X, F]
25-
imm-hist:
26-
opcodes:
27-
- "FADD_D":
28-
- [0, 1]
29-
- "FCVT_D_L":
30-
- [0, 1]
3116
histogram:
32-
- [ADDI, 1.0]
33-
- [FCVT_D_L, 1.0]
3417
- [FADD_D, 1.0]
18+
- [FMUL_D, 1.0]
19+
- [FDIV_D, 1.0]
20+
- [FSUB_D, 1.0]
21+
- [FCLASS_D, 4.0]
3522
- [JAL, 1.0]

test/snippy/fcmp_d.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# RUN: llvm-snippy -march=rv64ifd %S/inputs/options.yaml %s %S/inputs/sections.yaml %S/inputs/callgraph.yaml -o %t.elf
2+
# RUN: riscv64-unknown-linux-gnu-clang -march=rv64ifd %t.elf %S/inputs/main.c -o %t.out
3+
# RUN: %config-gen-path/config-gen.rb --march rv64imf \
4+
# RUN: --template-dir %config-gen-path/templates -o %t.yaml
5+
# RUN: ld.lld %t.elf -T %S/inputs/entry.ld -o %t.linked.elf
6+
# RUN: %bin/llvm-bleach %t.linked.elf --instructions %t.yaml -o %t.ll \
7+
# RUN: --state-struct-file=%t.state.h --noinline-instr
8+
# RUN: sed 's|STATE|%t.state.h|g' %S/inputs/native-main.c > \
9+
# RUN: %t.native-main.c
10+
# RUN: sed -i 's/define void \@bleached_print/define weak void @bleached_print/g' %t.ll
11+
# RUN: clang %t.native-main.c %t.ll -o %t.native.out -g -fsanitize=address,undefined \
12+
# RUN: -I %S/inputs -O0
13+
# RUN: qemu-riscv64 %t.out > %t.native.log
14+
# RUN: %t.native.out > %t.log
15+
# RUN: diff %t.native.log %t.log
16+
histogram:
17+
- [FEQ_D, 2.0]
18+
- [FLT_D, 2.0]
19+
- [FLE_D, 2.0]
20+
- [JAL, 1.0]

test/snippy/fma_d.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# RUN: llvm-snippy -march=rv64ifd %S/inputs/options.yaml %s %S/inputs/sections.yaml %S/inputs/callgraph.yaml -o %t.elf
2+
# RUN: riscv64-unknown-linux-gnu-clang -march=rv64ifd %t.elf %S/inputs/main.c -o %t.out
3+
# RUN: %config-gen-path/config-gen.rb --march rv64imf \
4+
# RUN: --template-dir %config-gen-path/templates -o %t.yaml
5+
# RUN: ld.lld %t.elf -T %S/inputs/entry.ld -o %t.linked.elf
6+
# RUN: %bin/llvm-bleach %t.linked.elf --instructions %t.yaml -o %t.ll \
7+
# RUN: --state-struct-file=%t.state.h --noinline-instr
8+
# RUN: sed 's|STATE|%t.state.h|g' %S/inputs/native-main.c > \
9+
# RUN: %t.native-main.c
10+
# RUN: sed -i 's/define void \@bleached_print/define weak void @bleached_print/g' %t.ll
11+
# RUN: clang %t.native-main.c %t.ll -o %t.native.out -g -fsanitize=address,undefined \
12+
# RUN: -I %S/inputs -O0
13+
# RUN: qemu-riscv64 %t.out > %t.native.log
14+
# RUN: %t.native.out > %t.log
15+
# RUN: diff %t.native.log %t.log
16+
histogram:
17+
- [FMADD_D, 2.0]
18+
- [FMSUB_D, 2.0]
19+
- [FNMADD_D, 2.0]
20+
- [FNMSUB_D, 2.0]
21+
- [FMADD_D, 2.0]
22+
- [JAL, 1.0]

test/snippy/fminmax_d.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# RUN: llvm-snippy -march=rv64ifd %S/inputs/options.yaml %s %S/inputs/sections.yaml %S/inputs/callgraph.yaml -o %t.elf
2+
# RUN: riscv64-unknown-linux-gnu-clang -march=rv64ifd %t.elf %S/inputs/main.c -o %t.out
3+
# RUN: %config-gen-path/config-gen.rb --march rv64imf \
4+
# RUN: --template-dir %config-gen-path/templates -o %t.yaml
5+
# RUN: ld.lld %t.elf -T %S/inputs/entry.ld -o %t.linked.elf
6+
# RUN: %bin/llvm-bleach %t.linked.elf --instructions %t.yaml -o %t.ll \
7+
# RUN: --state-struct-file=%t.state.h --noinline-instr
8+
# RUN: sed 's|STATE|%t.state.h|g' %S/inputs/native-main.c > \
9+
# RUN: %t.native-main.c
10+
# RUN: sed -i 's/define void \@bleached_print/define weak void @bleached_print/g' %t.ll
11+
# RUN: clang %t.native-main.c %t.ll -o %t.native.out -g -fsanitize=address,undefined \
12+
# RUN: -I %S/inputs -O0
13+
# RUN: qemu-riscv64 %t.out > %t.native.log
14+
# RUN: %t.native.out > %t.log
15+
# RUN: diff %t.native.log %t.log
16+
histogram:
17+
- [FMIN_D, 2.0]
18+
- [FMAX_D, 2.0]
19+
- [JAL, 1.0]

test/snippy/fmuldiv_d.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# RUN: llvm-snippy -march=rv64ifd %S/inputs/options.yaml %s %S/inputs/sections.yaml %S/inputs/callgraph.yaml -o %t.elf
2+
# RUN: riscv64-unknown-linux-gnu-clang -march=rv64ifd %t.elf %S/inputs/main.c -o %t.out
3+
# RUN: %config-gen-path/config-gen.rb --march rv64imf \
4+
# RUN: --template-dir %config-gen-path/templates -o %t.yaml
5+
# RUN: ld.lld %t.elf -T %S/inputs/entry.ld -o %t.linked.elf
6+
# RUN: %bin/llvm-bleach %t.linked.elf --instructions %t.yaml -o %t.ll \
7+
# RUN: --state-struct-file=%t.state.h --noinline-instr
8+
# RUN: sed 's|STATE|%t.state.h|g' %S/inputs/native-main.c > \
9+
# RUN: %t.native-main.c
10+
# RUN: sed -i 's/define void \@bleached_print/define weak void @bleached_print/g' %t.ll
11+
# RUN: clang %t.native-main.c %t.ll -o %t.native.out -g -fsanitize=address,undefined \
12+
# RUN: -I %S/inputs -O0
13+
# RUN: qemu-riscv64 %t.out > %t.native.log
14+
# RUN: %t.native.out > %t.log
15+
# RUN: diff %t.native.log %t.log
16+
histogram:
17+
- [FMUL_D, 2.0]
18+
- [FDIV_D, 2.0]
19+
- [JAL, 1.0]

test/snippy/fsgnj_d.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# RUN: llvm-snippy -march=rv64ifd %S/inputs/options.yaml %s %S/inputs/sections.yaml %S/inputs/callgraph.yaml -o %t.elf
2+
# RUN: riscv64-unknown-linux-gnu-clang -march=rv64ifd %t.elf %S/inputs/main.c -o %t.out
3+
# RUN: %config-gen-path/config-gen.rb --march rv64imf \
4+
# RUN: --template-dir %config-gen-path/templates -o %t.yaml
5+
# RUN: ld.lld %t.elf -T %S/inputs/entry.ld -o %t.linked.elf
6+
# RUN: %bin/llvm-bleach %t.linked.elf --instructions %t.yaml -o %t.ll \
7+
# RUN: --state-struct-file=%t.state.h --noinline-instr
8+
# RUN: sed 's|STATE|%t.state.h|g' %S/inputs/native-main.c > \
9+
# RUN: %t.native-main.c
10+
# RUN: sed -i 's/define void \@bleached_print/define weak void @bleached_print/g' %t.ll
11+
# RUN: clang %t.native-main.c %t.ll -o %t.native.out -g -fsanitize=address,undefined \
12+
# RUN: -I %S/inputs -O0
13+
# RUN: qemu-riscv64 %t.out > %t.native.log
14+
# RUN: %t.native.out > %t.log
15+
# RUN: diff %t.native.log %t.log
16+
histogram:
17+
- [FSGNJ_D, 2.0]
18+
- [FSGNJN_D, 2.0]
19+
- [FSGNJX_D, 2.0]
20+
- [JAL, 1.0]

test/snippy/fsqrt_d.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# RUN: llvm-snippy -march=rv64ifd %S/inputs/options.yaml %s %S/inputs/sections.yaml %S/inputs/callgraph.yaml -o %t.elf
2+
# RUN: riscv64-unknown-linux-gnu-clang -march=rv64ifd %t.elf %S/inputs/main.c -o %t.out
3+
# RUN: %config-gen-path/config-gen.rb --march rv64imf \
4+
# RUN: --template-dir %config-gen-path/templates -o %t.yaml
5+
# RUN: ld.lld %t.elf -T %S/inputs/entry.ld -o %t.linked.elf
6+
# RUN: %bin/llvm-bleach %t.linked.elf --instructions %t.yaml -o %t.ll \
7+
# RUN: --state-struct-file=%t.state.h --noinline-instr
8+
# RUN: sed 's|STATE|%t.state.h|g' %S/inputs/native-main.c > \
9+
# RUN: %t.native-main.c
10+
# RUN: sed -i 's/define void \@bleached_print/define weak void @bleached_print/g' %t.ll
11+
# RUN: clang %t.native-main.c %t.ll -o %t.native.out -g -fsanitize=address,undefined \
12+
# RUN: -I %S/inputs -O0
13+
# RUN: qemu-riscv64 %t.out > %t.native.log
14+
# RUN: %t.native.out > %t.log
15+
# RUN: diff %t.native.log %t.log
16+
histogram:
17+
- [FSQRT_D, 2.0]
18+
- [JAL, 1.0]

test/snippy/inputs/main-fx.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <stdint.h>
2+
#include <stdio.h>
3+
#include <string.h>
4+
5+
static uint64_t bitcast(double v) {
6+
uint64_t r;
7+
memcpy(&r, &v, sizeof(double));
8+
return r;
9+
}
10+
11+
extern void SnippyFunction();
12+
13+
void print(int64_t x10, int64_t x11, int64_t x12, int64_t x13, double d10,
14+
double d11, double d12, double d13) {
15+
printf("PRINT: %lx %lx %lx %lx %lx %lx %lx %lx\n", x10, x11, x12, x13,
16+
bitcast(d10), bitcast(d11), bitcast(d12), bitcast(d13));
17+
}
18+
19+
int main() {
20+
SnippyFunction();
21+
return 0;
22+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <STATE>
2+
#include <stdio.h>
3+
#include <string.h>
4+
5+
void print_one(uint64_t val) { printf("DEBUG: %lx\n", val); }
6+
7+
void bleached_print(struct register_state *st) {
8+
printf("PRINT: %lx %lx %lx %lx %lx %lx %lx %lx\n", st->GPR[10], st->GPR[11],
9+
st->GPR[12], st->GPR[13], st->FPR[10], st->FPR[11], st->FPR[12],
10+
st->FPR[13]);
11+
}
12+
13+
int main() {
14+
struct register_state regs = {};
15+
bleached_SnippyFunction(&regs);
16+
return 0;
17+
}

0 commit comments

Comments
 (0)