Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Coerce lane indexes with ToNumber(). #335

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Coerce lane indexes with ToNumber(). #335

wants to merge 3 commits into from

Conversation

stoklund
Copy link

SIMD functions that take a lane index (extractLane, replaceLane, swizzle,
shuffle) should use ToNumber() to coerce the lane index to a number before
checking that the index is an integer in range.

This behavior corresponds to the SIMDToLane() function in the SIMD.js
specification.

This fixes issues #319 and #237.

@PeterJensen
Copy link
Collaborator

I think you meant #329 instead of 319, right?

SIMD functions that take a lane index (extractLane, replaceLane, swizzle,
shuffle) should use ToNumber() to coerce the lane index to a number before
checking that the index is an integer in range.

This behavior corresponds to the SIMDToLane() function in the SIMD.js
specification.

This fixes issues #329 and #237.
@stoklund
Copy link
Author

Oops, you are right. Fixed.

throw new RangeError('Lane index must be in bounds');
if (index != Math.floor(index))
throw new RangeError('Lane index must be an integer');
return index;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe implement simdCoerceLaneIndex() using simdCoerceIndex(), just to avoid a little code duplication. It shouldn't matter that the index != Math.floor() check fails before the bounds check, I think.

@stoklund
Copy link
Author

Thanks, Peter. I found another mistake in the validLaneIndex() function.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants