Commit | Line | Data |
---|---|---|
332cb5d9 AC |
1 | /* This file is part of the program psim. |
2 | ||
3 | Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au> | |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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. | |
18 | ||
19 | */ | |
20 | ||
21 | ||
22 | #ifndef N | |
23 | #error "N must be #defined" | |
24 | #endif | |
25 | ||
26 | /* NOTE: See end of file for #undef */ | |
27 | #define unsigned_N XCONCAT2(unsigned_,N) | |
28 | #define endian_t2h_N XCONCAT2(endian_t2h_,N) | |
29 | #define endian_h2t_N XCONCAT2(endian_h2t_,N) | |
30 | #define _SWAP_N XCONCAT2(_SWAP_,N) | |
31 | #define swap_N XCONCAT2(swap_,N) | |
32 | #define endian_h2be_N XCONCAT2(endian_h2be_,N) | |
33 | #define endian_be2h_N XCONCAT2(endian_be2h_,N) | |
34 | #define endian_h2le_N XCONCAT2(endian_h2le_,N) | |
35 | #define endian_le2h_N XCONCAT2(endian_le2h_,N) | |
36 | #define offset_N XCONCAT2(offset_,N) | |
37 | ||
38 | ||
39 | INLINE_SIM_ENDIAN\ | |
40 | (unsigned_N) | |
41 | endian_t2h_N(unsigned_N raw_in) | |
42 | { | |
43 | if (CURRENT_TARGET_BYTE_ORDER == CURRENT_HOST_BYTE_ORDER) { | |
44 | return raw_in; | |
45 | } | |
46 | else { | |
47 | _SWAP_N(return,raw_in); | |
48 | } | |
49 | } | |
50 | ||
51 | ||
52 | INLINE_SIM_ENDIAN\ | |
53 | (unsigned_N) | |
54 | endian_h2t_N(unsigned_N raw_in) | |
55 | { | |
56 | if (CURRENT_TARGET_BYTE_ORDER == CURRENT_HOST_BYTE_ORDER) { | |
57 | return raw_in; | |
58 | } | |
59 | else { | |
60 | _SWAP_N(return,raw_in); | |
61 | } | |
62 | } | |
63 | ||
64 | ||
65 | INLINE_SIM_ENDIAN\ | |
66 | (unsigned_N) | |
67 | swap_N(unsigned_N raw_in) | |
68 | { | |
69 | _SWAP_N(return,raw_in); | |
70 | } | |
71 | ||
72 | ||
73 | ||
74 | INLINE_SIM_ENDIAN\ | |
75 | (unsigned_N) | |
76 | endian_h2be_N(unsigned_N raw_in) | |
77 | { | |
78 | if (CURRENT_HOST_BYTE_ORDER == BIG_ENDIAN) { | |
79 | return raw_in; | |
80 | } | |
81 | else { | |
82 | _SWAP_N(return,raw_in); | |
83 | } | |
84 | } | |
85 | ||
86 | ||
87 | INLINE_SIM_ENDIAN\ | |
88 | (unsigned_N) | |
89 | endian_be2h_N(unsigned_N raw_in) | |
90 | { | |
91 | if (CURRENT_HOST_BYTE_ORDER == BIG_ENDIAN) { | |
92 | return raw_in; | |
93 | } | |
94 | else { | |
95 | _SWAP_N(return,raw_in); | |
96 | } | |
97 | } | |
98 | ||
99 | ||
100 | INLINE_SIM_ENDIAN\ | |
101 | (unsigned_N) | |
102 | endian_h2le_N(unsigned_N raw_in) | |
103 | { | |
104 | if (CURRENT_HOST_BYTE_ORDER == LITTLE_ENDIAN) { | |
105 | return raw_in; | |
106 | } | |
107 | else { | |
108 | _SWAP_N(return,raw_in); | |
109 | } | |
110 | } | |
111 | ||
112 | ||
113 | INLINE_SIM_ENDIAN\ | |
114 | (unsigned_N) | |
115 | endian_le2h_N(unsigned_N raw_in) | |
116 | { | |
117 | if (CURRENT_HOST_BYTE_ORDER == LITTLE_ENDIAN) { | |
118 | return raw_in; | |
119 | } | |
120 | else { | |
121 | _SWAP_N(return,raw_in); | |
122 | } | |
123 | } | |
124 | ||
125 | ||
126 | ||
127 | INLINE_SIM_ENDIAN\ | |
128 | (void*) | |
129 | offset_N(unsigned_N *x, | |
130 | int sizeof_word, | |
131 | int word) | |
132 | { | |
133 | char *in = (char*)x; | |
134 | char *out; | |
135 | int offset = sizeof_word * word; | |
136 | ASSERT(offset + sizeof_word <= sizeof(unsigned_N)); | |
137 | ASSERT(word < (sizeof_word / sizeof(unsigned_N))); | |
138 | ASSERT((sizeof(unsigned_N) % sizeof_word) == 0); | |
139 | if (WITH_HOST_BYTE_ORDER == LITTLE_ENDIAN) { | |
140 | out = in + sizeof(unsigned_N) - offset; | |
141 | } | |
142 | else { | |
143 | out = in + offset; | |
144 | } | |
145 | return out; | |
146 | } | |
147 | ||
148 | ||
149 | /* NOTE: See start of file for #define */ | |
150 | #undef unsigned_N | |
151 | #undef endian_t2h_N | |
152 | #undef endian_h2t_N | |
153 | #undef _SWAP_N | |
154 | #undef swap_N | |
155 | #undef endian_h2be_N | |
156 | #undef endian_be2h_N | |
157 | #undef endian_h2le_N | |
158 | #undef endian_le2h_N | |
159 | #undef offset_N |