Closed Bug 1110656 Opened 10 years ago Closed 6 years ago

SIMD.js: Implement int32x4.shiftByVector and add it to asm.js (x86)

Categories

(Core :: JavaScript Engine, enhancement)

x86_64
Linux
enhancement
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: bbouvier, Unassigned)

References

Details

Dan tells me it might be necessary in the future to have int32x4.shiftByVector (i.e. each lane in the shifted vector is shifted by the other vector's corresponding lane) but it's not in the polyfill so far, because there is no single instruction mapping for x86, unless you have AVX2 (which means you have *at least* an Haswell CPU).

If we have AVX2, we can just use VPSLLVD, VPSRAVD, VPSRLVD (AVX2 variants of PSLLD, PSRLD, PSRAD).

There's a trick for left shift by vector, used by LLVM:
	pslld	$23, %xmm1
	paddd	(0x3f800000 x 4), %xmm1
	cvttps2dq	%xmm1, %xmm1
	pmulld	%xmm0, %xmm1
	movdqa	%xmm1, %xmm0

For other older x86 cpus, the most naive way to do it is:
- spill two vectors onto the stack (note: only one is we have SSE4.1 and we can use extractps et al.)
- for each lane of the shifted vector, load it in a register, shift it (using a stack memory operand as the count), store the register value onto the stack.
- reload the shifted vector to the result.

Not efficient though. If anybody can think of a better way to do it, I'm open to suggestions.
For right shift, I wonder if we can do something like convert/mangle the left operand into 2 float64x2 values, do floating-point divide by a power of 2 (or multiply by reciprocal), and then convert back to int32x4.

Or, maybe for int32x4 we could get away with doing 4 psrad/psrld instructions, one for each lane, plus copies and shuffles to glue it all together. Offhand, that seems like the most promising approach.

In any case, we're probably not going to include vector-vector shifts in the first iteration of SIMD.js, so this isn't urgent.
Severity: normal → enhancement
Per policy at https://wiki.mozilla.org/Bug_Triage/Projects/Bug_Handling/Bug_Husbandry#Inactive_Bugs. If this bug is not an enhancement request or a bug not present in a supported release of Firefox, then it may be reopened.
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → INACTIVE
Status: RESOLVED → REOPENED
Resolution: INACTIVE → ---
SIMD.js is being removed (bug 1416723).
Status: REOPENED → RESOLVED
Closed: 6 years ago6 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.