Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for f128 #16

Closed
tgross35 opened this issue Jul 13, 2023 · 3 comments · Fixed by #54
Closed

Test for f128 #16

tgross35 opened this issue Jul 13, 2023 · 3 comments · Fixed by #54
Labels
enhancement New feature or request help wanted Extra attention is needed test-request Add a test to the suite for this

Comments

@tgross35
Copy link

Is a test for f128 possible? To check GCC __float128 against LLVM's fp128

@Gankra
Copy link
Owner

Gankra commented Jun 30, 2024

Oh rad, thank you for letting me know about these!

Apologies for the radio silence, I just finished rewriting all of abi-cafe to make adding new stuff way easier >.>;

@tgross35
Copy link
Author

That is awesome! We have both f16 and f128 available unstably which could be checked against _Float16 and _Float128/__float128. These come with a handful of known ABI issues already rust-lang/rust#116909 (comment)

Any chance you are planning to upstream this in to Rust's CI somehow? I know there has been a lot of interest, just nobody has figured out how to do the work.

@Gankra Gankra added enhancement New feature or request help wanted Extra attention is needed test-request Add a test to the suite for this labels Jun 30, 2024
@Gankra
Copy link
Owner

Gankra commented Jun 30, 2024

Notes on adding support for these types:

First off, the type system already contains them, everything just refuses to implement them.

Adding to rust

There are two parts to support: teaching the rust backend to generate the values, and teaching it to detect that the test uses f128/f16, and emitting a feature gate/nightly check, similar to vectorcall.

Teaching to use the values/types

PrimitiveTy::Bool => "bool",
PrimitiveTy::Ptr => "*mut ()",
PrimitiveTy::I256 => {
Err(UnsupportedError::Other("rust doesn't have i256".to_owned()))?
}
PrimitiveTy::U256 => {
Err(UnsupportedError::Other("rust doesn't have u256".to_owned()))?
}
PrimitiveTy::F16 => {
Err(UnsupportedError::Other("rust doesn't have f16".to_owned()))?
}
PrimitiveTy::F128 => {
Err(UnsupportedError::Other("rust doesn't have f128".to_owned()))?
}

write!(f, "{:#X}u64 as *mut ()", val.generate_u64())?
} else {
write!(f, "{:#X}u32 as *mut ()", val.generate_u32())?
}
}
PrimitiveTy::I256 => {
Err(UnsupportedError::Other("rust doesn't have i256".to_owned()))?
}
PrimitiveTy::U256 => {
Err(UnsupportedError::Other("rust doesn't have u256".to_owned()))?
}
PrimitiveTy::F16 => {
Err(UnsupportedError::Other("rust doesn't have f16".to_owned()))?
}
PrimitiveTy::F128 => {
Err(UnsupportedError::Other("rust doesn't have f128".to_owned()))?

Detecting the feature

Kinda spaghetti for vectorcall here. Detecting f16/f128 usage is also a bit harder.

if state.options.convention == CallingConvention::Vectorcall {
writeln!(f, "#![feature(abi_vectorcall)]")?;
}

if self.is_nightly {
"vectorcall"
} else {
return Err(UnsupportedError::Other(
"vectorcall is an unstable rust feature, requires nightly".to_owned(),
))?;

You could maybe just do a prepass on the definitions list to sniff for those types?

self.write_harness_prefix(f, state)?;
for def in state.defs.definitions(state.desired_funcs.iter().copied()) {
match def {
kdl_script::Definition::DeclareTy(ty) => {
debug!("declare ty {}", state.types.format_ty(ty));
self.intern_tyname(state, ty)?;
}
kdl_script::Definition::DefineTy(ty) => {
debug!("define ty {}", state.types.format_ty(ty));
self.generate_tydef(f, state, ty)?;

Adding to C

Essentially the exact same thing as Rust, but less "detecting nightly and setting feature-gates" and more "detecting C toolchain, emitting toolchain-specific code". See for example where convention attributes get processed:

C => "",
Cdecl => {
if self.platform == Windows {
match self.cc_flavor {
Msvc => "__cdecl ",
Gcc | Clang => "__attribute__((cdecl)) ",
}
} else {
return Err(self.unsupported_convention(&convention))?;
}
}
Stdcall => {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed test-request Add a test to the suite for this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants