-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
139 lines (130 loc) · 4.38 KB
/
Copy pathbuild.rs
File metadata and controls
139 lines (130 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Build script for metal-softfloat.
//
// Only does work when the `testfloat-gpu` feature is enabled. In that
// case it compiles the vendored Berkeley SoftFloat-3e + TestFloat-3e
// case-generation sources into a static library that the
// `tests/testfloat_gpu_conformance.rs` integration test links against.
use std::path::PathBuf;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
if std::env::var_os("CARGO_FEATURE_TESTFLOAT_GPU").is_none() {
return;
}
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let sf_root = manifest_dir.join("vendor/SoftFloat-3e");
let sf_source = sf_root.join("source");
let sf_8086 = sf_source.join("8086-SSE");
let sf_include = sf_source.join("include");
let tf_root = manifest_dir.join("vendor/TestFloat-3e");
let tf_source = tf_root.join("source");
// Mirror SoftFloat-3e/build/Linux-x86_64-GCC/Makefile flags. The
// `8086-SSE` specialization sets canonical-NaN bit patterns that
// happen to match what this crate uses (qNaN bit 51 set, payload 0).
let mut sf = cc::Build::new();
sf.include(&sf_root) // platform.h
.include(&sf_8086) // specialize.h
.include(&sf_include) // softfloat.h, internals.h, primitives.h, ...
.define("SOFTFLOAT_FAST_INT64", None)
.define("SOFTFLOAT_ROUND_ODD", None)
.define("INLINE_LEVEL", "5")
.define("SOFTFLOAT_FAST_DIV32TO16", None)
.define("SOFTFLOAT_FAST_DIV64TO32", None)
.opt_level(2)
.warnings(false);
// SoftFloat top-level sources we need.
for f in [
// f64 arithmetic
"f64_add.c",
"f64_sub.c",
"f64_mul.c",
"f64_div.c",
"f64_sqrt.c",
"f64_mulAdd.c",
"s_addMagsF64.c",
"s_subMagsF64.c",
"s_mulAddF64.c",
"s_normSubnormalF64Sig.c",
"s_normRoundPackToF64.c",
"s_roundPackToF64.c",
// f64 conversions and comparisons
"i64_to_f64.c",
"ui64_to_f64.c",
"f64_to_i64.c",
"f32_to_f64.c",
"f64_to_f32.c",
"f64_eq.c",
"f64_lt_quiet.c",
"f64_le_quiet.c",
"s_roundToI64.c",
// f32 helpers (for f32↔f64 conversions)
"s_normSubnormalF32Sig.c",
"s_roundPackToF32.c",
"s_normRoundPackToF32.c",
// shift / count primitives
"s_shiftRightJam32.c",
"s_shiftRightJam64.c",
"s_shiftRightJam64Extra.c",
"s_shiftRightJam128.c",
"s_shiftRightJam128Extra.c",
"s_shortShiftRightJam64.c",
"s_shortShiftRightJam64Extra.c",
"s_shortShiftRightJam128.c",
"s_shortShiftRightJam128Extra.c",
"s_countLeadingZeros8.c",
"s_countLeadingZeros16.c",
"s_countLeadingZeros32.c",
"s_countLeadingZeros64.c",
"s_approxRecip32_1.c",
"s_approxRecipSqrt32_1.c",
"s_approxRecip_1Ks.c",
"s_approxRecipSqrt_1Ks.c",
"s_mul64To128.c",
"s_mul64ByShifted32To128.c",
"s_add128.c",
"s_sub128.c",
"s_eq128.c",
"s_le128.c",
"s_lt128.c",
"s_shortShiftLeft128.c",
"s_shortShiftRight128.c",
"softfloat_state.c",
] {
sf.file(sf_source.join(f));
}
// 8086-SSE specialization (NaN handling + raiseFlags stub).
for f in [
"s_propagateNaNF64UI.c",
"s_f64UIToCommonNaN.c",
"s_commonNaNToF64UI.c",
"s_propagateNaNF32UI.c",
"s_f32UIToCommonNaN.c",
"s_commonNaNToF32UI.c",
"softfloat_raiseFlags.c",
] {
sf.file(sf_8086.join(f));
}
println!("cargo:rerun-if-changed=vendor/SoftFloat-3e");
sf.compile("softfloat3e");
// TestFloat-3e case generators. Need its own platform.h and to see
// SoftFloat's headers for `float64_t` typedef.
let mut tf = cc::Build::new();
tf.include(&tf_root) // platform.h
.include(&tf_source) // genCases.h, fail.h, random.h
.include(&sf_include) // softfloat.h, softfloat_types.h
.define("FLOAT64", None)
.opt_level(2)
.warnings(false);
for f in [
"genCases_common.c",
"genCases_f64.c",
"genCases_f32.c",
"genCases_i64.c",
"genCases_ui64.c",
"random.c",
"fail.c",
] {
tf.file(tf_source.join(f));
}
println!("cargo:rerun-if-changed=vendor/TestFloat-3e");
tf.compile("testfloat3e_gen");
}