porffor 0.36.7 → 0.37.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/builtins/__internal_string.ts +111 -5
- package/compiler/builtins_precompiled.js +36 -36
- package/compiler/codegen.js +11 -13
- package/package.json +1 -1
- package/runner/index.js +1 -1
@@ -6,8 +6,8 @@ export const __Porffor_strcmp = (a: any, b: any): boolean => {
|
|
6
6
|
// fast path: check if pointers are equal
|
7
7
|
if (Porffor.wasm`local.get ${a}` == Porffor.wasm`local.get ${b}`) return true;
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
let al: i32 = Porffor.wasm.i32.load(a, 0, 0);
|
10
|
+
let bl: i32 = Porffor.wasm.i32.load(b, 0, 0);
|
11
11
|
|
12
12
|
// fast path: check if lengths are inequal
|
13
13
|
if (al != bl) return false;
|
@@ -15,9 +15,81 @@ export const __Porffor_strcmp = (a: any, b: any): boolean => {
|
|
15
15
|
if (Porffor.wasm`local.get ${a+1}` == Porffor.TYPES.bytestring) {
|
16
16
|
if (Porffor.wasm`local.get ${b+1}` == Porffor.TYPES.bytestring) {
|
17
17
|
// bytestring, bytestring
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
// this path is hyper-optimized as it is by far the most common and (perf) important
|
19
|
+
|
20
|
+
let ap: i32 = a - 4;
|
21
|
+
let bp: i32 = b - 4;
|
22
|
+
Porffor.wasm`
|
23
|
+
;; load in i64 chunks while length >= 8
|
24
|
+
local.get ${al}
|
25
|
+
i32.const 8
|
26
|
+
i32.ge_s
|
27
|
+
if 64
|
28
|
+
loop 64
|
29
|
+
local.get ${ap}
|
30
|
+
local.get ${al}
|
31
|
+
i32.add
|
32
|
+
i64.load 0 0
|
33
|
+
|
34
|
+
local.get ${bp}
|
35
|
+
local.get ${al}
|
36
|
+
i32.add
|
37
|
+
i64.load 0 0
|
38
|
+
|
39
|
+
i64.ne
|
40
|
+
if 64
|
41
|
+
i32.const 0
|
42
|
+
i32.const 2
|
43
|
+
return
|
44
|
+
end
|
45
|
+
|
46
|
+
local.get ${al}
|
47
|
+
i32.const 8
|
48
|
+
i32.sub
|
49
|
+
local.tee ${al}
|
50
|
+
i32.const 8
|
51
|
+
i32.ge_s
|
52
|
+
br_if 0
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
;; load in u16 chunks while length >= 2
|
57
|
+
local.get ${al}
|
58
|
+
i32.const 2
|
59
|
+
i32.ge_s
|
60
|
+
if 64
|
61
|
+
loop 64
|
62
|
+
local.get ${ap}
|
63
|
+
local.get ${al}
|
64
|
+
i32.add
|
65
|
+
i32.load16_u 0 6
|
66
|
+
|
67
|
+
local.get ${bp}
|
68
|
+
local.get ${al}
|
69
|
+
i32.add
|
70
|
+
i32.load16_u 0 6
|
71
|
+
|
72
|
+
i32.ne
|
73
|
+
if 64
|
74
|
+
i32.const 0
|
75
|
+
i32.const 2
|
76
|
+
return
|
77
|
+
end
|
78
|
+
|
79
|
+
local.get ${al}
|
80
|
+
i32.const 2
|
81
|
+
i32.sub
|
82
|
+
local.tee ${al}
|
83
|
+
i32.const 2
|
84
|
+
i32.ge_s
|
85
|
+
br_if 0
|
86
|
+
end
|
87
|
+
end`;
|
88
|
+
|
89
|
+
// check bonus char if exists
|
90
|
+
if (al == 1) {
|
91
|
+
if (Porffor.wasm.i32.load8_u(Porffor.wasm`local.get ${a}`, 0, 4) !=
|
92
|
+
Porffor.wasm.i32.load8_u(Porffor.wasm`local.get ${b}`, 0, 4)) return false;
|
21
93
|
}
|
22
94
|
return true;
|
23
95
|
} else {
|
@@ -38,6 +110,40 @@ export const __Porffor_strcmp = (a: any, b: any): boolean => {
|
|
38
110
|
return true;
|
39
111
|
} else {
|
40
112
|
// string, string
|
113
|
+
let ap: i32 = a - 4;
|
114
|
+
let bp: i32 = b - 4;
|
115
|
+
Porffor.wasm`
|
116
|
+
loop 64
|
117
|
+
local.get ${ap}
|
118
|
+
local.get ${al}
|
119
|
+
i32.const 2
|
120
|
+
i32.mul
|
121
|
+
i32.add
|
122
|
+
i64.load 0 0
|
123
|
+
|
124
|
+
local.get ${bp}
|
125
|
+
local.get ${al}
|
126
|
+
i32.const 2
|
127
|
+
i32.mul
|
128
|
+
i32.add
|
129
|
+
i64.load 0 0
|
130
|
+
|
131
|
+
i64.ne
|
132
|
+
if 64
|
133
|
+
i32.const 0
|
134
|
+
i32.const 2
|
135
|
+
return
|
136
|
+
end
|
137
|
+
|
138
|
+
local.get ${al}
|
139
|
+
i32.const 4
|
140
|
+
i32.sub
|
141
|
+
local.tee ${al}
|
142
|
+
i32.const 4
|
143
|
+
i32.ge_s
|
144
|
+
br_if 0
|
145
|
+
end`;
|
146
|
+
|
41
147
|
for (let i: i32 = 0; i < al; i++) {
|
42
148
|
if (Porffor.wasm.i32.load16_u(Porffor.wasm`local.get ${a}` + i*2, 0, 4) !=
|
43
149
|
Porffor.wasm.i32.load16_u(Porffor.wasm`local.get ${b}` + i*2, 0, 4)) return false;
|