Skip to content

Commit

Permalink
Harmonize byteorder/bswap_c.in with bswap.h
Browse files Browse the repository at this point in the history
Add ppc/darwin login (machine/endian.h)
  • Loading branch information
Reini Urban committed Sep 10, 2012
1 parent 6dffb3c commit c7748e6
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 64 deletions.
5 changes: 3 additions & 2 deletions config/auto/byteorder.pm
Expand Up @@ -38,7 +38,8 @@ sub runstep {
$self->_probe_byteswap($conf, "endian.h") || # Linux
$self->_probe_byteswap($conf, "sys/endian.h") || # Freebsd
$self->_probe_byteswap($conf, "sys/byteorder.h") || # BSWAP_32 on Solaris 10
$self->_probe_byteswap($conf, "libkern/OSByteOrder.h"); # OSX
$self->_probe_byteswap($conf, "libkern/OSByteOrder.h") || # OSX
$self->_probe_byteswap($conf, "machine/endian.h"); # Old OSX

return 1;
}
Expand Down Expand Up @@ -83,7 +84,7 @@ sub _probe_byteswap {
$i =~ s|\.h$||g;

$conf->cc_gen('config/auto/byteorder/bswap_c.in');
eval { $conf->cc_build("-DHAS_HEADER_".uc($i)) };
eval { $conf->cc_build("-DPARROT_HAS_HEADER_".uc($i)) };
my $ret = $@ ? 0 : $conf->cc_run();
$conf->cc_clean();
if ($ret and $ret ne '0x12345678') {
Expand Down
67 changes: 40 additions & 27 deletions config/auto/byteorder/bswap_c.in
Expand Up @@ -7,37 +7,50 @@ Copyright (C) 2012, Parrot Foundation.
#include <stdio.h>
#include <stdint.h>

#ifdef HAS_HEADER_BYTESWAP
# include <byteswap.h>
#else
# ifdef HAS_HEADER_ENDIAN
#ifdef PARROT_HAS_HEADER_BYTESWAP
# include <byteswap.h> /* GNU */
# ifndef bswap_16
# define bswap_16(x) __bswap_16(x)
# define bswap_32(x) __bswap_32(x)
# define bswap_64(x) __bswap_64(x)
# endif
#elif defined(PARROT_HAS_HEADER_ENDIAN) \
|| defined(PARROT_HAS_HEADER_SYS_ENDIAN)
# ifdef PARROT_HAS_HEADER_ENDIAN /* linux */
# include <endian.h>
# elif defined(HAS_HEADER_SYS_ENDIAN)
# elif defined(PARROT_HAS_HEADER_SYS_ENDIAN) /* FreeBSD */
# include <sys/endian.h>
# endif
# if defined(HAS_HEADER_ENDIAN) || defined(HAS_HEADER_SYS_ENDIAN)
# define bswap_16(x) __bswap_16(x)
# define bswap_32(x) __bswap_32(x)
# if __WORDSIZE == 64
# define bswap_16(x) __bswap_16(x)
# define bswap_32(x) __bswap_32(x)
# ifdef __bswap_64
# define bswap_64(x) __bswap_64(x)
# endif
# else
# ifdef HAS_HEADER_LIBKERN_OSBYTEORDER
# include <libkern/OSXByteOrder.h>
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define bswap_16(x) OSSwapHostToBigInt16(x)
# define bswap_32(x) OSSwapHostToBigInt32(x)
# if __WORDSIZE == 64
# define bswap_64(x) OSSwapHostToBigInt64(x)
# endif
# else
# define bswap_16(x) OSSwapBigToHostInt16(x)
# define bswap_32(x) OSSwapBigToHostInt32(x)
# if __WORDSIZE == 64
# define bswap_64(x) OSSwapBigToHostInt64(x)
# endif
# endif
# endif
# endif
#elif defined(PARROT_HAS_HEADER_LIBKERN_OSBYTEORDER) && defined(__APPLE__)
# include <libkern/OSByteOrder.h>
# define bswap_16(x) OSSwapInt16(x)
# define bswap_32(x) OSSwapInt32(x)
# ifdef OSSwapInt64
# define bswap_64(x) OSSwapInt64(x)
# endif
#elif defined(PARROT_HAS_HEADER_MACHINE_ENDIAN) && defined(__APPLE__)
# include <machine/endian.h>
# define bswap_16(x) __DARWIN_OSSwapInt16(x)
# define bswap_32(x) __DARWIN_OSSwapInt32(x)
# ifdef __DARWIN_OSSwapInt64
# define bswap_64(x) __DARWIN_OSSwapInt64(x)
# endif
#elif defined(PARROT_HAS_HEADER_SYS_BYTEORDER)
# define bswap_16(x) BSWAP_16(x)
# define bswap_32(x) BSWAP_32(x)
# ifdef BSWAP_64
# define bswap_64(x) BSWAP_64(x)
# endif
#elif defined(__MSC_VER)
# define bswap_16(x) _byteswap_ushort(x)
# define bswap_32(x) _byteswap_ulong(x)
# ifdef _byteswap_uint64
# define bswap_64(x) _byteswap_uint64(x)
# endif
#endif

Expand Down
68 changes: 33 additions & 35 deletions include/parrot/bswap.h
Expand Up @@ -14,42 +14,45 @@
# define bswap_32(x) __bswap_32(x)
# define bswap_64(x) __bswap_64(x)
# endif
#else
#elif defined(PARROT_HAS_HEADER_ENDIAN) \
|| defined(PARROT_HAS_HEADER_SYS_ENDIAN)
# ifdef PARROT_HAS_HEADER_ENDIAN /* linux */
# include <endian.h>
# elif defined(PARROT_HAS_HEADER_SYS_ENDIAN) /* FreeBSD */
# include <sys/endian.h>
# endif
# if defined(PARROT_HAS_HEADER_ENDIAN) \
|| defined(PARROT_HAS_HEADER_SYS_ENDIAN)
# define bswap_16(x) __bswap_16(x)
# define bswap_32(x) __bswap_32(x)
# ifdef HAS_LONGLONG
# define bswap_16(x) __bswap_16(x)
# define bswap_32(x) __bswap_32(x)
# ifdef __bswap_64
# define bswap_64(x) __bswap_64(x)
# endif
# else
# ifdef PARROT_HAS_HEADER_LIBKERN_OSBYTEORDER
# include <libkern/OSByteOrder.h>
# define bswap_16(x) OSSwapInt16(x)
# define bswap_32(x) OSSwapInt32(x)
# ifdef HAS_LONGLONG
# define bswap_64(x) OSSwapInt64(x)
# endif
# else
# ifdef PARROT_HAS_HEADER_SYS_BYTEORDER
# define bswap_16(x) BSWAP_16(x)
# define bswap_32(x) BSWAP_32(x)
# ifdef HAS_LONGLONG
# define bswap_64(x) BSWAP_64(x)
# endif
# else
# ifdef __MSC_VER
# define bswap_16(x) _byteswap_ushort(x)
# define bswap_32(x) _byteswap_ulong(x)
# ifdef HAS_LONGLONG
# define bswap_64(x) _byteswap_uint64(x)
# endif
# else
# endif
#elif defined(PARROT_HAS_HEADER_LIBKERN_OSBYTEORDER)
# include <libkern/OSByteOrder.h>
# define bswap_16(x) OSSwapInt16(x)
# define bswap_32(x) OSSwapInt32(x)
# ifdef OSSwapInt64
# define bswap_64(x) OSSwapInt64(x)
# endif
#elif defined(PARROT_HAS_HEADER_MACHINE_ENDIAN) && defined(__APPLE__)
# include <machine/endian.h>
# define bswap_16(x) __DARWIN_OSSwapInt16(x)
# define bswap_32(x) __DARWIN_OSSwapInt32(x)
# ifdef __DARWIN_OSSwapInt64
# define bswap_64(x) __DARWIN_OSSwapInt64(x)
# endif
#elif defined(PARROT_HAS_HEADER_SYS_BYTEORDER)
# define bswap_16(x) BSWAP_16(x)
# define bswap_32(x) BSWAP_32(x)
# ifdef BSWAP_64
# define bswap_64(x) BSWAP_64(x)
# endif
#elif defined(__MSC_VER)
# define bswap_16(x) _byteswap_ushort(x)
# define bswap_32(x) _byteswap_ulong(x)
# ifdef HAS_LONGLONG
# define bswap_64(x) _byteswap_uint64(x)
# endif
#else
/* no native bswap */
# define bswap_16(x) \
({ \
Expand Down Expand Up @@ -87,11 +90,6 @@
const unsigned char *c = &x; \
SWAB_8(rb, c); \
(Parrot_UInt8)rb; })
# endif
# endif
# endif
# endif
# endif
#endif

#define SWAB_4(rb,b) \
Expand Down

0 comments on commit c7748e6

Please sign in to comment.