aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-05-12 16:41:20 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-05-12 16:41:20 -0700
commitc9cc09a3bfb45d93b84577238047cd69ef0a7d88 (patch)
tree1686cda92ae0c5d9ae55c02e7755c55d4e6f3c18 /src/Module.zig
parent71afc3088009944fcd8339ac71e69a0b77a781ab (diff)
parent40a47eae65b918866abc9d745f89d837f6a1e591 (diff)
downloadzig-c9cc09a3bfb45d93b84577238047cd69ef0a7d88.tar.gz
zig-c9cc09a3bfb45d93b84577238047cd69ef0a7d88.zip
Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts: * lib/std/os/linux.zig * lib/std/os/windows/bits.zig * src/Module.zig * src/Sema.zig * test/stage2/test.zig Mainly I wanted Jakub's new macOS code for respecting stack size, since we now depend on it for debug builds able to pass one of the test cases for recursive comptime function calls with `@setEvalBranchQuota`. The conflicts were all trivial.
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 6dc8de90aa..18dbc9222a 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -4151,6 +4151,33 @@ pub fn intDiv(allocator: *Allocator, lhs: Value, rhs: Value) !Value {
}
}
+pub fn intMul(allocator: *Allocator, lhs: Value, rhs: Value) !Value {
+ // TODO is this a performance issue? maybe we should try the operation without
+ // resorting to BigInt first.
+ var lhs_space: Value.BigIntSpace = undefined;
+ var rhs_space: Value.BigIntSpace = undefined;
+ const lhs_bigint = lhs.toBigInt(&lhs_space);
+ const rhs_bigint = rhs.toBigInt(&rhs_space);
+ const limbs = try allocator.alloc(
+ std.math.big.Limb,
+ lhs_bigint.limbs.len + rhs_bigint.limbs.len + 1,
+ );
+ var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined };
+ var limbs_buffer = try allocator.alloc(
+ std.math.big.Limb,
+ std.math.big.int.calcMulLimbsBufferLen(lhs_bigint.limbs.len, rhs_bigint.limbs.len, 1),
+ );
+ defer allocator.free(limbs_buffer);
+ result_bigint.mul(lhs_bigint, rhs_bigint, limbs_buffer, allocator);
+ const result_limbs = result_bigint.limbs[0..result_bigint.len];
+
+ if (result_bigint.positive) {
+ return Value.Tag.int_big_positive.create(allocator, result_limbs);
+ } else {
+ return Value.Tag.int_big_negative.create(allocator, result_limbs);
+ }
+}
+
pub fn floatAdd(
arena: *Allocator,
float_type: Type,
@@ -4250,6 +4277,39 @@ pub fn floatDiv(
}
}
+pub fn floatMul(
+ arena: *Allocator,
+ float_type: Type,
+ src: LazySrcLoc,
+ lhs: Value,
+ rhs: Value,
+) !Value {
+ switch (float_type.tag()) {
+ .f16 => {
+ @panic("TODO add __trunctfhf2 to compiler-rt");
+ //const lhs_val = lhs.toFloat(f16);
+ //const rhs_val = rhs.toFloat(f16);
+ //return Value.Tag.float_16.create(arena, lhs_val * rhs_val);
+ },
+ .f32 => {
+ const lhs_val = lhs.toFloat(f32);
+ const rhs_val = rhs.toFloat(f32);
+ return Value.Tag.float_32.create(arena, lhs_val * rhs_val);
+ },
+ .f64 => {
+ const lhs_val = lhs.toFloat(f64);
+ const rhs_val = rhs.toFloat(f64);
+ return Value.Tag.float_64.create(arena, lhs_val * rhs_val);
+ },
+ .f128, .comptime_float, .c_longdouble => {
+ const lhs_val = lhs.toFloat(f128);
+ const rhs_val = rhs.toFloat(f128);
+ return Value.Tag.float_128.create(arena, lhs_val * rhs_val);
+ },
+ else => unreachable,
+ }
+}
+
pub fn simplePtrType(
mod: *Module,
arena: *Allocator,