diff --git a/std/assembly/map.ts b/std/assembly/map.ts
index c888cbc27f..1bdcdf06ae 100644
--- a/std/assembly/map.ts
+++ b/std/assembly/map.ts
@@ -1,6 +1,6 @@
///
-import { HASH } from "./util/hash";
+import { hash } from "./util/hash";
import { E_KEYNOTFOUND } from "./util/error";
// A deterministic hash map based on CloseTable from https://github.com/jorendorff/dht
@@ -96,19 +96,19 @@ export class Map {
}
has(key: K): bool {
- return this.find(key, HASH(key)) !== null;
+ return this.find(key, hash(key)) !== null;
}
@operator("[]")
get(key: K): V {
- var entry = this.find(key, HASH(key));
+ var entry = this.find(key, hash(key));
if (!entry) throw new Error(E_KEYNOTFOUND); // cannot represent `undefined`
return entry.value;
}
@operator("[]=")
set(key: K, value: V): this {
- var hashCode = HASH(key);
+ var hashCode = hash(key);
var entry = this.find(key, hashCode); // unmanaged!
if (entry) {
if (isManaged()) {
@@ -149,7 +149,7 @@ export class Map {
}
delete(key: K): bool {
- var entry = this.find(key, HASH(key));
+ var entry = this.find(key, hash(key));
if (!entry) return false;
if (isManaged()) __release(changetype(entry.key));
if (isManaged()) __release(changetype(entry.value));
@@ -181,7 +181,7 @@ export class Map {
let oldEntryKey = oldEntry.key;
newEntry.key = oldEntryKey;
newEntry.value = oldEntry.value;
- let newBucketIndex = HASH(oldEntryKey) & newBucketsMask;
+ let newBucketIndex = hash(oldEntryKey) & newBucketsMask;
let newBucketPtrBase = changetype(newBuckets) + newBucketIndex * BUCKET_SIZE;
newEntry.taggedNext = load(newBucketPtrBase);
store(newBucketPtrBase, newPtr);
diff --git a/std/assembly/set.ts b/std/assembly/set.ts
index 2fe540a551..baa4482108 100644
--- a/std/assembly/set.ts
+++ b/std/assembly/set.ts
@@ -1,6 +1,6 @@
///
-import { HASH } from "./util/hash";
+import { hash } from "./util/hash";
// A deterministic hash set based on CloseTable from https://github.com/jorendorff/dht
@@ -94,11 +94,11 @@ export class Set {
@operator("[]")
has(key: T): bool {
- return this.find(key, HASH(key)) !== null;
+ return this.find(key, hash(key)) !== null;
}
add(key: T): this {
- var hashCode = HASH(key);
+ var hashCode = hash(key);
var entry = this.find(key, hashCode); // unmanaged!
if (!entry) {
// check if rehashing is necessary
@@ -130,7 +130,7 @@ export class Set {
}
delete(key: T): bool {
- var entry = this.find(key, HASH(key)); // unmanaged!
+ var entry = this.find(key, hash(key)); // unmanaged!
if (!entry) return false;
if (isManaged()) __release(changetype(entry.key)); // exact 'key'
entry.taggedNext |= EMPTY;
@@ -160,7 +160,7 @@ export class Set {
let newEntry = changetype>(newPtr); // unmanaged!
let oldEntryKey = oldEntry.key;
newEntry.key = oldEntryKey;
- let newBucketIndex = HASH(oldEntryKey) & newBucketsMask;
+ let newBucketIndex = hash(oldEntryKey) & newBucketsMask;
let newBucketPtrBase = changetype(newBuckets) + newBucketIndex * BUCKET_SIZE;
newEntry.taggedNext = load(newBucketPtrBase);
store(newBucketPtrBase, newPtr);
diff --git a/std/assembly/util/hash.ts b/std/assembly/util/hash.ts
index c168fa4903..763c2a2254 100644
--- a/std/assembly/util/hash.ts
+++ b/std/assembly/util/hash.ts
@@ -1,6 +1,4 @@
-// @ts-ignore: decorator
-@inline
-export function HASH(key: T): u32 {
+export function hash(key: T): u32 {
if (isString()) {
return hashStr(changetype(key));
} else if (isReference()) {
@@ -26,19 +24,26 @@ export function HASH(key: T): u32 {
// @ts-ignore: decorator
@inline const FNV_PRIME: u32 = 16777619;
-function hash8(key: u32): u32 {
- return (FNV_OFFSET ^ key) * FNV_PRIME;
+
+// @ts-ignore: decorator
+@inline
+function hash8(key: u32, seed: u32 = FNV_OFFSET): u32 {
+ return (seed ^ key) * FNV_PRIME;
}
-function hash16(key: u32): u32 {
- var v = FNV_OFFSET;
+// @ts-ignore: decorator
+@inline
+function hash16(key: u32, seed: u32 = FNV_OFFSET): u32 {
+ var v = seed;
v = (v ^ ( key & 0xff)) * FNV_PRIME;
v = (v ^ ( key >> 8 )) * FNV_PRIME;
return v;
}
-function hash32(key: u32): u32 {
- var v = FNV_OFFSET;
+// @ts-ignore: decorator
+@inline
+function hash32(key: u32, seed: u32 = FNV_OFFSET): u32 {
+ var v = seed;
v = (v ^ ( key & 0xff)) * FNV_PRIME;
v = (v ^ ((key >> 8) & 0xff)) * FNV_PRIME;
v = (v ^ ((key >> 16) & 0xff)) * FNV_PRIME;
@@ -46,10 +51,12 @@ function hash32(key: u32): u32 {
return v;
}
-function hash64(key: u64): u32 {
+// @ts-ignore: decorator
+@inline
+function hash64(key: u64, seed: u32 = FNV_OFFSET): u32 {
var l = key;
var h = (key >>> 32);
- var v = FNV_OFFSET;
+ var v = seed;
v = (v ^ ( l & 0xff)) * FNV_PRIME;
v = (v ^ ((l >> 8) & 0xff)) * FNV_PRIME;
v = (v ^ ((l >> 16) & 0xff)) * FNV_PRIME;
@@ -61,11 +68,30 @@ function hash64(key: u64): u32 {
return v;
}
-function hashStr(key: string): u32 {
- var v = FNV_OFFSET;
+// @ts-ignore: decorator
+@inline
+function hashStr(key: string, seed: u32 = FNV_OFFSET): u32 {
+ var v = seed;
if (key !== null) {
- for (let i: usize = 0, k: usize = key.length << 1; i < k; ++i) {
- v = (v ^ load(changetype(key) + i)) * FNV_PRIME;
+ let len = key.length << 1;
+ if (ASC_SHRINK_LEVEL > 1) {
+ for (let i: usize = 0; i < len; ++i) {
+ v = (v ^ load(changetype(key) + i)) * FNV_PRIME;
+ }
+ } else {
+ let off: usize = 0;
+ while (len >= 8) {
+ v = hash64(load(changetype(key) + off), v);
+ off += 8; len -= 8;
+ }
+ if (len >= 4) {
+ v = hash32(load(changetype(key) + off), v);
+ off += 4; len -= 4;
+ }
+ if (len >= 2) {
+ v = hash16(load(changetype(key) + off), v);
+ }
+ // "len" always even so don't need hash8
}
}
return v;
diff --git a/tests/compiler/std/hash.optimized.wat b/tests/compiler/std/hash.optimized.wat
index e0f7a02167..d6af58da37 100644
--- a/tests/compiler/std/hash.optimized.wat
+++ b/tests/compiler/std/hash.optimized.wat
@@ -6,12 +6,15 @@
(data (i32.const 1068) "\02\00\00\00\01\00\00\00\00\00\00\00\01\00\00\00\02\00\00\00a")
(data (i32.const 1100) "\04\00\00\00\01\00\00\00\00\00\00\00\01\00\00\00\04\00\00\00a\00b")
(data (i32.const 1132) "\06\00\00\00\01\00\00\00\00\00\00\00\01\00\00\00\06\00\00\00a\00b\00c")
+ (data (i32.const 1164) "\08\00\00\00\01\00\00\00\00\00\00\00\01\00\00\00\08\00\00\00a\00b\00c\00d")
+ (data (i32.const 1196) "\n\00\00\00\01\00\00\00\00\00\00\00\01\00\00\00\n\00\00\00a\00b\00c\00d\00e")
(export "memory" (memory $0))
(start $~start)
- (func $~lib/util/hash/hashStr (param $0 i32)
+ (func $~lib/util/hash/hash<~lib/string/String|null> (param $0 i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
+ (local $4 i64)
i32.const -2128831035
local.set $2
local.get $0
@@ -24,40 +27,179 @@
i32.shr_u
i32.const 1
i32.shl
- local.set $3
- loop $for-loop|0
+ local.set $1
+ loop $while-continue|0
local.get $1
- local.get $3
- i32.lt_u
+ i32.const 8
+ i32.ge_s
if
local.get $2
local.get $0
- local.get $1
+ local.get $3
i32.add
- i32.load8_u
+ i64.load
+ local.tee $4
+ i32.wrap_i64
+ local.tee $2
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $2
+ i32.const 8
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $2
+ i32.const 16
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $2
+ i32.const 24
+ i32.shr_u
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $4
+ i64.const 32
+ i64.shr_u
+ i32.wrap_i64
+ local.tee $2
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $2
+ i32.const 8
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $2
+ i32.const 16
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $2
+ i32.const 24
+ i32.shr_u
i32.xor
i32.const 16777619
i32.mul
local.set $2
- local.get $1
- i32.const 1
+ local.get $3
+ i32.const 8
i32.add
+ local.set $3
+ local.get $1
+ i32.const 8
+ i32.sub
local.set $1
- br $for-loop|0
+ br $while-continue|0
end
end
+ local.get $1
+ i32.const 4
+ i32.ge_s
+ if (result i32)
+ local.get $2
+ local.get $0
+ local.get $3
+ i32.add
+ i32.load
+ local.tee $2
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $2
+ i32.const 8
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $2
+ i32.const 16
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $2
+ i32.const 24
+ i32.shr_u
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $2
+ local.get $3
+ i32.const 4
+ i32.add
+ local.set $3
+ local.get $1
+ i32.const 4
+ i32.sub
+ else
+ local.get $1
+ end
+ i32.const 2
+ i32.ge_s
+ if (result i32)
+ local.get $2
+ local.get $0
+ local.get $3
+ i32.add
+ i32.load16_u
+ local.tee $0
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $0
+ i32.const 8
+ i32.shr_u
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ else
+ local.get $2
+ end
+ drop
end
)
(func $~start
i32.const 0
- call $~lib/util/hash/hashStr
+ call $~lib/util/hash/hash<~lib/string/String|null>
i32.const 1056
- call $~lib/util/hash/hashStr
+ call $~lib/util/hash/hash<~lib/string/String|null>
i32.const 1088
- call $~lib/util/hash/hashStr
+ call $~lib/util/hash/hash<~lib/string/String|null>
i32.const 1120
- call $~lib/util/hash/hashStr
+ call $~lib/util/hash/hash<~lib/string/String|null>
i32.const 1152
- call $~lib/util/hash/hashStr
+ call $~lib/util/hash/hash<~lib/string/String|null>
+ i32.const 1184
+ call $~lib/util/hash/hash<~lib/string/String|null>
+ i32.const 1216
+ call $~lib/util/hash/hash<~lib/string/String|null>
)
)
diff --git a/tests/compiler/std/hash.ts b/tests/compiler/std/hash.ts
index b46889ba88..e99ddda546 100644
--- a/tests/compiler/std/hash.ts
+++ b/tests/compiler/std/hash.ts
@@ -1,25 +1,27 @@
-import { HASH } from "util/hash";
+import { hash } from "util/hash";
function check(hash: u32): bool {
return true;
}
-check(HASH(null));
-check(HASH(""));
-check(HASH("a"));
-check(HASH("ab"));
-check(HASH("abc"));
+check(hash(null));
+check(hash(""));
+check(hash("a"));
+check(hash("ab"));
+check(hash("abc"));
+check(hash("abcd"));
+check(hash("abcde"));
-check(HASH(0.0));
-check(HASH(1.0));
-check(HASH(1.1));
-check(HASH(-0));
-check(HASH(Infinity));
-check(HASH(NaN));
+check(hash(0.0));
+check(hash(1.0));
+check(hash(1.1));
+check(hash(-0));
+check(hash(Infinity));
+check(hash(NaN));
-check(HASH(0.0));
-check(HASH(1.0));
-check(HASH(1.1));
-check(HASH(-0));
-check(HASH(Infinity));
-check(HASH(NaN));
+check(hash(0.0));
+check(hash(1.0));
+check(hash(1.1));
+check(hash(-0));
+check(hash(Infinity));
+check(hash(NaN));
diff --git a/tests/compiler/std/hash.untouched.wat b/tests/compiler/std/hash.untouched.wat
index c1e7d41192..4879e4fcd0 100644
--- a/tests/compiler/std/hash.untouched.wat
+++ b/tests/compiler/std/hash.untouched.wat
@@ -2,13 +2,17 @@
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $none_=>_none (func))
(type $i32_=>_none (func (param i32)))
- (type $i64_=>_i32 (func (param i64) (result i32)))
+ (type $f32_=>_i32 (func (param f32) (result i32)))
+ (type $f64_=>_i32 (func (param f64) (result i32)))
(memory $0 1)
(data (i32.const 12) "\00\00\00\00\01\00\00\00\00\00\00\00\01\00\00\00\00\00\00\00")
(data (i32.const 44) "\02\00\00\00\01\00\00\00\00\00\00\00\01\00\00\00\02\00\00\00a\00")
(data (i32.const 76) "\04\00\00\00\01\00\00\00\00\00\00\00\01\00\00\00\04\00\00\00a\00b\00")
(data (i32.const 108) "\06\00\00\00\01\00\00\00\00\00\00\00\01\00\00\00\06\00\00\00a\00b\00c\00")
+ (data (i32.const 140) "\08\00\00\00\01\00\00\00\00\00\00\00\01\00\00\00\08\00\00\00a\00b\00c\00d\00")
+ (data (i32.const 172) "\n\00\00\00\01\00\00\00\00\00\00\00\01\00\00\00\n\00\00\00a\00b\00c\00d\00e\00")
(table $0 1 funcref)
+ (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0))
(export "memory" (memory $0))
(start $~start)
(func $~lib/rt/stub/__retain (param $0 i32) (result i32)
@@ -25,74 +29,544 @@
(func $~lib/rt/stub/__release (param $0 i32)
nop
)
- (func $~lib/util/hash/hashStr (param $0 i32) (result i32)
+ (func $~lib/util/hash/hash<~lib/string/String|null> (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
+ (local $5 i32)
+ (local $6 i32)
+ (local $7 i32)
+ (local $8 i64)
+ (local $9 i32)
+ (local $10 i32)
+ (local $11 i32)
local.get $0
call $~lib/rt/stub/__retain
local.set $0
- i32.const -2128831035
- local.set $1
+ i32.const 1
+ drop
local.get $0
+ call $~lib/rt/stub/__retain
+ local.set $1
+ i32.const -2128831035
+ local.set $2
+ local.get $2
+ local.set $3
+ local.get $1
i32.const 0
i32.ne
if
- i32.const 0
- local.set $2
- local.get $0
+ local.get $1
call $~lib/string/String#get:length
i32.const 1
i32.shl
- local.set $3
- loop $for-loop|0
- local.get $2
- local.get $3
- i32.lt_u
- local.set $4
+ local.set $4
+ i32.const 0
+ i32.const 1
+ i32.gt_s
+ drop
+ i32.const 0
+ local.set $5
+ loop $while-continue|0
local.get $4
+ i32.const 8
+ i32.ge_s
+ local.set $6
+ local.get $6
if
local.get $1
- local.get $0
- local.get $2
+ local.get $5
i32.add
- i32.load8_u
+ i64.load
+ local.set $8
+ local.get $3
+ local.set $7
+ local.get $8
+ i32.wrap_i64
+ local.set $9
+ local.get $8
+ i64.const 32
+ i64.shr_u
+ i32.wrap_i64
+ local.set $10
+ local.get $7
+ local.set $11
+ local.get $11
+ local.get $9
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $11
+ local.get $11
+ local.get $9
+ i32.const 8
+ i32.shr_u
+ i32.const 255
+ i32.and
i32.xor
i32.const 16777619
i32.mul
- local.set $1
- local.get $2
- i32.const 1
+ local.set $11
+ local.get $11
+ local.get $9
+ i32.const 16
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $11
+ local.get $11
+ local.get $9
+ i32.const 24
+ i32.shr_u
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $11
+ local.get $11
+ local.get $10
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $11
+ local.get $11
+ local.get $10
+ i32.const 8
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $11
+ local.get $11
+ local.get $10
+ i32.const 16
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $11
+ local.get $11
+ local.get $10
+ i32.const 24
+ i32.shr_u
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $11
+ local.get $11
+ local.set $3
+ local.get $5
+ i32.const 8
i32.add
- local.set $2
- br $for-loop|0
+ local.set $5
+ local.get $4
+ i32.const 8
+ i32.sub
+ local.set $4
+ br $while-continue|0
end
end
+ local.get $4
+ i32.const 4
+ i32.ge_s
+ if
+ local.get $1
+ local.get $5
+ i32.add
+ i32.load
+ local.set $9
+ local.get $3
+ local.set $7
+ local.get $7
+ local.set $6
+ local.get $6
+ local.get $9
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $6
+ local.get $6
+ local.get $9
+ i32.const 8
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $6
+ local.get $6
+ local.get $9
+ i32.const 16
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $6
+ local.get $6
+ local.get $9
+ i32.const 24
+ i32.shr_u
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $6
+ local.get $6
+ local.set $3
+ local.get $5
+ i32.const 4
+ i32.add
+ local.set $5
+ local.get $4
+ i32.const 4
+ i32.sub
+ local.set $4
+ end
+ local.get $4
+ i32.const 2
+ i32.ge_s
+ if
+ local.get $1
+ local.get $5
+ i32.add
+ i32.load16_u
+ local.set $11
+ local.get $3
+ local.set $10
+ local.get $10
+ local.set $6
+ local.get $6
+ local.get $11
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $6
+ local.get $6
+ local.get $11
+ i32.const 8
+ i32.shr_u
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $6
+ local.get $6
+ local.set $3
+ end
end
+ local.get $3
+ local.set $4
local.get $1
+ call $~lib/rt/stub/__release
+ local.get $4
local.set $3
local.get $0
call $~lib/rt/stub/__release
local.get $3
+ return
)
(func $std/hash/check (param $0 i32) (result i32)
i32.const 1
)
- (func $~lib/util/hash/hash32 (param $0 i32) (result i32)
+ (func $~lib/util/hash/hash<~lib/string/String> (param $0 i32) (result i32)
(local $1 i32)
- i32.const -2128831035
+ (local $2 i32)
+ (local $3 i32)
+ (local $4 i32)
+ (local $5 i32)
+ (local $6 i32)
+ (local $7 i32)
+ (local $8 i64)
+ (local $9 i32)
+ (local $10 i32)
+ (local $11 i32)
+ local.get $0
+ call $~lib/rt/stub/__retain
+ local.set $0
+ i32.const 1
+ drop
+ local.get $0
+ call $~lib/rt/stub/__retain
local.set $1
+ i32.const -2128831035
+ local.set $2
+ local.get $2
+ local.set $3
local.get $1
+ i32.const 0
+ i32.ne
+ if
+ local.get $1
+ call $~lib/string/String#get:length
+ i32.const 1
+ i32.shl
+ local.set $4
+ i32.const 0
+ i32.const 1
+ i32.gt_s
+ drop
+ i32.const 0
+ local.set $5
+ loop $while-continue|0
+ local.get $4
+ i32.const 8
+ i32.ge_s
+ local.set $6
+ local.get $6
+ if
+ local.get $1
+ local.get $5
+ i32.add
+ i64.load
+ local.set $8
+ local.get $3
+ local.set $7
+ local.get $8
+ i32.wrap_i64
+ local.set $9
+ local.get $8
+ i64.const 32
+ i64.shr_u
+ i32.wrap_i64
+ local.set $10
+ local.get $7
+ local.set $11
+ local.get $11
+ local.get $9
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $11
+ local.get $11
+ local.get $9
+ i32.const 8
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $11
+ local.get $11
+ local.get $9
+ i32.const 16
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $11
+ local.get $11
+ local.get $9
+ i32.const 24
+ i32.shr_u
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $11
+ local.get $11
+ local.get $10
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $11
+ local.get $11
+ local.get $10
+ i32.const 8
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $11
+ local.get $11
+ local.get $10
+ i32.const 16
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $11
+ local.get $11
+ local.get $10
+ i32.const 24
+ i32.shr_u
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $11
+ local.get $11
+ local.set $3
+ local.get $5
+ i32.const 8
+ i32.add
+ local.set $5
+ local.get $4
+ i32.const 8
+ i32.sub
+ local.set $4
+ br $while-continue|0
+ end
+ end
+ local.get $4
+ i32.const 4
+ i32.ge_s
+ if
+ local.get $1
+ local.get $5
+ i32.add
+ i32.load
+ local.set $9
+ local.get $3
+ local.set $7
+ local.get $7
+ local.set $6
+ local.get $6
+ local.get $9
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $6
+ local.get $6
+ local.get $9
+ i32.const 8
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $6
+ local.get $6
+ local.get $9
+ i32.const 16
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $6
+ local.get $6
+ local.get $9
+ i32.const 24
+ i32.shr_u
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $6
+ local.get $6
+ local.set $3
+ local.get $5
+ i32.const 4
+ i32.add
+ local.set $5
+ local.get $4
+ i32.const 4
+ i32.sub
+ local.set $4
+ end
+ local.get $4
+ i32.const 2
+ i32.ge_s
+ if
+ local.get $1
+ local.get $5
+ i32.add
+ i32.load16_u
+ local.set $11
+ local.get $3
+ local.set $10
+ local.get $10
+ local.set $6
+ local.get $6
+ local.get $11
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $6
+ local.get $6
+ local.get $11
+ i32.const 8
+ i32.shr_u
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.set $6
+ local.get $6
+ local.set $3
+ end
+ end
+ local.get $3
+ local.set $4
+ local.get $1
+ call $~lib/rt/stub/__release
+ local.get $4
+ local.set $3
+ local.get $0
+ call $~lib/rt/stub/__release
+ local.get $3
+ return
+ )
+ (func $~lib/util/hash/hash (param $0 f32) (result i32)
+ (local $1 i32)
+ (local $2 i32)
+ (local $3 i32)
+ i32.const 0
+ drop
+ i32.const 0
+ drop
+ i32.const 1
+ drop
+ i32.const 4
+ i32.const 4
+ i32.eq
+ drop
local.get $0
+ i32.reinterpret_f32
+ local.set $1
+ i32.const -2128831035
+ local.set $2
+ local.get $2
+ local.set $3
+ local.get $3
+ local.get $1
i32.const 255
i32.and
i32.xor
i32.const 16777619
i32.mul
- local.set $1
+ local.set $3
+ local.get $3
local.get $1
- local.get $0
i32.const 8
i32.shr_u
i32.const 255
@@ -100,9 +574,9 @@
i32.xor
i32.const 16777619
i32.mul
- local.set $1
+ local.set $3
+ local.get $3
local.get $1
- local.get $0
i32.const 16
i32.shr_u
i32.const 255
@@ -110,41 +584,63 @@
i32.xor
i32.const 16777619
i32.mul
- local.set $1
+ local.set $3
+ local.get $3
local.get $1
- local.get $0
i32.const 24
i32.shr_u
i32.xor
i32.const 16777619
i32.mul
- local.set $1
- local.get $1
+ local.set $3
+ local.get $3
+ return
)
- (func $~lib/util/hash/hash64 (param $0 i64) (result i32)
- (local $1 i32)
+ (func $~lib/util/hash/hash (param $0 f64) (result i32)
+ (local $1 i64)
(local $2 i32)
(local $3 i32)
+ (local $4 i32)
+ (local $5 i32)
+ i32.const 0
+ drop
+ i32.const 0
+ drop
+ i32.const 1
+ drop
+ i32.const 8
+ i32.const 4
+ i32.eq
+ drop
+ i32.const 8
+ i32.const 8
+ i32.eq
+ drop
local.get $0
- i32.wrap_i64
+ i64.reinterpret_f64
local.set $1
- local.get $0
+ i32.const -2128831035
+ local.set $2
+ local.get $1
+ i32.wrap_i64
+ local.set $3
+ local.get $1
i64.const 32
i64.shr_u
i32.wrap_i64
- local.set $2
- i32.const -2128831035
- local.set $3
+ local.set $4
+ local.get $2
+ local.set $5
+ local.get $5
local.get $3
- local.get $1
i32.const 255
i32.and
i32.xor
i32.const 16777619
i32.mul
- local.set $3
+ local.set $5
+ local.get $5
local.get $3
- local.get $1
i32.const 8
i32.shr_u
i32.const 255
@@ -152,9 +648,9 @@
i32.xor
i32.const 16777619
i32.mul
- local.set $3
+ local.set $5
+ local.get $5
local.get $3
- local.get $1
i32.const 16
i32.shr_u
i32.const 255
@@ -162,25 +658,25 @@
i32.xor
i32.const 16777619
i32.mul
- local.set $3
+ local.set $5
+ local.get $5
local.get $3
- local.get $1
i32.const 24
i32.shr_u
i32.xor
i32.const 16777619
i32.mul
- local.set $3
- local.get $3
- local.get $2
+ local.set $5
+ local.get $5
+ local.get $4
i32.const 255
i32.and
i32.xor
i32.const 16777619
i32.mul
- local.set $3
- local.get $3
- local.get $2
+ local.set $5
+ local.get $5
+ local.get $4
i32.const 8
i32.shr_u
i32.const 255
@@ -188,9 +684,9 @@
i32.xor
i32.const 16777619
i32.mul
- local.set $3
- local.get $3
- local.get $2
+ local.set $5
+ local.get $5
+ local.get $4
i32.const 16
i32.shr_u
i32.const 255
@@ -198,360 +694,93 @@
i32.xor
i32.const 16777619
i32.mul
- local.set $3
- local.get $3
- local.get $2
+ local.set $5
+ local.get $5
+ local.get $4
i32.const 24
i32.shr_u
i32.xor
i32.const 16777619
i32.mul
- local.set $3
- local.get $3
+ local.set $5
+ local.get $5
+ return
)
(func $start:std/hash
- (local $0 i32)
- (local $1 i32)
- (local $2 f32)
- (local $3 f64)
- block $~lib/util/hash/HASH<~lib/string/String|null>|inlined.0 (result i32)
- i32.const 0
- call $~lib/rt/stub/__retain
- local.set $0
- i32.const 1
- drop
- local.get $0
- call $~lib/util/hash/hashStr
- local.set $1
- local.get $0
- call $~lib/rt/stub/__release
- local.get $1
- br $~lib/util/hash/HASH<~lib/string/String|null>|inlined.0
- end
+ i32.const 0
+ call $~lib/util/hash/hash<~lib/string/String|null>
call $std/hash/check
drop
- block $~lib/util/hash/HASH<~lib/string/String>|inlined.0 (result i32)
- i32.const 32
- local.set $1
- i32.const 1
- drop
- local.get $1
- call $~lib/util/hash/hashStr
- local.set $0
- local.get $1
- call $~lib/rt/stub/__release
- local.get $0
- br $~lib/util/hash/HASH<~lib/string/String>|inlined.0
- end
+ i32.const 32
+ call $~lib/util/hash/hash<~lib/string/String>
call $std/hash/check
drop
- block $~lib/util/hash/HASH<~lib/string/String>|inlined.1 (result i32)
- i32.const 64
- local.set $0
- i32.const 1
- drop
- local.get $0
- call $~lib/util/hash/hashStr
- local.set $1
- local.get $0
- call $~lib/rt/stub/__release
- local.get $1
- br $~lib/util/hash/HASH<~lib/string/String>|inlined.1
- end
+ i32.const 64
+ call $~lib/util/hash/hash<~lib/string/String>
call $std/hash/check
drop
- block $~lib/util/hash/HASH<~lib/string/String>|inlined.2 (result i32)
- i32.const 96
- local.set $1
- i32.const 1
- drop
- local.get $1
- call $~lib/util/hash/hashStr
- local.set $0
- local.get $1
- call $~lib/rt/stub/__release
- local.get $0
- br $~lib/util/hash/HASH<~lib/string/String>|inlined.2
- end
+ i32.const 96
+ call $~lib/util/hash/hash<~lib/string/String>
call $std/hash/check
drop
- block $~lib/util/hash/HASH<~lib/string/String>|inlined.3 (result i32)
- i32.const 128
- local.set $0
- i32.const 1
- drop
- local.get $0
- call $~lib/util/hash/hashStr
- local.set $1
- local.get $0
- call $~lib/rt/stub/__release
- local.get $1
- br $~lib/util/hash/HASH<~lib/string/String>|inlined.3
- end
+ i32.const 128
+ call $~lib/util/hash/hash<~lib/string/String>
call $std/hash/check
drop
- block $~lib/util/hash/HASH|inlined.0 (result i32)
- f32.const 0
- local.set $2
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 1
- drop
- i32.const 4
- i32.const 4
- i32.eq
- drop
- local.get $2
- i32.reinterpret_f32
- call $~lib/util/hash/hash32
- br $~lib/util/hash/HASH|inlined.0
- end
+ i32.const 160
+ call $~lib/util/hash/hash<~lib/string/String>
call $std/hash/check
drop
- block $~lib/util/hash/HASH|inlined.1 (result i32)
- f32.const 1
- local.set $2
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 1
- drop
- i32.const 4
- i32.const 4
- i32.eq
- drop
- local.get $2
- i32.reinterpret_f32
- call $~lib/util/hash/hash32
- br $~lib/util/hash/HASH|inlined.1
- end
+ i32.const 192
+ call $~lib/util/hash/hash<~lib/string/String>
call $std/hash/check
drop
- block $~lib/util/hash/HASH|inlined.2 (result i32)
- f32.const 1.100000023841858
- local.set $2
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 1
- drop
- i32.const 4
- i32.const 4
- i32.eq
- drop
- local.get $2
- i32.reinterpret_f32
- call $~lib/util/hash/hash32
- br $~lib/util/hash/HASH|inlined.2
- end
+ f32.const 0
+ call $~lib/util/hash/hash
call $std/hash/check
drop
- block $~lib/util/hash/HASH|inlined.3 (result i32)
- f32.const 0
- local.set $2
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 1
- drop
- i32.const 4
- i32.const 4
- i32.eq
- drop
- local.get $2
- i32.reinterpret_f32
- call $~lib/util/hash/hash32
- br $~lib/util/hash/HASH|inlined.3
- end
+ f32.const 1
+ call $~lib/util/hash/hash
call $std/hash/check
drop
- block $~lib/util/hash/HASH|inlined.4 (result i32)
- f32.const inf
- local.set $2
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 1
- drop
- i32.const 4
- i32.const 4
- i32.eq
- drop
- local.get $2
- i32.reinterpret_f32
- call $~lib/util/hash/hash32
- br $~lib/util/hash/HASH|inlined.4
- end
+ f32.const 1.100000023841858
+ call $~lib/util/hash/hash
call $std/hash/check
drop
- block $~lib/util/hash/HASH|inlined.5 (result i32)
- f32.const nan:0x400000
- local.set $2
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 1
- drop
- i32.const 4
- i32.const 4
- i32.eq
- drop
- local.get $2
- i32.reinterpret_f32
- call $~lib/util/hash/hash32
- br $~lib/util/hash/HASH|inlined.5
- end
+ f32.const 0
+ call $~lib/util/hash/hash
call $std/hash/check
drop
- block $~lib/util/hash/HASH|inlined.0 (result i32)
- f64.const 0
- local.set $3
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 1
- drop
- i32.const 8
- i32.const 4
- i32.eq
- drop
- i32.const 8
- i32.const 8
- i32.eq
- drop
- local.get $3
- i64.reinterpret_f64
- call $~lib/util/hash/hash64
- br $~lib/util/hash/HASH|inlined.0
- end
+ f32.const inf
+ call $~lib/util/hash/hash
call $std/hash/check
drop
- block $~lib/util/hash/HASH|inlined.1 (result i32)
- f64.const 1
- local.set $3
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 1
- drop
- i32.const 8
- i32.const 4
- i32.eq
- drop
- i32.const 8
- i32.const 8
- i32.eq
- drop
- local.get $3
- i64.reinterpret_f64
- call $~lib/util/hash/hash64
- br $~lib/util/hash/HASH|inlined.1
- end
+ f32.const nan:0x400000
+ call $~lib/util/hash/hash
call $std/hash/check
drop
- block $~lib/util/hash/HASH|inlined.2 (result i32)
- f64.const 1.1
- local.set $3
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 1
- drop
- i32.const 8
- i32.const 4
- i32.eq
- drop
- i32.const 8
- i32.const 8
- i32.eq
- drop
- local.get $3
- i64.reinterpret_f64
- call $~lib/util/hash/hash64
- br $~lib/util/hash/HASH|inlined.2
- end
+ f64.const 0
+ call $~lib/util/hash/hash
call $std/hash/check
drop
- block $~lib/util/hash/HASH|inlined.3 (result i32)
- f64.const 0
- local.set $3
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 1
- drop
- i32.const 8
- i32.const 4
- i32.eq
- drop
- i32.const 8
- i32.const 8
- i32.eq
- drop
- local.get $3
- i64.reinterpret_f64
- call $~lib/util/hash/hash64
- br $~lib/util/hash/HASH|inlined.3
- end
+ f64.const 1
+ call $~lib/util/hash/hash
call $std/hash/check
drop
- block $~lib/util/hash/HASH|inlined.4 (result i32)
- f64.const inf
- local.set $3
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 1
- drop
- i32.const 8
- i32.const 4
- i32.eq
- drop
- i32.const 8
- i32.const 8
- i32.eq
- drop
- local.get $3
- i64.reinterpret_f64
- call $~lib/util/hash/hash64
- br $~lib/util/hash/HASH|inlined.4
- end
+ f64.const 1.1
+ call $~lib/util/hash/hash
call $std/hash/check
drop
- block $~lib/util/hash/HASH|inlined.5 (result i32)
- f64.const nan:0x8000000000000
- local.set $3
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 1
- drop
- i32.const 8
- i32.const 4
- i32.eq
- drop
- i32.const 8
- i32.const 8
- i32.eq
- drop
- local.get $3
- i64.reinterpret_f64
- call $~lib/util/hash/hash64
- br $~lib/util/hash/HASH|inlined.5
- end
+ f64.const 0
+ call $~lib/util/hash/hash
+ call $std/hash/check
+ drop
+ f64.const inf
+ call $~lib/util/hash/hash
+ call $std/hash/check
+ drop
+ f64.const nan:0x8000000000000
+ call $~lib/util/hash/hash
call $std/hash/check
drop
)
diff --git a/tests/compiler/std/map.optimized.wat b/tests/compiler/std/map.optimized.wat
index d65655a3d4..f841cd8c0b 100644
--- a/tests/compiler/std/map.optimized.wat
+++ b/tests/compiler/std/map.optimized.wat
@@ -22,6 +22,8 @@
(type $i32_f32_f32_=>_i32 (func (param i32 f32 f32) (result i32)))
(type $i32_f64_f64_=>_i32 (func (param i32 f64 f64) (result i32)))
(type $i64_=>_i32 (func (param i64) (result i32)))
+ (type $f32_=>_i32 (func (param f32) (result i32)))
+ (type $f64_=>_i32 (func (param f64) (result i32)))
(type $i32_i32_=>_i64 (func (param i32 i32) (result i64)))
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
(memory $0 1)
@@ -1290,6 +1292,17 @@
local.get $1
call $~lib/rt/pure/__retain
)
+ (func $~lib/util/hash/hash (param $0 i32) (result i32)
+ local.get $0
+ i32.const 24
+ i32.shl
+ i32.const 24
+ i32.shr_s
+ i32.const -2128831035
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ )
(func $~lib/map/Map#find (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
local.get $0
i32.load
@@ -1337,14 +1350,7 @@
local.get $0
local.get $1
local.get $1
- i32.const 24
- i32.shl
- i32.const 24
- i32.shr_s
- i32.const -2128831035
- i32.xor
- i32.const 16777619
- i32.mul
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
i32.const 0
i32.ne
@@ -1408,12 +1414,9 @@
i32.store offset=4
local.get $2
local.get $5
- local.get $1
local.get $6
- i32.const -2128831035
- i32.xor
- i32.const 16777619
- i32.mul
+ call $~lib/util/hash/hash
+ local.get $1
i32.and
i32.const 2
i32.shl
@@ -1487,20 +1490,11 @@
(local $3 i32)
(local $4 i32)
(local $5 i32)
- local.get $1
- i32.const 24
- i32.shl
- i32.const 24
- i32.shr_s
- i32.const -2128831035
- i32.xor
- i32.const 16777619
- i32.mul
- local.tee $3
- local.set $5
local.get $0
local.get $1
- local.get $3
+ local.get $1
+ call $~lib/util/hash/hash
+ local.tee $5
call $~lib/map/Map#find
local.tee $3
if
@@ -1591,14 +1585,7 @@
local.get $0
local.get $1
local.get $1
- i32.const 24
- i32.shl
- i32.const 24
- i32.shr_s
- i32.const -2128831035
- i32.xor
- i32.const 16777619
- i32.mul
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
local.tee $0
i32.eqz
@@ -2475,12 +2462,9 @@
i32.store8 offset=1
local.get $2
local.get $5
- local.get $1
local.get $6
- i32.const -2128831035
- i32.xor
- i32.const 16777619
- i32.mul
+ call $~lib/util/hash/hash
+ local.get $1
i32.and
i32.const 2
i32.shl
@@ -2554,19 +2538,13 @@
(local $3 i32)
(local $4 i32)
(local $5 i32)
- local.get $0
- i32.load
local.get $1
local.tee $3
- i32.const 24
- i32.shl
- i32.const 24
- i32.shr_s
- i32.const -2128831035
- i32.xor
- i32.const 16777619
- i32.mul
- local.tee $5
+ call $~lib/util/hash/hash
+ local.set $5
+ local.get $0
+ i32.load
+ local.get $5
local.get $0
i32.load offset=4
i32.and
@@ -2690,7 +2668,7 @@
local.get $0
call $~lib/rt/pure/__retain
)
- (func $~lib/util/hash/hash32 (param $0 i32) (result i32)
+ (func $~lib/util/hash/hash (param $0 i32) (result i32)
local.get $0
i32.const 255
i32.and
@@ -2822,7 +2800,7 @@
local.get $2
local.get $5
local.get $6
- call $~lib/util/hash/hash32
+ call $~lib/util/hash/hash
local.get $1
i32.and
i32.const 2
@@ -2900,7 +2878,7 @@
local.get $0
local.get $1
local.get $1
- call $~lib/util/hash/hash32
+ call $~lib/util/hash/hash
local.tee $5
call $~lib/map/Map#find
local.tee $3
@@ -2993,14 +2971,7 @@
local.get $0
local.get $1
local.get $1
- i32.const 24
- i32.shl
- i32.const 24
- i32.shr_s
- i32.const -2128831035
- i32.xor
- i32.const 16777619
- i32.mul
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
local.tee $1
i32.eqz
@@ -3610,16 +3581,20 @@
local.get $0
call $~lib/rt/pure/__release
)
- (func $~lib/map/Map#has (param $0 i32) (param $1 i32) (result i32)
+ (func $~lib/util/hash/hash (param $0 i32) (result i32)
local.get $0
- local.get $1
- local.get $1
i32.const 255
i32.and
i32.const -2128831035
i32.xor
i32.const 16777619
i32.mul
+ )
+ (func $~lib/map/Map#has (param $0 i32) (param $1 i32) (result i32)
+ local.get $0
+ local.get $1
+ local.get $1
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
i32.const 0
i32.ne
@@ -3683,12 +3658,9 @@
i32.store offset=4
local.get $2
local.get $5
- local.get $1
local.get $6
- i32.const -2128831035
- i32.xor
- i32.const 16777619
- i32.mul
+ call $~lib/util/hash/hash
+ local.get $1
i32.and
i32.const 2
i32.shl
@@ -3762,18 +3734,11 @@
(local $3 i32)
(local $4 i32)
(local $5 i32)
- local.get $1
- i32.const 255
- i32.and
- i32.const -2128831035
- i32.xor
- i32.const 16777619
- i32.mul
- local.tee $3
- local.set $5
local.get $0
local.get $1
- local.get $3
+ local.get $1
+ call $~lib/util/hash/hash
+ local.tee $5
call $~lib/map/Map#find
local.tee $3
if
@@ -3864,12 +3829,7 @@
local.get $0
local.get $1
local.get $1
- i32.const 255
- i32.and
- i32.const -2128831035
- i32.xor
- i32.const 16777619
- i32.mul
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
local.tee $0
i32.eqz
@@ -4056,12 +4016,9 @@
i32.store8 offset=1
local.get $2
local.get $5
- local.get $1
local.get $6
- i32.const -2128831035
- i32.xor
- i32.const 16777619
- i32.mul
+ call $~lib/util/hash/hash
+ local.get $1
i32.and
i32.const 2
i32.shl
@@ -4135,17 +4092,13 @@
(local $3 i32)
(local $4 i32)
(local $5 i32)
- local.get $0
- i32.load
local.get $1
local.tee $3
- i32.const 255
- i32.and
- i32.const -2128831035
- i32.xor
- i32.const 16777619
- i32.mul
- local.tee $5
+ call $~lib/util/hash/hash
+ local.set $5
+ local.get $0
+ i32.load
+ local.get $5
local.get $0
i32.load offset=4
i32.and
@@ -4274,12 +4227,7 @@
local.get $0
local.get $1
local.get $1
- i32.const 255
- i32.and
- i32.const -2128831035
- i32.xor
- i32.const 16777619
- i32.mul
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
local.tee $1
i32.eqz
@@ -4834,8 +4782,13 @@
local.get $0
call $~lib/rt/pure/__release
)
- (func $~lib/util/hash/hash16 (param $0 i32) (result i32)
+ (func $~lib/util/hash/hash (param $0 i32) (result i32)
local.get $0
+ i32.const 16
+ i32.shl
+ i32.const 16
+ i32.shr_s
+ local.tee $0
i32.const 255
i32.and
i32.const -2128831035
@@ -4896,11 +4849,7 @@
local.get $0
local.get $1
local.get $1
- i32.const 16
- i32.shl
- i32.const 16
- i32.shr_s
- call $~lib/util/hash/hash16
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
i32.const 0
i32.ne
@@ -4965,7 +4914,7 @@
local.get $2
local.get $5
local.get $6
- call $~lib/util/hash/hash16
+ call $~lib/util/hash/hash
local.get $1
i32.and
i32.const 2
@@ -5043,11 +4992,7 @@
local.get $0
local.get $1
local.get $1
- i32.const 16
- i32.shl
- i32.const 16
- i32.shr_s
- call $~lib/util/hash/hash16
+ call $~lib/util/hash/hash
local.tee $5
call $~lib/map/Map#find
local.tee $3
@@ -5139,11 +5084,7 @@
local.get $0
local.get $1
local.get $1
- i32.const 16
- i32.shl
- i32.const 16
- i32.shr_s
- call $~lib/util/hash/hash16
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
local.tee $0
i32.eqz
@@ -5385,7 +5326,7 @@
local.get $2
local.get $5
local.get $6
- call $~lib/util/hash/hash16
+ call $~lib/util/hash/hash
local.get $1
i32.and
i32.const 2
@@ -5462,11 +5403,7 @@
(local $5 i32)
local.get $1
local.tee $3
- i32.const 16
- i32.shl
- i32.const 16
- i32.shr_s
- call $~lib/util/hash/hash16
+ call $~lib/util/hash/hash
local.set $5
local.get $0
i32.load
@@ -5599,11 +5536,7 @@
local.get $0
local.get $1
local.get $1
- i32.const 16
- i32.shl
- i32.const 16
- i32.shr_s
- call $~lib/util/hash/hash16
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
local.tee $1
i32.eqz
@@ -6182,13 +6115,29 @@
local.get $0
call $~lib/rt/pure/__release
)
+ (func $~lib/util/hash/hash (param $0 i32) (result i32)
+ local.get $0
+ i32.const 65535
+ i32.and
+ local.tee $0
+ i32.const 255
+ i32.and
+ i32.const -2128831035
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $0
+ i32.const 8
+ i32.shr_u
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ )
(func $~lib/map/Map#has (param $0 i32) (param $1 i32) (result i32)
local.get $0
local.get $1
local.get $1
- i32.const 65535
- i32.and
- call $~lib/util/hash/hash16
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
i32.const 0
i32.ne
@@ -6253,7 +6202,7 @@
local.get $2
local.get $5
local.get $6
- call $~lib/util/hash/hash16
+ call $~lib/util/hash/hash
local.get $1
i32.and
i32.const 2
@@ -6331,9 +6280,7 @@
local.get $0
local.get $1
local.get $1
- i32.const 65535
- i32.and
- call $~lib/util/hash/hash16
+ call $~lib/util/hash/hash
local.tee $5
call $~lib/map/Map#find
local.tee $3
@@ -6425,9 +6372,7 @@
local.get $0
local.get $1
local.get $1
- i32.const 65535
- i32.and
- call $~lib/util/hash/hash16
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
local.tee $0
i32.eqz
@@ -6619,7 +6564,7 @@
local.get $2
local.get $5
local.get $6
- call $~lib/util/hash/hash16
+ call $~lib/util/hash/hash
local.get $1
i32.and
i32.const 2
@@ -6696,9 +6641,7 @@
(local $5 i32)
local.get $1
local.tee $3
- i32.const 65535
- i32.and
- call $~lib/util/hash/hash16
+ call $~lib/util/hash/hash
local.set $5
local.get $0
i32.load
@@ -6831,9 +6774,7 @@
local.get $0
local.get $1
local.get $1
- i32.const 65535
- i32.and
- call $~lib/util/hash/hash16
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
local.tee $1
i32.eqz
@@ -7394,7 +7335,7 @@
local.get $0
local.get $1
local.get $1
- call $~lib/util/hash/hash32
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
i32.const 0
i32.ne
@@ -7403,7 +7344,7 @@
local.get $0
local.get $1
local.get $1
- call $~lib/util/hash/hash32
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
local.tee $0
i32.eqz
@@ -7423,7 +7364,7 @@
local.get $0
local.get $1
local.get $1
- call $~lib/util/hash/hash32
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
local.tee $1
i32.eqz
@@ -8521,7 +8462,7 @@
local.get $0
call $~lib/rt/pure/__release
)
- (func $~lib/util/hash/hash64 (param $0 i64) (result i32)
+ (func $~lib/util/hash/hash (param $0 i64) (result i32)
(local $1 i32)
local.get $0
i32.wrap_i64
@@ -8632,7 +8573,7 @@
local.get $0
local.get $1
local.get $1
- call $~lib/util/hash/hash64
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
i32.const 0
i32.ne
@@ -8698,7 +8639,7 @@
local.get $2
local.get $5
local.get $8
- call $~lib/util/hash/hash64
+ call $~lib/util/hash/hash
local.get $1
i32.and
i32.const 2
@@ -8776,7 +8717,7 @@
local.get $0
local.get $1
local.get $1
- call $~lib/util/hash/hash64
+ call $~lib/util/hash/hash
local.tee $5
call $~lib/map/Map#find
local.tee $3
@@ -8868,7 +8809,7 @@
local.get $0
local.get $1
local.get $1
- call $~lib/util/hash/hash64
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
local.tee $0
i32.eqz
@@ -9184,7 +9125,7 @@
local.get $2
local.get $5
local.get $8
- call $~lib/util/hash/hash64
+ call $~lib/util/hash/hash
local.get $1
i32.and
i32.const 2
@@ -9260,7 +9201,7 @@
(local $4 i32)
(local $5 i32)
local.get $1
- call $~lib/util/hash/hash64
+ call $~lib/util/hash/hash
local.set $4
local.get $0
i32.load
@@ -9392,7 +9333,7 @@
local.get $0
local.get $1
local.get $1
- call $~lib/util/hash/hash64
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
local.tee $2
i32.eqz
@@ -10542,6 +10483,40 @@
local.get $1
call $~lib/rt/pure/__release
)
+ (func $~lib/util/hash/hash (param $0 f32) (result i32)
+ (local $1 i32)
+ local.get $0
+ i32.reinterpret_f32
+ local.tee $1
+ i32.const 255
+ i32.and
+ i32.const -2128831035
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $1
+ i32.const 8
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $1
+ i32.const 16
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $1
+ i32.const 24
+ i32.shr_u
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ )
(func $~lib/map/Map#find (param $0 i32) (param $1 f32) (param $2 i32) (result i32)
local.get $0
i32.load
@@ -10587,8 +10562,7 @@
local.get $0
local.get $1
local.get $1
- i32.reinterpret_f32
- call $~lib/util/hash/hash32
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
i32.const 0
i32.ne
@@ -10654,8 +10628,7 @@
local.get $2
local.get $5
local.get $8
- i32.reinterpret_f32
- call $~lib/util/hash/hash32
+ call $~lib/util/hash/hash
local.get $1
i32.and
i32.const 2
@@ -10733,8 +10706,7 @@
local.get $0
local.get $1
local.get $1
- i32.reinterpret_f32
- call $~lib/util/hash/hash32
+ call $~lib/util/hash/hash
local.tee $5
call $~lib/map/Map#find
local.tee $3
@@ -10826,8 +10798,7 @@
local.get $0
local.get $1
local.get $1
- i32.reinterpret_f32
- call $~lib/util/hash/hash32
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
local.tee $0
i32.eqz
@@ -11054,8 +11025,7 @@
local.get $2
local.get $5
local.get $8
- i32.reinterpret_f32
- call $~lib/util/hash/hash32
+ call $~lib/util/hash/hash
local.get $1
i32.and
i32.const 2
@@ -11133,8 +11103,7 @@
local.get $0
local.get $1
local.get $1
- i32.reinterpret_f32
- call $~lib/util/hash/hash32
+ call $~lib/util/hash/hash
local.tee $4
call $~lib/map/Map#find
local.tee $3
@@ -11228,8 +11197,7 @@
local.get $0
local.get $1
local.get $1
- i32.reinterpret_f32
- call $~lib/util/hash/hash32
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
local.tee $2
i32.eqz
@@ -11772,6 +11740,75 @@
local.get $1
call $~lib/rt/pure/__release
)
+ (func $~lib/util/hash/hash (param $0 f64) (result i32)
+ (local $1 i32)
+ (local $2 i64)
+ local.get $0
+ i64.reinterpret_f64
+ local.tee $2
+ i32.wrap_i64
+ local.tee $1
+ i32.const 255
+ i32.and
+ i32.const -2128831035
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $1
+ i32.const 8
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $1
+ i32.const 16
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $1
+ i32.const 24
+ i32.shr_u
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $2
+ i64.const 32
+ i64.shr_u
+ i32.wrap_i64
+ local.tee $1
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $1
+ i32.const 8
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $1
+ i32.const 16
+ i32.shr_u
+ i32.const 255
+ i32.and
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ local.get $1
+ i32.const 24
+ i32.shr_u
+ i32.xor
+ i32.const 16777619
+ i32.mul
+ )
(func $~lib/map/Map#find (param $0 i32) (param $1 f64) (param $2 i32) (result i32)
local.get $0
i32.load
@@ -11817,8 +11854,7 @@
local.get $0
local.get $1
local.get $1
- i64.reinterpret_f64
- call $~lib/util/hash/hash64
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
i32.const 0
i32.ne
@@ -11884,8 +11920,7 @@
local.get $2
local.get $5
local.get $8
- i64.reinterpret_f64
- call $~lib/util/hash/hash64
+ call $~lib/util/hash/hash
local.get $1
i32.and
i32.const 2
@@ -11963,8 +11998,7 @@
local.get $0
local.get $1
local.get $1
- i64.reinterpret_f64
- call $~lib/util/hash/hash64
+ call $~lib/util/hash/hash
local.tee $5
call $~lib/map/Map#find
local.tee $3
@@ -12056,8 +12090,7 @@
local.get $0
local.get $1
local.get $1
- i64.reinterpret_f64
- call $~lib/util/hash/hash64
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
local.tee $0
i32.eqz
@@ -12284,8 +12317,7 @@
local.get $2
local.get $5
local.get $8
- i64.reinterpret_f64
- call $~lib/util/hash/hash64
+ call $~lib/util/hash/hash
local.get $1
i32.and
i32.const 2
@@ -12361,8 +12393,7 @@
(local $4 i32)
(local $5 i32)
local.get $1
- i64.reinterpret_f64
- call $~lib/util/hash/hash64
+ call $~lib/util/hash/hash
local.set $4
local.get $0
i32.load
@@ -12494,8 +12525,7 @@
local.get $0
local.get $1
local.get $1
- i64.reinterpret_f64
- call $~lib/util/hash/hash64
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
local.tee $2
i32.eqz
diff --git a/tests/compiler/std/map.untouched.wat b/tests/compiler/std/map.untouched.wat
index 19ba13b674..ffca4ccf7a 100644
--- a/tests/compiler/std/map.untouched.wat
+++ b/tests/compiler/std/map.untouched.wat
@@ -17,12 +17,14 @@
(type $i32_i32_f32_=>_none (func (param i32 i32 f32)))
(type $i32_i32_f64_=>_none (func (param i32 i32 f64)))
(type $i32_i64_i64_=>_i32 (func (param i32 i64 i64) (result i32)))
+ (type $i64_=>_i32 (func (param i64) (result i32)))
(type $i32_i32_=>_f32 (func (param i32 i32) (result f32)))
(type $i32_i32_=>_f64 (func (param i32 i32) (result f64)))
(type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32)))
(type $i32_f32_f32_=>_i32 (func (param i32 f32 f32) (result i32)))
(type $i32_f64_f64_=>_i32 (func (param i32 f64 f64) (result i32)))
- (type $i64_=>_i32 (func (param i64) (result i32)))
+ (type $f32_=>_i32 (func (param f32) (result i32)))
+ (type $f64_=>_i32 (func (param f64) (result i32)))
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
(memory $0 1)
(data (i32.const 12) "(\00\00\00\01\00\00\00\00\00\00\00\01\00\00\00(\00\00\00a\00l\00l\00o\00c\00a\00t\00i\00o\00n\00 \00t\00o\00o\00 \00l\00a\00r\00g\00e\00")
@@ -1803,12 +1805,33 @@
i32.store offset=20
local.get $0
)
- (func $~lib/util/hash/hash8 (param $0 i32) (result i32)
- i32.const -2128831035
+ (func $~lib/util/hash/hash (param $0 i32) (result i32)
+ (local $1 i32)
+ (local $2 i32)
+ i32.const 0
+ drop
+ i32.const 0
+ drop
+ i32.const 0
+ drop
+ i32.const 1
+ i32.const 1
+ i32.eq
+ drop
local.get $0
+ i32.const 24
+ i32.shl
+ i32.const 24
+ i32.shr_s
+ local.set $1
+ i32.const -2128831035
+ local.set $2
+ local.get $2
+ local.get $1
i32.xor
i32.const 16777619
i32.mul
+ return
)
(func $~lib/map/Map#find (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
@@ -1865,30 +1888,10 @@
i32.const 0
)
(func $~lib/map/Map#has (param $0 i32) (param $1 i32) (result i32)
- (local $2 i32)
local.get $0
local.get $1
- block $~lib/util/hash/HASH|inlined.0 (result i32)
- local.get $1
- local.set $2
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 1
- i32.const 1
- i32.eq
- drop
- local.get $2
- i32.const 24
- i32.shl
- i32.const 24
- i32.shr_s
- call $~lib/util/hash/hash8
- br $~lib/util/hash/HASH|inlined.0
- end
+ local.get $1
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
i32.const 0
i32.ne
@@ -1968,23 +1971,8 @@
local.get $10
i32.load offset=4
i32.store offset=4
- block $~lib/util/hash/HASH|inlined.2 (result i32)
- local.get $12
- local.set $13
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 1
- i32.const 1
- i32.eq
- drop
- local.get $13
- call $~lib/util/hash/hash8
- br $~lib/util/hash/HASH|inlined.2
- end
+ local.get $12
+ call $~lib/util/hash/hash
local.get $1
i32.and
local.set $13
@@ -2067,38 +2055,19 @@
(local $4 i32)
(local $5 i32)
(local $6 i32)
- block $~lib/util/hash/HASH|inlined.1 (result i32)
- local.get $1
- local.set $3
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 1
- i32.const 1
- i32.eq
- drop
- local.get $3
- i32.const 24
- i32.shl
- i32.const 24
- i32.shr_s
- call $~lib/util/hash/hash8
- br $~lib/util/hash/HASH|inlined.1
- end
- local.set $4
+ local.get $1
+ call $~lib/util/hash/hash
+ local.set $3
local.get $0
local.get $1
- local.get $4
+ local.get $3
call $~lib/map/Map#find
- local.set $5
- local.get $5
+ local.set $4
+ local.get $4
if
i32.const 0
drop
- local.get $5
+ local.get $4
local.get $2
i32.store offset=4
else
@@ -2134,8 +2103,8 @@
local.get $0
i32.load offset=8
call $~lib/rt/pure/__retain
- local.set $3
- local.get $3
+ local.set $5
+ local.get $5
local.get $0
local.get $0
i32.load offset=16
@@ -2147,11 +2116,11 @@
i32.const 12
i32.mul
i32.add
- local.set $5
- local.get $5
+ local.set $4
+ local.get $4
local.get $1
i32.store8
- local.get $5
+ local.get $4
local.get $2
i32.store offset=4
local.get $0
@@ -2162,7 +2131,7 @@
i32.store offset=20
local.get $0
i32.load
- local.get $4
+ local.get $3
local.get $0
i32.load offset=4
i32.and
@@ -2170,14 +2139,14 @@
i32.mul
i32.add
local.set $6
- local.get $5
+ local.get $4
local.get $6
i32.load
i32.store offset=8
local.get $6
- local.get $5
+ local.get $4
i32.store
- local.get $3
+ local.get $5
call $~lib/rt/pure/__release
end
local.get $0
@@ -2185,33 +2154,13 @@
)
(func $~lib/map/Map#get (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
- (local $3 i32)
local.get $0
local.get $1
- block $~lib/util/hash/HASH|inlined.3 (result i32)
- local.get $1
- local.set $2
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 0
- drop
- i32.const 1
- i32.const 1
- i32.eq
- drop
- local.get $2
- i32.const 24
- i32.shl
- i32.const 24
- i32.shr_s
- call $~lib/util/hash/hash8
- br $~lib/util/hash/HASH|inlined.3
- end
+ local.get $1
+ call $~lib/util/hash/hash
call $~lib/map/Map#find
- local.set $3
- local.get $3
+ local.set $2
+ local.get $2
i32.eqz
if
i32.const 384
@@ -2221,7 +2170,7 @@
call $~lib/builtins/abort
unreachable
end
- local.get $3
+ local.get $2
i32.load offset=4
)
(func $~lib/map/Map