Skip to content

Commit 0449df8

Browse files
committed
feat(riscv): implement most of the F and D extensions
1 parent aa890fd commit 0449df8

4 files changed

Lines changed: 607 additions & 5 deletions

File tree

test/integration/doubles-mixed.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// RUN: %config-gen-path/config-gen.rb --march rv64imfd \
22
// RUN: --template-dir %config-gen-path/templates -o %t.yaml
33
// RUN: riscv64-unknown-linux-gnu-clang %s -O2 -c -o %t.out -march=rv64imfd
4-
// -nostdlib -static
54
// RUN: %bin/llvm-bleach %t.out --instructions %t.yaml -o %t.ll \
65
// RUN: --state-struct-file=%t.state.h
76
// RUN: sed 's|STATE|%t.state.h|g' %S/inputs/doubles-mixed-main.c > %t.main.c
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <STATE>
2+
#include <stdint.h>
3+
#include <stdio.h>
4+
#include <string.h>
5+
6+
struct register_state regs = {};
7+
8+
int64_t bitcast_to_int(double v) {
9+
int64_t res;
10+
memcpy(&res, &v, sizeof(double));
11+
return res;
12+
}
13+
14+
double bitcast_to_double(int64_t v) {
15+
double res;
16+
memcpy(&res, &v, sizeof(double));
17+
return res;
18+
}
19+
20+
// This should be in sync with test/integration/riscv-mixed-fp.c
21+
// TODO: automate this
22+
double ref_calc2(double prod, double sum, int x) {
23+
return prod + sum - (double)x;
24+
}
25+
26+
double ref_calc1(double a, double b, int x) {
27+
return ref_calc2(a * b, (a + b), x);
28+
}
29+
30+
double reference(double a, double b, int x) { return ref_calc1(a, b, x); }
31+
32+
int main() {
33+
printf("Hello from main\n");
34+
// random values
35+
double arg_1 = 34.33;
36+
double arg_2 = 0.0003344;
37+
int arg_3 = 5;
38+
regs.FPR[10] = bitcast_to_int(arg_1);
39+
regs.FPR[11] = bitcast_to_int(arg_2);
40+
regs.GPR[10] = arg_3;
41+
top_small(&regs);
42+
double res1 = reference(arg_1, arg_2, arg_3);
43+
double res2 = bitcast_to_double(regs.FPR[10]);
44+
printf("result: %lf\n", res2);
45+
printf("reference: %lf\n", res1);
46+
return res1 - res2 > 0.1;
47+
}

test/integration/riscv-mixed-fp.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %config-gen-path/config-gen.rb --march rv64imfd \
2+
// RUN: --template-dir %config-gen-path/templates -o %t.yaml
3+
// RUN: riscv64-unknown-linux-gnu-clang %s -O2 -c -o %t.out -march=rv64imfd
4+
// RUN: %bin/llvm-bleach %t.out --instructions %t.yaml -o %t.ll \
5+
// RUN: --state-struct-file=%t.state.h
6+
// RUN: sed 's|STATE|%t.state.h|g' %S/inputs/riscv-mixed-fp.c > %t.main.c
7+
// RUN: clang %t.main.c %t.ll -o %t.native.out -g -fsanitize=address,undefined
8+
// RUN: %t.native.out
9+
10+
double calc2(double prod, double sum, int x) { return prod + sum - (double)x; }
11+
12+
double calc1(double a, double b, int x) { return calc2(a * b, (a + b), x); }
13+
14+
double top_small(double a, double b, int x) { return calc1(a, b, x); }

0 commit comments

Comments
 (0)