adjust the check! macro to accept AAPCS intrinsics

master
Jorge Aparicio 2017-02-07 23:07:51 -05:00
parent 57085be2ea
commit 47b45d1d62
7 changed files with 52 additions and 34 deletions

View File

@ -203,14 +203,14 @@ mod tests {
use qc::{F32, F64}; use qc::{F32, F64};
check! { check! {
fn __addsf3(f: extern fn(f32, f32) -> f32, fn __addsf3(f: extern "C" fn(f32, f32) -> f32,
a: F32, a: F32,
b: F32) b: F32)
-> Option<F32> { -> Option<F32> {
Some(F32(f(a.0, b.0))) Some(F32(f(a.0, b.0)))
} }
fn __adddf3(f: extern fn(f64, f64) -> f64, fn __adddf3(f: extern "C" fn(f64, f64) -> f64,
a: F64, a: F64,
b: F64) -> Option<F64> { b: F64) -> Option<F64> {
Some(F64(f(a.0, b.0))) Some(F64(f(a.0, b.0)))

View File

@ -34,13 +34,13 @@ mod tests {
use qc::{I32, F32, F64}; use qc::{I32, F32, F64};
check! { check! {
fn __powisf2(f: extern fn(f32, i32) -> f32, fn __powisf2(f: extern "C" fn(f32, i32) -> f32,
a: F32, a: F32,
b: I32) -> Option<F32> { b: I32) -> Option<F32> {
Some(F32(f(a.0, b.0))) Some(F32(f(a.0, b.0)))
} }
fn __powidf2(f: extern fn(f64, i32) -> f64, fn __powidf2(f: extern "C" fn(f64, i32) -> f64,
a: F64, a: F64,
b: I32) -> Option<F64> { b: I32) -> Option<F64> {
Some(F64(f(a.0, b.0))) Some(F64(f(a.0, b.0)))

View File

@ -99,12 +99,12 @@ mod tests {
use qc::{I32, I64, U64}; use qc::{I32, I64, U64};
check! { check! {
fn __muldi3(f: extern fn(u64, u64) -> u64, a: U64, b: U64) fn __muldi3(f: extern "C" fn(u64, u64) -> u64, a: U64, b: U64)
-> Option<u64> { -> Option<u64> {
Some(f(a.0, b.0)) Some(f(a.0, b.0))
} }
fn __mulosi4(f: extern fn(i32, i32, &mut i32) -> i32, fn __mulosi4(f: extern "C" fn(i32, i32, &mut i32) -> i32,
a: I32, a: I32,
b: I32) -> Option<(i32, i32)> { b: I32) -> Option<(i32, i32)> {
let (a, b) = (a.0, b.0); let (a, b) = (a.0, b.0);
@ -116,7 +116,7 @@ mod tests {
Some((r, overflow)) Some((r, overflow))
} }
fn __mulodi4(f: extern fn(i64, i64, &mut i32) -> i64, fn __mulodi4(f: extern "C" fn(i64, i64, &mut i32) -> i64,
a: I64, a: I64,
b: I64) -> Option<(i64, i32)> { b: I64) -> Option<(i64, i32)> {
let (a, b) = (a.0, b.0); let (a, b) = (a.0, b.0);
@ -139,11 +139,11 @@ mod tests_i128 {
use qc::I128; use qc::I128;
check! { check! {
fn __multi3(f: extern fn(i128, i128) -> i128, a: I128, b: I128) fn __multi3(f: extern "C" fn(i128, i128) -> i128, a: I128, b: I128)
-> Option<i128> { -> Option<i128> {
Some(f(a.0, b.0)) Some(f(a.0, b.0))
} }
fn __muloti4(f: extern fn(i128, i128, &mut i32) -> i128, fn __muloti4(f: extern "C" fn(i128, i128, &mut i32) -> i128,
a: I128, a: I128,
b: I128) -> Option<(i128, i32)> { b: I128) -> Option<(i128, i32)> {
let (a, b) = (a.0, b.0); let (a, b) = (a.0, b.0);

View File

@ -99,7 +99,7 @@ mod tests {
use qc::{U32, U64}; use qc::{U32, U64};
check! { check! {
fn __divdi3(f: extern fn(i64, i64) -> i64, n: U64, d: U64) -> Option<i64> { fn __divdi3(f: extern "C" fn(i64, i64) -> i64, n: U64, d: U64) -> Option<i64> {
let (n, d) = (n.0 as i64, d.0 as i64); let (n, d) = (n.0 as i64, d.0 as i64);
if d == 0 { if d == 0 {
None None
@ -108,7 +108,7 @@ mod tests {
} }
} }
fn __moddi3(f: extern fn(i64, i64) -> i64, n: U64, d: U64) -> Option<i64> { fn __moddi3(f: extern "C" fn(i64, i64) -> i64, n: U64, d: U64) -> Option<i64> {
let (n, d) = (n.0 as i64, d.0 as i64); let (n, d) = (n.0 as i64, d.0 as i64);
if d == 0 { if d == 0 {
None None
@ -117,7 +117,8 @@ mod tests {
} }
} }
fn __divmoddi4(f: extern fn(i64, i64, &mut i64) -> i64, #[cfg(target_arch = "arm")]
fn __divmoddi4(f: extern "aapcs" fn(i64, i64, &mut i64) -> i64,
n: U64, n: U64,
d: U64) -> Option<(i64, i64)> { d: U64) -> Option<(i64, i64)> {
let (n, d) = (n.0 as i64, d.0 as i64); let (n, d) = (n.0 as i64, d.0 as i64);
@ -130,7 +131,21 @@ mod tests {
} }
} }
fn __divsi3(f: extern fn(i32, i32) -> i32, #[cfg(not(target_arch = "arm"))]
fn __divmoddi4(f: extern "C" fn(i64, i64, &mut i64) -> i64,
n: U64,
d: U64) -> Option<(i64, i64)> {
let (n, d) = (n.0 as i64, d.0 as i64);
if d == 0 {
None
} else {
let mut r = 0;
let q = f(n, d, &mut r);
Some((q, r))
}
}
fn __divsi3(f: extern "C" fn(i32, i32) -> i32,
n: U32, n: U32,
d: U32) -> Option<i32> { d: U32) -> Option<i32> {
let (n, d) = (n.0 as i32, d.0 as i32); let (n, d) = (n.0 as i32, d.0 as i32);
@ -141,7 +156,7 @@ mod tests {
} }
} }
fn __modsi3(f: extern fn(i32, i32) -> i32, fn __modsi3(f: extern "C" fn(i32, i32) -> i32,
n: U32, n: U32,
d: U32) -> Option<i32> { d: U32) -> Option<i32> {
let (n, d) = (n.0 as i32, d.0 as i32); let (n, d) = (n.0 as i32, d.0 as i32);
@ -152,7 +167,7 @@ mod tests {
} }
} }
fn __divmodsi4(f: extern fn(i32, i32, &mut i32) -> i32, fn __divmodsi4(f: extern "C" fn(i32, i32, &mut i32) -> i32,
n: U32, n: U32,
d: U32) -> Option<(i32, i32)> { d: U32) -> Option<(i32, i32)> {
let (n, d) = (n.0 as i32, d.0 as i32); let (n, d) = (n.0 as i32, d.0 as i32);
@ -176,7 +191,7 @@ mod tests_i128 {
use qc::U128; use qc::U128;
check! { check! {
fn __divti3(f: extern fn(i128, i128) -> i128, n: U128, d: U128) -> Option<i128> { fn __divti3(f: extern "C" fn(i128, i128) -> i128, n: U128, d: U128) -> Option<i128> {
let (n, d) = (n.0 as i128, d.0 as i128); let (n, d) = (n.0 as i128, d.0 as i128);
if d == 0 { if d == 0 {
None None
@ -185,7 +200,7 @@ mod tests_i128 {
} }
} }
fn __modti3(f: extern fn(i128, i128) -> i128, n: U128, d: U128) -> Option<i128> { fn __modti3(f: extern "C" fn(i128, i128) -> i128, n: U128, d: U128) -> Option<i128> {
let (n, d) = (n.0 as i128, d.0 as i128); let (n, d) = (n.0 as i128, d.0 as i128);
if d == 0 { if d == 0 {
None None

View File

@ -79,7 +79,7 @@ mod tests {
// NOTE We purposefully stick to `u32` for `b` here because we want "small" values (b < 64) // NOTE We purposefully stick to `u32` for `b` here because we want "small" values (b < 64)
check! { check! {
fn __ashldi3(f: extern fn(u64, u32) -> u64, a: U64, b: u32) -> Option<u64> { fn __ashldi3(f: extern "C" fn(u64, u32) -> u64, a: U64, b: u32) -> Option<u64> {
let a = a.0; let a = a.0;
if b >= 64 { if b >= 64 {
None None
@ -88,7 +88,7 @@ mod tests {
} }
} }
fn __ashrdi3(f: extern fn(i64, u32) -> i64, a: I64, b: u32) -> Option<i64> { fn __ashrdi3(f: extern "C" fn(i64, u32) -> i64, a: I64, b: u32) -> Option<i64> {
let a = a.0; let a = a.0;
if b >= 64 { if b >= 64 {
None None
@ -97,7 +97,7 @@ mod tests {
} }
} }
fn __lshrdi3(f: extern fn(u64, u32) -> u64, a: U64, b: u32) -> Option<u64> { fn __lshrdi3(f: extern "C" fn(u64, u32) -> u64, a: U64, b: u32) -> Option<u64> {
let a = a.0; let a = a.0;
if b >= 64 { if b >= 64 {
None None
@ -118,7 +118,7 @@ mod tests_i128 {
// NOTE We purposefully stick to `u32` for `b` here because we want "small" values (b < 64) // NOTE We purposefully stick to `u32` for `b` here because we want "small" values (b < 64)
check! { check! {
fn __ashlti3(f: extern fn(u128, u32) -> u128, a: U128, b: u32) -> Option<u128> { fn __ashlti3(f: extern "C" fn(u128, u32) -> u128, a: U128, b: u32) -> Option<u128> {
let a = a.0; let a = a.0;
if b >= 64 { if b >= 64 {
None None
@ -127,7 +127,7 @@ mod tests_i128 {
} }
} }
fn __ashrti3(f: extern fn(i128, u32) -> i128, a: I128, b: u32) -> Option<i128> { fn __ashrti3(f: extern "C" fn(i128, u32) -> i128, a: I128, b: u32) -> Option<i128> {
let a = a.0; let a = a.0;
if b >= 64 { if b >= 64 {
None None
@ -136,7 +136,7 @@ mod tests_i128 {
} }
} }
fn __lshrti3(f: extern fn(u128, u32) -> u128, a: U128, b: u32) -> Option<u128> { fn __lshrti3(f: extern "C" fn(u128, u32) -> u128, a: U128, b: u32) -> Option<u128> {
let a = a.0; let a = a.0;
if b >= 128 { if b >= 128 {
None None

View File

@ -318,7 +318,7 @@ mod tests {
use qc::{U32, U64}; use qc::{U32, U64};
check! { check! {
fn __udivdi3(f: extern fn(u64, u64) -> u64, n: U64, d: U64) -> Option<u64> { fn __udivdi3(f: extern "C" fn(u64, u64) -> u64, n: U64, d: U64) -> Option<u64> {
let (n, d) = (n.0, d.0); let (n, d) = (n.0, d.0);
if d == 0 { if d == 0 {
None None
@ -327,7 +327,7 @@ mod tests {
} }
} }
fn __umoddi3(f: extern fn(u64, u64) -> u64, n: U64, d: U64) -> Option<u64> { fn __umoddi3(f: extern "C" fn(u64, u64) -> u64, n: U64, d: U64) -> Option<u64> {
let (n, d) = (n.0, d.0); let (n, d) = (n.0, d.0);
if d == 0 { if d == 0 {
None None
@ -336,7 +336,7 @@ mod tests {
} }
} }
fn __udivmoddi4(f: extern fn(u64, u64, Option<&mut u64>) -> u64, fn __udivmoddi4(f: extern "C" fn(u64, u64, Option<&mut u64>) -> u64,
n: U64, n: U64,
d: U64) -> Option<(u64, u64)> { d: U64) -> Option<(u64, u64)> {
let (n, d) = (n.0, d.0); let (n, d) = (n.0, d.0);
@ -349,7 +349,7 @@ mod tests {
} }
} }
fn __udivsi3(f: extern fn(u32, u32) -> u32, n: U32, d: U32) -> Option<u32> { fn __udivsi3(f: extern "C" fn(u32, u32) -> u32, n: U32, d: U32) -> Option<u32> {
let (n, d) = (n.0, d.0); let (n, d) = (n.0, d.0);
if d == 0 { if d == 0 {
None None
@ -358,7 +358,7 @@ mod tests {
} }
} }
fn __umodsi3(f: extern fn(u32, u32) -> u32, n: U32, d: U32) -> Option<u32> { fn __umodsi3(f: extern "C" fn(u32, u32) -> u32, n: U32, d: U32) -> Option<u32> {
let (n, d) = (n.0, d.0); let (n, d) = (n.0, d.0);
if d == 0 { if d == 0 {
None None
@ -367,7 +367,7 @@ mod tests {
} }
} }
fn __udivmodsi4(f: extern fn(u32, u32, Option<&mut u32>) -> u32, fn __udivmodsi4(f: extern "C" fn(u32, u32, Option<&mut u32>) -> u32,
n: U32, n: U32,
d: U32) -> Option<(u32, u32)> { d: U32) -> Option<(u32, u32)> {
let (n, d) = (n.0, d.0); let (n, d) = (n.0, d.0);
@ -391,7 +391,7 @@ mod tests_i128 {
use qc::U128; use qc::U128;
check! { check! {
fn __udivti3(f: extern fn(u128, u128) -> u128, fn __udivti3(f: extern "C" fn(u128, u128) -> u128,
n: U128, n: U128,
d: U128) -> Option<u128> { d: U128) -> Option<u128> {
let (n, d) = (n.0, d.0); let (n, d) = (n.0, d.0);
@ -402,7 +402,7 @@ mod tests_i128 {
} }
} }
fn __umodti3(f: extern fn(u128, u128) -> u128, fn __umodti3(f: extern "C" fn(u128, u128) -> u128,
n: U128, n: U128,
d: U128) -> Option<u128> { d: U128) -> Option<u128> {
let (n, d) = (n.0, d.0); let (n, d) = (n.0, d.0);
@ -413,7 +413,7 @@ mod tests_i128 {
} }
} }
fn __udivmodti4(f: extern fn(u128, u128, Option<&mut u128>) -> u128, fn __udivmodti4(f: extern "C" fn(u128, u128, Option<&mut u128>) -> u128,
n: U128, n: U128,
d: U128) -> Option<u128> { d: U128) -> Option<u128> {
let (n, d) = (n.0, d.0); let (n, d) = (n.0, d.0);

View File

@ -240,7 +240,8 @@ arbitrary_float!(F64: f64);
// fails. // fails.
macro_rules! check { macro_rules! check {
($( ($(
fn $name:ident($f:ident: extern fn($($farg:ty),*) -> $fret:ty, $(#[$cfg:meta])*
fn $name:ident($f:ident: extern $abi:tt fn($($farg:ty),*) -> $fret:ty,
$($arg:ident: $t:ty),*) $($arg:ident: $t:ty),*)
-> Option<$ret:ty> -> Option<$ret:ty>
{ {
@ -248,7 +249,8 @@ macro_rules! check {
} }
)*) => ( )*) => (
$( $(
fn $name($f: extern fn($($farg),*) -> $fret, $(#[$cfg])*
fn $name($f: extern $abi fn($($farg),*) -> $fret,
$($arg: $t),*) -> Option<$ret> { $($arg: $t),*) -> Option<$ret> {
$($code)* $($code)*
} }
@ -260,6 +262,7 @@ macro_rules! check {
use quickcheck::TestResult; use quickcheck::TestResult;
$( $(
$(#[$cfg])*
#[test] #[test]
fn $name() { fn $name() {
fn my_check($($arg:$t),*) -> TestResult { fn my_check($($arg:$t),*) -> TestResult {