commit 9aa3304e2fa4134ff8306ee1a69a6f1b00cc3bc7
parent f6e86e9a5e2b3a964e777495238bced8cb2126e8
Author: André Bargull <andre.bargull@gmail.com>
Date: Thu, 23 Oct 2025 09:56:06 +0000
Bug 1995488 - Part 2: Remove branches from clampDoubleToUint8 on riscv64. r=spidermonkey-reviewers,iain
Improves the generated code from:
```asm
feq.d t4, ft1, ft1
beq t4, zero, 0 -> nan
addi zero, t4, 17
fcvt.w.d [RNE] t0, ft1
sgtz t5, t0
neg t5, t5
and t0, t0, t5
li t5, 255
bge t5, t0, 0 -> skip
li t0, 255
j 0 -> done
mv t0, zero
```
To:
```asm
fcvt.w.d [RNE] t0, ft1
feq.d t4, ft1, ft1
neg t4, t4
and t0, t0, t4
sgtz t4, t0
neg t4, t4
and t0, t0, t4
li t4, 255
bge t4, t0, 0 -> skip
li t0, 255
```
Two less instructions and only a single conditional jump.
Differential Revision: https://phabricator.services.mozilla.com/D269351
Diffstat:
1 file changed, 1 insertion(+), 13 deletions(-)
diff --git a/js/src/jit/riscv64/MacroAssembler-riscv64.cpp b/js/src/jit/riscv64/MacroAssembler-riscv64.cpp
@@ -2456,21 +2456,9 @@ void MacroAssembler::subFromStackPtr(Imm32 imm32) {
}
void MacroAssembler::clampDoubleToUint8(FloatRegister input, Register output) {
- JitSpew(JitSpew_Codegen, "[ clampDoubleToUint8");
- Label nan, done;
- UseScratchRegisterScope temps(this);
- Register scratch = temps.Acquire();
- feq_d(scratch, input, input);
- beqz(scratch, &nan);
- addi(zero, scratch, 0x11);
Round_w_d(output, input);
+ Clear_if_nan_d(output, input);
clampIntToUint8(output);
- ma_branch(&done);
- // Input is nan
- bind(&nan);
- mv(output, zero_reg);
- bind(&done);
- JitSpew(JitSpew_Codegen, "]");
}
//{{{ check_macroassembler_style