rustc_codegen_cranelift
rustc_codegen_cranelift copied to clipboard
Support `f16` and `f128`
As of https://github.com/rust-lang/rust/pull/121728, the backends now have stubs for f16 and f128: https://github.com/rust-lang/rust/blob/6cbf0926d54c80ea6d15df333be9281f65bbeb36/compiler/rustc_codegen_cranelift/src/common.rs#L36-L39.
It will be a while before these codepaths can even be exercised since the frontend isn't hooked up yet, but at some point this should be changed to either gracefully fail or do the right thing.
This will need direct Cranelift support. Back ib the day before Cranelift had native 128bit int support I had a whole bunch of hacks to make it work. They were really fragile and I don't think they will work anymore for the current structure of cg_clif.
What all would be needed for clif to support these in a minimal state?
At a minimum Cranelift support for the f16 and f128 values. And either Cranelift support for float instructions for these types or emulation in cg_clif using libm calls in https://github.com/rust-lang/rustc_codegen_cranelift/blob/8c46d93ca0f287ea3b284c061eebcb4a275fc43a/src/num.rs#L313-L363 and https://github.com/rust-lang/rustc_codegen_cranelift/blob/8c46d93ca0f287ea3b284c061eebcb4a275fc43a/src/intrinsics/mod.rs#L309-L349.
It seems like the frontend is now hooked up and this is used in some sysroot crates like compiler-builtins so using -Zbuild-std with cranelift fails, is there some way to avoid this now?
compiler-builtins has the no-f16-f128 feature to disable both of these https://github.com/rust-lang/compiler-builtins/blob/adaef3265c560998a03b6902bd63d88009d3a132/Cargo.toml#L55, and then std carries a flag to propagate that https://github.com/rust-lang/rust/blob/017ae1b21f7be6dcdcfc95631e54bde806653a8a/library/std/Cargo.toml#L103. Maybe there is a way to automatically set this flag based on codegen backend in build-std?
Ah yes, I'd found the compiler-builtins feature but missed the std one, this works now:
export CARGO_UNSTABLE_BUILD_STD_FEATURES=compiler-builtins-no-f16-f128
export CARGO_UNSTABLE_BUILD_STD=std,panic_abort