/[pearpc]/src/system/arch/x86/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

Contents of /src/system/arch/x86/sysendian.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Wed Sep 5 17:11:21 2007 UTC (16 years, 7 months ago) by dpavlin
File MIME type: text/plain
File size: 1907 byte(s)
import upstream CVS
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
26 static inline FUNCTION_CONST uint32 ppc_bswap_word(uint32 data)
27 {
28 asm (
29 "bswap %0": "=r" (data) : "0" (data)
30 );
31 return data;
32 }
33
34 static inline FUNCTION_CONST uint16 ppc_bswap_half(uint16 data)
35 {
36 asm (
37 "xchgb %b0,%h0": "=q" (data): "0" (data)
38 );
39 return data;
40 }
41
42 static inline FUNCTION_CONST uint64 ppc_bswap_dword(uint64 data)
43 {
44 return (((uint64)ppc_bswap_word(data)) << 32) | (uint64)ppc_bswap_word(data >> 32);
45 }
46
47 # define ppc_dword_from_BE(data) (ppc_bswap_dword(data))
48 # define ppc_word_from_BE(data) (ppc_bswap_word(data))
49 # define ppc_half_from_BE(data) (ppc_bswap_half(data))
50
51 # define ppc_dword_from_LE(data) ((uint64)(data))
52 # define ppc_word_from_LE(data) ((uint32)(data))
53 # define ppc_half_from_LE(data) ((uint16)(data))
54
55 # define ppc_dword_to_LE(data) ppc_dword_from_LE(data)
56 # define ppc_word_to_LE(data) ppc_word_from_LE(data)
57 # define ppc_half_to_LE(data) ppc_half_from_LE(data)
58
59 # define ppc_dword_to_BE(data) ppc_dword_from_BE(data)
60 # define ppc_word_to_BE(data) ppc_word_from_BE(data)
61 # define ppc_half_to_BE(data) ppc_half_from_BE(data)
62
63 #endif

  ViewVC Help
Powered by ViewVC 1.1.26