| ... | ... | @@ -4585,6 +4585,37 @@ pub fn intSub(allocator: *Allocator, lhs: Value, rhs: Value) !Value { |
| 4585 | 4585 | } |
| 4586 | 4586 | } |
| 4587 | 4587 | |
| 4588 | pub fn intDiv(allocator: *Allocator, lhs: Value, rhs: Value) !Value { |
| 4589 | // TODO is this a performance issue? maybe we should try the operation without |
| 4590 | // resorting to BigInt first. |
| 4591 | var lhs_space: Value.BigIntSpace = undefined; |
| 4592 | var rhs_space: Value.BigIntSpace = undefined; |
| 4593 | const lhs_bigint = lhs.toBigInt(&lhs_space); |
| 4594 | const rhs_bigint = rhs.toBigInt(&rhs_space); |
| 4595 | const limbs_q = try allocator.alloc( |
| 4596 | std.math.big.Limb, |
| 4597 | lhs_bigint.limbs.len + rhs_bigint.limbs.len + 1, |
| 4598 | ); |
| 4599 | const limbs_r = try allocator.alloc( |
| 4600 | std.math.big.Limb, |
| 4601 | lhs_bigint.limbs.len, |
| 4602 | ); |
| 4603 | const limbs_buffer = try allocator.alloc( |
| 4604 | std.math.big.Limb, |
| 4605 | std.math.big.int.calcDivLimbsBufferLen(lhs_bigint.limbs.len, rhs_bigint.limbs.len), |
| 4606 | ); |
| 4607 | var result_q = BigIntMutable{ .limbs = limbs_q, .positive = undefined, .len = undefined }; |
| 4608 | var result_r = BigIntMutable{ .limbs = limbs_r, .positive = undefined, .len = undefined }; |
| 4609 | result_q.divTrunc(&result_r, lhs_bigint, rhs_bigint, limbs_buffer, null); |
| 4610 | const result_limbs = result_q.limbs[0..result_q.len]; |
| 4611 | |
| 4612 | if (result_q.positive) { |
| 4613 | return Value.Tag.int_big_positive.create(allocator, result_limbs); |
| 4614 | } else { |
| 4615 | return Value.Tag.int_big_negative.create(allocator, result_limbs); |
| 4616 | } |
| 4617 | } |
| 4618 | |
| 4588 | 4619 | pub fn floatAdd( |
| 4589 | 4620 | arena: *Allocator, |
| 4590 | 4621 | float_type: Type, |
| ... | ... | @@ -4651,6 +4682,39 @@ pub fn floatSub( |
| 4651 | 4682 | } |
| 4652 | 4683 | } |
| 4653 | 4684 | |
| 4685 | pub fn floatDiv( |
| 4686 | arena: *Allocator, |
| 4687 | float_type: Type, |
| 4688 | src: LazySrcLoc, |
| 4689 | lhs: Value, |
| 4690 | rhs: Value, |
| 4691 | ) !Value { |
| 4692 | switch (float_type.tag()) { |
| 4693 | .f16 => { |
| 4694 | @panic("TODO add __trunctfhf2 to compiler-rt"); |
| 4695 | //const lhs_val = lhs.toFloat(f16); |
| 4696 | //const rhs_val = rhs.toFloat(f16); |
| 4697 | //return Value.Tag.float_16.create(arena, lhs_val / rhs_val); |
| 4698 | }, |
| 4699 | .f32 => { |
| 4700 | const lhs_val = lhs.toFloat(f32); |
| 4701 | const rhs_val = rhs.toFloat(f32); |
| 4702 | return Value.Tag.float_32.create(arena, lhs_val / rhs_val); |
| 4703 | }, |
| 4704 | .f64 => { |
| 4705 | const lhs_val = lhs.toFloat(f64); |
| 4706 | const rhs_val = rhs.toFloat(f64); |
| 4707 | return Value.Tag.float_64.create(arena, lhs_val / rhs_val); |
| 4708 | }, |
| 4709 | .f128, .comptime_float, .c_longdouble => { |
| 4710 | const lhs_val = lhs.toFloat(f128); |
| 4711 | const rhs_val = rhs.toFloat(f128); |
| 4712 | return Value.Tag.float_128.create(arena, lhs_val / rhs_val); |
| 4713 | }, |
| 4714 | else => unreachable, |
| 4715 | } |
| 4716 | } |
| 4717 | |
| 4654 | 4718 | pub fn simplePtrType( |
| 4655 | 4719 | mod: *Module, |
| 4656 | 4720 | arena: *Allocator, |