aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-06-05 23:06:15 +0100
committerGinger Bill <bill@gingerbill.org>2017-06-05 23:06:15 +0100
commitd2e7d730ac88bf0ce4f9c823085d7880c30db01e (patch)
treea60d484850e5b83a32a94a76ab77c095bc22f6e1
parent817e4b663e111f768a8fe9af4d3bc53f56de08b6 (diff)
Fix key generation for constant strings in IR
-rw-r--r--src/common.c10
-rw-r--r--src/exact_value.c5
-rw-r--r--src/ir.c6
3 files changed, 18 insertions, 3 deletions
diff --git a/src/common.c b/src/common.c
index f7d16cf8a..54d938c92 100644
--- a/src/common.c
+++ b/src/common.c
@@ -19,6 +19,16 @@ gbAllocator heap_allocator(void) {
#include "integer128.c"
#include "murmurhash3.c"
+u128 fnv128a(void const *data, isize len) {
+ u128 o = u128_lo_hi(0x13bull, 0x1000000ull);
+ u128 h = u128_lo_hi(0x62b821756295c58dull, 0x6c62272e07bb0142ull);
+ u8 const *bytes = cast(u8 const *)data;
+ for (isize i = 0; i < len; i++) {
+ h = u128_mul(u128_xor(h, u128_from_u64(bytes[i])), o);
+ }
+ return h;
+}
+
gb_global String global_module_path = {0};
gb_global bool global_module_path_set = false;
diff --git a/src/exact_value.c b/src/exact_value.c
index 759187f19..8261d8a1f 100644
--- a/src/exact_value.c
+++ b/src/exact_value.c
@@ -71,6 +71,11 @@ ExactValue exact_value_i128(i128 i) {
result.value_integer = i;
return result;
}
+ExactValue exact_value_u128(u128 i) {
+ ExactValue result = {ExactValue_Integer};
+ result.value_integer = *cast(i128 *)&i;
+ return result;
+}
ExactValue exact_value_float(f64 f) {
ExactValue result = {ExactValue_Float};
diff --git a/src/ir.c b/src/ir.c
index f5f48ec9c..e4b086eb1 100644
--- a/src/ir.c
+++ b/src/ir.c
@@ -1682,8 +1682,8 @@ irValue *ir_gen_map_key(irProcedure *proc, irValue *key, Type *key_type) {
if (str->kind == irValue_Constant) {
ExactValue ev = str->Constant.value;
GB_ASSERT(ev.kind == ExactValue_String);
- u64 hs = gb_fnv64a(ev.value_string.text, ev.value_string.len);
- hashed_str = ir_const_u64(proc->module->allocator, hs);
+ u128 hs = fnv128a(ev.value_string.text, ev.value_string.len);
+ hashed_str = ir_value_constant(proc->module->allocator, t_u128, exact_value_u128(hs));
} else {
irValue **args = gb_alloc_array(proc->module->allocator, irValue *, 1);
args[0] = str;
@@ -1729,7 +1729,7 @@ Type *ir_addr_type(irAddr addr) {
}
irValue *ir_insert_dynamic_map_key_and_value(irProcedure *proc, irValue *addr, Type *map_type,
- irValue *map_key, irValue *map_value) {
+ irValue *map_key, irValue *map_value) {
map_type = base_type(map_type);
irValue *h = ir_gen_map_header(proc, addr, map_type);