Add rounding operations
Explicit rounding operations:
- Ceil
- Floor
A more general solution would be to emulate something like SSE's _mm_round_ps which takes a mode argument:
- round to nearest int
- round to negative infinity
- round to positive infinity
- round towards zero
A possible API: SIMD.float32x4.round(instance, mode)
where mode is a constant.
Having a mode argument and requiring it to be constant is problematic, as we discussed with shuffles. Fortunately, since the number of modes will always be pretty small, we can afford a function for each mode. The following names are hopefully non-controversial:
SIMD.float32x4.ceil // round towards positive infinity
SIMD.float32x4.floor // round towards negative infinity
SIMD.float32x4.trunc // round towards zero
since they exactly correspond to existing JS Math functions of the same name and are widely used in other areas too. For reference, in IEEE-754 these operations correspond to roundToIntegralTiesTowardPositive, roundToIntegralTiesTowardNegative, and roundToIntegralTiesTowardZero.
JS also has Math.round, which does round-to-nearest, however it doesn't do ties-to-even and doesn't match any of the IEEE-754 roundToIntegral operations, so I don't think we should use round for our round-to-nearest operation, to avoid confusion. I tentatively suggest the following name:
SIMD.float32x4.nearestInteger // round to nearest, ties to even
though I'm not attached to it. This operation is roundToIntegralTiesToEven in IEEE-754.
Do we want these for Phase 1, or are we OK with delaying until Phase 2?
We should probably include these in Phase 1.
OK, who wants to add these to the polyfill, including tests? Once that's done, I'll update the spec text.
We are running out of time to make API additions like this. Assuming TC39 will follow through with its annual release model, we might have a couple more weeks or maybe a month left, and then the window will close, unless we're OK with letting SIMD.js wait another year for standardization. In the last call, we decided to aim for the July meeting (in 3 weeks) for Stage 3, and that should include these operations, with spec, polyfill and a conforming implementation. I think we could still get things through if we let it slip until September, but not later than that. So, if there's anything more to add, let's get on it now.
At the last call, we decided to delay these until Phase 2. Current ports have not required these operations, and we want to get to Stage 3 at the July TC39 meeting.