Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/binary

Package Overview
Dependencies
Maintainers
1
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/binary - npm Package Compare versions

Comparing version 1.0.8 to 1.1.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [1.1.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/binary@1.0.8...@thi.ng/binary@1.1.0) (2019-07-31)
### Features
* **binary:** add setLane8/4/2 fns ([7e24f5e](https://github.com/thi-ng/umbrella/commit/7e24f5e))
## [1.0.8](https://github.com/thi-ng/umbrella/compare/@thi.ng/binary@1.0.7...@thi.ng/binary@1.0.8) (2019-07-12)

@@ -8,0 +19,0 @@

25

lib/index.js

@@ -102,4 +102,4 @@ 'use strict';

const splat4_24 = (x) => ((x &= 0xf), splat8_24(x | (x << 4)));
const splat4_32 = (x) => ((x &= 0xf), splat8_32(x | (x << 4)));
const splat4_24 = (x) => (x & 0xf) * 0x111111;
const splat4_32 = (x) => ((x & 0xf) * 0x11111111) >>> 0;
const splat8_24 = (x) => (x & 0xff) * 0x010101;

@@ -111,5 +111,17 @@ const splat8_32 = (x) => ((x & 0xff) * 0x01010101) >>> 0;

const lane8 = (x, l) => (x >>> ((3 - l) << 3)) & 0xff;
const lane4 = (x, l) => (x >>> ((7 - l) << 2)) & 0xf;
const lane2 = (x, l) => (x >>> ((15 - l) << 1)) & 0x3;
const lane8 = (x, lane) => (x >>> ((3 - lane) << 3)) & 0xff;
const lane4 = (x, lane) => (x >>> ((7 - lane) << 2)) & 0xf;
const lane2 = (x, lane) => (x >>> ((15 - lane) << 1)) & 0x3;
const setLane8 = (x, y, lane) => {
const l = (3 - lane) << 3;
return ((~(0xff << l) & x) | ((y & 0xff) << l)) >>> 0;
};
const setLane4 = (x, y, lane) => {
const l = (7 - lane) << 2;
return ((~(0xf << l) & x) | ((y & 0xf) << l)) >>> 0;
};
const setLane2 = (x, y, lane) => {
const l = (15 - lane) << 1;
return ((~(0x3 << l) & x) | ((y & 0x3) << l)) >>> 0;
};
const swizzle8 = (x, a, b, c, d) => ((lane8(x, a) << 24) |

@@ -177,2 +189,5 @@ (lane8(x, b) << 16) |

exports.same8 = same8;
exports.setLane2 = setLane2;
exports.setLane4 = setLane4;
exports.setLane8 = setLane8;
exports.splat16_32 = splat16_32;

@@ -179,0 +194,0 @@ exports.splat4_24 = splat4_24;

189

lib/index.umd.js

@@ -1,188 +0,1 @@

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory((global.thi = global.thi || {}, global.thi.ng = global.thi.ng || {}, global.thi.ng.binary = {})));
}(this, function (exports) { 'use strict';
const MASKS = new Array(33).fill(0).map((_, i) => Math.pow(2, i) - 1);
const align = (addr, size) => (size--, (addr + size) & ~size);
const isAligned = (addr, size) => !(addr & (size - 1));
const popCount = (x) => ((x = x - ((x >>> 1) & 0x55555555)),
(x = (x & 0x33333333) + ((x >>> 2) & 0x33333333)),
(((x + (x >>> 4)) & 0xf0f0f0f) * 0x1010101) >>> 24);
const hammingDist = (x, y) => popCount(x ^ y);
const clz32 = (x) => x !== 0 ? 31 - ((Math.log(x >>> 0) / Math.LN2) | 0) : 32;
const ctz32 = (x) => {
let c = 32;
x &= -x;
x && c--;
x & 0x0000ffff && (c -= 16);
x & 0x00ff00ff && (c -= 8);
x & 0x0f0f0f0f && (c -= 4);
x & 0x33333333 && (c -= 2);
x & 0x55555555 && (c -= 1);
return c;
};
const defMask = (a, b) => (~MASKS[a] & MASKS[b]) >>> 0;
const maskL = (n, x) => (x & MASKS[n]) >>> 0;
const maskH = (n, x) => (x & ~MASKS[n]) >>> 0;
const bitClear = (x, bit) => (x & ~(1 << bit)) >>> 0;
const bitFlip = (x, bit) => (x ^ (1 << bit)) >>> 0;
const bitSet = (x, bit) => (x | (1 << bit)) >>> 0;
const bitSetWindow = (x, y, from, to) => {
const m = defMask(from, to);
return (x & ~m) | ((y << (1 << from)) & m);
};
const bitClearWindow = (x, from, to) => x & ~defMask(from, to);
const F32 = new Float32Array(1);
const I32 = new Int32Array(F32.buffer);
const U32 = new Uint32Array(F32.buffer);
const floatToIntBits = (x) => ((F32[0] = x), I32[0]);
const floatToUintBits = (x) => ((F32[0] = x), U32[0]);
const intBitsToFloat = (x) => ((I32[0] = x), F32[0]);
const uintBitsToFloat = (x) => ((U32[0] = x), F32[0]);
const floatToSortableInt = (x) => {
if (x === -0)
x = 0;
const i = floatToIntBits(x);
return x < 0 ? ~i | (1 << 31) : i;
};
const encodeGray32 = (x) => (x ^ (x >>> 1)) >>> 0;
const decodeGray32 = (x) => {
x = x ^ (x >>> 16);
x = x ^ (x >>> 8);
x = x ^ (x >>> 4);
x = x ^ (x >>> 2);
x = x ^ (x >>> 1);
return x >>> 0;
};
const bitNot = (n, x) => maskL(n, ~x);
const bitAnd = (n, a, b) => maskL(n, a & b);
const bitNand = (n, a, b) => maskL(n, ~(a & b));
const bitOr = (n, a, b) => maskL(n, a | b);
const bitNor = (n, a, b) => maskL(n, ~(a & b));
const bitXor = (n, a, b) => maskL(n, a ^ b);
const bitXnor = (n, a, b) => maskL(n, ~(a ^ b));
const bitImply = (n, a, b) => maskL(n, ~a | b);
const bitAoi21 = (n, a, b, c) => maskL(n, ~(a | (b & c)));
const bitOai21 = (n, a, b, c) => maskL(n, ~(a & (b | c)));
const bitAoi22 = (n, a, b, c, d) => maskL(n, ~((a & b) | (c & d)));
const bitOai22 = (n, a, b, c, d) => maskL(n, ~((a | b) & (c | d)));
const bitMux = (n, a, b, s) => maskL(n, (a & ~s) | (b & s));
const bitDemux = (n, a, b, s) => [maskL(n, a & ~s), maskL(n, b & s)];
const isPow2 = (x) => !!x && !(x & (x - 1));
const ceilPow2 = (x) => {
x += (x === 0);
--x;
x |= x >>> 1;
x |= x >>> 2;
x |= x >>> 4;
x |= x >>> 8;
x |= x >>> 16;
return x + 1;
};
const floorPow2 = (x) => {
x |= x >>> 1;
x |= x >>> 2;
x |= x >>> 4;
x |= x >>> 8;
x |= x >>> 16;
return x - (x >>> 1);
};
const rotateLeft = (x, n) => ((x << n) | (x >>> (32 - n))) >>> 0;
const rotateRight = (x, n) => ((x >>> n) | (x << (32 - n))) >>> 0;
const splat4_24 = (x) => ((x &= 0xf), splat8_24(x | (x << 4)));
const splat4_32 = (x) => ((x &= 0xf), splat8_32(x | (x << 4)));
const splat8_24 = (x) => (x & 0xff) * 0x010101;
const splat8_32 = (x) => ((x & 0xff) * 0x01010101) >>> 0;
const splat16_32 = (x) => ((x &= 0xffff), ((x << 16) | x) >>> 0);
const same4 = (x) => ((x >> 4) & 0xf) === (x & 0xf);
const same8 = (x) => ((x >> 8) & 0xff) === (x & 0xff);
const lane8 = (x, l) => (x >>> ((3 - l) << 3)) & 0xff;
const lane4 = (x, l) => (x >>> ((7 - l) << 2)) & 0xf;
const lane2 = (x, l) => (x >>> ((15 - l) << 1)) & 0x3;
const swizzle8 = (x, a, b, c, d) => ((lane8(x, a) << 24) |
(lane8(x, b) << 16) |
(lane8(x, c) << 8) |
lane8(x, d)) >>>
0;
const swizzle4 = (x, a, b, c, d, e, f, g, h) => ((lane4(x, a) << 28) |
(lane4(x, b) << 24) |
(lane4(x, c) << 20) |
(lane4(x, d) << 16) |
(lane4(x, e) << 12) |
(lane4(x, f) << 8) |
(lane4(x, g) << 4) |
lane4(x, h)) >>>
0;
const flipBytes = (x) => ((x >>> 24) | ((x >> 8) & 0xff00) | ((x & 0xff00) << 8) | (x << 24)) >>> 0;
exports.MASKS = MASKS;
exports.align = align;
exports.bitAnd = bitAnd;
exports.bitAoi21 = bitAoi21;
exports.bitAoi22 = bitAoi22;
exports.bitClear = bitClear;
exports.bitClearWindow = bitClearWindow;
exports.bitDemux = bitDemux;
exports.bitFlip = bitFlip;
exports.bitImply = bitImply;
exports.bitMux = bitMux;
exports.bitNand = bitNand;
exports.bitNor = bitNor;
exports.bitNot = bitNot;
exports.bitOai21 = bitOai21;
exports.bitOai22 = bitOai22;
exports.bitOr = bitOr;
exports.bitSet = bitSet;
exports.bitSetWindow = bitSetWindow;
exports.bitXnor = bitXnor;
exports.bitXor = bitXor;
exports.ceilPow2 = ceilPow2;
exports.clz32 = clz32;
exports.ctz32 = ctz32;
exports.decodeGray32 = decodeGray32;
exports.defMask = defMask;
exports.encodeGray32 = encodeGray32;
exports.flipBytes = flipBytes;
exports.floatToIntBits = floatToIntBits;
exports.floatToSortableInt = floatToSortableInt;
exports.floatToUintBits = floatToUintBits;
exports.floorPow2 = floorPow2;
exports.hammingDist = hammingDist;
exports.intBitsToFloat = intBitsToFloat;
exports.isAligned = isAligned;
exports.isPow2 = isPow2;
exports.lane2 = lane2;
exports.lane4 = lane4;
exports.lane8 = lane8;
exports.maskH = maskH;
exports.maskL = maskL;
exports.popCount = popCount;
exports.rotateLeft = rotateLeft;
exports.rotateRight = rotateRight;
exports.same4 = same4;
exports.same8 = same8;
exports.splat16_32 = splat16_32;
exports.splat4_24 = splat4_24;
exports.splat4_32 = splat4_32;
exports.splat8_24 = splat8_24;
exports.splat8_32 = splat8_32;
exports.swizzle4 = swizzle4;
exports.swizzle8 = swizzle8;
exports.uintBitsToFloat = uintBitsToFloat;
Object.defineProperty(exports, '__esModule', { value: true });
}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(((t=t||self).thi=t.thi||{},t.thi.ng=t.thi.ng||{},t.thi.ng.binary={}))}(this,function(t){"use strict";const e=new Array(33).fill(0).map((t,e)=>Math.pow(2,e)-1),i=t=>(t-=t>>>1&1431655765,t=(858993459&t)+(t>>>2&858993459),16843009*(t+(t>>>4)&252645135)>>>24),n=(t,i)=>(~e[t]&e[i])>>>0,o=(t,i)=>(i&e[t])>>>0,a=new Float32Array(1),r=new Int32Array(a.buffer),s=new Uint32Array(a.buffer),l=t=>(a[0]=t,r[0]),b=(t,e)=>t>>>(3-e<<3)&255,f=(t,e)=>t>>>(7-e<<2)&15;t.MASKS=e,t.align=(t,e)=>(e--,t+e&~e),t.bitAnd=(t,e,i)=>o(t,e&i),t.bitAoi21=(t,e,i,n)=>o(t,~(e|i&n)),t.bitAoi22=(t,e,i,n,a)=>o(t,~(e&i|n&a)),t.bitClear=(t,e)=>(t&~(1<<e))>>>0,t.bitClearWindow=(t,e,i)=>t&~n(e,i),t.bitDemux=(t,e,i,n)=>[o(t,e&~n),o(t,i&n)],t.bitFlip=(t,e)=>(t^1<<e)>>>0,t.bitImply=(t,e,i)=>o(t,~e|i),t.bitMux=(t,e,i,n)=>o(t,e&~n|i&n),t.bitNand=(t,e,i)=>o(t,~(e&i)),t.bitNor=(t,e,i)=>o(t,~(e&i)),t.bitNot=(t,e)=>o(t,~e),t.bitOai21=(t,e,i,n)=>o(t,~(e&(i|n))),t.bitOai22=(t,e,i,n,a)=>o(t,~((e|i)&(n|a))),t.bitOr=(t,e,i)=>o(t,e|i),t.bitSet=(t,e)=>(t|1<<e)>>>0,t.bitSetWindow=(t,e,i,o)=>{const a=n(i,o);return t&~a|e<<(1<<i)&a},t.bitXnor=(t,e,i)=>o(t,~(e^i)),t.bitXor=(t,e,i)=>o(t,e^i),t.ceilPow2=t=>(t+=0===t,--t,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,1+(t|=t>>>16)),t.clz32=t=>0!==t?31-(Math.log(t>>>0)/Math.LN2|0):32,t.ctz32=t=>{let e=32;return(t&=-t)&&e--,65535&t&&(e-=16),16711935&t&&(e-=8),252645135&t&&(e-=4),858993459&t&&(e-=2),1431655765&t&&(e-=1),e},t.decodeGray32=t=>(t^=t>>>16,t^=t>>>8,t^=t>>>4,t^=t>>>2,(t^=t>>>1)>>>0),t.defMask=n,t.encodeGray32=t=>(t^t>>>1)>>>0,t.flipBytes=t=>(t>>>24|t>>8&65280|(65280&t)<<8|t<<24)>>>0,t.floatToIntBits=l,t.floatToSortableInt=t=>{-0===t&&(t=0);const e=l(t);return t<0?~e|1<<31:e},t.floatToUintBits=t=>(a[0]=t,s[0]),t.floorPow2=t=>(t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,(t|=t>>>16)-(t>>>1)),t.hammingDist=(t,e)=>i(t^e),t.intBitsToFloat=t=>(r[0]=t,a[0]),t.isAligned=(t,e)=>!(t&e-1),t.isPow2=t=>!(!t||t&t-1),t.lane2=(t,e)=>t>>>(15-e<<1)&3,t.lane4=f,t.lane8=b,t.maskH=(t,i)=>(i&~e[t])>>>0,t.maskL=o,t.popCount=i,t.rotateLeft=(t,e)=>(t<<e|t>>>32-e)>>>0,t.rotateRight=(t,e)=>(t>>>e|t<<32-e)>>>0,t.same4=t=>(t>>4&15)==(15&t),t.same8=t=>(t>>8&255)==(255&t),t.setLane2=(t,e,i)=>{const n=15-i<<1;return(~(3<<n)&t|(3&e)<<n)>>>0},t.setLane4=(t,e,i)=>{const n=7-i<<2;return(~(15<<n)&t|(15&e)<<n)>>>0},t.setLane8=(t,e,i)=>{const n=3-i<<3;return(~(255<<n)&t|(255&e)<<n)>>>0},t.splat16_32=t=>(t&=65535,(t<<16|t)>>>0),t.splat4_24=t=>1118481*(15&t),t.splat4_32=t=>286331153*(15&t)>>>0,t.splat8_24=t=>65793*(255&t),t.splat8_32=t=>16843009*(255&t)>>>0,t.swizzle4=(t,e,i,n,o,a,r,s,l)=>(f(t,e)<<28|f(t,i)<<24|f(t,n)<<20|f(t,o)<<16|f(t,a)<<12|f(t,r)<<8|f(t,s)<<4|f(t,l))>>>0,t.swizzle8=(t,e,i,n,o)=>(b(t,e)<<24|b(t,i)<<16|b(t,n)<<8|b(t,o))>>>0,t.uintBitsToFloat=t=>(s[0]=t,a[0]),Object.defineProperty(t,"__esModule",{value:!0})});
{
"name": "@thi.ng/binary",
"version": "1.0.8",
"version": "1.1.0",
"description": "Assorted binary / bitwise operations, conversions, utilities.",

@@ -17,18 +17,19 @@ "module": "./index.js",

"scripts": {
"build": "yarn clean && yarn build:es6 && yarn build:bundle",
"build": "yarn clean && yarn build:es6 && node ../../scripts/bundle-module",
"build:release": "yarn clean && yarn build:es6 && node ../../scripts/bundle-module all",
"build:es6": "tsc --declaration",
"build:bundle": "../../scripts/bundle-module",
"test": "rimraf build && tsc -p test/tsconfig.json && nyc mocha build/test/*.js",
"build:test": "rimraf build && tsc -p test/tsconfig.json",
"test": "yarn build:test && mocha build/test/*.js",
"cover": "yarn build:test && nyc mocha build/test/*.js && nyc report --reporter=lcov",
"clean": "rimraf *.js *.d.ts .nyc_output build coverage doc lib",
"cover": "yarn test && nyc report --reporter=lcov",
"doc": "node_modules/.bin/typedoc --mode modules --out doc --ignoreCompilerErrors src",
"pub": "yarn build && yarn publish --access public"
"pub": "yarn build:release && yarn publish --access public"
},
"devDependencies": {
"@types/mocha": "^5.2.6",
"@types/node": "^12.0.8",
"@types/node": "^12.6.3",
"mocha": "^6.1.4",
"nyc": "^14.0.0",
"typedoc": "^0.14.2",
"typescript": "^3.5.2"
"typescript": "^3.5.3"
},

@@ -52,3 +53,3 @@ "keywords": [

"sideEffects": false,
"gitHead": "47075afc37f3a16adee7c903a2935304c7cf5daf"
"gitHead": "53eec7988c378fc37ae140e7174f36ef9b6208fe"
}

@@ -6,3 +6,3 @@ /**

*/
export const splat4_24 = (x) => ((x &= 0xf), splat8_24(x | (x << 4)));
export const splat4_24 = (x) => (x & 0xf) * 0x111111;
/**

@@ -13,3 +13,3 @@ * Repeats lowest nibble of `x` as 32 bit uint.

*/
export const splat4_32 = (x) => ((x &= 0xf), splat8_32(x | (x << 4)));
export const splat4_32 = (x) => ((x & 0xf) * 0x11111111) >>> 0;
/**

@@ -16,0 +16,0 @@ * Repeats lowest byte of `x` as 24 bit uint.

@@ -11,5 +11,5 @@ import { Lane2, Lane4, Lane8 } from "./api";

* @param x
* @param l
* @param lane
*/
export declare const lane8: (x: number, l: Lane8) => number;
export declare const lane8: (x: number, lane: Lane8) => number;
/**

@@ -28,7 +28,37 @@ * Extracts 4-bit lane from given 32bit uint.

* @param x
* @param l
* @param lane
*/
export declare const lane4: (x: number, l: Lane4) => number;
export declare const lane2: (x: number, l: Lane2) => number;
export declare const lane4: (x: number, lane: Lane4) => number;
export declare const lane2: (x: number, lane: Lane2) => number;
/**
* Sets 8-bit `lane` with value`y` in `x`.
*
* @see lane8
*
* @param x
* @param y
* @param lane
*/
export declare const setLane8: (x: number, y: number, lane: Lane8) => number;
/**
* Sets 4-bit `lane` with value `y` in `x`.
*
* @see lane4
*
* @param x
* @param y
* @param lane
*/
export declare const setLane4: (x: number, y: number, lane: Lane4) => number;
/**
* Sets 2-bit `lane` with value `y` in `x`.
*
* @see lane2
*
* @param x
* @param y
* @param lane
*/
export declare const setLane2: (x: number, y: number, lane: Lane2) => number;
/**
* Re-orders byte lanes in given order (MSB).

@@ -35,0 +65,0 @@ *

@@ -10,5 +10,5 @@ /**

* @param x
* @param l
* @param lane
*/
export const lane8 = (x, l) => (x >>> ((3 - l) << 3)) & 0xff;
export const lane8 = (x, lane) => (x >>> ((3 - lane) << 3)) & 0xff;
/**

@@ -27,7 +27,46 @@ * Extracts 4-bit lane from given 32bit uint.

* @param x
* @param l
* @param lane
*/
export const lane4 = (x, l) => (x >>> ((7 - l) << 2)) & 0xf;
export const lane2 = (x, l) => (x >>> ((15 - l) << 1)) & 0x3;
export const lane4 = (x, lane) => (x >>> ((7 - lane) << 2)) & 0xf;
export const lane2 = (x, lane) => (x >>> ((15 - lane) << 1)) & 0x3;
/**
* Sets 8-bit `lane` with value`y` in `x`.
*
* @see lane8
*
* @param x
* @param y
* @param lane
*/
export const setLane8 = (x, y, lane) => {
const l = (3 - lane) << 3;
return ((~(0xff << l) & x) | ((y & 0xff) << l)) >>> 0;
};
/**
* Sets 4-bit `lane` with value `y` in `x`.
*
* @see lane4
*
* @param x
* @param y
* @param lane
*/
export const setLane4 = (x, y, lane) => {
const l = (7 - lane) << 2;
return ((~(0xf << l) & x) | ((y & 0xf) << l)) >>> 0;
};
/**
* Sets 2-bit `lane` with value `y` in `x`.
*
* @see lane2
*
* @param x
* @param y
* @param lane
*/
export const setLane2 = (x, y, lane) => {
const l = (15 - lane) << 1;
return ((~(0x3 << l) & x) | ((y & 0x3) << l)) >>> 0;
};
/**
* Re-orders byte lanes in given order (MSB).

@@ -34,0 +73,0 @@ *

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc