diff options
| author | gingerBill <bill@gingerbill.org> | 2020-11-23 19:14:36 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-11-23 19:14:36 +0000 |
| commit | a55568b0c480b8a4ba7cf2f24ff2bb41cfc759ff (patch) | |
| tree | 7f2634130ec16da3655fe292f036173abe4c64c2 /src | |
| parent | b08ec005b29c28917cfe6ae664dcdb7b97f8f6b6 (diff) | |
Make hash internal key be `uintptr` rather than `u64` to reduce entry size
Diffstat (limited to 'src')
| -rw-r--r-- | src/ir.cpp | 5 | ||||
| -rw-r--r-- | src/llvm_backend.cpp | 6 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index e9f0b5647..b545e7ce3 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -3624,7 +3624,10 @@ irValue *ir_gen_map_hash(irProcedure *proc, irValue *key, Type *key_type) { ExactValue ev = str->Constant.value; GB_ASSERT(ev.kind == ExactValue_String); u64 hs = fnv64a(ev.value_string.text, ev.value_string.len); - hashed_str = ir_value_constant(t_u64, exact_value_u64(hs)); + if (build_context.word_size == 4) { + hs &= 0xffffffff; + } + hashed_str = ir_value_constant(t_uintptr, exact_value_u64(hs)); } else { auto args = array_make<irValue *>(ir_allocator(), 1); args[0] = str; diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index f41f206b9..5bbccc18a 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -10272,7 +10272,10 @@ lbValue lb_gen_map_key(lbProcedure *p, lbValue key, Type *key_type) { if (lb_is_const(str)) { String v = lb_get_const_string(p->module, str); u64 hs = fnv64a(v.text, v.len); - hashed_str = lb_const_int(p->module, t_u64, hs); + if (build_context.word_size == 4) { + hs &= 0xffffffff; + } + hashed_str = lb_const_int(p->module, t_uintptr, hs); } else { auto args = array_make<lbValue>(permanent_allocator(), 1); args[0] = str; @@ -10287,7 +10290,6 @@ lbValue lb_gen_map_key(lbProcedure *p, lbValue key, Type *key_type) { args[0] = lb_address_from_load_or_generate_local(p, key); args[1] = lb_const_int(p->module, t_int, sz); lbValue hash = lb_emit_runtime_call(p, "default_hash_ptr", args); - lb_emit_store(p, lb_emit_struct_ep(p, vp, 0), hash); } } |