Skip to content

Commit

Permalink
Merge pull request #109 from bcc2528/bcc2528-Opt-GetAs
Browse files Browse the repository at this point in the history
Minor optimize GetAsDword, and GetAsByte.
  • Loading branch information
captainys authored Nov 24, 2023
2 parents b79e986 + 3c4d7e3 commit 20f0ba1
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions src/cpu/i486.h
Original file line number Diff line number Diff line change
Expand Up @@ -1367,20 +1367,23 @@ class i486DXCommon : public CPU
*/
inline unsigned int GetAsDword(void) const
{
static const unsigned int numBytesMask[MAX_NUM_BYTES]=
unsigned int dword=cpputil::GetDword(byteData);
switch(numBytes)
{
0x00000000,
0x000000FF,
0x0000FFFF,
0x00FFFFFF,
0xFFFFFFFF,
0xFFFFFFFF,
0xFFFFFFFF,
0xFFFFFFFF,
0xFFFFFFFF,
0xFFFFFFFF,
};
return cpputil::GetDword(byteData)&numBytesMask[numBytes];
case 0:
dword=0;
break;
case 1:
dword&=0x000000FF;
break;
case 2:
dword&=0x0000FFFF;
break;
case 3:
dword&=0x00FFFFFF;
break;
}
return dword;
}
/*! Returns a value as an unsigned byte.
It won't evaluate beyond numBytes.
Expand All @@ -1395,22 +1398,19 @@ class i486DXCommon : public CPU
*/
inline unsigned int GetAsWord(void) const
{
static const unsigned int numBytesMask[MAX_NUM_BYTES]=
{
0x00000000,
0x000000FF,
0x0000FFFF,
0x0000FFFF,
0x0000FFFF,
0x0000FFFF,
0x0000FFFF,
0x0000FFFF,
0x0000FFFF,
0x0000FFFF,
};

unsigned int word=cpputil::GetWord(byteData);
word&=numBytesMask[numBytes];
switch(numBytes)
{
case 0:
word=0;
break;
case 1:
word&=0x000000FF;
break;
default:
word&=0x0000FFFF;
break;
}
return word;
}

Expand Down

0 comments on commit 20f0ba1

Please sign in to comment.