Add bswap/bswap16 post MVP polyfills (#34)

This commit is contained in:
Max Graey
2018-02-19 13:35:28 +02:00
committed by Daniel Wirtz
parent 31633899f9
commit de1c4b3da5
8 changed files with 3301 additions and 0 deletions

View File

@ -71,6 +71,19 @@ globalScope["select"] = function select(ifTrue, ifFalse, condition) { return con
globalScope["sqrt"] = Math.sqrt;
globalScope["trunc"] = Math.trunc;
globalScope["bswap"] = function bswap(value) {
var a = value >> 8 & 0x00FF00FF;
var b = (value & 0x00FF00FF) << 8;
value = a | b;
a = value >> 16 & 0x0000FFFF;
b = (value & 0x0000FFFF) << 16;
return a | b;
}
globalScope["bswap16"] = function bswap16(value) {
return ((value << 8) & 0xFF00) | ((value >> 8) & 0x00FF) | (value & 0xFFFF0000);
}
function UnreachableError() {
if (Error.captureStackTrace)
Error.captureStackTrace(this, UnreachableError);