This commit was generated by cvs2svn to track changes on a CVS vendor
[deliverable/binutils-gdb.git] / sim / common / sim-n-endian.h
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 #include "sim-xcat.h"
27
28 /* NOTE: See end of file for #undef */
29 #define unsigned_N XCONCAT2(unsigned_,N)
30 #define endian_t2h_N XCONCAT2(endian_t2h_,N)
31 #define endian_h2t_N XCONCAT2(endian_h2t_,N)
32 #define _SWAP_N XCONCAT2(_SWAP_,N)
33 #define swap_N XCONCAT2(swap_,N)
34 #define endian_h2be_N XCONCAT2(endian_h2be_,N)
35 #define endian_be2h_N XCONCAT2(endian_be2h_,N)
36 #define endian_h2le_N XCONCAT2(endian_h2le_,N)
37 #define endian_le2h_N XCONCAT2(endian_le2h_,N)
38 #define offset_N XCONCAT2(offset_,N)
39
40
41 INLINE_SIM_ENDIAN\
42 (unsigned_N)
43 endian_t2h_N(unsigned_N raw_in)
44 {
45 if (CURRENT_TARGET_BYTE_ORDER == CURRENT_HOST_BYTE_ORDER) {
46 return raw_in;
47 }
48 else {
49 _SWAP_N(return,raw_in);
50 }
51 }
52
53
54 INLINE_SIM_ENDIAN\
55 (unsigned_N)
56 endian_h2t_N(unsigned_N raw_in)
57 {
58 if (CURRENT_TARGET_BYTE_ORDER == CURRENT_HOST_BYTE_ORDER) {
59 return raw_in;
60 }
61 else {
62 _SWAP_N(return,raw_in);
63 }
64 }
65
66
67 INLINE_SIM_ENDIAN\
68 (unsigned_N)
69 swap_N(unsigned_N raw_in)
70 {
71 _SWAP_N(return,raw_in);
72 }
73
74
75
76 INLINE_SIM_ENDIAN\
77 (unsigned_N)
78 endian_h2be_N(unsigned_N raw_in)
79 {
80 if (CURRENT_HOST_BYTE_ORDER == BIG_ENDIAN) {
81 return raw_in;
82 }
83 else {
84 _SWAP_N(return,raw_in);
85 }
86 }
87
88
89 INLINE_SIM_ENDIAN\
90 (unsigned_N)
91 endian_be2h_N(unsigned_N raw_in)
92 {
93 if (CURRENT_HOST_BYTE_ORDER == BIG_ENDIAN) {
94 return raw_in;
95 }
96 else {
97 _SWAP_N(return,raw_in);
98 }
99 }
100
101
102 INLINE_SIM_ENDIAN\
103 (unsigned_N)
104 endian_h2le_N(unsigned_N raw_in)
105 {
106 if (CURRENT_HOST_BYTE_ORDER == LITTLE_ENDIAN) {
107 return raw_in;
108 }
109 else {
110 _SWAP_N(return,raw_in);
111 }
112 }
113
114
115 INLINE_SIM_ENDIAN\
116 (unsigned_N)
117 endian_le2h_N(unsigned_N raw_in)
118 {
119 if (CURRENT_HOST_BYTE_ORDER == LITTLE_ENDIAN) {
120 return raw_in;
121 }
122 else {
123 _SWAP_N(return,raw_in);
124 }
125 }
126
127
128
129 INLINE_SIM_ENDIAN\
130 (void*)
131 offset_N (unsigned_N *x,
132 unsigned sizeof_word,
133 unsigned word)
134 {
135 char *in = (char*)x;
136 char *out;
137 unsigned offset = sizeof_word * word;
138 ASSERT (offset + sizeof_word <= sizeof(unsigned_N));
139 ASSERT (word < (sizeof (unsigned_N) / sizeof_word));
140 ASSERT ((sizeof (unsigned_N) % sizeof_word) == 0);
141 if (WITH_HOST_BYTE_ORDER == LITTLE_ENDIAN)
142 {
143 out = in + sizeof (unsigned_N) - offset - sizeof_word;
144 }
145 else
146 {
147 out = in + offset;
148 }
149 return out;
150 }
151
152
153 /* NOTE: See start of file for #define */
154 #undef unsigned_N
155 #undef endian_t2h_N
156 #undef endian_h2t_N
157 #undef _SWAP_N
158 #undef swap_N
159 #undef endian_h2be_N
160 #undef endian_be2h_N
161 #undef endian_h2le_N
162 #undef endian_le2h_N
163 #undef offset_N
This page took 0.037421 seconds and 5 git commands to generate.