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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [utils/] [bswap.h] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
#ifndef _BSWAP_H
2
#define _BSWAP_H 1
3
 
4
#if !defined(__BYTE_ORDER) && defined(BYTE_ORDER)
5
#  define __BYTE_ORDER = BYTE_ORDER
6
#endif
7
 
8
#ifndef __BYTE_ORDER
9
#ifdef __linux__
10
#include <endian.h>
11
#else
12
#define __LITTLE_ENDIAN 1234    /* least-significant byte first (vax, pc) */
13
#define __BIG_ENDIAN    4321    /* most-significant byte first (IBM, net) */
14
#define __PDP_ENDIAN    3412    /* LSB first in word, MSW first in long (pdp) */
15
 
16
#if defined(sun386) || defined(i386)
17
#define __BYTE_ORDER    __LITTLE_ENDIAN
18
#endif
19
 
20
#if defined(sparc)
21
#define __BYTE_ORDER    __BIG_ENDIAN
22
#endif
23
 
24
#endif /* __linux__ */
25
#endif /* __BYTE_ORDER */
26
 
27
 
28
#ifndef __BYTE_ORDER
29
# error "Undefined __BYTE_ORDER"
30
#endif
31
 
32
#ifdef __linux__
33
#include <byteswap.h>
34
#else
35
#include <string.h>
36
static __inline__ uint32_t bswap_32(uint32_t x)
37
     {
38
       uint32_t res;
39
 
40
       swab((void*)&x, (void*)&res, sizeof(uint32_t));
41
 
42
       return res;
43
     }
44
 
45
static __inline__ uint16_t bswap_16(uint16_t x)
46
     {
47
       uint16_t res;
48
 
49
       swab((void*)&x, (void*)&res, sizeof(uint16_t));
50
       return res;
51
     }
52
#endif
53
 
54
#endif

powered by: WebSVN 2.1.0

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