Closed Bug 1690538 Opened 4 years ago Closed 3 years ago

SIMD optimization x64/x86: Better code for float->int conversion

Categories

(Core :: JavaScript: WebAssembly, enhancement, P3)

x86_64
All
enhancement

Tracking

()

RESOLVED FIXED
102 Branch
Tracking Status
firefox102 --- fixed

People

(Reporter: lth, Assigned: yury)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

We have fairly elaborate code for int->float conversion, see eg MacroAssemblerX86Shared::truncSatFloat32x4Toint32x2 or the even worse unsigned variant right below it. We can do better: https://github.com/WebAssembly/simd/issues/173, in the third comment, "option 2" is appealing. It's also possible v8 has updated its code since I let myself be inspired by it for these functions, and we should let it inspire us again.

(Also: https://github.com/WebAssembly/simd/issues/190, though it mostly points to #173.)

Looked into "option 2" (vmaxps dst, src, [rip + OFFSET_THAT_CONTAINS_INT_MAX_AS_FLOAT] looks incorrect):

  • even with vminps...
  • there is no exact representation for INT_MAX as float: 2147483520.f as INT_MAX produces 0x7FFFFF80, and 2147483647.f gives 0x80000000f

Surely there is a canonical representation for INT_MAX as float on the architecture even if it is not exact? Indeed our own unsignedTruncSatFloat32x4ToInt32x4 uses such a representation.

Happy to delay this until we have time to concentrate on those details.

For non-AVX, the approach saves one instruction.

For AVX, the savings are 3 instructions.

Assignee: nobody → ydelendik
Status: NEW → ASSIGNED
Summary: SIMD optimization x64/x86: Better code for int->float conversion → SIMD optimization x64/x86: Better code for float->int conversion

Fix alu vs fpu xor, reword comment.

Depends on D144463

Pushed by ydelendik@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/8bd424227b76 Better code for i32x4.trunc_sat_f32x4_s conversion. r=jseward https://hg.mozilla.org/integration/autoland/rev/4ee04d98cd3d Revise unsignedTruncSatFloat32x4ToInt32x4 code. r=jseward
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 102 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: