diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-06-30 17:34:05 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-30 17:34:05 -0400 |
| commit | 77a334451f1329110d6c1bd07b46813cef10e97c (patch) | |
| tree | 6708ceee35b9c7fc1c358696cd18a7b05d87bbf7 /src/codegen/c.zig | |
| parent | be18459c81f831e455750e62f37dae6aeef62f1d (diff) | |
| parent | b3b96b5e288ddf3694b4a0d203c684b9b8f6b49f (diff) | |
| download | zig-77a334451f1329110d6c1bd07b46813cef10e97c.tar.gz zig-77a334451f1329110d6c1bd07b46813cef10e97c.zip | |
Merge pull request #11967 from ziglang/runtime-float-negation
stage2: lower float negation explicitly + modify hash/eql logic for floats
Diffstat (limited to 'src/codegen/c.zig')
| -rw-r--r-- | src/codegen/c.zig | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 54c0dfb3c7..15eb917fda 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -1755,6 +1755,8 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO .mul_sat => try airSatOp(f, inst, "muls_"), .shl_sat => try airSatOp(f, inst, "shls_"), + .neg => try airNeg(f, inst), + .sqrt, .sin, .cos, @@ -4098,6 +4100,20 @@ fn airWasmMemoryGrow(f: *Function, inst: Air.Inst.Index) !CValue { return local; } +fn airNeg(f: *Function, inst: Air.Inst.Index) !CValue { + if (f.liveness.isUnused(inst)) return CValue.none; + + const un_op = f.air.instructions.items(.data)[inst].un_op; + const writer = f.object.writer(); + const inst_ty = f.air.typeOfIndex(inst); + const operand = try f.resolveInst(un_op); + const local = try f.allocLocal(inst_ty, .Const); + try writer.writeAll("-"); + try f.writeCValue(writer, operand); + try writer.writeAll(";\n"); + return local; +} + fn airMulAdd(f: *Function, inst: Air.Inst.Index) !CValue { if (f.liveness.isUnused(inst)) return CValue.none; const pl_op = f.air.instructions.items(.data)[inst].pl_op; |
