Ticket #10800: 0001-Replace-arch-dependent-integer-byteswap-routines-wit.patch

File 0001-Replace-arch-dependent-integer-byteswap-routines-wit.patch, 3.7 KB (added by jessicah, 6 years ago)
  • headers/os/support/ByteOrder.h

    From e5d922335ee69b525d9f8356e674fb9cc49ff83c Mon Sep 17 00:00:00 2001
    From: Jessica Hamilton <jessica.l.hamilton@gmail.com>
    Date: Sat, 3 May 2014 11:55:08 +1200
    Subject: [PATCH] Replace arch-dependent integer byteswap routines with gcc
     builtins
    
    ---
     headers/os/support/ByteOrder.h | 35 ++++++++++++++++-------------------
     1 file changed, 16 insertions(+), 19 deletions(-)
    
    diff --git a/headers/os/support/ByteOrder.h b/headers/os/support/ByteOrder.h
    index 96e9961..a0cde4a 100644
    a b typedef enum {  
    3434/* always swap macros */
    3535#define B_SWAP_DOUBLE(arg)   __swap_double(arg)
    3636#define B_SWAP_FLOAT(arg)    __swap_float(arg)
    37 #define B_SWAP_INT64(arg)    __swap_int64(arg)
    38 #define B_SWAP_INT32(arg)    __swap_int32(arg)
    39 #define B_SWAP_INT16(arg)    __swap_int16(arg)
     37#define B_SWAP_INT64(arg)    __builtin_bswap64(arg)
     38#define B_SWAP_INT32(arg)    __builtin_bswap32(arg)
     39#define B_SWAP_INT16(arg)    __builtin_bswap16(arg)
    4040
    4141#if BYTE_ORDER == __LITTLE_ENDIAN
    4242/* Host is little endian */
    typedef enum {  
    6161/* Host native to big endian */
    6262#define B_HOST_TO_BENDIAN_DOUBLE(arg)   __swap_double(arg)
    6363#define B_HOST_TO_BENDIAN_FLOAT(arg)    __swap_float(arg)
    64 #define B_HOST_TO_BENDIAN_INT64(arg)    __swap_int64(arg)
    65 #define B_HOST_TO_BENDIAN_INT32(arg)    __swap_int32(arg)
    66 #define B_HOST_TO_BENDIAN_INT16(arg)    __swap_int16(arg)
     64#define B_HOST_TO_BENDIAN_INT64(arg)    __builtin_bswap64(arg)
     65#define B_HOST_TO_BENDIAN_INT32(arg)    __builtin_bswap32(arg)
     66#define B_HOST_TO_BENDIAN_INT16(arg)    __builtin_bswap16(arg)
    6767
    6868/* Big endian to host native */
    6969#define B_BENDIAN_TO_HOST_DOUBLE(arg)   __swap_double(arg)
    7070#define B_BENDIAN_TO_HOST_FLOAT(arg)    __swap_float(arg)
    71 #define B_BENDIAN_TO_HOST_INT64(arg)    __swap_int64(arg)
    72 #define B_BENDIAN_TO_HOST_INT32(arg)    __swap_int32(arg)
    73 #define B_BENDIAN_TO_HOST_INT16(arg)    __swap_int16(arg)
     71#define B_BENDIAN_TO_HOST_INT64(arg)    __builtin_bswap64(arg)
     72#define B_BENDIAN_TO_HOST_INT32(arg)    __builtin_bswap32(arg)
     73#define B_BENDIAN_TO_HOST_INT16(arg)    __builtin_bswap16(arg)
    7474
    7575#else   /* BYTE_ORDER */
    7676/* Host is big endian */
    typedef enum {  
    8181/* Host native to little endian */
    8282#define B_HOST_TO_LENDIAN_DOUBLE(arg)   __swap_double(arg)
    8383#define B_HOST_TO_LENDIAN_FLOAT(arg)    __swap_float(arg)
    84 #define B_HOST_TO_LENDIAN_INT64(arg)    __swap_int64(arg)
    85 #define B_HOST_TO_LENDIAN_INT32(arg)    __swap_int32(arg)
    86 #define B_HOST_TO_LENDIAN_INT16(arg)    __swap_int16(arg)
     84#define B_HOST_TO_LENDIAN_INT64(arg)    __builtin_bswap64(arg)
     85#define B_HOST_TO_LENDIAN_INT32(arg)    __builtin_bswap32(arg)
     86#define B_HOST_TO_LENDIAN_INT16(arg)    __builtin_bswap16(arg)
    8787
    8888/* Little endian to host native */
    8989#define B_LENDIAN_TO_HOST_DOUBLE(arg)   __swap_double(arg)
    9090#define B_LENDIAN_TO_HOST_FLOAT(arg)    __swap_float(arg)
    91 #define B_LENDIAN_TO_HOST_INT64(arg)    __swap_int64(arg)
    92 #define B_LENDIAN_TO_HOST_INT32(arg)    __swap_int32(arg)
    93 #define B_LENDIAN_TO_HOST_INT16(arg)    __swap_int16(arg)
     91#define B_LENDIAN_TO_HOST_INT64(arg)    __builtin_bswap64(arg)
     92#define B_LENDIAN_TO_HOST_INT32(arg)    __builtin_bswap32(arg)
     93#define B_LENDIAN_TO_HOST_INT16(arg)    __builtin_bswap16(arg)
    9494
    9595/* Host native to big endian */
    9696#define B_HOST_TO_BENDIAN_DOUBLE(arg)   (double)(arg)
    typedef enum {  
    111111
    112112#ifdef __cplusplus
    113113extern "C" {
    114 #endif 
     114#endif
    115115
    116116extern status_t swap_data(type_code type, void *data, size_t length,
    117117    swap_action action);
    extern bool is_type_swapped(type_code type);  
    121121/* Private implementations */
    122122extern double __swap_double(double arg);
    123123extern float  __swap_float(float arg);
    124 extern uint64 __swap_int64(uint64 arg);
    125 extern uint32 __swap_int32(uint32 arg);
    126 extern uint16 __swap_int16(uint16 arg);
    127124
    128125#ifdef __cplusplus
    129126}