Skip to content

Update wifi.cpp - added faster reflect functions #896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions desmume/src/wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,24 @@ static u32 reflect(u32 ref, char ch)
return value;
}

static u32 reflect8(u32 ref)
{
ref = ((ref & 0x0F) << 4) | ((ref & 0xF0) >> 4);
ref = ((ref & 0x33) << 2) | ((ref & 0xCC) >> 2);
ref = ((ref & 0x55) << 1) | ((ref & 0xAA) >> 1);
return ref;
}

static u32 reflect32(u32 ref)
{
ref = ((ref & 0x0000FFFF) << 16) | ((ref & 0xFFFF0000) >> 16);
ref = ((ref & 0x00FF00FF) << 8) | ((ref & 0xFF00FF00) >> 8);
ref = ((ref & 0x0F0F0F0F) << 4) | ((ref & 0xF0F0F0F0) >> 4);
ref = ((ref & 0x33333333) << 2) | ((ref & 0xCCCCCCCC) >> 2);
ref = ((ref & 0x55555555) << 1) | ((ref & 0xAAAAAAAA) >> 1);
return ref;
}

static u32 WIFI_calcCRC32(u8* data, int len)
{
u32 crc = 0xFFFFFFFF;
Expand All @@ -366,10 +384,10 @@ static void WIFI_initCRC32Table()

for(int i = 0; i < 0x100; i++)
{
WIFI_CRC32Table[i] = reflect(i, 8) << 24;
WIFI_CRC32Table[i] = reflect8(i) << 24;
for(int j = 0; j < 8; j++)
WIFI_CRC32Table[i] = (WIFI_CRC32Table[i] << 1) ^ (WIFI_CRC32Table[i] & (1 << 31) ? polynomial : 0);
WIFI_CRC32Table[i] = reflect(WIFI_CRC32Table[i], 32);
WIFI_CRC32Table[i] = reflect32(WIFI_CRC32Table[i]);
}
}

Expand Down