Skip to content

Instantly share code, notes, and snippets.

@ageekymonk
Created February 3, 2012 02:10
Show Gist options
  • Save ageekymonk/1727213 to your computer and use it in GitHub Desktop.
Save ageekymonk/1727213 to your computer and use it in GitHub Desktop.
Optimized Inline Function for ntohl and htonl
// Using the X86 instruction bswap and gcc inline assembly
inline unsigned int ntohl(unsigned int x)
{
asm("bswapl %1" : "=a" (x) : "a"(x));
}
inline unsigned int htonl(unsigned int x)
{
asm("bswapl %1" : "=a" (x) : "a"(x));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment