[ENet-discuss] ENET_HOST_TO_NET/ENET_NET_TO_HOST
Lee Salzman
lsalzman at gmail.com
Sun Jul 14 11:14:11 PDT 2013
That's not what I meant. the host byte order is not fixed, even though net byte order is always big-endian. So hton/ntoh may simply be a no-op on a big-endian platform. The byteswap intrinsics always unconditionally swap, so you can't just blindly use them on all platforms as a replacement.
On 07/14/2013 08:35 PM, dmex wrote:
> You don't need to check for platform support... Intrinsics are special, the
> compiler will emit the appropriate code if the function is not supported for
> the target processor at compile time.
>
> -----Original Message-----
> From: enet-discuss-bounces at cubik.org [mailto:enet-discuss-bounces at cubik.org]
> On Behalf Of Lee Salzman
> Sent: Sunday, 14 July 2013 8:04 PM
> To: Discussion of the ENet library
> Subject: Re: [ENet-discuss] ENET_HOST_TO_NET/ENET_NET_TO_HOST
>
> Well, there would need to be a check that the platform is little-endian as
> well, so it would need to check for x86/arm platforms and it could use
> those, otherwise default to the ntoh/hton versions.
>
> On 07/14/2013 01:27 PM, dmex wrote:
>> Hello,
>>
>> On Windows the htons/htonl/ntohs/ntohl functions are much older and
>> slower than the same functions found on other Operating Systems since
>> the Windows versions of these functions do not make use of the native
>> bswap processor instruction.
>>
>> Intrinsic functions are available in both stdlib.h and intrin.h on
>> multiple platforms for solving this issue, you can simply define the
>> following in win32.h or enet.h for slightly better enet library
> performance:
>> #define ntohl(x) _byteswap_ulong(x)
>> #define ntohs(x) _byteswap_ushort(x)
>> #define htonl(x) _byteswap_ulong(x)
>> #define htons(x) _byteswap_ushort(x)
>>
>> #define ENET_HOST_TO_NET_16(value) (htons(value)) #define
>> ENET_HOST_TO_NET_32(value) (htonl(value)) #define
>> ENET_NET_TO_HOST_16(value) (ntohs(value)) #define
>> ENET_NET_TO_HOST_32(value) (ntohl(value))
>>
>> Would it be possible to include these in the enet library by default?
>>
>> -dmex
>>
>> _______________________________________________
>> ENet-discuss mailing list
>> ENet-discuss at cubik.org
>> http://lists.cubik.org/mailman/listinfo/enet-discuss
>>
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss
>
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss
>
More information about the ENet-discuss
mailing list