From owner-freebsd-current Fri Oct 27 6:10: 3 2000 Delivered-To: freebsd-current@freebsd.org Received: from whale.sunbay.crimea.ua (whale.sunbay.crimea.ua [212.110.138.65]) by hub.freebsd.org (Postfix) with ESMTP id 2F27C37B4D7; Fri, 27 Oct 2000 06:07:36 -0700 (PDT) Received: (from ru@localhost) by whale.sunbay.crimea.ua (8.11.0/8.11.0) id e9RD7Pa33837; Fri, 27 Oct 2000 16:07:25 +0300 (EEST) (envelope-from ru) Date: Fri, 27 Oct 2000 16:07:25 +0300 From: Ruslan Ermilov To: Bruce Evans Cc: Konstantin Chuguev , Brian Somers , kargl@apl.washington.edu, freebsd-current@FreeBSD.org Subject: Re: platform byte order macros? Message-ID: <20001027160724.A29559@sunbay.com> Mail-Followup-To: Bruce Evans , Konstantin Chuguev , Brian Somers , kargl@apl.washington.edu, freebsd-current@FreeBSD.ORG References: <39F94740.66FCEB9E@dante.org.uk> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="opJtzjQTFsWo+cga" Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from bde@zeta.org.au on Fri, Oct 27, 2000 at 09:49:57PM +1100 Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG --opJtzjQTFsWo+cga Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Oct 27, 2000 at 09:49:57PM +1100, Bruce Evans wrote: [...] > > NetBSD supports the ntohl family on constants, but only on some arches > (at least in last year's version). It takes fancier macros to support > constants. This gives an excuse to change the inline functions back to > macros :-). > Cool! My upcoming byte-swapping changes to IPv4 code would benefit from having these macros. Could you please review the attached patch (it was obtained from NetBSD)? BTW, converting from macros to inline functions slightly broke the things. It is currently impossible to simply include the , since it now depends on . -- Ruslan Ermilov Oracle Developer/DBA, ru@sunbay.com Sunbay Software AG, ru@FreeBSD.org FreeBSD committer, +380.652.512.251 Simferopol, Ukraine http://www.FreeBSD.org The Power To Serve http://www.oracle.com Enabling The Information Age --opJtzjQTFsWo+cga Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=p Index: endian.h =================================================================== RCS file: /home/ncvs/src/sys/i386/include/endian.h,v retrieving revision 1.21 diff -u -p -r1.21 endian.h --- endian.h 2000/10/16 17:06:48 1.21 +++ endian.h 2000/10/27 13:03:55 @@ -69,7 +69,7 @@ __END_DECLS #ifdef __GNUC__ static __inline uint32_t -__uint16_swap_uint32(uint32_t __x) +__uint16_swap_uint32_variable(uint32_t __x) { __asm ("rorl $16, %1" : "=r" (__x) : "0" (__x)); @@ -77,7 +77,7 @@ __uint16_swap_uint32(uint32_t __x) } static __inline uint32_t -__uint8_swap_uint32(uint32_t __x) +__uint8_swap_uint32_variable(uint32_t __x) { #if defined(_KERNEL) && (defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)) && !defined(I386_CPU) __asm ("bswap %0" : "=r" (__x) : "0" (__x)); @@ -89,12 +89,36 @@ __uint8_swap_uint32(uint32_t __x) } static __inline uint16_t -__uint8_swap_uint16(uint16_t __x) +__uint8_swap_uint16_variable(uint16_t __x) { __asm ("xchgb %h1, %b1" : "=q" (__x) : "0" (__x)); return __x; } + +#ifdef __OPTIMIZE__ + +#define __uint8_swap_uint32_constant(x) \ + ((((x) & 0xff000000) >> 24) | \ + (((x) & 0x00ff0000) >> 8) | \ + (((x) & 0x0000ff00) << 8) | \ + (((x) & 0x000000ff) << 24)) +#define __uint8_swap_uint16_constant(x) \ + ((((x) & 0xff00) >> 8) | \ + (((x) & 0x00ff) << 8)) +#define __uint8_swap_uint32(x) \ + (__builtin_constant_p((x)) ? \ + __uint8_swap_uint32_constant(x) : __uint8_swap_uint32_variable(x)) +#define __uint8_swap_uint16(x) \ + (__builtin_constant_p((x)) ? \ + __uint8_swap_uint16_constant(x) : __uint8_swap_uint16_variable(x)) + +#else /* __OPTIMIZE__ */ + +#define __uint8_swap_uint32(x) __uint8_swap_uint32_variable(x) +#define __uint8_swap_uint16(x) __uint8_swap_uint16_variable(x) + +#endif /* __OPTIMIZE__ */ /* * Macros for network/external number representation conversion. --opJtzjQTFsWo+cga-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message