Hi I'm using C++ / Boost ASIO and I have to inline ntohl()
for performance reasons. Each data packet contains 256 int32s, hence a lot of calls to ntohl()
. Has anyone done this?
Here is the compiled assembly output out of VC10++ with all optimizations turned on:
; int32_t d = boost::asio::detail::socket_ops::network_to_host_long(*pdw++);
mov esi, DWORD PTR _pdw$[esp+64]
mov eax, DWORD PTR [esi]
push eax
call DWORD PTR __imp__ntohl@4
I've also tried the regular ntohl()
provided by winsock. Any help would be greatly appreciated.
Also, I've been thinking the C way of having a #define
macro that does simple int32 barrel shifts (if the network order doesn't match the machines order at compile time). And if anyone knows and can provide the most efficient assembly for ntohl()
on a x86 / x64 architecture, that would be awesome. Eventually my code needs to be portable to ARM as well.