From f66085f4a7eb9a21143e822055f8e3f32ec03c19 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 22 Jan 2024 14:24:06 -0400 Subject: [PATCH] OpcodeDispatcher: optimize bextr's (1 << x) - 1 little algebraic trick I cribbed from llvm Signed-off-by: Alyssa Rosenzweig --- FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp b/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp index 8c25b811a..a023d759b 100644 --- a/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp +++ b/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp @@ -2138,12 +2138,12 @@ void OpDispatchBuilder::BEXTRBMIOp(OpcodeArgs) { Length, MaxSrcBitOp); // Now build up the mask - // (1 << SanitizedLength) - 1 - auto One = _Constant(SrcSize, 1); - auto Mask = _Sub(IR::SizeToOpSize(Size), _Lshl(IR::SizeToOpSize(Size), One, SanitizedLength), One); + // (1 << SanitizedLength) - 1 = ~(~0 << SanitizedLength) + auto AllOnes = _Constant(~0ull); + auto InvertedMask = _Lshl(IR::SizeToOpSize(Size), AllOnes, SanitizedLength); // Now put it all together and make the result. - auto Dest = _And(IR::SizeToOpSize(Size), SanitizedShifted, Mask); + auto Dest = _Andn(IR::SizeToOpSize(Size), SanitizedShifted, InvertedMask); // Finally store the result. StoreResult(GPRClass, Op, Dest, -1);