porffor 0.36.7 → 0.37.0

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.
@@ -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
- const al: i32 = Porffor.wasm.i32.load(a, 0, 0);
10
- const bl: i32 = Porffor.wasm.i32.load(b, 0, 0);
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
- for (let i: i32 = 0; i < al; i++) {
19
- if (Porffor.wasm.i32.load8_u(Porffor.wasm`local.get ${a}` + i, 0, 4) !=
20
- Porffor.wasm.i32.load8_u(Porffor.wasm`local.get ${b}` + i, 0, 4)) return false;
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;
@@ -15,9 +15,9 @@ locals:[124,124,124,127,127,124,124,124,127,124,124,124,124,127,127,127],localNa
15
15
  globalInits:{underlyingKeys:(_,{allocPage,glbl,loc})=>[...number(allocPage(_,'array: __internal_object.ts/underlyingKeys','f64'),124),...glbl(36,'underlyingKeys',124),...glbl(35,'underlyingKeys',124),[252,3],[33,loc('#makearray_pointer_tmp',127)],[32,loc('#makearray_pointer_tmp',127)],[65,0],[54,1,0],[32,loc('#makearray_pointer_tmp',127)],[68,0],[252,3],[54,1,0],[32,loc('#makearray_pointer_tmp',127)],[26]],underlyingVals:(_,{allocPage,glbl,loc})=>[...number(allocPage(_,'array: __internal_object.ts/underlyingVals','f64'),124),...glbl(36,'underlyingVals',124),...glbl(35,'underlyingVals',124),[252,3],[33,loc('#makearray_pointer_tmp',127)],[32,loc('#makearray_pointer_tmp',127)],[65,0],[54,1,0],[32,loc('#makearray_pointer_tmp',127)],[68,0],[252,3],[54,1,0],[32,loc('#makearray_pointer_tmp',127)],[26]]},data:{"bytestring: __Porffor_object_makeObject/key1":[9,0,0,0,112,114,111,116,111,116,121,112,101],"bytestring: __Porffor_object_makeObject/key2":[11,0,0,0,99,111,110,115,116,114,117,99,116,111,114]},
16
16
  };
17
17
  this.__Porffor_strcmp = {
18
- wasm:()=>[[32,0],[32,2],[70],[4,64],[65,1],[65,2],[15],[11],[32,0],[40,0,0],[33,4],[32,2],[40,0,0],[33,5],[32,4],[32,5],[71],[4,64],[65,0],[65,2],[15],[11],[32,1],[65,195,1],[70],[4,64],[32,3],[65,195,1],[70],[4,64],[65,0],[33,6],[3,64],[32,6],[32,4],[72],[4,64],[32,0],[32,6],[106],[45,0,4],[32,2],[32,6],[106],[45,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[32,6],[65,1],[106],[33,6],[12,1],[11],[11],[65,1],[65,2],[15],[5],[65,0],[33,6],[3,64],[32,6],[32,4],[72],[4,64],[32,0],[32,6],[106],[45,0,4],[32,2],[32,6],[65,2],[108],[106],[47,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[32,6],[65,1],[106],[33,6],[12,1],[11],[11],[65,1],[65,2],[15],[11],[5],[32,3],[65,195,1],[70],[4,64],[65,0],[33,6],[3,64],[32,6],[32,4],[72],[4,64],[32,0],[32,6],[65,2],[108],[106],[47,0,4],[32,2],[32,6],[106],[45,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[32,6],[65,1],[106],[33,6],[12,1],[11],[11],[65,1],[65,2],[15],[5],[65,0],[33,6],[3,64],[32,6],[32,4],[72],[4,64],[32,0],[32,6],[65,2],[108],[106],[47,0,4],[32,2],[32,6],[65,2],[108],[106],[47,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[32,6],[65,1],[106],[33,6],[12,1],[11],[11],[65,1],[65,2],[15],[11],[11],[65,0],[65,128,1],[15]],
18
+ wasm:()=>[[32,0],[32,2],[70],[4,64],[65,1],[65,2],[15],[11],[32,0],[40,0,0],[33,4],[32,2],[40,0,0],[33,5],[32,4],[32,5],[71],[4,64],[65,0],[65,2],[15],[11],[32,1],[65,195,1],[70],[4,64],[32,3],[65,195,1],[70],[4,64],[32,0],[65,4],[107],[33,6],[32,2],[65,4],[107],[33,7],[32,4],[65,8],[78],[4,64],[3,64],[32,6],[32,4],[106],[41,0,0],[32,7],[32,4],[106],[41,0,0],[82],[4,64],[65,0],[65,2],[15],[11],[32,4],[65,8],[107],[34,4],[65,8],[78],[13,0],[11],[11],[32,4],[65,2],[78],[4,64],[3,64],[32,6],[32,4],[106],[47,0,6],[32,7],[32,4],[106],[47,0,6],[71],[4,64],[65,0],[65,2],[15],[11],[32,4],[65,2],[107],[34,4],[65,2],[78],[13,0],[11],[11],[32,4],[65,1],[70],[4,64],[32,0],[45,0,4],[32,2],[45,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[11],[65,1],[65,2],[15],[5],[65,0],[33,8],[3,64],[32,8],[32,4],[72],[4,64],[32,0],[32,8],[106],[45,0,4],[32,2],[32,8],[65,2],[108],[106],[47,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[32,8],[65,1],[106],[33,8],[12,1],[11],[11],[65,1],[65,2],[15],[11],[5],[32,3],[65,195,1],[70],[4,64],[65,0],[33,8],[3,64],[32,8],[32,4],[72],[4,64],[32,0],[32,8],[65,2],[108],[106],[47,0,4],[32,2],[32,8],[106],[45,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[32,8],[65,1],[106],[33,8],[12,1],[11],[11],[65,1],[65,2],[15],[5],[32,0],[65,4],[107],[33,6],[32,2],[65,4],[107],[33,7],[3,64],[32,6],[32,4],[65,2],[108],[106],[41,0,0],[32,7],[32,4],[65,2],[108],[106],[41,0,0],[82],[4,64],[65,0],[65,2],[15],[11],[32,4],[65,4],[107],[34,4],[65,4],[78],[13,0],[11],[65,0],[33,8],[3,64],[32,8],[32,4],[72],[4,64],[32,0],[32,8],[65,2],[108],[106],[47,0,4],[32,2],[32,8],[65,2],[108],[106],[47,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[32,8],[65,1],[106],[33,8],[12,1],[11],[11],[65,1],[65,2],[15],[11],[11],[65,0],[65,128,1],[15]],
19
19
  params:[127,127,127,127],typedParams:1,returns:[127,127],typedReturns:1,
20
- locals:[127,127,127],localNames:["a","a#type","b","b#type","al","bl","i"],
20
+ locals:[127,127,127,127,127],localNames:["a","a#type","b","b#type","al","bl","ap","bp","i"],
21
21
  };
22
22
  this.__Porffor_strcat = {
23
23
  wasm:(_,{builtin})=>[[32,0],[40,0,0],[33,4],[32,2],[40,0,0],[33,5],[32,1],[65,195,1],[70],[4,64],[32,3],[65,195,1],[70],[4,64],[65,4],[32,4],[106],[32,5],[106],[16,builtin('__Porffor_allocateBytes')],[34,6],[32,4],[32,5],[106],[54,0,0],[32,6],[65,4],[106],[32,0],[65,4],[106],[32,4],[252,10,0,0],[32,6],[65,4],[106],[32,4],[106],[32,2],[65,4],[106],[32,5],[252,10,0,0],[32,6],[65,195,1],[15],[5],[65,4],[32,4],[32,5],[106],[65,2],[108],[106],[16,builtin('__Porffor_allocateBytes')],[34,6],[32,4],[32,5],[106],[54,0,0],[65,0],[33,7],[3,64],[32,7],[32,4],[72],[4,64],[32,6],[32,7],[65,2],[108],[106],[32,0],[32,7],[106],[45,0,4],[59,0,4],[32,7],[65,1],[106],[33,7],[12,1],[11],[11],[32,6],[65,4],[106],[32,4],[65,2],[108],[106],[32,2],[65,4],[106],[32,5],[65,2],[108],[252,10,0,0],[32,6],[65,195,0],[15],[11],[5],[32,3],[65,195,1],[70],[4,64],[65,4],[32,4],[32,5],[106],[65,2],[108],[106],[16,builtin('__Porffor_allocateBytes')],[34,6],[32,4],[32,5],[106],[54,0,0],[32,6],[65,4],[106],[32,0],[65,4],[106],[32,4],[65,2],[108],[252,10,0,0],[32,6],[32,4],[65,2],[108],[106],[33,8],[65,0],[33,7],[3,64],[32,7],[32,5],[72],[4,64],[32,8],[32,7],[65,2],[108],[106],[32,2],[32,7],[106],[45,0,4],[59,0,4],[32,7],[65,1],[106],[33,7],[12,1],[11],[11],[32,6],[65,195,0],[15],[5],[65,4],[32,4],[32,5],[106],[65,2],[108],[106],[16,builtin('__Porffor_allocateBytes')],[34,6],[32,4],[32,5],[106],[54,0,0],[32,6],[65,4],[106],[32,0],[65,4],[106],[32,4],[65,2],[108],[252,10,0,0],[32,6],[65,4],[106],[32,4],[65,2],[108],[106],[32,2],[65,4],[106],[32,5],[65,2],[108],[252,10,0,0],[32,6],[65,195,0],[15],[11],[11],[65,0],[65,128,1],[15]],
@@ -248,7 +248,8 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
248
248
 
249
249
  const encodeFunc = ({
250
250
  [Opcodes.f64_const]: x => x,
251
- [Opcodes.if]: unsignedLEB128
251
+ [Opcodes.if]: unsignedLEB128,
252
+ [Opcodes.loop]: unsignedLEB128
252
253
  })[inst[0]] ?? signedLEB128;
253
254
  out.push([ ...inst, ...immediates.flatMap(x => encodeFunc(x)) ]);
254
255
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
4
- "version": "0.36.7+e872827a7",
4
+ "version": "0.37.0+44ce75202",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/runner/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.36.7+e872827a7';
3
+ globalThis.version = '0.37.0+44ce75202';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {