Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: Simplify SIMD setup #8579

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 16 additions & 28 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,23 @@ if (typeof global.SIMD === 'object' && global.SIMD !== null) {

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

if (typeof SIMD.Bool16x8 === 'function')
simdFormatters.set(SIMD.Bool16x8, make(SIMD.Bool16x8.extractLane, 8));

if (typeof SIMD.Bool32x4 === 'function')
simdFormatters.set(SIMD.Bool32x4, make(SIMD.Bool32x4.extractLane, 4));

if (typeof SIMD.Bool8x16 === 'function')
simdFormatters.set(SIMD.Bool8x16, make(SIMD.Bool8x16.extractLane, 16));

if (typeof SIMD.Float32x4 === 'function')
simdFormatters.set(SIMD.Float32x4, make(SIMD.Float32x4.extractLane, 4));

if (typeof SIMD.Int16x8 === 'function')
simdFormatters.set(SIMD.Int16x8, make(SIMD.Int16x8.extractLane, 8));

if (typeof SIMD.Int32x4 === 'function')
simdFormatters.set(SIMD.Int32x4, make(SIMD.Int32x4.extractLane, 4));

if (typeof SIMD.Int8x16 === 'function')
simdFormatters.set(SIMD.Int8x16, make(SIMD.Int8x16.extractLane, 16));

if (typeof SIMD.Uint16x8 === 'function')
simdFormatters.set(SIMD.Uint16x8, make(SIMD.Uint16x8.extractLane, 8));

if (typeof SIMD.Uint32x4 === 'function')
simdFormatters.set(SIMD.Uint32x4, make(SIMD.Uint32x4.extractLane, 4));
const countPerType = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a Map be more useful here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it would. This object is just here to be iterated on two lines below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A literal map, using the SIMD fields as keys?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah as in new Map()
@targos simdFormatters is kind of the same case so consistency(?) :P

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just keep it as an Object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Bool16x8: 8,
Bool32x4: 4,
Bool8x16: 16,
Float32x4: 4,
Int16x8: 8,
Int32x4: 4,
Int8x16: 16,
Uint16x8: 8,
Uint32x4: 4,
Uint8x16: 16
};

if (typeof SIMD.Uint8x16 === 'function')
simdFormatters.set(SIMD.Uint8x16, make(SIMD.Uint8x16.extractLane, 16));
for (const key in countPerType) {
const type = SIMD[key];
simdFormatters.set(type, make(type.extractLane, countPerType[key]));
}
}

function tryStringify(arg) {
Expand Down