diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-09-27 17:25:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-27 17:25:19 -0700 |
| commit | 937138cb90ae9327b0f7a932910c8d6080984f5c (patch) | |
| tree | 458e4beacf025609f843d2db1188f5b9bd8488d5 /src/codegen/llvm.zig | |
| parent | ab3ac1e6701431ae7dea99b23852e36b369d6b87 (diff) | |
| parent | 9763573ebb4f05eaa1c0bd5598f8dd6aee20ae9c (diff) | |
| download | zig-937138cb90ae9327b0f7a932910c8d6080984f5c.tar.gz zig-937138cb90ae9327b0f7a932910c8d6080984f5c.zip | |
Merge pull request #17248 from antlilja/abs
Replace @fabs builtin with new @abs builtin
Diffstat (limited to 'src/codegen/llvm.zig')
| -rw-r--r-- | src/codegen/llvm.zig | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index bfbcac1e73..4e6f7733fe 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -4729,6 +4729,7 @@ pub const FuncGen = struct { .div_exact => try self.airDivExact(inst, .normal), .rem => try self.airRem(inst, .normal), .mod => try self.airMod(inst, .normal), + .abs => try self.airAbs(inst), .ptr_add => try self.airPtrAdd(inst), .ptr_sub => try self.airPtrSub(inst), .shl => try self.airShl(inst), @@ -4766,7 +4767,6 @@ pub const FuncGen = struct { .log => try self.airUnaryOp(inst, .log), .log2 => try self.airUnaryOp(inst, .log2), .log10 => try self.airUnaryOp(inst, .log10), - .fabs => try self.airUnaryOp(inst, .fabs), .floor => try self.airUnaryOp(inst, .floor), .ceil => try self.airUnaryOp(inst, .ceil), .round => try self.airUnaryOp(inst, .round), @@ -8237,6 +8237,28 @@ pub const FuncGen = struct { else if (is_signed_int) .ashr else .lshr, lhs, casted_rhs, ""); } + fn airAbs(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { + const o = self.dg.object; + const mod = o.module; + const ty_op = self.air.instructions.items(.data)[inst].ty_op; + const operand = try self.resolveInst(ty_op.operand); + const operand_ty = self.typeOf(ty_op.operand); + const scalar_ty = operand_ty.scalarType(mod); + + switch (scalar_ty.zigTypeTag(mod)) { + .Int => return self.wip.callIntrinsic( + .normal, + .none, + .abs, + &.{try o.lowerType(operand_ty)}, + &.{ operand, try o.builder.intValue(.i1, 0) }, + "", + ), + .Float => return self.buildFloatOp(.fabs, .normal, operand_ty, 1, .{operand}), + else => unreachable, + } + } + fn airIntCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { const o = self.dg.object; const mod = o.module; |
