From 3215f75b081fc0f44e932b76830e6861853883d0 Mon Sep 17 00:00:00 2001 From: Basilisk-Dev Date: Sun, 26 Apr 2026 10:03:49 -0400 Subject: [PATCH] Issue #3049 - loongarch64: fix JIT uint8 clamp lowering --- .../loongarch64/MacroAssembler-loongarch64-inl.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/js/src/jit/loongarch64/MacroAssembler-loongarch64-inl.h b/js/src/jit/loongarch64/MacroAssembler-loongarch64-inl.h index 3ef9f420e2..4396242353 100644 --- a/js/src/jit/loongarch64/MacroAssembler-loongarch64-inl.h +++ b/js/src/jit/loongarch64/MacroAssembler-loongarch64-inl.h @@ -1455,15 +1455,19 @@ void MacroAssembler::storeUncanonicalizedFloat32(FloatRegister src, void MacroAssembler::clampIntToUint8(Register reg) { ScratchRegisterScope scratch(asMasm()); - SecondScratchRegisterScope scratch2(asMasm()); - MOZ_ASSERT(reg != scratch && reg != scratch2); + MOZ_ASSERT(reg != scratch); + + // Clamp semantics operate on int32 values; normalize the upper bits first in + // case the producer left the high 32 bits undefined. + as_slli_w(reg, reg, 0); as_slt(scratch, reg, zero); - moveIfNotZero(reg, zero, scratch); + as_masknez(reg, reg, scratch); - ma_li(scratch2, Imm32(255)); as_sltui(scratch, reg, 255); - moveIfZero(reg, scratch2, scratch); + as_addi_d(reg, reg, -255); + as_maskeqz(reg, reg, scratch); + as_addi_d(reg, reg, 255); } template