/[pearpc]/src/system/arch/generic/sysendian.h
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /src/system/arch/generic/sysendian.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (hide annotations)
Wed Sep 5 17:11:21 2007 UTC (16 years, 7 months ago) by dpavlin
File MIME type: text/plain
File size: 2896 byte(s)
import upstream CVS
1 dpavlin 1 /*
2     * PearPC
3     * sysendian.h
4     *
5     * Copyright (C) 1999-2004 Stefan Weyergraf
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License version 2 as
9     * published by the Free Software Foundation.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19     */
20    
21     #ifndef __SYSTEM_ARCH_SPECIFIC_SYSENDIAN_H__
22     #define __SYSTEM_ARCH_SPECIFIC_SYSENDIAN_H__
23    
24     #include "system/types.h"
25     #include "config.h"
26    
27     static inline FUNCTION_CONST uint32 ppc_bswap_word(uint32 data)
28     {
29     return (data>>24)|((data>>8)&0xff00)|((data<<8)&0xff0000)|(data<<24);
30     }
31    
32     static inline FUNCTION_CONST uint64 ppc_bswap_dword(uint64 data)
33     {
34     return (((uint64)ppc_bswap_word(data)) << 32) | (uint64)ppc_bswap_word(data >> 32);
35     }
36    
37     static inline FUNCTION_CONST uint16 ppc_bswap_half(uint16 data)
38     {
39     return (data<<8)|(data>>8);
40     }
41    
42     #if HOST_ENDIANESS == HOST_ENDIANESS_LE
43    
44     /*
45     * Little-endian machine
46     */
47    
48     # define ppc_dword_from_BE(data) (ppc_bswap_dword(data))
49     # define ppc_word_from_BE(data) (ppc_bswap_word(data))
50     # define ppc_half_from_BE(data) (ppc_bswap_half(data))
51    
52     # define ppc_dword_from_LE(data) ((uint64)(data))
53     # define ppc_word_from_LE(data) ((uint32)(data))
54     # define ppc_half_from_LE(data) ((uint16)(data))
55    
56     # define ppc_dword_to_LE(data) ppc_dword_from_LE(data)
57     # define ppc_word_to_LE(data) ppc_word_from_LE(data)
58     # define ppc_half_to_LE(data) ppc_half_from_LE(data)
59    
60     # define ppc_dword_to_BE(data) ppc_dword_from_BE(data)
61     # define ppc_word_to_BE(data) ppc_word_from_BE(data)
62     # define ppc_half_to_BE(data) ppc_half_from_BE(data)
63    
64     #elif HOST_ENDIANESS == HOST_ENDIANESS_BE
65    
66     /*
67     * Big-endian machine
68     */
69     # define ppc_dword_from_BE(data) ((uint64)(data))
70     # define ppc_word_from_BE(data) ((uint32)(data))
71     # define ppc_half_from_BE(data) ((uint16)(data))
72    
73     # define ppc_dword_from_LE(data) (ppc_bswap_dword(data))
74     # define ppc_word_from_LE(data) (ppc_bswap_word(data))
75     # define ppc_half_from_LE(data) (ppc_bswap_half(data))
76    
77     # define ppc_dword_to_LE(data) ppc_dword_from_LE(data)
78     # define ppc_word_to_LE(data) ppc_word_from_LE(data)
79     # define ppc_half_to_LE(data) ppc_half_from_LE(data)
80    
81     # define ppc_dword_to_BE(data) ppc_dword_from_BE(data)
82     # define ppc_word_to_BE(data) ppc_word_from_BE(data)
83     # define ppc_half_to_BE(data) ppc_half_from_BE(data)
84    
85     #else
86    
87     /*
88     * Weird-endian machine
89     * HOST_ENDIANESS is neither little- nor big-endian?
90     */
91     # error "What kind of a weird machine do you have? It's neither little- nor big-endian??? This is unsupported."
92    
93     #endif
94    
95     #endif

  ViewVC Help
Powered by ViewVC 1.1.26