OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [sysdeps/] [linux/] [v850/] [bits/] [byteswap.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/*
2
 * libc/sysdeps/linux/v850/bits/byteswap.h -- Macros to swap the order
3
 *      of bytes in integer values
4
 *
5
 *  Copyright (C) 2001  NEC Corporation
6
 *  Copyright (C) 2001  Miles Bader <miles@gnu.org>
7
 *  Copyright (C) 1997,1998,2001  Free Software Foundation, Inc.
8
 *
9
 * This file is subject to the terms and conditions of the GNU Lesser
10
 * General Public License.  See the file COPYING.LIB in the main
11
 * directory of this archive for more details.
12
 */
13
 
14
#if !defined _BYTESWAP_H && !defined _NETINET_IN_H
15
# error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
16
#endif
17
 
18
/* Swap bytes in 16 bit value.  */
19
#define __bswap_constant_16(x) \
20
  ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
21
 
22
#ifdef __GNUC__
23
# define __bswap_16(x)                                                        \
24
    (__extension__                                                            \
25
     ({ unsigned long int __bswap_16_v;                                       \
26
        if (__builtin_constant_p (x))                                         \
27
          __bswap_16_v = __bswap_constant_16 (x);                             \
28
        else                                                                  \
29
          __asm__ ("bsh %1, %0" : "=r" (__bswap_16_v) : "r" (x));             \
30
        __bswap_16_v; }))
31
#else
32
# define __bswap_16(x) __bswap_constant_16 (x)
33
#endif
34
 
35
/* Swap bytes in 32 bit value.  */
36
#define __bswap_constant_32(x) \
37
  ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) | \
38
   (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24))
39
 
40
#ifdef __GNUC__
41
# define __bswap_32(x)                                                        \
42
    (__extension__                                                            \
43
     ({ unsigned long int __bswap_32_v;                                       \
44
        if (__builtin_constant_p (x))                                         \
45
          __bswap_32_v = __bswap_constant_32 (x);                             \
46
        else                                                                  \
47
          __asm__ ("bsw %1, %0" : "=r" (__bswap_32_v) : "r" (x));             \
48
        __bswap_32_v; }))
49
#else
50
# define __bswap_32(x) __bswap_constant_32 (x)
51
#endif
52
 
53
#if defined __GNUC__ && __GNUC__ >= 2
54
/* Swap bytes in 64 bit value.  */
55
# define __bswap_64(x)                                                        \
56
     (__extension__                                                           \
57
      ({ union { unsigned long long int __ll;                                 \
58
                 unsigned long int __l[2]; } __bswap_64_v, __bswap_64_r;      \
59
         __bswap_64_v.__ll = (x);                                             \
60
         __bswap_64_r.__l[0] = __bswap_32 (__bswap_64_v.__l[1]);       \
61
         __bswap_64_r.__l[1] = __bswap_32 (__bswap_64_v.__l[0]);       \
62
         __bswap_64_r.__ll; }))
63
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.