authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-08-25 06:56:41+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-09-10 08:53:30+02:00
log68367999351663421939d17c87af8269c824c1b0
tree21e4396b927272a42275ea4734c04affc7606276
parent92517fbd625b1f6d6162ce2875ef167701b99733
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

llvm: Set use-soft-float and noimplicitfloat on functions for soft float.

Closes #10961.

1 files changed, 24 insertions(+), 0 deletions(-)

src/codegen/llvm.zig+24
...@@ -3108,6 +3108,30 @@ pub const Object = struct {...@@ -3108,6 +3108,30 @@ pub const Object = struct {
3108 .value = .empty,3108 .value = .empty,
3109 } }, &o.builder);3109 } }, &o.builder);
3110 }3110 }
3111 if (target.floatAbi() == .soft) {
3112 // `use-soft-float` means "use software routines for floating point computations". In
3113 // other words, it configures how LLVM lowers basic float instructions like `fcmp`,
3114 // `fadd`, etc. The float calling convention is configured on `TargetMachine` and is
3115 // mostly an orthogonal concept, although obviously we do need hardware float operations
3116 // to actually be able to pass float values in float registers.
3117 //
3118 // Ideally, we would support something akin to the `-mfloat-abi=softfp` option that GCC
3119 // and Clang support for Arm32 and CSKY. We don't currently expose such an option in
3120 // Zig, and using CPU features as the source of truth for this makes for a miserable
3121 // user experience since people expect e.g. `arm-linux-gnueabi` to mean full soft float
3122 // unless the compiler has explicitly been told otherwise. (And note that our baseline
3123 // CPU models almost all include FPU features!)
3124 //
3125 // Revisit this at some point.
3126 try attributes.addFnAttr(.{ .string = .{
3127 .kind = try o.builder.string("use-soft-float"),
3128 .value = try o.builder.string("true"),
3129 } }, &o.builder);
3130
3131 // This prevents LLVM from using FPU/SIMD code for things like `memcpy`. As for the
3132 // above, this should be revisited if `softfp` support is added.
3133 try attributes.addFnAttr(.noimplicitfloat, &o.builder);
3134 }
3111 }3135 }
31123136
3113 fn resolveGlobalUav(3137 fn resolveGlobalUav(