Skip to content

Instantly share code, notes, and snippets.

@merryhime
Created April 5, 2017 08:54
Show Gist options
  • Save merryhime/0c381a6ff5a4a01df476591f351d8af7 to your computer and use it in GitHub Desktop.
Save merryhime/0c381a6ff5a4a01df476591f351d8af7 to your computer and use it in GitHub Desktop.
std::uint32_t duplicate(std::uint32_t o) {
return ((o & 0x80808080) >> 7) * 0xFF;
}
# compiler suggestion:
duplicate(unsigned int):
shr edi, 7
and edi, 16843009
mov eax, edi
shl eax, 8
sub eax, edi
ret
# hand optimized:
duplicate(unsigned int):
and edi, 0x80808080
mov eax, edi
shr edi, 7
sub eax, edi
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment