-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1835034 - Part 9: Inline storing into Float16Array. r=jandem
Slightly larger changes when compared to the previous two parts, because `MacroAssembler::storeToTypedFloatArray` had to be changed to support conversions instead of performing conversion in its caller: - `CacheIRCompiler::emitStoreTypedArrayElement` used `ScratchFloat32Scope` to convert `double -> float32`, but using the same approach won't work for float16, because `ScratchFloat32Scope` is also needed in `MacroAssembler::storeFloat16` to convert `float32 -> float16`. - Therefore move the conversion `double -> float32` into `StoreToTypedFloatArray` - And the conversions `double -> float16` into `MacroAssembler::storeFloat16`. Codegen for `StoreUnboxedScalar` on x64 looks like: vcvtps2ph $0x4, %xmm0, %xmm15 vmovd %xmm15, %r11d movw %r11w, 0x0(%rdx,%rbx,2) And on ARM64: h31, s0 h31, [x2, x4, lsl #1] Depends on D215769 Differential Revision: https://phabricator.services.mozilla.com/D215770
- Loading branch information
Showing
23 changed files
with
436 additions
and
39 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
js/src/jit-test/tests/warp/float16-as-float32-specialization-for-float16array-hole.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
function float32(f16, i, index) { | ||
// Unbox to Int32. | ||
i = i|0; | ||
|
||
// Float32 addition. | ||
let x = Math.fround(i + 0.1); | ||
|
||
// Float32 square root. | ||
let y = Math.fround(Math.sqrt(x)); | ||
|
||
// Store as Float16. | ||
f16[index] = y; | ||
} | ||
|
||
function float64(f16, i, index) { | ||
// Unbox to Int32. | ||
i = i|0; | ||
|
||
// Float32 addition. | ||
let x = Math.fround(i + 0.1); | ||
|
||
// Float64 square root. | ||
let y = Math.sqrt(x); | ||
|
||
// Store as Float16. | ||
f16[index] = y; | ||
} | ||
|
||
function toBaseline(f) { | ||
let source = f.toString(); | ||
assertEq(source.at(-1), "}"); | ||
|
||
// Add with-statement to disable Ion compilation. | ||
source = source.slice(0, -1) + "; with ({}); }"; | ||
|
||
return Function(`return ${source};`)(); | ||
} | ||
|
||
// Different results are expected for these inputs: | ||
// | ||
// Input Float64-SQRT Float32-SQRT | ||
// ----------------------------------- | ||
// 1527 39.09375 39.0625 | ||
// 16464 128.375 128.25 | ||
// 18581 136.375 136.25 | ||
// 20826 144.375 144.25 | ||
// 23199 152.375 152.25 | ||
// 25700 160.375 160.25 | ||
// 28329 168.375 168.25 | ||
// 31086 176.375 176.25 | ||
// | ||
// Limit execution to 1550 to avoid spending too much time on this single test. | ||
// | ||
// 1550 iterations should still be enough to allow tiering up to Ion, at least | ||
// under eager compilation settings. | ||
const LIMIT = 1550; | ||
|
||
let float32_baseline = toBaseline(float32); | ||
let float64_baseline = toBaseline(float64); | ||
|
||
let f16 = new Float16Array(1); | ||
let u16 = new Uint16Array(f16.buffer); | ||
|
||
let n = 0; | ||
for (let i = 0; i < LIMIT; ++i) { | ||
// Call with out-of-bounds indices to trigger compilation with | ||
// MStoreTypedArrayElementHole. | ||
float32(f16, i, 100_000); | ||
float64(f16, i, 100_000); | ||
|
||
float32(f16, i, 0); | ||
let x = u16[0]; | ||
|
||
float32_baseline(f16, i, 0); | ||
assertEq(x, u16[0]); | ||
|
||
float64(f16, i, 0); | ||
let y = u16[0]; | ||
|
||
float64_baseline(f16, i, 0); | ||
assertEq(y, u16[0]); | ||
|
||
if (x !== y) { | ||
n++; | ||
} | ||
} | ||
assertEq(n, 1); |
82 changes: 82 additions & 0 deletions
82
js/src/jit-test/tests/warp/float16-as-float32-specialization-for-float16array.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
function float32(f16, i) { | ||
// Unbox to Int32. | ||
i = i|0; | ||
|
||
// Float32 addition. | ||
let x = Math.fround(i + 0.1); | ||
|
||
// Float32 square root. | ||
let y = Math.fround(Math.sqrt(x)); | ||
|
||
// Store as Float16. | ||
f16[0] = y; | ||
} | ||
|
||
function float64(f16, i) { | ||
// Unbox to Int32. | ||
i = i|0; | ||
|
||
// Float32 addition. | ||
let x = Math.fround(i + 0.1); | ||
|
||
// Float64 square root. | ||
let y = Math.sqrt(x); | ||
|
||
// Store as Float16. | ||
f16[0] = y; | ||
} | ||
|
||
function toBaseline(f) { | ||
let source = f.toString(); | ||
assertEq(source.at(-1), "}"); | ||
|
||
// Add with-statement to disable Ion compilation. | ||
source = source.slice(0, -1) + "; with ({}); }"; | ||
|
||
return Function(`return ${source};`)(); | ||
} | ||
|
||
// Different results are expected for these inputs: | ||
// | ||
// Input Float64-SQRT Float32-SQRT | ||
// ----------------------------------- | ||
// 1527 39.09375 39.0625 | ||
// 16464 128.375 128.25 | ||
// 18581 136.375 136.25 | ||
// 20826 144.375 144.25 | ||
// 23199 152.375 152.25 | ||
// 25700 160.375 160.25 | ||
// 28329 168.375 168.25 | ||
// 31086 176.375 176.25 | ||
// | ||
// Limit execution to 1550 to avoid spending too much time on this single test. | ||
// | ||
// 1550 iterations should still be enough to allow tiering up to Ion, at least | ||
// under eager compilation settings. | ||
const LIMIT = 1550; | ||
|
||
let float32_baseline = toBaseline(float32); | ||
let float64_baseline = toBaseline(float64); | ||
|
||
let f16 = new Float16Array(1); | ||
let u16 = new Uint16Array(f16.buffer); | ||
|
||
let n = 0; | ||
for (let i = 0; i < LIMIT; ++i) { | ||
float32(f16, i); | ||
let x = u16[0]; | ||
|
||
float32_baseline(f16, i); | ||
assertEq(x, u16[0]); | ||
|
||
float64(f16, i); | ||
let y = u16[0]; | ||
|
||
float64_baseline(f16, i); | ||
assertEq(y, u16[0]); | ||
|
||
if (x !== y) { | ||
n++; | ||
} | ||
} | ||
assertEq(n, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.