Skip to content

Instantly share code, notes, and snippets.

@mafintosh
Last active November 26, 2022 00:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mafintosh/5fa2470266de1583c4038e4e84f4e32d to your computer and use it in GitHub Desktop.
Save mafintosh/5fa2470266de1583c4038e4e84f4e32d to your computer and use it in GitHub Desktop.
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