Closed
Bug 894105
Opened 11 years ago
Closed 5 years ago
Add SIMD support for JavaScript
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
WONTFIX
People
(Reporter: mohammad.r.haghighat, Unassigned)
References
(Depends on 1 open bug)
Details
(Keywords: feature, Whiteboard: [platform-rel-Games])
Attachments
(2 files, 1 obsolete file)
11.12 KB,
patch
|
Details | Diff | Splinter Review | |
3.82 KB,
text/plain
|
Details |
The purpose of this entry is discussing addition of SIMD support for JavaScript, tracking the progress towards that goal, and the related performance measurements. Comments, suggestions, and constructive critiques are all welcome. Cheers! -moh
Comment 1•11 years ago
|
||
dupe of bug 644389?
Comment 2•11 years ago
|
||
We have a prototype of SIMD vaddf and vmulf running in SpiderMonkey. The purpose of this prototype is to establish a base line and measure some estimates on performance gains we can obtain using SIMD for certain typed array operations. A native SIMD object that currently has two static methods, vaddf and vmulf, is added to SpiderMonkey. The operations are currently implemented as runtime calls in C/C++ using intrinsics. The implementation does not currently deal with the alignment of the data and also assumes that the array sizes are multiples of 4. Of course, we’ll take care of these as we make progress. As the base, we use the following JavaScript code for float32 typed array addition: // SIMD_JS.vaddf implementation SIMD_JS.vaddf = function (dst, op1, op2) { for (var i = 0, n = dst.length; i < n; ++i) { dst[i] = op1[i] + op2[i]; } } We compare the performance of the SIMD version against the above code. To make a fair comparison of the execution time of the SIMD version and the reference, we pre-allocate the destination array so we actually measure only the cost of the math operations and not the array allocation. Note that this is just for prototyping purposes and the final version could be in functional form, that is vaddf would return the result. The new JavaScript SIMD capability is currently used as: // SIMD.vaddf implementation SIMD.vaddf (dst, op1, op2); The JS test file we used to obtain our numbers as well as the patch to SpiderMonkey that creates the SIMD object and implements vaddf and vmulf are attached. Here are the performance results we measure on MacOS X running on Intel Ivy Bridge using SM JS shell with the patch applied to revision 137197: +-------+------------+---------------+---------+ | aSize | SIMD.vaddf | SIMD_JS.vaddf | speedup | | words | in ms | in ms | | | | | | | +-------+------------+---------------+---------+ | 4 | 83 | 58 | 0.70 | +-------+------------+---------------+---------+ | 8 | 75 | 65 | 0.87 | +-------+------------+---------------+---------+ | 16 | 79 | 95 | 1.20 | +-------+------------+---------------+---------+ | 32 | 81 | 138 | 1.70 | +-------+------------+---------------+---------+ | 64 | 88 | 226 | 2.57 | +-------+------------+---------------+---------+ | 128 | 104 | 398 | 3.83 | +-------+------------+---------------+---------+ | 256 | 128 | 738 | 5.77 | +-------+------------+---------------+---------+ | 512 | 167 | 1429 | 8.56 | +-------+------------+---------------+---------+ | 1024 | 241 | 2801 | 11.62 | +-------+------------+---------------+---------+ | 2048 | 395 | 5543 | 14.03 | +-------+------------+---------------+---------+ | 4096 | 928 | 11040 | 11.90 | +-------+------------+---------------+---------+ | 9192 | 2020 | 24621 | 12.19 | +-------+------------+---------------+---------+ +-------+------------+---------------+---------+ | aSize | SIMD.vmulf | SIMD_JS.vmulf | speedup | | words | in ms | in ms | | | | | | | +-------+------------+---------------+---------+ | 4 | 83 | 62 | 0.75 | +-------+------------+---------------+---------+ | 8 | 84 | 71 | 0.85 | +-------+------------+---------------+---------+ | 16 | 85 | 102 | 1.20 | +-------+------------+---------------+---------+ | 32 | 90 | 145 | 1.61 | +-------+------------+---------------+---------+ | 64 | 94 | 231 | 2.46 | +-------+------------+---------------+---------+ | 128 | 102 | 403 | 3.95 | +-------+------------+---------------+---------+ | 256 | 127 | 743 | 5.85 | +-------+------------+---------------+---------+ | 512 | 166 | 1428 | 8.60 | +-------+------------+---------------+---------+ | 1024 | 240 | 2812 | 11.72 | +-------+------------+---------------+---------+ | 2048 | 393 | 5547 | 14.11 | +-------+------------+---------------+---------+ | 4096 | 938 | 11024 | 11.75 | +-------+------------+---------------+---------+ | 9192 | 2039 | 24657 | 12.09 | +-------+------------+---------------+---------+ As can be seen from the data points, the potential gains can be significant for large arrays. Our next step is to make the JIT generate the SIMD instructions directly as opposed to calling functions that are implemented in intrinsics. Later on, we will take care of other aspects of the SIMD object including proper handling of alignment and different array sizes.
Comment 3•11 years ago
|
||
Comment 4•11 years ago
|
||
Comment 5•11 years ago
|
||
See John McCutchan's http://wiki.ecmascript.org/doku.php?id=strawman:simd_number and https://github.com/johnmccutchan/ecmascript_simd See also https://github.com/jussi-kalliokoski/node-dsp /be
Comment 6•11 years ago
|
||
Original test file was for wrong version, re-attaching the right one.
Attachment #776064 -
Attachment is obsolete: true
Updated•10 years ago
|
Attachment #778189 -
Attachment mime type: application/octet-stream → text/plain
Updated•10 years ago
|
Attachment #776063 -
Attachment is patch: true
Comment 7•10 years ago
|
||
Comment on attachment 776063 [details] [diff] [review] Prototype Patch for SIMD.vaddf and SIMD.vmulf functions Review of attachment 776063 [details] [diff] [review]: ----------------------------------------------------------------- ::: js/src/jsSIMD.h @@ +20,5 @@ > + > +namespace js { > + > +extern JSBool > +js_vaddf4(JSContext *cx, unsigned argc, Value *vp); style nit: No need for a double prefix (js::js_…). js_ is the C namespace scheme.
Assignee | ||
Updated•10 years ago
|
Assignee: general → nobody
Updated•8 years ago
|
Whiteboard: [platform-rel-Games]
Updated•8 years ago
|
platform-rel: --- → ?
Updated•7 years ago
|
platform-rel: ? → ---
Comment 9•5 years ago
|
||
SIMD.js is being removed (bug 1416723). Instead, we'll likely implement the wasm SIMD proposal at some point in the future.
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → WONTFIX
You need to log in
before you can comment on or make changes to this bug.
Description
•