mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1207843 - Part 3/3 - Clean up ARM Imm8::EncodeImm(). r=h4writer
This commit is contained in:
parent
07561ec9ed
commit
ea32fe0397
@ -647,33 +647,13 @@ class Imm8 : public Operand2
|
||||
|
||||
public:
|
||||
static datastore::Imm8mData EncodeImm(uint32_t imm) {
|
||||
// mozilla::CountLeadingZeroes32(imm) requires imm != 0.
|
||||
if (imm == 0)
|
||||
return datastore::Imm8mData(0, 0);
|
||||
int left = mozilla::CountLeadingZeroes32(imm) & 30;
|
||||
// See if imm is a simple value that can be encoded with a rotate of 0.
|
||||
// This is effectively imm <= 0xff, but I assume this can be optimized
|
||||
// more.
|
||||
if (left >= 24)
|
||||
return datastore::Imm8mData(imm, 0);
|
||||
|
||||
// Mask out the 8 bits following the first bit that we found, see if we
|
||||
// have 0 yet.
|
||||
int no_imm = imm & ~(0xff << (24 - left));
|
||||
if (no_imm == 0) {
|
||||
return datastore::Imm8mData(imm >> (24 - left), ((8 + left) >> 1));
|
||||
// An encodable integer has a maximum of 8 contiguous set bits,
|
||||
// with an optional wrapped left rotation to even bit positions.
|
||||
for (int rot = 0; rot < 16; rot++) {
|
||||
uint32_t rotimm = mozilla::RotateLeft(imm, rot*2);
|
||||
if (rotimm <= 0xFF)
|
||||
return datastore::Imm8mData(rotimm, rot);
|
||||
}
|
||||
// Look for the most signifigant bit set, once again.
|
||||
int right = 32 - (mozilla::CountLeadingZeroes32(no_imm) & 30);
|
||||
// If it is in the bottom 8 bits, there is a chance that this is a
|
||||
// wraparound case.
|
||||
if (right >= 8)
|
||||
return datastore::Imm8mData();
|
||||
// Rather than masking out bits and checking for 0, just rotate the
|
||||
// immediate that we were passed in, and see if it fits into 8 bits.
|
||||
unsigned int mask = imm << (8 - right) | imm >> (24 + right);
|
||||
if (mask <= 0xff)
|
||||
return datastore::Imm8mData(mask, (8 - right) >> 1);
|
||||
return datastore::Imm8mData();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user