Fix array comparisons and fix f32 literal LLVM issue regarding accurate representation

This commit is contained in:
gingerBill
2019-07-27 11:33:22 +01:00
parent 14059583cd
commit 912fc2890b
2 changed files with 32 additions and 12 deletions

View File

@@ -3652,12 +3652,12 @@ struct irLoopData {
irBlock *loop;
};
irLoopData ir_loop_start(irProcedure *proc, isize count) {
irLoopData ir_loop_start(irProcedure *proc, isize count, Type *index_type=t_int) {
irLoopData data = {};
irValue *max = ir_const_int(count);
data.idx_addr = ir_add_local_generated(proc, t_int, true);
data.idx_addr = ir_add_local_generated(proc, index_type, true);
data.body = ir_new_block(proc, nullptr, "loop.body");
data.done = ir_new_block(proc, nullptr, "loop.done");
@@ -3727,7 +3727,7 @@ irValue *ir_emit_unary_arith(irProcedure *proc, TokenKind op, irValue *x, Type *
ir_emit_store(proc, ir_emit_array_epi(proc, res, i), z);
}
} else {
auto loop_data = ir_loop_start(proc, count);
auto loop_data = ir_loop_start(proc, count, t_i32);
irValue *e = ir_emit_load(proc, ir_emit_array_ep(proc, val, loop_data.idx));
irValue *z = ir_emit_unary_arith(proc, op, e, elem_type);
@@ -3786,7 +3786,7 @@ irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue *
ir_emit_store(proc, ir_emit_array_epi(proc, res, i), z);
}
} else {
auto loop_data = ir_loop_start(proc, count);
auto loop_data = ir_loop_start(proc, count, t_i32);
irValue *x = ir_emit_load(proc, ir_emit_array_ep(proc, lhs, loop_data.idx));
irValue *y = ir_emit_load(proc, ir_emit_array_ep(proc, rhs, loop_data.idx));
@@ -4104,6 +4104,9 @@ irValue *ir_emit_comp(irProcedure *proc, TokenKind op_kind, irValue *left, irVal
if (op_kind == Token_NotEq) {
res = v_false;
cmp_op = Token_Or;
} else if (op_kind == Token_CmpEq) {
res = v_true;
cmp_op = Token_And;
}
bool inline_array_arith = type_size_of(tl) <= build_context.max_align;
@@ -4125,12 +4128,13 @@ irValue *ir_emit_comp(irProcedure *proc, TokenKind op_kind, irValue *left, irVal
} else {
irValue *val = ir_add_local_generated(proc, t_bool, false);
ir_emit_store(proc, val, res);
auto loop_data = ir_loop_start(proc, count);
auto loop_data = ir_loop_start(proc, count, t_i32);
{
irValue *x = ir_emit_load(proc, ir_emit_array_ep(proc, lhs, loop_data.idx));
irValue *y = ir_emit_load(proc, ir_emit_array_ep(proc, rhs, loop_data.idx));
irValue *i = loop_data.idx;
irValue *x = ir_emit_load(proc, ir_emit_array_ep(proc, lhs, i));
irValue *y = ir_emit_load(proc, ir_emit_array_ep(proc, rhs, i));
irValue *cmp = ir_emit_comp(proc, op_kind, x, y);
irValue *new_res = ir_emit_arith(proc, cmp_op, res, ir_emit_load(proc, val), t_bool);
irValue *new_res = ir_emit_arith(proc, cmp_op, ir_emit_load(proc, val), cmp, t_bool);
ir_emit_store(proc, val, ir_emit_conv(proc, new_res, t_bool));
}
ir_loop_end(proc, loop_data);

View File

@@ -767,15 +767,17 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type *
case ExactValue_Float: {
GB_ASSERT_MSG(is_type_float(type), "%s", type_to_string(type));
type = core_type(type);
u64 u = bit_cast<u64>(value.value_float);
u64 u_64 = bit_cast<u64>(value.value_float);
u32 u_32 = bit_cast<u32>(cast(f32)value.value_float);
#if 0
switch (type->Basic.kind) {
case Basic_f32:
// IMPORTANT NOTE(bill): LLVM requires all floating point constants to be
// a 64 bit number if bits_of(float type) <= 64.
// https://groups.google.com/forum/#!topic/llvm-dev/IlqV3TbSk6M
// 64 bit mantissa: 52 bits
// 32 bit mantissa: 23 bits
// 16 bit mantissa: 10 bits
// 64 bit mantissa: 52 bits ==> 52-52 == 0
// 32 bit mantissa: 23 bits ==> 52-23 == 29
// 16 bit mantissa: 10 bits ==> 52=10 == 42
// 29 == 52-23
u >>= 29;
u <<= 29;
@@ -792,6 +794,20 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type *
ir_fprintf(f, "0x%016llx", u);
break;
}
#else
switch (type->Basic.kind) {
case Basic_f32: {
ir_fprintf(f, "bitcast (i32 %u to float)", u_32);
break;
}
case Basic_f64:
ir_fprintf(f, "0x%016llx", u_64);
break;
default:
ir_fprintf(f, "0x%016llx", u_64);
break;
}
#endif
break;
}
case ExactValue_Complex: {