Skip to content

Commit 7728f95

Browse files
danyshaananFishrock123
authored andcommitted
util: simplify SIMD setup
PR-URL: #8579 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
1 parent a425c4d commit 7728f95

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

lib/util.js

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,23 @@ if (typeof global.SIMD === 'object' && global.SIMD !== null) {
3838

3939
const SIMD = global.SIMD; // Pacify eslint.
4040

41-
if (typeof SIMD.Bool16x8 === 'function')
42-
simdFormatters.set(SIMD.Bool16x8, make(SIMD.Bool16x8.extractLane, 8));
43-
44-
if (typeof SIMD.Bool32x4 === 'function')
45-
simdFormatters.set(SIMD.Bool32x4, make(SIMD.Bool32x4.extractLane, 4));
46-
47-
if (typeof SIMD.Bool8x16 === 'function')
48-
simdFormatters.set(SIMD.Bool8x16, make(SIMD.Bool8x16.extractLane, 16));
49-
50-
if (typeof SIMD.Float32x4 === 'function')
51-
simdFormatters.set(SIMD.Float32x4, make(SIMD.Float32x4.extractLane, 4));
52-
53-
if (typeof SIMD.Int16x8 === 'function')
54-
simdFormatters.set(SIMD.Int16x8, make(SIMD.Int16x8.extractLane, 8));
55-
56-
if (typeof SIMD.Int32x4 === 'function')
57-
simdFormatters.set(SIMD.Int32x4, make(SIMD.Int32x4.extractLane, 4));
58-
59-
if (typeof SIMD.Int8x16 === 'function')
60-
simdFormatters.set(SIMD.Int8x16, make(SIMD.Int8x16.extractLane, 16));
61-
62-
if (typeof SIMD.Uint16x8 === 'function')
63-
simdFormatters.set(SIMD.Uint16x8, make(SIMD.Uint16x8.extractLane, 8));
64-
65-
if (typeof SIMD.Uint32x4 === 'function')
66-
simdFormatters.set(SIMD.Uint32x4, make(SIMD.Uint32x4.extractLane, 4));
41+
const countPerType = {
42+
Bool16x8: 8,
43+
Bool32x4: 4,
44+
Bool8x16: 16,
45+
Float32x4: 4,
46+
Int16x8: 8,
47+
Int32x4: 4,
48+
Int8x16: 16,
49+
Uint16x8: 8,
50+
Uint32x4: 4,
51+
Uint8x16: 16
52+
};
6753

68-
if (typeof SIMD.Uint8x16 === 'function')
69-
simdFormatters.set(SIMD.Uint8x16, make(SIMD.Uint8x16.extractLane, 16));
54+
for (const key in countPerType) {
55+
const type = SIMD[key];
56+
simdFormatters.set(type, make(type.extractLane, countPerType[key]));
57+
}
7058
}
7159

7260
function tryStringify(arg) {

0 commit comments

Comments
 (0)