On Jan 7 12:56, Jon Turney wrote: > On 07/01/2026 11:17, Corinna Vinschen wrote: > > Hi Thirumalai, > > > > On Jan 5 12:40, Thirumalai Nagalingam wrote: > > > Hello Everyone, > > > > > > This patch adds AArch64-specific inline asm implementations of __ntohl() > > > and __ntohs() in `winsup/cygwin/include/machine/_endian.h`. > > > > > > For AArch64 targets, the patch uses the REV and REV16 instructions > > > to perform byte swapping, with explicit zero-extension for 16-bit > > > values to ensure correct register semantics. > > > > > > Comments and reviews are welcome. > > > > > > Thanks & regards > > > Thirumalai Nagalingam > > > <[email protected]<mailto:[email protected]>> > > > > > > In-lined patch: > > > > > > diff --git a/winsup/cygwin/include/machine/_endian.h > > > b/winsup/cygwin/include/machine/_endian.h > > > index dbd4429b8..129cba66b 100644 > > > --- a/winsup/cygwin/include/machine/_endian.h > > > +++ b/winsup/cygwin/include/machine/_endian.h > > > @@ -26,16 +26,26 @@ _ELIDABLE_INLINE __uint16_t __ntohs(__uint16_t); > > > _ELIDABLE_INLINE __uint32_t > > > __ntohl(__uint32_t _x) > > > { > > > +#if defined(__x86_64__) > > > __asm__("bswap %0" : "=r" (_x) : "0" (_x)); > > > +#elif defined(__aarch64__) > > > + __asm__("rev %w0, %w0" : "=r" (_x) : "0" (_x)); > > > +#endif > > For a bit of future proofing, maybe this should end with > > #else > #error unknown architecture > > rather than ploughing on to silently return the unmodified x?
You're right, of course. Thirumalai, if you'd like to add this in another patch, that would be great. > (That's probably an observation which applies generally to aarch64 patches > :)) Indeed. Most of the patches are adding aarch64 code to places already guarded against wrong architectures like this, so this is often not a problem. To be honest, the real bug here is that we didn't add that #if defined(__x86_64__) already long ago. > Also, to be hypercorrect (that is, I do not expect anyone to do anything > about this): since big-endian ARM is a thing (although not for Windows) is > there a more tightly scoped define we might use here? Isn't the aarch64 architecture support on Windows restricted to LE anyway? Corinna
