Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
26 | pmbaty | 1 | /* ACC -- Automatic Compiler Configuration |
2 | |||
3 | Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer |
||
4 | All Rights Reserved. |
||
5 | |||
6 | This software is a copyrighted work licensed under the terms of |
||
7 | the GNU General Public License. Please consult the file "ACC_LICENSE" |
||
8 | for details. |
||
9 | |||
10 | Markus F.X.J. Oberhumer |
||
11 | <markus@oberhumer.com> |
||
12 | http://www.oberhumer.com/ |
||
13 | */ |
||
14 | |||
15 | |||
16 | #define __ACCLIB_BELE_CH_INCLUDED 1 |
||
17 | #if !defined(ACCLIB_PUBLIC) |
||
18 | # define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f) |
||
19 | #endif |
||
20 | |||
21 | |||
22 | /************************************************************************* |
||
23 | // be16 / be24 / be32 |
||
24 | **************************************************************************/ |
||
25 | |||
26 | ACCLIB_PUBLIC(unsigned, acc_get_be16) (const acc_hvoid_p p) |
||
27 | { |
||
28 | const acc_hbyte_p b = (const acc_hbyte_p) p; |
||
29 | return ((unsigned)b[1]) | ((unsigned)b[0] << 8); |
||
30 | } |
||
31 | |||
32 | ACCLIB_PUBLIC(acc_uint32l_t, acc_get_be24) (const acc_hvoid_p p) |
||
33 | { |
||
34 | const acc_hbyte_p b = (const acc_hbyte_p) p; |
||
35 | return ((acc_uint32l_t)b[2]) | ((acc_uint32l_t)b[1] << 8) | ((acc_uint32l_t)b[0] << 16); |
||
36 | } |
||
37 | |||
38 | ACCLIB_PUBLIC(acc_uint32l_t, acc_get_be32) (const acc_hvoid_p p) |
||
39 | { |
||
40 | const acc_hbyte_p b = (const acc_hbyte_p) p; |
||
41 | return ((acc_uint32l_t)b[3]) | ((acc_uint32l_t)b[2] << 8) | ((acc_uint32l_t)b[1] << 16) | ((acc_uint32l_t)b[0] << 24); |
||
42 | } |
||
43 | |||
44 | |||
45 | |||
46 | ACCLIB_PUBLIC(void, acc_set_be16) (acc_hvoid_p p, unsigned v) |
||
47 | { |
||
48 | acc_hbyte_p b = (acc_hbyte_p) p; |
||
49 | b[1] = (unsigned char) ((v >> 0) & 0xff); |
||
50 | b[0] = (unsigned char) ((v >> 8) & 0xff); |
||
51 | } |
||
52 | |||
53 | ACCLIB_PUBLIC(void, acc_set_be24) (acc_hvoid_p p, acc_uint32l_t v) |
||
54 | { |
||
55 | acc_hbyte_p b = (acc_hbyte_p) p; |
||
56 | b[2] = (unsigned char) ((v >> 0) & 0xff); |
||
57 | b[1] = (unsigned char) ((v >> 8) & 0xff); |
||
58 | b[0] = (unsigned char) ((v >> 16) & 0xff); |
||
59 | } |
||
60 | |||
61 | ACCLIB_PUBLIC(void, acc_set_be32) (acc_hvoid_p p, acc_uint32l_t v) |
||
62 | { |
||
63 | acc_hbyte_p b = (acc_hbyte_p) p; |
||
64 | b[3] = (unsigned char) ((v >> 0) & 0xff); |
||
65 | b[2] = (unsigned char) ((v >> 8) & 0xff); |
||
66 | b[1] = (unsigned char) ((v >> 16) & 0xff); |
||
67 | b[0] = (unsigned char) ((v >> 24) & 0xff); |
||
68 | } |
||
69 | |||
70 | |||
71 | |||
72 | ACCLIB_PUBLIC(unsigned, acc_get_le16) (const acc_hvoid_p p) |
||
73 | { |
||
74 | #if (ACC_ARCH_AMD64 || ACC_ARCH_IA32) |
||
75 | return (* (const unsigned short *) (p)); |
||
76 | #else |
||
77 | const acc_hbyte_p b = (const acc_hbyte_p) p; |
||
78 | return ((unsigned)b[0]) | ((unsigned)b[1] << 8); |
||
79 | #endif |
||
80 | } |
||
81 | |||
82 | ACCLIB_PUBLIC(acc_uint32l_t, acc_get_le24) (const acc_hvoid_p p) |
||
83 | { |
||
84 | const acc_hbyte_p b = (const acc_hbyte_p) p; |
||
85 | return ((acc_uint32l_t)b[0]) | ((acc_uint32l_t)b[1] << 8) | ((acc_uint32l_t)b[2] << 16); |
||
86 | } |
||
87 | |||
88 | ACCLIB_PUBLIC(acc_uint32l_t, acc_get_le32) (const acc_hvoid_p p) |
||
89 | { |
||
90 | #if (ACC_ARCH_AMD64 || ACC_ARCH_IA32) |
||
91 | return (* (const acc_uint32e_t *) (p)); |
||
92 | #else |
||
93 | const acc_hbyte_p b = (const acc_hbyte_p) p; |
||
94 | return ((acc_uint32l_t)b[0]) | ((acc_uint32l_t)b[1] << 8) | ((acc_uint32l_t)b[2] << 16) | ((acc_uint32l_t)b[3] << 24); |
||
95 | #endif |
||
96 | } |
||
97 | |||
98 | |||
99 | /************************************************************************* |
||
100 | // le16 / le24 / le32 |
||
101 | **************************************************************************/ |
||
102 | |||
103 | ACCLIB_PUBLIC(void, acc_set_le16) (acc_hvoid_p p, unsigned v) |
||
104 | { |
||
105 | #if (ACC_ARCH_AMD64 || ACC_ARCH_IA32) |
||
106 | (* (unsigned short *) (p) = (unsigned short) (v)); |
||
107 | #else |
||
108 | acc_hbyte_p b = (acc_hbyte_p) p; |
||
109 | b[0] = (unsigned char) ((v >> 0) & 0xff); |
||
110 | b[1] = (unsigned char) ((v >> 8) & 0xff); |
||
111 | #endif |
||
112 | } |
||
113 | |||
114 | ACCLIB_PUBLIC(void, acc_set_le24) (acc_hvoid_p p, acc_uint32l_t v) |
||
115 | { |
||
116 | acc_hbyte_p b = (acc_hbyte_p) p; |
||
117 | b[0] = (unsigned char) ((v >> 0) & 0xff); |
||
118 | b[1] = (unsigned char) ((v >> 8) & 0xff); |
||
119 | b[2] = (unsigned char) ((v >> 16) & 0xff); |
||
120 | } |
||
121 | |||
122 | ACCLIB_PUBLIC(void, acc_set_le32) (acc_hvoid_p p, acc_uint32l_t v) |
||
123 | { |
||
124 | #if (ACC_ARCH_AMD64 || ACC_ARCH_IA32) |
||
125 | (* (acc_uint32e_t *) (p) = (acc_uint32e_t) (v)); |
||
126 | #else |
||
127 | acc_hbyte_p b = (acc_hbyte_p) p; |
||
128 | b[0] = (unsigned char) ((v >> 0) & 0xff); |
||
129 | b[1] = (unsigned char) ((v >> 8) & 0xff); |
||
130 | b[2] = (unsigned char) ((v >> 16) & 0xff); |
||
131 | b[3] = (unsigned char) ((v >> 24) & 0xff); |
||
132 | #endif |
||
133 | } |
||
134 | |||
135 | |||
136 | /************************************************************************* |
||
137 | // be64 |
||
138 | **************************************************************************/ |
||
139 | |||
140 | #if defined(acc_uint64l_t) |
||
141 | |||
142 | ACCLIB_PUBLIC(acc_uint64l_t, acc_get_be64) (const acc_hvoid_p p) |
||
143 | { |
||
144 | const acc_hbyte_p b = (const acc_hbyte_p) p; |
||
145 | #if (SIZEOF_LONG >= 8) || (SIZEOF_SIZE_T >= 8) |
||
146 | return ((acc_uint64l_t)b[7]) | ((acc_uint64l_t)b[6] << 8) | ((acc_uint64l_t)b[5] << 16) | ((acc_uint64l_t)b[4] << 24) | ((acc_uint64l_t)b[3] << 32) | ((acc_uint64l_t)b[2] << 40) | ((acc_uint64l_t)b[1] << 48) | ((acc_uint64l_t)b[0] << 56); |
||
147 | #else |
||
148 | acc_uint32l_t v0, v1; |
||
149 | v1 = ((acc_uint32l_t)b[3]) | ((acc_uint32l_t)b[2] << 8) | ((acc_uint32l_t)b[1] << 16) | ((acc_uint32l_t)b[0] << 24); |
||
150 | b += 4; |
||
151 | v0 = ((acc_uint32l_t)b[3]) | ((acc_uint32l_t)b[2] << 8) | ((acc_uint32l_t)b[1] << 16) | ((acc_uint32l_t)b[0] << 24); |
||
152 | return ((acc_uint64l_t)v0) | ((acc_uint64l_t)v1 << 32); |
||
153 | #endif |
||
154 | } |
||
155 | |||
156 | ACCLIB_PUBLIC(void, acc_set_be64) (acc_hvoid_p p, acc_uint64l_t v) |
||
157 | { |
||
158 | acc_hbyte_p b = (acc_hbyte_p) p; |
||
159 | #if (SIZEOF_LONG >= 8) || (SIZEOF_SIZE_T >= 8) |
||
160 | b[7] = (unsigned char) ((v >> 0) & 0xff); |
||
161 | b[6] = (unsigned char) ((v >> 8) & 0xff); |
||
162 | b[5] = (unsigned char) ((v >> 16) & 0xff); |
||
163 | b[4] = (unsigned char) ((v >> 24) & 0xff); |
||
164 | b[3] = (unsigned char) ((v >> 32) & 0xff); |
||
165 | b[2] = (unsigned char) ((v >> 40) & 0xff); |
||
166 | b[1] = (unsigned char) ((v >> 48) & 0xff); |
||
167 | b[0] = (unsigned char) ((v >> 56) & 0xff); |
||
168 | #else |
||
169 | acc_uint32l_t x; |
||
170 | x = (acc_uint32l_t) (v >> 0); |
||
171 | b[7] = (unsigned char) ((x >> 0) & 0xff); |
||
172 | b[6] = (unsigned char) ((x >> 8) & 0xff); |
||
173 | b[5] = (unsigned char) ((x >> 16) & 0xff); |
||
174 | b[4] = (unsigned char) ((x >> 24) & 0xff); |
||
175 | x = (acc_uint32l_t) (v >> 32); |
||
176 | b[3] = (unsigned char) ((x >> 0) & 0xff); |
||
177 | b[2] = (unsigned char) ((x >> 8) & 0xff); |
||
178 | b[1] = (unsigned char) ((x >> 16) & 0xff); |
||
179 | b[0] = (unsigned char) ((x >> 24) & 0xff); |
||
180 | #endif |
||
181 | } |
||
182 | |||
183 | #endif /* acc_uint64l_t */ |
||
184 | |||
185 | |||
186 | /************************************************************************* |
||
187 | // le64 |
||
188 | **************************************************************************/ |
||
189 | |||
190 | #if defined(acc_uint64l_t) |
||
191 | |||
192 | ACCLIB_PUBLIC(acc_uint64l_t, acc_get_le64) (const acc_hvoid_p p) |
||
193 | { |
||
194 | #if (ACC_ARCH_AMD64) |
||
195 | return (* (const acc_uint64l_t *) (p)); |
||
196 | #elif (ACC_ARCH_IA32) |
||
197 | const acc_uint32e_t* b = (const acc_uint32e_t*) p; |
||
198 | return ((acc_uint64l_t)b[0]) | ((acc_uint64l_t)b[1] << 32); |
||
199 | #elif (SIZEOF_LONG >= 8) || (SIZEOF_SIZE_T >= 8) |
||
200 | const acc_hbyte_p b = (const acc_hbyte_p) p; |
||
201 | return ((acc_uint64l_t)b[0]) | ((acc_uint64l_t)b[1] << 8) | ((acc_uint64l_t)b[2] << 16) | ((acc_uint64l_t)b[3] << 24) | ((acc_uint64l_t)b[4] << 32) | ((acc_uint64l_t)b[5] << 40) | ((acc_uint64l_t)b[6] << 48) | ((acc_uint64l_t)b[7] << 56); |
||
202 | #else |
||
203 | const acc_hbyte_p b = (const acc_hbyte_p) p; |
||
204 | acc_uint32l_t v0, v1; |
||
205 | v0 = ((acc_uint32l_t)b[0]) | ((acc_uint32l_t)b[1] << 8) | ((acc_uint32l_t)b[2] << 16) | ((acc_uint32l_t)b[3] << 24); |
||
206 | b += 4; |
||
207 | v1 = ((acc_uint32l_t)b[0]) | ((acc_uint32l_t)b[1] << 8) | ((acc_uint32l_t)b[2] << 16) | ((acc_uint32l_t)b[3] << 24); |
||
208 | return ((acc_uint64l_t)v0) | ((acc_uint64l_t)v1 << 32); |
||
209 | #endif |
||
210 | } |
||
211 | |||
212 | ACCLIB_PUBLIC(void, acc_set_le64) (acc_hvoid_p p, acc_uint64l_t v) |
||
213 | { |
||
214 | #if (ACC_ARCH_AMD64) |
||
215 | (* (acc_uint64l_t *) (p)) = v; |
||
216 | #elif (ACC_ARCH_IA32) |
||
217 | (((acc_uint32e_t *)(p))[0] = (acc_uint32e_t) (v >> 0)); |
||
218 | (((acc_uint32e_t *)(p))[1] = (acc_uint32e_t) (v >> 32)); |
||
219 | #elif (SIZEOF_LONG >= 8) || (SIZEOF_SIZE_T >= 8) |
||
220 | acc_hbyte_p b = (acc_hbyte_p) p; |
||
221 | b[0] = (unsigned char) ((v >> 0) & 0xff); |
||
222 | b[1] = (unsigned char) ((v >> 8) & 0xff); |
||
223 | b[2] = (unsigned char) ((v >> 16) & 0xff); |
||
224 | b[3] = (unsigned char) ((v >> 24) & 0xff); |
||
225 | b[4] = (unsigned char) ((v >> 32) & 0xff); |
||
226 | b[5] = (unsigned char) ((v >> 40) & 0xff); |
||
227 | b[6] = (unsigned char) ((v >> 48) & 0xff); |
||
228 | b[7] = (unsigned char) ((v >> 56) & 0xff); |
||
229 | #else |
||
230 | acc_hbyte_p b = (acc_hbyte_p) p; |
||
231 | acc_uint32l_t x; |
||
232 | x = (acc_uint32l_t) (v >> 0); |
||
233 | b[0] = (unsigned char) ((x >> 0) & 0xff); |
||
234 | b[1] = (unsigned char) ((x >> 8) & 0xff); |
||
235 | b[2] = (unsigned char) ((x >> 16) & 0xff); |
||
236 | b[3] = (unsigned char) ((x >> 24) & 0xff); |
||
237 | x = (acc_uint32l_t) (v >> 32); |
||
238 | b[4] = (unsigned char) ((x >> 0) & 0xff); |
||
239 | b[5] = (unsigned char) ((x >> 8) & 0xff); |
||
240 | b[6] = (unsigned char) ((x >> 16) & 0xff); |
||
241 | b[7] = (unsigned char) ((x >> 24) & 0xff); |
||
242 | #endif |
||
243 | } |
||
244 | |||
245 | #endif /* acc_uint64l_t */ |
||
246 | |||
247 | |||
248 | /* |
||
249 | vi:ts=4:et |
||
250 | */ |