-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
68 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const f1_10000 = 26844; | ||
|
||
@inline export function itoa_fast(out: usize, val: u32): void { | ||
const low = val % 100000; | ||
const high = val / 100000; | ||
|
||
let tmp_high = high * (f1_10000) - (high / 4); | ||
let tmp_low = low * (f1_10000) - (low / 4); | ||
|
||
const h1 = 48 + (tmp_high >> 28); | ||
tmp_high = (tmp_high & 0x0fffffff) * 5; | ||
|
||
const h2 = 48 + (tmp_high >> 27); | ||
tmp_high = (tmp_high & 134217727) * 5; | ||
|
||
const h3 = 48 + (tmp_high >> 26); | ||
tmp_high = (tmp_high & 67108863) * 5; | ||
|
||
const h4 = 48 + (tmp_high >> 25); | ||
tmp_high = (tmp_high & 33554431) * 5; | ||
|
||
const h5 = 48 + (tmp_low >> 24); | ||
|
||
const l1 = 48 + (tmp_low >> 28); | ||
tmp_low = (tmp_low & 0x0fffffff) * 5; | ||
|
||
const l2 = 48 + (tmp_low >> 27); | ||
tmp_low = (tmp_low & 134217727) * 5; | ||
|
||
const l3 = 48 + (tmp_low >> 26); | ||
tmp_low = (tmp_low & 67108863) * 5; | ||
|
||
const l4 = 48 + (tmp_low >> 25); | ||
tmp_low = (tmp_low & 33554431) * 5; | ||
|
||
const l5 = 48 + (tmp_low >> 24); | ||
|
||
store<v128>(out, i32x4(h1 | (h2 << 16), h3 | (h4 << 16), h5 | (l1 << 16), l2 | (l3 << 16))); | ||
store<u32>(out, l4 | (l5 << 16), 16); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
// import { JSON } from "."; | ||
import { JSON } from "."; | ||
import { itoa_fast } from "./custom/itoa"; | ||
|
||
@json | ||
class ContentBlock { | ||
@omitnull() | ||
input: JSON.Raw | null = null; | ||
} | ||
|
||
const foo: ContentBlock = { | ||
input: "123" | ||
} | ||
|
||
console.log(JSON.stringify(foo)) | ||
const out = changetype<usize>(new ArrayBuffer(40)); | ||
itoa_fast(out, 1234567890); | ||
console.log(String.UTF16.decodeUnsafe(out, 20)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters