Austin Schuh | 7c75e58 | 2020-11-14 16:41:18 -0800 | [diff] [blame^] | 1 | "use strict"; |
| 2 | Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 | exports.paddingSize = exports.fromByteWidth = exports.uwidth = exports.fwidth = exports.iwidth = exports.toByteWidth = void 0; |
| 4 | var bit_width_1 = require("./bit-width"); |
| 5 | function toByteWidth(bitWidth) { |
| 6 | return 1 << bitWidth; |
| 7 | } |
| 8 | exports.toByteWidth = toByteWidth; |
| 9 | function iwidth(value) { |
| 10 | if (value >= -128 && value <= 127) |
| 11 | return bit_width_1.BitWidth.WIDTH8; |
| 12 | if (value >= -32768 && value <= 32767) |
| 13 | return bit_width_1.BitWidth.WIDTH16; |
| 14 | if (value >= -2147483648 && value <= 2147483647) |
| 15 | return bit_width_1.BitWidth.WIDTH32; |
| 16 | return bit_width_1.BitWidth.WIDTH64; |
| 17 | } |
| 18 | exports.iwidth = iwidth; |
| 19 | function fwidth(value) { |
| 20 | return value === Math.fround(value) ? bit_width_1.BitWidth.WIDTH32 : bit_width_1.BitWidth.WIDTH64; |
| 21 | } |
| 22 | exports.fwidth = fwidth; |
| 23 | function uwidth(value) { |
| 24 | if (value <= 255) |
| 25 | return bit_width_1.BitWidth.WIDTH8; |
| 26 | if (value <= 65535) |
| 27 | return bit_width_1.BitWidth.WIDTH16; |
| 28 | if (value <= 4294967295) |
| 29 | return bit_width_1.BitWidth.WIDTH32; |
| 30 | return bit_width_1.BitWidth.WIDTH64; |
| 31 | } |
| 32 | exports.uwidth = uwidth; |
| 33 | function fromByteWidth(value) { |
| 34 | if (value === 1) |
| 35 | return bit_width_1.BitWidth.WIDTH8; |
| 36 | if (value === 2) |
| 37 | return bit_width_1.BitWidth.WIDTH16; |
| 38 | if (value === 4) |
| 39 | return bit_width_1.BitWidth.WIDTH32; |
| 40 | return bit_width_1.BitWidth.WIDTH64; |
| 41 | } |
| 42 | exports.fromByteWidth = fromByteWidth; |
| 43 | function paddingSize(bufSize, scalarSize) { |
| 44 | return (~bufSize + 1) & (scalarSize - 1); |
| 45 | } |
| 46 | exports.paddingSize = paddingSize; |