rustc_codegen_cranelift icon indicating copy to clipboard operation
rustc_codegen_cranelift copied to clipboard

Support `f16` and `f128`

Open tgross35 opened this issue 1 year ago • 3 comments

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.

tgross35 avatar Mar 01 '24 07:03 tgross35

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.

bjorn3 avatar Mar 01 '24 14:03 bjorn3

What all would be needed for clif to support these in a minimal state?

tgross35 avatar Mar 05 '24 06:03 tgross35

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.

bjorn3 avatar Mar 05 '24 10:03 bjorn3

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?

Nemo157 avatar Oct 25 '24 09:10 Nemo157

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?

tgross35 avatar Oct 25 '24 10:10 tgross35

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

Nemo157 avatar Oct 25 '24 10:10 Nemo157