Skip to content

Commit

Permalink
encoding: optimize ieee754_binary64
Browse files Browse the repository at this point in the history
test262: 19.11% | πŸ§ͺ 50032 | 🀠 9559 | ❌ 3068 | πŸ’€ 19121 | πŸ—οΈ 486 | πŸ’₯ 425 | ⏰ 6 | πŸ“ 17367
  • Loading branch information
CanadaHonk committed Jun 14, 2024
1 parent e7c4ae0 commit 23594c2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
20 changes: 14 additions & 6 deletions compiler/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,20 @@ export const read_unsignedLEB128 = _input => {
};

// ieee 754 binary64
// const ieee754Cache = {};
// export const ieee754_binary64 = value => {
// if (ieee754Cache[value]) return ieee754Cache[value];
// return ieee754Cache[value] = [...new Uint8Array(new Float64Array([ value ]).buffer)];
// };
export const ieee754_binary64 = value => [...new Uint8Array(new Float64Array([ value ]).buffer)];
const ieee754Buffer = new Float64Array(1);
const ieee754Cache = {};
export const ieee754_binary64 = value => {
if (value === 0) {
if (1 / value === -Infinity) return [ 0, 0, 0, 0, 0, 0, 0, 128 ]; // -0
return [ 0, 0, 0, 0, 0, 0, 0, 0 ]; // +0
}

if (ieee754Cache[value]) return ieee754Cache[value].slice();

ieee754Buffer[0] = value;
return ieee754Cache[value] = [...new Uint8Array(ieee754Buffer.buffer)];
};

export const read_ieee754_binary64 = buffer => new Float64Array(new Uint8Array(buffer).buffer)[0];


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "porffor",
"description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
"version": "0.18.40+9c2421a79",
"version": "0.18.41+a97365a88",
"author": "CanadaHonk",
"license": "MIT",
"scripts": {},
Expand Down
2 changes: 1 addition & 1 deletion runner/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import fs from 'node:fs';
globalThis.version = '0.18.40+9c2421a79';
globalThis.version = '0.18.41+a97365a88';

// deno compat
if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion test262/history.json

Large diffs are not rendered by default.

0 comments on commit 23594c2

Please sign in to comment.