Last active
November 26, 2022 00:01
-
-
Save mafintosh/5fa2470266de1583c4038e4e84f4e32d to your computer and use it in GitHub Desktop.
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
var v0 = 0 // represent the first 24bit of an uint64 | |
var v1 = 0 // next 8bit | |
var v2 = 0 // final 32bit | |
function addUint64 (b0, b1, b2) { | |
v0 = (v0 & 0xffffff) + b0 // cast to 24bit and add b0 | |
v1 = (v1 & 0xff) + b1 + (v0 >>> 24) // cast to 8bit, add b1 one plus the carry from v0 | |
v2 = (v2 + b2 + (v1 >>> 8)) | 0 // add b2 and carry from v1. cast to int to make v8 happy | |
} | |
function toUint32LEArray () { | |
return new Uint32Array([(v1 << 24) | v0, v2]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment