Floating-point support in RISC-V ISA
RISC-V does not mandate the support of any floating-point operations as part of the base ISA (RV32I and RV64I) but single precision and double-precision extensions (e.g. RV64F and RV64D) were among the first to be specified. The F extension added 32 floating-point registers, floating-point arithmetic operations, moves and conversions instructions. The D extension (which requires the F extension) extended this set of operation to also support double precision. There also exists a Q extension for quad-precision.
In reality, there are multiple F and D extensions: RV32F (to extend the 32-bit base ISA) and RV64F (for the 64-bit base ISA), similarly there are RV32D and RV64D. RV32D has the particularity of adding 64-bit wide floating-point registers when the associated general purpose registers are only 32-bit wide. This flexibility of RISC-V ISA is reviewed in the post RISC-V Register Files.
Initially, smaller floaitng-point formats, such as half precision, were not supported.
Half precision used to be lagging behind in term of ISA and hardware support. It was only specified has a storage format in the 2008 revision of the IEEE-754 standard (the IEEE standard specifying floating-point formats and operations). The momentum of deep learning and convolutional neural networks has kick-started a renewed interest for small number formats and in particular half precision (among many others).
Note: In the IEEE-754 2019 revision, half precision is still not defined has a basic format but as an interchange format. Although the standard is more permissive in terms of which formats can admit arithmetic operations.
RISC-V International (the association behind the RISC-V specification(s)) recently ratified two extensions specifying sets of instructions for half-precision support: Zfh and Zfhmin. The later being defined as a subset of the former, we will review Zfh first.
Zfh: full half-precision support
- Instruction to move data (with or without conversions):
- flh: load from memory into an F register
- fsh: store to memory from an F register
- fmv.h.x, fmv.x.h: bit pattern move between X and F register files (unmodified)
- fcvt.h.(w/l)[u], fcvt.(w/l)[u].h: conversions between X and F register files (from/to integer)
- Arithmetic operations: fadd.h, fsub.h, fmul.h, fsqrt.h, fdiv.h, fmin.h, fmax.h, f(n)madd/f(n)msub.h
- Floating-point comparisons: fcmp.h
- Conversions between half precision and other floating-point formats
- Miscellaneous: fclass.h, fsgn(/n/x).h
Zfhmin: reduced half-precision support
Vector support for half precision: Zvfh and Zvfhmin
Half precision in RVA22 profile
The RISC-V consortium defines profiles. These profiles aim at defining a common set of mandatory extensions and a reduced set of optional extensions which can be used by hardware and software providers to build a compatible ecosystem without having to deal with more specialized ISA extensions. Profile descriptions can be found on RISC-V github.
RVA22 is the most recent profile, it is dedicated for 64-bit application processors
Zfhmin is part of the mandatory extensions of the RVA22 profile, while Zfh is an optional extension (which supersede Zfhmin when selected). This means that all application processors targeting compatibility with the RISC-V ecosystem must have a minimal support for half precision, and than extended support is part of the extended profile. Neither of the vector extensions Zvfh nor Zvfhmin are required in the RVA22 profile.
Conclusion
Reference:
- RISC-V specification: "Zfh" and "Zfhmin" Standard Extensions for Half-Precision Floating-Point
- RISC-V RVA22 profiles https://github.com/riscv/riscv-profiles/blob/main/profiles.adoc#6-rva22-profiles
- RISC-V vector draft specification for Zvfh section
- RISC-V vector draft specification for Zvfhmin section
No comments:
Post a Comment