Enable f16 and f128 in assembly on platforms that support it · Issue #125398 · rust-lang/rust (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

@tgross35

Description

@tgross35

The below should work, but errors that f16 is not usable for registers:

#![feature(f16, f128)]

use core::arch::asm;

#[inline(never)] pub fn f32_to_f16(a: f32) -> f16 { a as f16 }

#[inline(never)] pub fn f32_to_f16_asm(a: f32) -> f16 { let ret: f16; unsafe { asm!( "fcvt {ret:h}, {a:s}", a = in(vreg) a, ret = lateout(vreg) ret, options(nomem, nostack), ); }

ret

}

On aarch64 the first function generates:

example::f32_to_f16::hc897184dfb47f3d6: fcvt h0, s0 ret

f16 types should be supported as a vreg on aarch64 in order to reproduce that code.


The following other platforms also apparently have some level of instruction support, but are less well documented:

Additionally, for f128:

Tracking issue: #116909