authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-17 22:01:19-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-17 22:01:19-04:00
log2173e1f457f49990313e1ad038187af8a78205ab
tree187401e5d1294f234efd9f7747c5e0cc860cc141
parente63d864c1ee343dff13b1e165079e092ee93e273

fix big integer shifting by large number


4 files changed, 23 insertions(+), 2 deletions(-)

src/bigint.cpp+1-1
......@@ -826,7 +826,7 @@ void bigint_shl(BigInt *dest, const BigInt *op1, const BigInt *op2) {
826826 const uint64_t *op1_digits = bigint_ptr(op1);
827827 uint64_t shift_amt = bigint_as_unsigned(op2);
828828
829 if (op1->digit_count == 1) {
829 if (op1->digit_count == 1 && shift_amt < 64) {
830830 dest->data.digit = op1_digits[0] << shift_amt;
831831 if (dest->data.digit > op1_digits[0]) {
832832 dest->digit_count = 1;
src/codegen.cpp+11
......@@ -3852,6 +3852,10 @@ static void build_all_basic_blocks(CodeGen *g, FnTableEntry *fn) {
38523852static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef init_val,
38533853 TypeTableEntry *type_entry)
38543854{
3855 if (g->strip_debug_symbols) {
3856 return;
3857 }
3858
38553859 assert(var->gen_is_const);
38563860 assert(type_entry);
38573861
......@@ -3863,6 +3867,7 @@ static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef ini
38633867 buf_ptr(&var->name), import->di_file,
38643868 (unsigned)(var->decl_node->line + 1),
38653869 type_entry->di_type, is_local_to_unit);
3870
38663871 // TODO ^^ make an actual global variable
38673872}
38683873
......@@ -5127,6 +5132,12 @@ static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {
51275132 case 64:
51285133 buf_init_from_str(out_buf, "double");
51295134 break;
5135 case 80:
5136 buf_init_from_str(out_buf, "__float80");
5137 break;
5138 case 128:
5139 buf_init_from_str(out_buf, "__float128");
5140 break;
51305141 default:
51315142 zig_unreachable();
51325143 }
std/special/compiler_rt/comparetf2.zig-1
......@@ -68,7 +68,6 @@ const GE_GREATER = c_int(1);
6868const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED
6969
7070export fn __getf2(a: f128, b: f128) -> c_int {
71
7271 const aInt = @bitCast(srep_t, a);
7372 const bInt = @bitCast(srep_t, b);
7473 const aAbs = @bitCast(rep_t, aInt) & absMask;
test/cases/math.zig+11
......@@ -313,6 +313,12 @@ test "big number multiplication" {
313313 }
314314}
315315
316test "big number shifting" {
317 comptime {
318 assert((u128(1) << 127) == 0x80000000000000000000000000000000);
319 }
320}
321
316322test "f128" {
317323 test_f128();
318324 comptime test_f128();
......@@ -327,4 +333,9 @@ fn test_f128() {
327333 assert(make_f128(1.0) > 0.9);
328334 assert(make_f128(1.0) >= 0.9);
329335 assert(make_f128(1.0) >= 1.0);
336 should_not_be_zero(1.0);
337}
338
339fn should_not_be_zero(x: f128) {
340 assert(x != 0.0);
330341}