diff options
| author | Matthew Lugg <mlugg@mlugg.co.uk> | 2025-11-13 10:18:01 +0000 |
|---|---|---|
| committer | Matthew Lugg <mlugg@mlugg.co.uk> | 2025-11-15 09:49:01 +0000 |
| commit | bc78d8efdb90c77670c30474071942f093a2427f (patch) | |
| tree | 21038abbc15d9e4c037b5e9981274d741659a332 /src/codegen/aarch64/Select.zig | |
| parent | 9c45a87490dab538ee480549d3194e946f2ae6b2 (diff) | |
| download | zig-bc78d8efdb90c77670c30474071942f093a2427f.tar.gz zig-bc78d8efdb90c77670c30474071942f093a2427f.zip | |
Legalize: implement soft-float legalizations
A new `Legalize.Feature` tag is introduced for each float bit width
(16/32/64/80/128). When e.g. `soft_f16` is enabled, all arithmetic and
comparison operations on `f16` are converted to calls to the appropriate
compiler_rt function using the new AIR tag `.legalize_compiler_rt_call`.
This includes casts where the source *or* target type is `f16`, or
integer<=>float conversions to or from `f16`. Occasionally, operations
are legalized to blocks because there is extra code required; for
instance, legalizing `@floatFromInt` where the integer type is larger
than 64 bits requires calling an arbitrary-width integer conversion
function which accepts a pointer to the integer, so we need to use
`alloc` to create such a pointer, and store the integer there (after
possibly zero-extending or sign-extending it).
No backend currently uses these new legalizations (and as such, no
backend currently needs to implement `.legalize_compiler_rt_call`).
However, for testing purposes, I tried modifying the self-hosted x86_64
backend to enable all of the soft-float features (and implement the AIR
instruction). This modified backend was able to pass all of the behavior
tests (except for one `@mod` test where the LLVM backend has a bug
resulting in incorrect compiler-rt behavior!), including the tests
specific to the self-hosted x86_64 backend.
`f16` and `f80` legalizations are likely of particular interest to
backend developers, because most architectures do not have instructions
to operate on these types. However, enabling *all* of these legalization
passes can be useful when developing a new backend to hit the ground
running and pass a good amount of tests more easily.
Diffstat (limited to 'src/codegen/aarch64/Select.zig')
| -rw-r--r-- | src/codegen/aarch64/Select.zig | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/codegen/aarch64/Select.zig b/src/codegen/aarch64/Select.zig index 64aeeb7ff4..b19f6f77cc 100644 --- a/src/codegen/aarch64/Select.zig +++ b/src/codegen/aarch64/Select.zig @@ -137,6 +137,8 @@ pub fn analyze(isel: *Select, air_body: []const Air.Inst.Index) !void { // No "scalarize" legalizations are enabled, so these instructions never appear. .legalize_vec_elem_val => unreachable, .legalize_vec_store_elem => unreachable, + // No soft float legalizations are enabled. + .legalize_compiler_rt_call => unreachable, .arg, .ret_addr, |
