authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-17 17:29:19+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-17 23:06:46+02:00
log6235afc63207bae564725adec202fc2e7a3ba930
tree7b8ccfc2c6acf714f91671c49acff3a0d814b20d
parentf20929bd8b6cd2b0af5edade9c27a5e002480d65

stage1: fix f80 negation


2 files changed, 21 insertions(+), 7 deletions(-)

src/stage1/codegen.cpp+3-7
......@@ -4139,13 +4139,9 @@ static LLVMValueRef ir_render_binary_not(CodeGen *g, Stage1Air *executable,
41394139static LLVMValueRef ir_gen_soft_f80_neg(CodeGen *g, ZigType *op_type, LLVMValueRef operand) {
41404140 uint32_t vector_len = op_type->id == ZigTypeIdVector ? op_type->data.vector.len : 0;
41414141
4142 uint64_t buf[2] = {0, 0};
4143 if (g->is_big_endian != native_is_big_endian) {
4144 buf[1] = 0x8000000000000000;
4145 } else {
4146 buf[1] = 0x8000;
4147 }
4148 LLVMValueRef sign_mask = LLVMConstIntOfArbitraryPrecision(LLVMInt128Type(), 2, buf);
4142 LLVMTypeRef llvm_i80 = LLVMIntType(80);
4143 LLVMValueRef sign_mask = LLVMConstInt(llvm_i80, 1, false);
4144 sign_mask = LLVMConstShl(sign_mask, LLVMConstInt(llvm_i80, 79, false));
41494145
41504146 LLVMValueRef result;
41514147 if (vector_len == 0) {
test/behavior/floatop.zig+18
......@@ -448,3 +448,21 @@ fn testTrunc() !void {
448448 try expect(math.approxEqAbs(f32, @trunc(@as(f32, -0.4)), result[3], epsilon));
449449 }
450450}
451
452test "negation" {
453 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
454 if (builtin.os.tag == .freebsd) return error.SkipZigTest;
455
456 const S = struct {
457 fn doTheTest() !void {
458 inline for ([_]type{ f16, f32, f64, f80, f128 }) |T| {
459 var a: T = 1;
460 a = -a;
461 try expect(a == -1);
462 }
463 }
464 };
465
466 try S.doTheTest();
467 comptime try S.doTheTest();
468}