Skip to content

Commit 384c48c

Browse files
author
Jorge Aparicio
committed
don't test always against gcc_s
instead test half of the time against gcc_s and the other half test against the native operation (\*). (\*) Not all the targets have available a native version of the intrinsics under test. On those targets we'll end up testing our implementation against itself half of the time. This is not much of a problem because we do several quickcheck runs per intrinsic.
1 parent 337bd7e commit 384c48c

File tree

7 files changed

+141
-106
lines changed

7 files changed

+141
-106
lines changed

Cargo.toml

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ name = "rustc_builtins"
55
version = "0.1.0"
66

77
[dependencies]
8-
rlibc = { git = "https://github.com/alexcrichton/rlibc", optional = true }
8+
9+
[dependencies.rlibc]
10+
git = "https://github.com/alexcrichton/rlibc"
11+
optional = true
912

1013
[dev-dependencies]
11-
gcc_s = { path = "gcc_s" }
1214
quickcheck = "0.3.1"
15+
rand = "0.3.14"
16+
17+
[dev-dependencies.gcc_s]
18+
path = "gcc_s"
1319

1420
[features]
1521
default = ["rlibc/weak"]

src/float/add.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,11 @@ pub extern fn __aeabi_fadd(a: f32, b: f32) -> f32 {
200200
mod tests {
201201
use core::{f32, f64};
202202

203-
use gcc_s;
204-
use qc::{U32, U64};
205203
use float::Float;
204+
use qc::{U32, U64};
205+
206+
use gcc_s;
207+
use rand;
206208

207209
// NOTE The tests below have special handing for NaN values.
208210
// Because NaN != NaN, the floating-point representations must be used
@@ -223,7 +225,7 @@ mod tests {
223225
// implementation matches the output of the FPU instruction on *hard* float targets
224226
// and matches its gcc_s counterpart on *soft* float targets.
225227
#[cfg(not(gnueabihf))]
226-
Some(addsf3) => x.eq_repr(unsafe { addsf3(a, b) }),
228+
Some(addsf3) if rand::random() => x.eq_repr(unsafe { addsf3(a, b) }),
227229
_ => x.eq_repr(a + b),
228230
}
229231
}
@@ -235,7 +237,7 @@ mod tests {
235237
match gcc_s::adddf3() {
236238
// NOTE(cfg) See NOTE above
237239
#[cfg(not(gnueabihf))]
238-
Some(adddf3) => x.eq_repr(unsafe { adddf3(a, b) }),
240+
Some(adddf3) if rand::random() => x.eq_repr(unsafe { adddf3(a, b) }),
239241
_ => x.eq_repr(a + b),
240242

241243
}

src/int/mul.rs

+24-21
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,19 @@ mulo!(__mulodi4: i64);
7272

7373
#[cfg(test)]
7474
mod tests {
75-
use gcc_s;
7675
use qc::{I32, I64, U64};
7776

77+
use gcc_s;
78+
use rand;
79+
7880
quickcheck! {
7981
fn muldi(a: U64, b: U64) -> bool {
8082
let (a, b) = (a.0, b.0);
8183
let r = super::__muldi3(a, b);
8284

83-
if let Some(muldi3) = gcc_s::muldi3() {
84-
r == unsafe { muldi3(a, b) }
85-
} else {
86-
r == a.wrapping_mul(b)
85+
match gcc_s::muldi3() {
86+
Some(muldi3) if rand::random() => r == unsafe { muldi3(a, b) },
87+
_ => r == a.wrapping_mul(b),
8788
}
8889
}
8990

@@ -95,15 +96,16 @@ mod tests {
9596
return false;
9697
}
9798

98-
if let Some(mulosi4) = gcc_s::mulosi4() {
99-
let mut gcc_s_overflow = 2;
100-
let gcc_s_r = unsafe {
101-
mulosi4(a, b, &mut gcc_s_overflow)
102-
};
99+
match gcc_s::mulosi4() {
100+
Some(mulosi4) if rand::random() => {
101+
let mut gcc_s_overflow = 2;
102+
let gcc_s_r = unsafe {
103+
mulosi4(a, b, &mut gcc_s_overflow)
104+
};
103105

104-
(r, overflow) == (gcc_s_r, gcc_s_overflow)
105-
} else {
106-
(r, overflow != 0) == a.overflowing_mul(b)
106+
(r, overflow) == (gcc_s_r, gcc_s_overflow)
107+
},
108+
_ => (r, overflow != 0) == a.overflowing_mul(b),
107109
}
108110
}
109111

@@ -115,15 +117,16 @@ mod tests {
115117
return false;
116118
}
117119

118-
if let Some(mulodi4) = gcc_s::mulodi4() {
119-
let mut gcc_s_overflow = 2;
120-
let gcc_s_r = unsafe {
121-
mulodi4(a, b, &mut gcc_s_overflow)
122-
};
120+
match gcc_s::mulodi4() {
121+
Some(mulodi4) if rand::random() => {
122+
let mut gcc_s_overflow = 2;
123+
let gcc_s_r = unsafe {
124+
mulodi4(a, b, &mut gcc_s_overflow)
125+
};
123126

124-
(r, overflow) == (gcc_s_r, gcc_s_overflow)
125-
} else {
126-
(r, overflow != 0) == a.overflowing_mul(b)
127+
(r, overflow) == (gcc_s_r, gcc_s_overflow)
128+
},
129+
_ => (r, overflow != 0) == a.overflowing_mul(b),
127130
}
128131
}
129132
}

src/int/sdiv.rs

+41-33
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ divmod!(__divmoddi4, __divdi3: i64);
5252

5353
#[cfg(test)]
5454
mod tests {
55+
use qc::{U32, U64};
56+
5557
use gcc_s;
5658
use quickcheck::TestResult;
57-
use qc::{U32, U64};
59+
use rand;
5860

5961
quickcheck!{
6062
fn divdi3(n: U64, d: U64) -> TestResult {
@@ -64,10 +66,11 @@ mod tests {
6466
} else {
6567
let q = super::__divdi3(n, d);
6668

67-
if let Some(divdi3) = gcc_s::divdi3() {
68-
TestResult::from_bool(q == unsafe { divdi3(n, d) })
69-
} else {
70-
TestResult::from_bool(q == n / d)
69+
match gcc_s::divdi3() {
70+
Some(divdi3) if rand::random() => {
71+
TestResult::from_bool(q == unsafe { divdi3(n, d) })
72+
},
73+
_ => TestResult::from_bool(q == n / d),
7174
}
7275
}
7376
}
@@ -79,10 +82,11 @@ mod tests {
7982
} else {
8083
let r = super::__moddi3(n, d);
8184

82-
if let Some(moddi3) = gcc_s::moddi3() {
83-
TestResult::from_bool(r == unsafe { moddi3(n, d) })
84-
} else {
85-
TestResult::from_bool(r == n % d)
85+
match gcc_s::moddi3() {
86+
Some(moddi3) if rand::random() => {
87+
TestResult::from_bool(r == unsafe { moddi3(n, d) })
88+
},
89+
_ => TestResult::from_bool(r == n % d),
8690
}
8791
}
8892
}
@@ -95,15 +99,16 @@ mod tests {
9599
let mut r = 0;
96100
let q = super::__divmoddi4(n, d, &mut r);
97101

98-
if let Some(divmoddi4) = gcc_s::divmoddi4() {
99-
let mut gcc_s_r = 0;
100-
let gcc_s_q = unsafe {
101-
divmoddi4(n, d, &mut gcc_s_r)
102-
};
102+
match gcc_s::divmoddi4() {
103+
Some(divmoddi4) if rand::random() => {
104+
let mut gcc_s_r = 0;
105+
let gcc_s_q = unsafe {
106+
divmoddi4(n, d, &mut gcc_s_r)
107+
};
103108

104-
TestResult::from_bool(q == gcc_s_q && r == gcc_s_r)
105-
} else {
106-
TestResult::from_bool(q == n / d && r == n % d)
109+
TestResult::from_bool(q == gcc_s_q && r == gcc_s_r)
110+
},
111+
_ => TestResult::from_bool(q == n / d && r == n % d),
107112
}
108113
}
109114
}
@@ -115,10 +120,11 @@ mod tests {
115120
} else {
116121
let q = super::__divsi3(n, d);
117122

118-
if let Some(divsi3) = gcc_s::divsi3() {
119-
TestResult::from_bool(q == unsafe { divsi3(n, d)})
120-
} else {
121-
TestResult::from_bool(q == n / d)
123+
match gcc_s::divsi3() {
124+
Some(divsi3) if rand::random() => {
125+
TestResult::from_bool(q == unsafe { divsi3(n, d)})
126+
},
127+
_ => TestResult::from_bool(q == n / d),
122128
}
123129
}
124130
}
@@ -130,10 +136,11 @@ mod tests {
130136
} else {
131137
let r = super::__modsi3(n, d);
132138

133-
if let Some(modsi3) = gcc_s::modsi3() {
134-
TestResult::from_bool(r == unsafe { modsi3(n, d) })
135-
} else {
136-
TestResult::from_bool(r == n % d)
139+
match gcc_s::modsi3() {
140+
Some(modsi3) if rand::random() => {
141+
TestResult::from_bool(r == unsafe { modsi3(n, d) })
142+
},
143+
_ => TestResult::from_bool(r == n % d),
137144
}
138145
}
139146
}
@@ -146,15 +153,16 @@ mod tests {
146153
let mut r = 0;
147154
let q = super::__divmodsi4(n, d, &mut r);
148155

149-
if let Some(divmodsi4) = gcc_s::divmodsi4() {
150-
let mut gcc_s_r = 0;
151-
let gcc_s_q = unsafe {
152-
divmodsi4(n, d, &mut gcc_s_r)
153-
};
156+
match gcc_s::divmodsi4() {
157+
Some(divmodsi4) if rand::random() => {
158+
let mut gcc_s_r = 0;
159+
let gcc_s_q = unsafe {
160+
divmodsi4(n, d, &mut gcc_s_r)
161+
};
154162

155-
TestResult::from_bool(q == gcc_s_q && r == gcc_s_r)
156-
} else {
157-
TestResult::from_bool(q == n / d && r == n % d)
163+
TestResult::from_bool(q == gcc_s_q && r == gcc_s_r)
164+
},
165+
_ => TestResult::from_bool(q == n / d && r == n % d),
158166
}
159167
}
160168
}

src/int/shift.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ lshr!(__lshrdi3: u64);
6060

6161
#[cfg(test)]
6262
mod tests {
63+
use qc::{I64, U64};
64+
6365
use gcc_s;
6466
use quickcheck::TestResult;
65-
use qc::{I64, U64};
67+
use rand;
6668

6769
// NOTE We purposefully stick to `u32` for `b` here because we want "small" values (b < 64)
6870
quickcheck! {
@@ -73,10 +75,11 @@ mod tests {
7375
} else {
7476
let r = super::__ashldi3(a, b);
7577

76-
if let Some(ashldi3) = gcc_s::ashldi3() {
77-
TestResult::from_bool(r == unsafe { ashldi3(a, b) })
78-
} else {
79-
TestResult::from_bool(r == a << b)
78+
match gcc_s::ashldi3() {
79+
Some(ashldi3) if rand::random() => {
80+
TestResult::from_bool(r == unsafe { ashldi3(a, b) })
81+
},
82+
_ => TestResult::from_bool(r == a << b),
8083
}
8184
}
8285
}
@@ -88,10 +91,11 @@ mod tests {
8891
} else {
8992
let r = super::__ashrdi3(a, b);
9093

91-
if let Some(ashrdi3) = gcc_s::ashrdi3() {
92-
TestResult::from_bool(r == unsafe { ashrdi3(a, b) })
93-
} else {
94-
TestResult::from_bool(r == a >> b)
94+
match gcc_s::ashrdi3() {
95+
Some(ashrdi3) if rand::random() => {
96+
TestResult::from_bool(r == unsafe { ashrdi3(a, b) })
97+
},
98+
_ => TestResult::from_bool(r == a >> b),
9599
}
96100
}
97101
}
@@ -103,10 +107,11 @@ mod tests {
103107
} else {
104108
let r = super::__lshrdi3(a, b);
105109

106-
if let Some(lshrdi3) = gcc_s::lshrdi3() {
107-
TestResult::from_bool(r == unsafe { lshrdi3(a, b) })
108-
} else {
109-
TestResult::from_bool(r == a >> b)
110+
match gcc_s::lshrdi3() {
111+
Some(lshrdi3) if rand::random() => {
112+
TestResult::from_bool(r == unsafe { lshrdi3(a, b) })
113+
},
114+
_ => TestResult::from_bool(r == a >> b),
110115
}
111116
}
112117
}

0 commit comments

Comments
 (0)