Skip to content

Commit b14e2e7

Browse files
thiru-mcwgithub-cygwin
authored andcommitted
Cygwin: _endian.h: Add AArch64 implementations for ntohl and ntohs
Add AArch64-specific implementations of __ntohl() and __ntohs() in `winsup/cygwin/include/machine/_endian.h`. For AArch64 targets, use the `REV` and `REV16` instructions to perform byte swapping, with explicit zero-extension for 16-bit values to ensure correct register semantics. Signed-off-by: Thirumalai Nagalingam <thirumalai.nagalingam@multicorewareinc.com>
1 parent b41e3b6 commit b14e2e7

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

winsup/cygwin/include/machine/_endian.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,26 @@ _ELIDABLE_INLINE __uint16_t __ntohs(__uint16_t);
2626
_ELIDABLE_INLINE __uint32_t
2727
__ntohl(__uint32_t _x)
2828
{
29+
#if defined(__x86_64__)
2930
__asm__("bswap %0" : "=r" (_x) : "0" (_x));
31+
#elif defined(__aarch64__)
32+
__asm__("rev %w0, %w0" : "=r" (_x) : "0" (_x));
33+
#endif
3034
return _x;
3135
}
3236

3337
_ELIDABLE_INLINE __uint16_t
3438
__ntohs(__uint16_t _x)
3539
{
40+
#if defined(__x86_64__)
3641
__asm__("xchgb %b0,%h0" /* swap bytes */
3742
: "=Q" (_x)
3843
: "0" (_x));
44+
#elif defined(__aarch64__)
45+
__asm__("uxth %w0, %w0\n\t"
46+
"rev16 %w0, %w0"
47+
: "+r" (_x));
48+
#endif
3949
return _x;
4050
}
4151

0 commit comments

Comments
 (0)