From 97774ea7aced3a9d921dc0b8ab0e44881abfef68 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 18 Jul 2023 04:21:27 -0400 Subject: [PATCH] Begin prototyping f128 tests --- src/abis.rs | 1 + src/abis/c.rs | 8 ++++++++ src/abis/rust.rs | 10 ++++++++++ src/procgen.rs | 3 +++ src/report.rs | 4 +++- tests/normal/f128.ron | 11 +++++++++++ 6 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/normal/f128.ron diff --git a/src/abis.rs b/src/abis.rs index 6b5523b..bc9aabd 100644 --- a/src/abis.rs +++ b/src/abis.rs @@ -227,6 +227,7 @@ pub enum IntVal { pub enum FloatVal { c_double(f64), c_float(f32), + c_float128(f64), // Is there a reason to mess with `long double`? Surely not. } diff --git a/src/abis/c.rs b/src/abis/c.rs index 2bb0901..e00010c 100644 --- a/src/abis/c.rs +++ b/src/abis/c.rs @@ -610,6 +610,7 @@ impl CcAbiImpl { )); } Struct(name, _) => format!("struct {name}"), + Float(FloatVal::c_float128(_)) => "__float128".to_string(), Float(FloatVal::c_double(_)) => "double".to_string(), Float(FloatVal::c_float(_)) => "float".to_string(), Int(int_val) => match int_val { @@ -680,6 +681,13 @@ impl CcAbiImpl { output.push_str(" }"); output } + Float(FloatVal::c_float128(val)) => { + if val.fract() == 0.0 { + format!("{val}.0") + } else { + format!("{val}") + } + } Float(FloatVal::c_double(val)) => { if val.fract() == 0.0 { format!("{val}.0") diff --git a/src/abis/rust.rs b/src/abis/rust.rs index ab31bfc..afdc33d 100644 --- a/src/abis/rust.rs +++ b/src/abis/rust.rs @@ -442,6 +442,9 @@ impl RustcAbiImpl { Bool(_) => "bool".to_string(), Array(vals) => format!("[{}; {}]", self.rust_arg_type(&vals[0])?, vals.len()), Struct(name, _) => name.to_string(), + Float(FloatVal::c_float128(_)) => { + return Err(GenerateError::RustUnsupported("f128".to_owned())) + } Float(FloatVal::c_double(_)) => "f64".to_string(), Float(FloatVal::c_float(_)) => "f32".to_string(), Int(int_val) => match int_val { @@ -509,6 +512,13 @@ impl RustcAbiImpl { output.push_str(" }"); output } + Float(FloatVal::c_float128(val)) => { + if val.fract() == 0.0 { + format!("{val}.0") + } else { + format!("{val}") + } + } Float(FloatVal::c_double(val)) => { if val.fract() == 0.0 { format!("{val}.0") diff --git a/src/procgen.rs b/src/procgen.rs index 7b612cd..7cf9a9a 100644 --- a/src/procgen.rs +++ b/src/procgen.rs @@ -38,6 +38,7 @@ pub fn procgen_tests(regenerate: bool) { ("u8", &[Val::Int(IntVal::c_uint8_t(0x1a))]), ("ptr", &[Val::Ptr(0x1a2b_3c4d_23ea_f142)]), ("bool", &[Val::Bool(true)]), + ("f128", &[Val::Float(FloatVal::c_float128(809239021.392))]), ("f64", &[Val::Float(FloatVal::c_double(809239021.392))]), ("f32", &[Val::Float(FloatVal::c_float(-4921.3527))]), // These are split out because they are the buggy mess that inspired this whole enterprise! @@ -99,6 +100,7 @@ pub fn procgen_tests(regenerate: bool) { Val::Float(float_val) => match float_val { FloatVal::c_double(out) => graffiti_primitive(out, i), FloatVal::c_float(out) => graffiti_primitive(out, i), + FloatVal::c_float128(out) => graffiti_primitive(out, i), }, Val::Bool(out) => *out = true, } @@ -342,6 +344,7 @@ pub fn arg_ty(val: &Val) -> String { arg_ty(vals.get(0).expect("arrays must have length > 0")), ), Struct(name, _) => format!("struct_{name}"), + Float(FloatVal::c_float128(_)) => "f128".to_string(), Float(FloatVal::c_double(_)) => "f64".to_string(), Float(FloatVal::c_float(_)) => "f32".to_string(), Int(int_val) => match int_val { diff --git a/src/report.rs b/src/report.rs index eeec614..8f3e4b9 100644 --- a/src/report.rs +++ b/src/report.rs @@ -26,7 +26,9 @@ pub fn get_test_rules(test: &TestKey, caller: &dyn AbiImpl, callee: &dyn AbiImpl // This is Bad! Ideally we should check for all clang<->gcc pairs but to start // let's mark rust <-> C as disagreeing (because rust also disagrees with clang). if !cfg!(any(target_arch = "aarch64", target_arch = "s390x")) - && test.test_name == "ui128" && is_rust_and_c { + && test.test_name == "ui128" + && is_rust_and_c + { result.check = Busted(Check); } diff --git a/tests/normal/f128.ron b/tests/normal/f128.ron new file mode 100644 index 0000000..dbc1ad5 --- /dev/null +++ b/tests/normal/f128.ron @@ -0,0 +1,11 @@ +Test( + name: "f128", + funcs: [ + ( + name: "f128", + conventions: [c], + inputs: [Float(c_float128(5))], + output: None, + ), + ] +)