1 /* This file is part of the program psim.
3 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #ifndef _SIM_ENDIAN_C_
23 #define _SIM_ENDIAN_C_
25 #include "sim-basics.h"
26 #include "sim-assert.h"
31 #define _SWAP_1(SET,RAW) SET (RAW)
34 #if !defined(_SWAP_2) && (WITH_HOST_BYTE_ORDER == LITTLE_ENDIAN) && defined(htons)
35 #define _SWAP_2(SET,RAW) SET htons (RAW)
39 #define _SWAP_2(SET,RAW) SET (((RAW) >> 8) | ((RAW) << 8))
42 #if !defined(_SWAP_4) && (WITH_HOST_BYTE_ORDER == LITTLE_ENDIAN) && defined(htonl)
43 #define _SWAP_4(SET,RAW) SET htonl (RAW)
47 #define _SWAP_4(SET,RAW) SET (((RAW) << 24) | (((RAW) & 0xff00) << 8) | (((RAW) & 0xff0000) >> 8) | ((RAW) >> 24))
51 #define _SWAP_8(SET,RAW) \
52 union { unsigned_8 dword; unsigned_4 words[2]; } in, out; \
54 _SWAP_4 (out.words[0] =, in.words[1]); \
55 _SWAP_4 (out.words[1] =, in.words[0]); \
60 #define _SWAP_16(SET,RAW) \
61 union { unsigned_16 word; unsigned_4 words[4]; } in, out; \
63 _SWAP_4 (out.words[0] =, in.words[3]); \
64 _SWAP_4 (out.words[1] =, in.words[2]); \
65 _SWAP_4 (out.words[2] =, in.words[1]); \
66 _SWAP_4 (out.words[3] =, in.words[0]); \
72 #include "sim-n-endian.h"
76 #include "sim-n-endian.h"
80 #include "sim-n-endian.h"
84 #include "sim-n-endian.h"
88 #include "sim-n-endian.h"
94 sim_endian_split_16 (unsigned_16 word
, int w
)
96 if (CURRENT_HOST_BYTE_ORDER
== LITTLE_ENDIAN
)
109 sim_endian_join_16 (unsigned_8 h
, unsigned_8 l
)
113 if (CURRENT_HOST_BYTE_ORDER
== LITTLE_ENDIAN
)
128 #endif /* _SIM_ENDIAN_C_ */
This page took 0.042339 seconds and 4 git commands to generate.