arc-fxi.h revision 1.8 1 1.1 christos /* Insert/extract functions for the ARC opcodes.
2 1.8 christos Copyright (C) 2015-2025 Free Software Foundation, Inc.
3 1.1 christos
4 1.1 christos Contributed by Claudiu Zissulescu (claziss (at) synopsys.com)
5 1.1 christos
6 1.1 christos This file is part of libopcodes.
7 1.1 christos
8 1.1 christos This library is free software; you can redistribute it and/or modify
9 1.1 christos it under the terms of the GNU General Public License as published by
10 1.1 christos the Free Software Foundation; either version 3, or (at your option)
11 1.1 christos any later version.
12 1.1 christos
13 1.1 christos It is distributed in the hope that it will be useful, but WITHOUT
14 1.1 christos ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 1.1 christos or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 1.1 christos License for more details.
17 1.1 christos
18 1.1 christos You should have received a copy of the GNU General Public License
19 1.1 christos along with this program; if not, write to the Free Software Foundation,
20 1.1 christos Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
21 1.1 christos
22 1.1 christos #ifndef INSERT_LIMM
23 1.1 christos #define INSERT_LIMM
24 1.1 christos /* mask = 00000000000000000000000000000000
25 1.1 christos insn = 00100bbb00101111FBBB111110001001. */
26 1.4 christos static unsigned long long
27 1.4 christos insert_limm (unsigned long long insn ATTRIBUTE_UNUSED,
28 1.6 christos long long int value ATTRIBUTE_UNUSED,
29 1.6 christos const char **errmsg ATTRIBUTE_UNUSED)
30 1.1 christos {
31 1.1 christos
32 1.1 christos return insn;
33 1.1 christos }
34 1.1 christos #endif /* INSERT_LIMM */
35 1.1 christos
36 1.1 christos #ifndef EXTRACT_LIMM
37 1.1 christos #define EXTRACT_LIMM
38 1.1 christos /* mask = 00000000000000000000000000000000. */
39 1.1 christos static ATTRIBUTE_UNUSED int
40 1.6 christos extract_limm (unsigned long long insn ATTRIBUTE_UNUSED,
41 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
42 1.1 christos {
43 1.1 christos unsigned value = 0;
44 1.1 christos
45 1.1 christos return value;
46 1.1 christos }
47 1.1 christos #endif /* EXTRACT_LIMM */
48 1.1 christos
49 1.1 christos #ifndef INSERT_UIMM6_20
50 1.1 christos #define INSERT_UIMM6_20
51 1.1 christos /* mask = 00000000000000000000111111000000
52 1.1 christos insn = 00100bbb01101111FBBBuuuuuu001001. */
53 1.4 christos static unsigned long long
54 1.4 christos insert_uimm6_20 (unsigned long long insn ATTRIBUTE_UNUSED,
55 1.4 christos long long int value ATTRIBUTE_UNUSED,
56 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
57 1.1 christos {
58 1.1 christos
59 1.1 christos insn |= ((value >> 0) & 0x003f) << 6;
60 1.1 christos
61 1.1 christos return insn;
62 1.1 christos }
63 1.1 christos #endif /* INSERT_UIMM6_20 */
64 1.1 christos
65 1.1 christos #ifndef EXTRACT_UIMM6_20
66 1.1 christos #define EXTRACT_UIMM6_20
67 1.1 christos /* mask = 00000000000000000000111111000000. */
68 1.4 christos static long long int
69 1.4 christos extract_uimm6_20 (unsigned long long insn ATTRIBUTE_UNUSED,
70 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
71 1.1 christos {
72 1.1 christos unsigned value = 0;
73 1.1 christos
74 1.1 christos value |= ((insn >> 6) & 0x003f) << 0;
75 1.1 christos
76 1.1 christos return value;
77 1.1 christos }
78 1.1 christos #endif /* EXTRACT_UIMM6_20 */
79 1.1 christos
80 1.1 christos #ifndef INSERT_SIMM12_20
81 1.1 christos #define INSERT_SIMM12_20
82 1.1 christos /* mask = 00000000000000000000111111222222
83 1.1 christos insn = 00110bbb10101000FBBBssssssSSSSSS. */
84 1.4 christos static unsigned long long
85 1.4 christos insert_simm12_20 (unsigned long long insn ATTRIBUTE_UNUSED,
86 1.4 christos long long int value ATTRIBUTE_UNUSED,
87 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
88 1.1 christos {
89 1.1 christos
90 1.1 christos insn |= ((value >> 0) & 0x003f) << 6;
91 1.1 christos insn |= ((value >> 6) & 0x003f) << 0;
92 1.1 christos
93 1.1 christos return insn;
94 1.1 christos }
95 1.1 christos #endif /* INSERT_SIMM12_20 */
96 1.1 christos
97 1.1 christos #ifndef EXTRACT_SIMM12_20
98 1.1 christos #define EXTRACT_SIMM12_20
99 1.1 christos /* mask = 00000000000000000000111111222222. */
100 1.4 christos static long long int
101 1.4 christos extract_simm12_20 (unsigned long long insn ATTRIBUTE_UNUSED,
102 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
103 1.1 christos {
104 1.1 christos int value = 0;
105 1.1 christos
106 1.1 christos value |= ((insn >> 6) & 0x003f) << 0;
107 1.1 christos value |= ((insn >> 0) & 0x003f) << 6;
108 1.1 christos
109 1.1 christos /* Extend the sign. */
110 1.1 christos int signbit = 1 << (12 - 1);
111 1.1 christos value = (value ^ signbit) - signbit;
112 1.1 christos
113 1.1 christos return value;
114 1.1 christos }
115 1.1 christos #endif /* EXTRACT_SIMM12_20 */
116 1.1 christos
117 1.1 christos #ifndef INSERT_SIMM3_5_S
118 1.1 christos #define INSERT_SIMM3_5_S
119 1.1 christos /* mask = 0000011100000000
120 1.1 christos insn = 01110ssshhh001HH. */
121 1.1 christos static ATTRIBUTE_UNUSED unsigned
122 1.4 christos insert_simm3_5_s (unsigned long long insn ATTRIBUTE_UNUSED,
123 1.4 christos long long int value ATTRIBUTE_UNUSED,
124 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
125 1.1 christos {
126 1.1 christos
127 1.1 christos insn |= ((value >> 0) & 0x0007) << 8;
128 1.1 christos
129 1.1 christos return insn;
130 1.1 christos }
131 1.1 christos #endif /* INSERT_SIMM3_5_S */
132 1.1 christos
133 1.1 christos #ifndef EXTRACT_SIMM3_5_S
134 1.1 christos #define EXTRACT_SIMM3_5_S
135 1.1 christos /* mask = 0000011100000000. */
136 1.1 christos static ATTRIBUTE_UNUSED int
137 1.4 christos extract_simm3_5_s (unsigned long long insn ATTRIBUTE_UNUSED,
138 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
139 1.1 christos {
140 1.1 christos int value = 0;
141 1.1 christos
142 1.1 christos value |= ((insn >> 8) & 0x0007) << 0;
143 1.1 christos
144 1.1 christos /* Extend the sign. */
145 1.1 christos int signbit = 1 << (3 - 1);
146 1.1 christos value = (value ^ signbit) - signbit;
147 1.1 christos
148 1.1 christos return value;
149 1.1 christos }
150 1.1 christos #endif /* EXTRACT_SIMM3_5_S */
151 1.1 christos
152 1.1 christos #ifndef INSERT_LIMM_S
153 1.1 christos #define INSERT_LIMM_S
154 1.1 christos /* mask = 0000000000000000
155 1.1 christos insn = 01110sss11000111. */
156 1.1 christos static ATTRIBUTE_UNUSED unsigned
157 1.4 christos insert_limm_s (unsigned long long insn ATTRIBUTE_UNUSED,
158 1.4 christos long long int value ATTRIBUTE_UNUSED,
159 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
160 1.1 christos {
161 1.1 christos
162 1.1 christos return insn;
163 1.1 christos }
164 1.1 christos #endif /* INSERT_LIMM_S */
165 1.1 christos
166 1.1 christos #ifndef EXTRACT_LIMM_S
167 1.1 christos #define EXTRACT_LIMM_S
168 1.1 christos /* mask = 0000000000000000. */
169 1.1 christos static ATTRIBUTE_UNUSED int
170 1.6 christos extract_limm_s (unsigned long long insn ATTRIBUTE_UNUSED,
171 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
172 1.1 christos {
173 1.1 christos unsigned value = 0;
174 1.1 christos
175 1.1 christos return value;
176 1.1 christos }
177 1.1 christos #endif /* EXTRACT_LIMM_S */
178 1.1 christos
179 1.1 christos #ifndef INSERT_UIMM7_A32_11_S
180 1.1 christos #define INSERT_UIMM7_A32_11_S
181 1.1 christos /* mask = 0000000000011111
182 1.1 christos insn = 11000bbb100uuuuu. */
183 1.4 christos static unsigned long long
184 1.4 christos insert_uimm7_a32_11_s (unsigned long long insn ATTRIBUTE_UNUSED,
185 1.4 christos long long int value ATTRIBUTE_UNUSED,
186 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
187 1.1 christos {
188 1.1 christos if (value & 0x03)
189 1.1 christos *errmsg = _("Target address is not 32bit aligned.");
190 1.1 christos
191 1.1 christos insn |= ((value >> 2) & 0x001f) << 0;
192 1.1 christos
193 1.1 christos return insn;
194 1.1 christos }
195 1.1 christos #endif /* INSERT_UIMM7_A32_11_S */
196 1.1 christos
197 1.1 christos #ifndef EXTRACT_UIMM7_A32_11_S
198 1.1 christos #define EXTRACT_UIMM7_A32_11_S
199 1.1 christos /* mask = 0000000000011111. */
200 1.4 christos static long long int
201 1.4 christos extract_uimm7_a32_11_s (unsigned long long insn ATTRIBUTE_UNUSED,
202 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
203 1.1 christos {
204 1.1 christos unsigned value = 0;
205 1.1 christos
206 1.1 christos value |= ((insn >> 0) & 0x001f) << 2;
207 1.1 christos
208 1.1 christos return value;
209 1.1 christos }
210 1.1 christos #endif /* EXTRACT_UIMM7_A32_11_S */
211 1.1 christos
212 1.1 christos #ifndef INSERT_UIMM7_9_S
213 1.1 christos #define INSERT_UIMM7_9_S
214 1.1 christos /* mask = 0000000001111111
215 1.1 christos insn = 11100bbb0uuuuuuu. */
216 1.4 christos static unsigned long long
217 1.4 christos insert_uimm7_9_s (unsigned long long insn ATTRIBUTE_UNUSED,
218 1.4 christos long long int value ATTRIBUTE_UNUSED,
219 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
220 1.1 christos {
221 1.1 christos
222 1.1 christos insn |= ((value >> 0) & 0x007f) << 0;
223 1.1 christos
224 1.1 christos return insn;
225 1.1 christos }
226 1.1 christos #endif /* INSERT_UIMM7_9_S */
227 1.1 christos
228 1.1 christos #ifndef EXTRACT_UIMM7_9_S
229 1.1 christos #define EXTRACT_UIMM7_9_S
230 1.1 christos /* mask = 0000000001111111. */
231 1.4 christos static long long int
232 1.4 christos extract_uimm7_9_s (unsigned long long insn ATTRIBUTE_UNUSED,
233 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
234 1.1 christos {
235 1.1 christos unsigned value = 0;
236 1.1 christos
237 1.1 christos value |= ((insn >> 0) & 0x007f) << 0;
238 1.1 christos
239 1.1 christos return value;
240 1.1 christos }
241 1.1 christos #endif /* EXTRACT_UIMM7_9_S */
242 1.1 christos
243 1.1 christos #ifndef INSERT_UIMM3_13_S
244 1.1 christos #define INSERT_UIMM3_13_S
245 1.1 christos /* mask = 0000000000000111
246 1.1 christos insn = 01101bbbccc00uuu. */
247 1.4 christos static unsigned long long
248 1.4 christos insert_uimm3_13_s (unsigned long long insn ATTRIBUTE_UNUSED,
249 1.4 christos long long int value ATTRIBUTE_UNUSED,
250 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
251 1.1 christos {
252 1.1 christos
253 1.1 christos insn |= ((value >> 0) & 0x0007) << 0;
254 1.1 christos
255 1.1 christos return insn;
256 1.1 christos }
257 1.1 christos #endif /* INSERT_UIMM3_13_S */
258 1.1 christos
259 1.1 christos #ifndef EXTRACT_UIMM3_13_S
260 1.1 christos #define EXTRACT_UIMM3_13_S
261 1.1 christos /* mask = 0000000000000111. */
262 1.4 christos static long long int
263 1.4 christos extract_uimm3_13_s (unsigned long long insn ATTRIBUTE_UNUSED,
264 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
265 1.1 christos {
266 1.1 christos unsigned value = 0;
267 1.1 christos
268 1.1 christos value |= ((insn >> 0) & 0x0007) << 0;
269 1.1 christos
270 1.1 christos return value;
271 1.1 christos }
272 1.1 christos #endif /* EXTRACT_UIMM3_13_S */
273 1.1 christos
274 1.1 christos #ifndef INSERT_SIMM11_A32_7_S
275 1.1 christos #define INSERT_SIMM11_A32_7_S
276 1.1 christos /* mask = 0000000111111111
277 1.1 christos insn = 1100111sssssssss. */
278 1.4 christos static unsigned long long
279 1.4 christos insert_simm11_a32_7_s (unsigned long long insn ATTRIBUTE_UNUSED,
280 1.4 christos long long int value ATTRIBUTE_UNUSED,
281 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
282 1.1 christos {
283 1.1 christos if (value & 0x03)
284 1.1 christos *errmsg = _("Target address is not 32bit aligned.");
285 1.1 christos
286 1.1 christos insn |= ((value >> 2) & 0x01ff) << 0;
287 1.1 christos
288 1.1 christos return insn;
289 1.1 christos }
290 1.1 christos #endif /* INSERT_SIMM11_A32_7_S */
291 1.1 christos
292 1.1 christos #ifndef EXTRACT_SIMM11_A32_7_S
293 1.1 christos #define EXTRACT_SIMM11_A32_7_S
294 1.1 christos /* mask = 0000000111111111. */
295 1.4 christos static long long int
296 1.4 christos extract_simm11_a32_7_s (unsigned long long insn ATTRIBUTE_UNUSED,
297 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
298 1.1 christos {
299 1.1 christos int value = 0;
300 1.1 christos
301 1.1 christos value |= ((insn >> 0) & 0x01ff) << 2;
302 1.1 christos
303 1.1 christos /* Extend the sign. */
304 1.1 christos int signbit = 1 << (11 - 1);
305 1.1 christos value = (value ^ signbit) - signbit;
306 1.1 christos
307 1.1 christos return value;
308 1.1 christos }
309 1.1 christos #endif /* EXTRACT_SIMM11_A32_7_S */
310 1.1 christos
311 1.1 christos #ifndef INSERT_UIMM6_13_S
312 1.1 christos #define INSERT_UIMM6_13_S
313 1.1 christos /* mask = 0000000002220111
314 1.1 christos insn = 01001bbb0UUU1uuu. */
315 1.4 christos static unsigned long long
316 1.4 christos insert_uimm6_13_s (unsigned long long insn ATTRIBUTE_UNUSED,
317 1.4 christos long long int value ATTRIBUTE_UNUSED,
318 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
319 1.1 christos {
320 1.1 christos
321 1.1 christos insn |= ((value >> 0) & 0x0007) << 0;
322 1.1 christos insn |= ((value >> 3) & 0x0007) << 4;
323 1.1 christos
324 1.1 christos return insn;
325 1.1 christos }
326 1.1 christos #endif /* INSERT_UIMM6_13_S */
327 1.1 christos
328 1.1 christos #ifndef EXTRACT_UIMM6_13_S
329 1.1 christos #define EXTRACT_UIMM6_13_S
330 1.1 christos /* mask = 0000000002220111. */
331 1.4 christos static long long int
332 1.4 christos extract_uimm6_13_s (unsigned long long insn ATTRIBUTE_UNUSED,
333 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
334 1.1 christos {
335 1.1 christos unsigned value = 0;
336 1.1 christos
337 1.1 christos value |= ((insn >> 0) & 0x0007) << 0;
338 1.1 christos value |= ((insn >> 4) & 0x0007) << 3;
339 1.1 christos
340 1.1 christos return value;
341 1.1 christos }
342 1.1 christos #endif /* EXTRACT_UIMM6_13_S */
343 1.1 christos
344 1.1 christos #ifndef INSERT_UIMM5_11_S
345 1.1 christos #define INSERT_UIMM5_11_S
346 1.1 christos /* mask = 0000000000011111
347 1.1 christos insn = 10111bbb000uuuuu. */
348 1.4 christos static unsigned long long
349 1.4 christos insert_uimm5_11_s (unsigned long long insn ATTRIBUTE_UNUSED,
350 1.4 christos long long int value ATTRIBUTE_UNUSED,
351 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
352 1.1 christos {
353 1.1 christos
354 1.1 christos insn |= ((value >> 0) & 0x001f) << 0;
355 1.1 christos
356 1.1 christos return insn;
357 1.1 christos }
358 1.1 christos #endif /* INSERT_UIMM5_11_S */
359 1.1 christos
360 1.1 christos #ifndef EXTRACT_UIMM5_11_S
361 1.1 christos #define EXTRACT_UIMM5_11_S
362 1.1 christos /* mask = 0000000000011111. */
363 1.4 christos static long long int
364 1.4 christos extract_uimm5_11_s (unsigned long long insn ATTRIBUTE_UNUSED,
365 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
366 1.1 christos {
367 1.1 christos unsigned value = 0;
368 1.1 christos
369 1.1 christos value |= ((insn >> 0) & 0x001f) << 0;
370 1.1 christos
371 1.1 christos return value;
372 1.1 christos }
373 1.1 christos #endif /* EXTRACT_UIMM5_11_S */
374 1.1 christos
375 1.1 christos #ifndef INSERT_SIMM9_A16_8
376 1.1 christos #define INSERT_SIMM9_A16_8
377 1.1 christos /* mask = 00000000111111102000000000000000
378 1.1 christos insn = 00001bbbsssssss1SBBBCCCCCCN01110. */
379 1.4 christos static unsigned long long
380 1.4 christos insert_simm9_a16_8 (unsigned long long insn ATTRIBUTE_UNUSED,
381 1.4 christos long long int value ATTRIBUTE_UNUSED,
382 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
383 1.1 christos {
384 1.1 christos if (value & 0x01)
385 1.1 christos *errmsg = _("Target address is not 16bit aligned.");
386 1.1 christos
387 1.1 christos insn |= ((value >> 1) & 0x007f) << 17;
388 1.1 christos insn |= ((value >> 8) & 0x0001) << 15;
389 1.1 christos
390 1.1 christos return insn;
391 1.1 christos }
392 1.1 christos #endif /* INSERT_SIMM9_A16_8 */
393 1.1 christos
394 1.1 christos #ifndef EXTRACT_SIMM9_A16_8
395 1.1 christos #define EXTRACT_SIMM9_A16_8
396 1.1 christos /* mask = 00000000111111102000000000000000. */
397 1.4 christos static long long int
398 1.4 christos extract_simm9_a16_8 (unsigned long long insn ATTRIBUTE_UNUSED,
399 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
400 1.1 christos {
401 1.1 christos int value = 0;
402 1.1 christos
403 1.1 christos value |= ((insn >> 17) & 0x007f) << 1;
404 1.1 christos value |= ((insn >> 15) & 0x0001) << 8;
405 1.1 christos
406 1.1 christos /* Extend the sign. */
407 1.1 christos int signbit = 1 << (9 - 1);
408 1.1 christos value = (value ^ signbit) - signbit;
409 1.1 christos
410 1.1 christos return value;
411 1.1 christos }
412 1.1 christos #endif /* EXTRACT_SIMM9_A16_8 */
413 1.1 christos
414 1.1 christos #ifndef INSERT_UIMM6_8
415 1.1 christos #define INSERT_UIMM6_8
416 1.1 christos /* mask = 00000000000000000000111111000000
417 1.1 christos insn = 00001bbbsssssss1SBBBuuuuuuN11110. */
418 1.4 christos static unsigned long long
419 1.4 christos insert_uimm6_8 (unsigned long long insn ATTRIBUTE_UNUSED,
420 1.4 christos long long int value ATTRIBUTE_UNUSED,
421 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
422 1.1 christos {
423 1.1 christos
424 1.1 christos insn |= ((value >> 0) & 0x003f) << 6;
425 1.1 christos
426 1.1 christos return insn;
427 1.1 christos }
428 1.1 christos #endif /* INSERT_UIMM6_8 */
429 1.1 christos
430 1.1 christos #ifndef EXTRACT_UIMM6_8
431 1.1 christos #define EXTRACT_UIMM6_8
432 1.1 christos /* mask = 00000000000000000000111111000000. */
433 1.4 christos static long long int
434 1.4 christos extract_uimm6_8 (unsigned long long insn ATTRIBUTE_UNUSED,
435 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
436 1.1 christos {
437 1.1 christos unsigned value = 0;
438 1.1 christos
439 1.1 christos value |= ((insn >> 6) & 0x003f) << 0;
440 1.1 christos
441 1.1 christos return value;
442 1.1 christos }
443 1.1 christos #endif /* EXTRACT_UIMM6_8 */
444 1.1 christos
445 1.1 christos #ifndef INSERT_SIMM21_A16_5
446 1.1 christos #define INSERT_SIMM21_A16_5
447 1.1 christos /* mask = 00000111111111102222222222000000
448 1.1 christos insn = 00000ssssssssss0SSSSSSSSSSNQQQQQ. */
449 1.4 christos static unsigned long long
450 1.4 christos insert_simm21_a16_5 (unsigned long long insn ATTRIBUTE_UNUSED,
451 1.4 christos long long int value ATTRIBUTE_UNUSED,
452 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
453 1.1 christos {
454 1.1 christos if (value & 0x01)
455 1.1 christos *errmsg = _("Target address is not 16bit aligned.");
456 1.1 christos
457 1.1 christos insn |= ((value >> 1) & 0x03ff) << 17;
458 1.1 christos insn |= ((value >> 11) & 0x03ff) << 6;
459 1.1 christos
460 1.1 christos return insn;
461 1.1 christos }
462 1.1 christos #endif /* INSERT_SIMM21_A16_5 */
463 1.1 christos
464 1.1 christos #ifndef EXTRACT_SIMM21_A16_5
465 1.1 christos #define EXTRACT_SIMM21_A16_5
466 1.1 christos /* mask = 00000111111111102222222222000000. */
467 1.4 christos static long long int
468 1.4 christos extract_simm21_a16_5 (unsigned long long insn ATTRIBUTE_UNUSED,
469 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
470 1.1 christos {
471 1.1 christos int value = 0;
472 1.1 christos
473 1.1 christos value |= ((insn >> 17) & 0x03ff) << 1;
474 1.1 christos value |= ((insn >> 6) & 0x03ff) << 11;
475 1.1 christos
476 1.1 christos /* Extend the sign. */
477 1.1 christos int signbit = 1 << (21 - 1);
478 1.1 christos value = (value ^ signbit) - signbit;
479 1.1 christos
480 1.1 christos return value;
481 1.1 christos }
482 1.1 christos #endif /* EXTRACT_SIMM21_A16_5 */
483 1.1 christos
484 1.1 christos #ifndef INSERT_SIMM25_A16_5
485 1.1 christos #define INSERT_SIMM25_A16_5
486 1.1 christos /* mask = 00000111111111102222222222003333
487 1.1 christos insn = 00000ssssssssss1SSSSSSSSSSNRtttt. */
488 1.4 christos static unsigned long long
489 1.4 christos insert_simm25_a16_5 (unsigned long long insn ATTRIBUTE_UNUSED,
490 1.4 christos long long int value ATTRIBUTE_UNUSED,
491 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
492 1.1 christos {
493 1.1 christos if (value & 0x01)
494 1.1 christos *errmsg = _("Target address is not 16bit aligned.");
495 1.1 christos
496 1.1 christos insn |= ((value >> 1) & 0x03ff) << 17;
497 1.1 christos insn |= ((value >> 11) & 0x03ff) << 6;
498 1.1 christos insn |= ((value >> 21) & 0x000f) << 0;
499 1.1 christos
500 1.1 christos return insn;
501 1.1 christos }
502 1.1 christos #endif /* INSERT_SIMM25_A16_5 */
503 1.1 christos
504 1.1 christos #ifndef EXTRACT_SIMM25_A16_5
505 1.1 christos #define EXTRACT_SIMM25_A16_5
506 1.1 christos /* mask = 00000111111111102222222222003333. */
507 1.4 christos static long long int
508 1.4 christos extract_simm25_a16_5 (unsigned long long insn ATTRIBUTE_UNUSED,
509 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
510 1.1 christos {
511 1.1 christos int value = 0;
512 1.1 christos
513 1.1 christos value |= ((insn >> 17) & 0x03ff) << 1;
514 1.1 christos value |= ((insn >> 6) & 0x03ff) << 11;
515 1.1 christos value |= ((insn >> 0) & 0x000f) << 21;
516 1.1 christos
517 1.1 christos /* Extend the sign. */
518 1.1 christos int signbit = 1 << (25 - 1);
519 1.1 christos value = (value ^ signbit) - signbit;
520 1.1 christos
521 1.1 christos return value;
522 1.1 christos }
523 1.1 christos #endif /* EXTRACT_SIMM25_A16_5 */
524 1.1 christos
525 1.1 christos #ifndef INSERT_SIMM10_A16_7_S
526 1.1 christos #define INSERT_SIMM10_A16_7_S
527 1.1 christos /* mask = 0000000111111111
528 1.1 christos insn = 1111001sssssssss. */
529 1.4 christos static unsigned long long
530 1.4 christos insert_simm10_a16_7_s (unsigned long long insn ATTRIBUTE_UNUSED,
531 1.4 christos long long int value ATTRIBUTE_UNUSED,
532 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
533 1.1 christos {
534 1.1 christos if (value & 0x01)
535 1.1 christos *errmsg = _("Target address is not 16bit aligned.");
536 1.1 christos
537 1.1 christos insn |= ((value >> 1) & 0x01ff) << 0;
538 1.1 christos
539 1.1 christos return insn;
540 1.1 christos }
541 1.1 christos #endif /* INSERT_SIMM10_A16_7_S */
542 1.1 christos
543 1.1 christos #ifndef EXTRACT_SIMM10_A16_7_S
544 1.1 christos #define EXTRACT_SIMM10_A16_7_S
545 1.1 christos /* mask = 0000000111111111. */
546 1.4 christos static long long int
547 1.4 christos extract_simm10_a16_7_s (unsigned long long insn ATTRIBUTE_UNUSED,
548 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
549 1.1 christos {
550 1.1 christos int value = 0;
551 1.1 christos
552 1.1 christos value |= ((insn >> 0) & 0x01ff) << 1;
553 1.1 christos
554 1.1 christos /* Extend the sign. */
555 1.1 christos int signbit = 1 << (10 - 1);
556 1.1 christos value = (value ^ signbit) - signbit;
557 1.1 christos
558 1.1 christos return value;
559 1.1 christos }
560 1.1 christos #endif /* EXTRACT_SIMM10_A16_7_S */
561 1.1 christos
562 1.1 christos #ifndef INSERT_SIMM7_A16_10_S
563 1.1 christos #define INSERT_SIMM7_A16_10_S
564 1.1 christos /* mask = 0000000000111111
565 1.1 christos insn = 1111011000ssssss. */
566 1.4 christos static unsigned long long
567 1.4 christos insert_simm7_a16_10_s (unsigned long long insn ATTRIBUTE_UNUSED,
568 1.4 christos long long int value ATTRIBUTE_UNUSED,
569 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
570 1.1 christos {
571 1.1 christos if (value & 0x01)
572 1.1 christos *errmsg = _("Target address is not 16bit aligned.");
573 1.1 christos
574 1.1 christos insn |= ((value >> 1) & 0x003f) << 0;
575 1.1 christos
576 1.1 christos return insn;
577 1.1 christos }
578 1.1 christos #endif /* INSERT_SIMM7_A16_10_S */
579 1.1 christos
580 1.1 christos #ifndef EXTRACT_SIMM7_A16_10_S
581 1.1 christos #define EXTRACT_SIMM7_A16_10_S
582 1.1 christos /* mask = 0000000000111111. */
583 1.4 christos static long long int
584 1.4 christos extract_simm7_a16_10_s (unsigned long long insn ATTRIBUTE_UNUSED,
585 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
586 1.1 christos {
587 1.1 christos int value = 0;
588 1.1 christos
589 1.1 christos value |= ((insn >> 0) & 0x003f) << 1;
590 1.1 christos
591 1.1 christos /* Extend the sign. */
592 1.1 christos int signbit = 1 << (7 - 1);
593 1.1 christos value = (value ^ signbit) - signbit;
594 1.1 christos
595 1.1 christos return value;
596 1.1 christos }
597 1.1 christos #endif /* EXTRACT_SIMM7_A16_10_S */
598 1.1 christos
599 1.1 christos #ifndef INSERT_SIMM21_A32_5
600 1.1 christos #define INSERT_SIMM21_A32_5
601 1.1 christos /* mask = 00000111111111002222222222000000
602 1.1 christos insn = 00001sssssssss00SSSSSSSSSSNQQQQQ. */
603 1.4 christos static unsigned long long
604 1.4 christos insert_simm21_a32_5 (unsigned long long insn ATTRIBUTE_UNUSED,
605 1.4 christos long long int value ATTRIBUTE_UNUSED,
606 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
607 1.1 christos {
608 1.1 christos if (value & 0x03)
609 1.1 christos *errmsg = _("Target address is not 32bit aligned.");
610 1.1 christos
611 1.1 christos insn |= ((value >> 2) & 0x01ff) << 18;
612 1.1 christos insn |= ((value >> 11) & 0x03ff) << 6;
613 1.1 christos
614 1.1 christos return insn;
615 1.1 christos }
616 1.1 christos #endif /* INSERT_SIMM21_A32_5 */
617 1.1 christos
618 1.1 christos #ifndef EXTRACT_SIMM21_A32_5
619 1.1 christos #define EXTRACT_SIMM21_A32_5
620 1.1 christos /* mask = 00000111111111002222222222000000. */
621 1.4 christos static long long int
622 1.4 christos extract_simm21_a32_5 (unsigned long long insn ATTRIBUTE_UNUSED,
623 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
624 1.1 christos {
625 1.1 christos int value = 0;
626 1.1 christos
627 1.1 christos value |= ((insn >> 18) & 0x01ff) << 2;
628 1.1 christos value |= ((insn >> 6) & 0x03ff) << 11;
629 1.1 christos
630 1.1 christos /* Extend the sign. */
631 1.1 christos int signbit = 1 << (21 - 1);
632 1.1 christos value = (value ^ signbit) - signbit;
633 1.1 christos
634 1.1 christos return value;
635 1.1 christos }
636 1.1 christos #endif /* EXTRACT_SIMM21_A32_5 */
637 1.1 christos
638 1.1 christos #ifndef INSERT_SIMM25_A32_5
639 1.1 christos #define INSERT_SIMM25_A32_5
640 1.1 christos /* mask = 00000111111111002222222222003333
641 1.1 christos insn = 00001sssssssss10SSSSSSSSSSNRtttt. */
642 1.4 christos static unsigned long long
643 1.4 christos insert_simm25_a32_5 (unsigned long long insn ATTRIBUTE_UNUSED,
644 1.4 christos long long int value ATTRIBUTE_UNUSED,
645 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
646 1.1 christos {
647 1.1 christos if (value & 0x03)
648 1.1 christos *errmsg = _("Target address is not 32bit aligned.");
649 1.1 christos
650 1.1 christos insn |= ((value >> 2) & 0x01ff) << 18;
651 1.1 christos insn |= ((value >> 11) & 0x03ff) << 6;
652 1.1 christos insn |= ((value >> 21) & 0x000f) << 0;
653 1.1 christos
654 1.1 christos return insn;
655 1.1 christos }
656 1.1 christos #endif /* INSERT_SIMM25_A32_5 */
657 1.1 christos
658 1.1 christos #ifndef EXTRACT_SIMM25_A32_5
659 1.1 christos #define EXTRACT_SIMM25_A32_5
660 1.1 christos /* mask = 00000111111111002222222222003333. */
661 1.4 christos static long long int
662 1.4 christos extract_simm25_a32_5 (unsigned long long insn ATTRIBUTE_UNUSED,
663 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
664 1.1 christos {
665 1.1 christos int value = 0;
666 1.1 christos
667 1.1 christos value |= ((insn >> 18) & 0x01ff) << 2;
668 1.1 christos value |= ((insn >> 6) & 0x03ff) << 11;
669 1.1 christos value |= ((insn >> 0) & 0x000f) << 21;
670 1.1 christos
671 1.1 christos /* Extend the sign. */
672 1.1 christos int signbit = 1 << (25 - 1);
673 1.1 christos value = (value ^ signbit) - signbit;
674 1.1 christos
675 1.1 christos return value;
676 1.1 christos }
677 1.1 christos #endif /* EXTRACT_SIMM25_A32_5 */
678 1.1 christos
679 1.1 christos #ifndef INSERT_SIMM13_A32_5_S
680 1.1 christos #define INSERT_SIMM13_A32_5_S
681 1.1 christos /* mask = 0000011111111111
682 1.1 christos insn = 11111sssssssssss. */
683 1.4 christos static unsigned long long
684 1.4 christos insert_simm13_a32_5_s (unsigned long long insn ATTRIBUTE_UNUSED,
685 1.4 christos long long int value ATTRIBUTE_UNUSED,
686 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
687 1.1 christos {
688 1.1 christos if (value & 0x03)
689 1.1 christos *errmsg = _("Target address is not 32bit aligned.");
690 1.1 christos
691 1.1 christos insn |= ((value >> 2) & 0x07ff) << 0;
692 1.1 christos
693 1.1 christos return insn;
694 1.1 christos }
695 1.1 christos #endif /* INSERT_SIMM13_A32_5_S */
696 1.1 christos
697 1.1 christos #ifndef EXTRACT_SIMM13_A32_5_S
698 1.1 christos #define EXTRACT_SIMM13_A32_5_S
699 1.1 christos /* mask = 0000011111111111. */
700 1.4 christos static long long int
701 1.4 christos extract_simm13_a32_5_s (unsigned long long insn ATTRIBUTE_UNUSED,
702 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
703 1.1 christos {
704 1.1 christos int value = 0;
705 1.1 christos
706 1.1 christos value |= ((insn >> 0) & 0x07ff) << 2;
707 1.1 christos
708 1.1 christos /* Extend the sign. */
709 1.1 christos int signbit = 1 << (13 - 1);
710 1.1 christos value = (value ^ signbit) - signbit;
711 1.1 christos
712 1.1 christos return value;
713 1.1 christos }
714 1.1 christos #endif /* EXTRACT_SIMM13_A32_5_S */
715 1.1 christos
716 1.1 christos #ifndef INSERT_SIMM8_A16_9_S
717 1.1 christos #define INSERT_SIMM8_A16_9_S
718 1.1 christos /* mask = 0000000001111111
719 1.1 christos insn = 11101bbb1sssssss. */
720 1.4 christos static unsigned long long
721 1.4 christos insert_simm8_a16_9_s (unsigned long long insn ATTRIBUTE_UNUSED,
722 1.4 christos long long int value ATTRIBUTE_UNUSED,
723 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
724 1.1 christos {
725 1.1 christos if (value & 0x01)
726 1.1 christos *errmsg = _("Target address is not 16bit aligned.");
727 1.1 christos
728 1.1 christos insn |= ((value >> 1) & 0x007f) << 0;
729 1.1 christos
730 1.1 christos return insn;
731 1.1 christos }
732 1.1 christos #endif /* INSERT_SIMM8_A16_9_S */
733 1.1 christos
734 1.1 christos #ifndef EXTRACT_SIMM8_A16_9_S
735 1.1 christos #define EXTRACT_SIMM8_A16_9_S
736 1.1 christos /* mask = 0000000001111111. */
737 1.4 christos static long long int
738 1.4 christos extract_simm8_a16_9_s (unsigned long long insn ATTRIBUTE_UNUSED,
739 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
740 1.1 christos {
741 1.1 christos int value = 0;
742 1.1 christos
743 1.1 christos value |= ((insn >> 0) & 0x007f) << 1;
744 1.1 christos
745 1.1 christos /* Extend the sign. */
746 1.1 christos int signbit = 1 << (8 - 1);
747 1.1 christos value = (value ^ signbit) - signbit;
748 1.1 christos
749 1.1 christos return value;
750 1.1 christos }
751 1.1 christos #endif /* EXTRACT_SIMM8_A16_9_S */
752 1.1 christos
753 1.1 christos #ifndef INSERT_UIMM3_23
754 1.1 christos #define INSERT_UIMM3_23
755 1.1 christos /* mask = 00000000000000000000000111000000
756 1.1 christos insn = 00100011011011110001RRRuuu111111. */
757 1.4 christos static unsigned long long
758 1.4 christos insert_uimm3_23 (unsigned long long insn ATTRIBUTE_UNUSED,
759 1.4 christos long long int value ATTRIBUTE_UNUSED,
760 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
761 1.1 christos {
762 1.1 christos
763 1.1 christos insn |= ((value >> 0) & 0x0007) << 6;
764 1.1 christos
765 1.1 christos return insn;
766 1.1 christos }
767 1.1 christos #endif /* INSERT_UIMM3_23 */
768 1.1 christos
769 1.1 christos #ifndef EXTRACT_UIMM3_23
770 1.1 christos #define EXTRACT_UIMM3_23
771 1.1 christos /* mask = 00000000000000000000000111000000. */
772 1.4 christos static long long int
773 1.4 christos extract_uimm3_23 (unsigned long long insn ATTRIBUTE_UNUSED,
774 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
775 1.1 christos {
776 1.1 christos unsigned value = 0;
777 1.1 christos
778 1.1 christos value |= ((insn >> 6) & 0x0007) << 0;
779 1.1 christos
780 1.1 christos return value;
781 1.1 christos }
782 1.1 christos #endif /* EXTRACT_UIMM3_23 */
783 1.1 christos
784 1.1 christos #ifndef INSERT_UIMM10_6_S
785 1.1 christos #define INSERT_UIMM10_6_S
786 1.1 christos /* mask = 0000001111111111
787 1.1 christos insn = 010111uuuuuuuuuu. */
788 1.4 christos static unsigned long long
789 1.4 christos insert_uimm10_6_s (unsigned long long insn ATTRIBUTE_UNUSED,
790 1.4 christos long long int value ATTRIBUTE_UNUSED,
791 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
792 1.1 christos {
793 1.1 christos
794 1.1 christos insn |= ((value >> 0) & 0x03ff) << 0;
795 1.1 christos
796 1.1 christos return insn;
797 1.1 christos }
798 1.1 christos #endif /* INSERT_UIMM10_6_S */
799 1.1 christos
800 1.1 christos #ifndef EXTRACT_UIMM10_6_S
801 1.1 christos #define EXTRACT_UIMM10_6_S
802 1.1 christos /* mask = 0000001111111111. */
803 1.4 christos static long long int
804 1.4 christos extract_uimm10_6_s (unsigned long long insn ATTRIBUTE_UNUSED,
805 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
806 1.1 christos {
807 1.1 christos unsigned value = 0;
808 1.1 christos
809 1.1 christos value |= ((insn >> 0) & 0x03ff) << 0;
810 1.1 christos
811 1.1 christos return value;
812 1.1 christos }
813 1.1 christos #endif /* EXTRACT_UIMM10_6_S */
814 1.1 christos
815 1.1 christos #ifndef INSERT_UIMM6_11_S
816 1.1 christos #define INSERT_UIMM6_11_S
817 1.1 christos /* mask = 0000002200011110
818 1.1 christos insn = 110000UU111uuuu0. */
819 1.4 christos static unsigned long long
820 1.4 christos insert_uimm6_11_s (unsigned long long insn ATTRIBUTE_UNUSED,
821 1.4 christos long long int value ATTRIBUTE_UNUSED,
822 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
823 1.1 christos {
824 1.1 christos
825 1.1 christos insn |= ((value >> 0) & 0x000f) << 1;
826 1.1 christos insn |= ((value >> 4) & 0x0003) << 8;
827 1.1 christos
828 1.1 christos return insn;
829 1.1 christos }
830 1.1 christos #endif /* INSERT_UIMM6_11_S */
831 1.1 christos
832 1.1 christos #ifndef EXTRACT_UIMM6_11_S
833 1.1 christos #define EXTRACT_UIMM6_11_S
834 1.1 christos /* mask = 0000002200011110. */
835 1.4 christos static long long int
836 1.4 christos extract_uimm6_11_s (unsigned long long insn ATTRIBUTE_UNUSED,
837 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
838 1.1 christos {
839 1.1 christos unsigned value = 0;
840 1.1 christos
841 1.1 christos value |= ((insn >> 1) & 0x000f) << 0;
842 1.1 christos value |= ((insn >> 8) & 0x0003) << 4;
843 1.1 christos
844 1.1 christos return value;
845 1.1 christos }
846 1.1 christos #endif /* EXTRACT_UIMM6_11_S */
847 1.1 christos
848 1.1 christos #ifndef INSERT_SIMM9_8
849 1.1 christos #define INSERT_SIMM9_8
850 1.1 christos /* mask = 00000000111111112000000000000000
851 1.1 christos insn = 00010bbbssssssssSBBBDaaZZXAAAAAA. */
852 1.4 christos static unsigned long long
853 1.4 christos insert_simm9_8 (unsigned long long insn ATTRIBUTE_UNUSED,
854 1.4 christos long long int value ATTRIBUTE_UNUSED,
855 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
856 1.1 christos {
857 1.1 christos
858 1.1 christos insn |= ((value >> 0) & 0x00ff) << 16;
859 1.1 christos insn |= ((value >> 8) & 0x0001) << 15;
860 1.1 christos
861 1.1 christos return insn;
862 1.1 christos }
863 1.1 christos #endif /* INSERT_SIMM9_8 */
864 1.1 christos
865 1.1 christos #ifndef EXTRACT_SIMM9_8
866 1.1 christos #define EXTRACT_SIMM9_8
867 1.1 christos /* mask = 00000000111111112000000000000000. */
868 1.4 christos static long long int
869 1.4 christos extract_simm9_8 (unsigned long long insn ATTRIBUTE_UNUSED,
870 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
871 1.1 christos {
872 1.1 christos int value = 0;
873 1.1 christos
874 1.1 christos value |= ((insn >> 16) & 0x00ff) << 0;
875 1.1 christos value |= ((insn >> 15) & 0x0001) << 8;
876 1.1 christos
877 1.1 christos /* Extend the sign. */
878 1.1 christos int signbit = 1 << (9 - 1);
879 1.1 christos value = (value ^ signbit) - signbit;
880 1.1 christos
881 1.1 christos return value;
882 1.1 christos }
883 1.1 christos #endif /* EXTRACT_SIMM9_8 */
884 1.1 christos
885 1.1 christos #ifndef INSERT_UIMM10_A32_8_S
886 1.1 christos #define INSERT_UIMM10_A32_8_S
887 1.1 christos /* mask = 0000000011111111
888 1.1 christos insn = 11010bbbuuuuuuuu. */
889 1.4 christos static unsigned long long
890 1.4 christos insert_uimm10_a32_8_s (unsigned long long insn ATTRIBUTE_UNUSED,
891 1.4 christos long long int value ATTRIBUTE_UNUSED,
892 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
893 1.1 christos {
894 1.1 christos if (value & 0x03)
895 1.1 christos *errmsg = _("Target address is not 32bit aligned.");
896 1.1 christos
897 1.1 christos insn |= ((value >> 2) & 0x00ff) << 0;
898 1.1 christos
899 1.1 christos return insn;
900 1.1 christos }
901 1.1 christos #endif /* INSERT_UIMM10_A32_8_S */
902 1.1 christos
903 1.1 christos #ifndef EXTRACT_UIMM10_A32_8_S
904 1.1 christos #define EXTRACT_UIMM10_A32_8_S
905 1.1 christos /* mask = 0000000011111111. */
906 1.4 christos static long long int
907 1.4 christos extract_uimm10_a32_8_s (unsigned long long insn ATTRIBUTE_UNUSED,
908 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
909 1.1 christos {
910 1.1 christos unsigned value = 0;
911 1.1 christos
912 1.1 christos value |= ((insn >> 0) & 0x00ff) << 2;
913 1.1 christos
914 1.1 christos return value;
915 1.1 christos }
916 1.1 christos #endif /* EXTRACT_UIMM10_A32_8_S */
917 1.1 christos
918 1.1 christos #ifndef INSERT_SIMM9_7_S
919 1.1 christos #define INSERT_SIMM9_7_S
920 1.1 christos /* mask = 0000000111111111
921 1.1 christos insn = 1100101sssssssss. */
922 1.4 christos static unsigned long long
923 1.4 christos insert_simm9_7_s (unsigned long long insn ATTRIBUTE_UNUSED,
924 1.4 christos long long int value ATTRIBUTE_UNUSED,
925 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
926 1.1 christos {
927 1.1 christos
928 1.1 christos insn |= ((value >> 0) & 0x01ff) << 0;
929 1.1 christos
930 1.1 christos return insn;
931 1.1 christos }
932 1.1 christos #endif /* INSERT_SIMM9_7_S */
933 1.1 christos
934 1.1 christos #ifndef EXTRACT_SIMM9_7_S
935 1.1 christos #define EXTRACT_SIMM9_7_S
936 1.1 christos /* mask = 0000000111111111. */
937 1.4 christos static long long int
938 1.4 christos extract_simm9_7_s (unsigned long long insn ATTRIBUTE_UNUSED,
939 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
940 1.1 christos {
941 1.1 christos int value = 0;
942 1.1 christos
943 1.1 christos value |= ((insn >> 0) & 0x01ff) << 0;
944 1.1 christos
945 1.1 christos /* Extend the sign. */
946 1.1 christos int signbit = 1 << (9 - 1);
947 1.1 christos value = (value ^ signbit) - signbit;
948 1.1 christos
949 1.1 christos return value;
950 1.1 christos }
951 1.1 christos #endif /* EXTRACT_SIMM9_7_S */
952 1.1 christos
953 1.1 christos #ifndef INSERT_UIMM6_A16_11_S
954 1.1 christos #define INSERT_UIMM6_A16_11_S
955 1.1 christos /* mask = 0000000000011111
956 1.1 christos insn = 10010bbbcccuuuuu. */
957 1.4 christos static unsigned long long
958 1.4 christos insert_uimm6_a16_11_s (unsigned long long insn ATTRIBUTE_UNUSED,
959 1.4 christos long long int value ATTRIBUTE_UNUSED,
960 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
961 1.1 christos {
962 1.1 christos if (value & 0x01)
963 1.1 christos *errmsg = _("Target address is not 16bit aligned.");
964 1.1 christos
965 1.1 christos insn |= ((value >> 1) & 0x001f) << 0;
966 1.1 christos
967 1.1 christos return insn;
968 1.1 christos }
969 1.1 christos #endif /* INSERT_UIMM6_A16_11_S */
970 1.1 christos
971 1.1 christos #ifndef EXTRACT_UIMM6_A16_11_S
972 1.1 christos #define EXTRACT_UIMM6_A16_11_S
973 1.1 christos /* mask = 0000000000011111. */
974 1.4 christos static long long int
975 1.4 christos extract_uimm6_a16_11_s (unsigned long long insn ATTRIBUTE_UNUSED,
976 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
977 1.1 christos {
978 1.1 christos unsigned value = 0;
979 1.1 christos
980 1.1 christos value |= ((insn >> 0) & 0x001f) << 1;
981 1.1 christos
982 1.1 christos return value;
983 1.1 christos }
984 1.1 christos #endif /* EXTRACT_UIMM6_A16_11_S */
985 1.1 christos
986 1.1 christos #ifndef INSERT_UIMM5_A32_11_S
987 1.1 christos #define INSERT_UIMM5_A32_11_S
988 1.1 christos /* mask = 0000020000011000
989 1.1 christos insn = 01000U00hhhuu1HH. */
990 1.4 christos static unsigned long long
991 1.4 christos insert_uimm5_a32_11_s (unsigned long long insn ATTRIBUTE_UNUSED,
992 1.4 christos long long int value ATTRIBUTE_UNUSED,
993 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
994 1.1 christos {
995 1.1 christos if (value & 0x03)
996 1.1 christos *errmsg = _("Target address is not 32bit aligned.");
997 1.1 christos
998 1.1 christos insn |= ((value >> 2) & 0x0003) << 3;
999 1.1 christos insn |= ((value >> 4) & 0x0001) << 10;
1000 1.1 christos
1001 1.1 christos return insn;
1002 1.1 christos }
1003 1.1 christos #endif /* INSERT_UIMM5_A32_11_S */
1004 1.1 christos
1005 1.1 christos #ifndef EXTRACT_UIMM5_A32_11_S
1006 1.1 christos #define EXTRACT_UIMM5_A32_11_S
1007 1.1 christos /* mask = 0000020000011000. */
1008 1.4 christos static long long int
1009 1.4 christos extract_uimm5_a32_11_s (unsigned long long insn ATTRIBUTE_UNUSED,
1010 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
1011 1.1 christos {
1012 1.1 christos unsigned value = 0;
1013 1.1 christos
1014 1.1 christos value |= ((insn >> 3) & 0x0003) << 2;
1015 1.1 christos value |= ((insn >> 10) & 0x0001) << 4;
1016 1.1 christos
1017 1.1 christos return value;
1018 1.1 christos }
1019 1.1 christos #endif /* EXTRACT_UIMM5_A32_11_S */
1020 1.1 christos
1021 1.1 christos #ifndef INSERT_SIMM11_A32_13_S
1022 1.1 christos #define INSERT_SIMM11_A32_13_S
1023 1.1 christos /* mask = 0000022222200111
1024 1.1 christos insn = 01010SSSSSS00sss. */
1025 1.4 christos static unsigned long long
1026 1.4 christos insert_simm11_a32_13_s (unsigned long long insn ATTRIBUTE_UNUSED,
1027 1.4 christos long long int value ATTRIBUTE_UNUSED,
1028 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
1029 1.1 christos {
1030 1.1 christos if (value & 0x03)
1031 1.1 christos *errmsg = _("Target address is not 32bit aligned.");
1032 1.1 christos
1033 1.1 christos insn |= ((value >> 2) & 0x0007) << 0;
1034 1.1 christos insn |= ((value >> 5) & 0x003f) << 5;
1035 1.1 christos
1036 1.1 christos return insn;
1037 1.1 christos }
1038 1.1 christos #endif /* INSERT_SIMM11_A32_13_S */
1039 1.1 christos
1040 1.1 christos #ifndef EXTRACT_SIMM11_A32_13_S
1041 1.1 christos #define EXTRACT_SIMM11_A32_13_S
1042 1.1 christos /* mask = 0000022222200111. */
1043 1.4 christos static long long int
1044 1.4 christos extract_simm11_a32_13_s (unsigned long long insn ATTRIBUTE_UNUSED,
1045 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
1046 1.1 christos {
1047 1.1 christos int value = 0;
1048 1.1 christos
1049 1.1 christos value |= ((insn >> 0) & 0x0007) << 2;
1050 1.1 christos value |= ((insn >> 5) & 0x003f) << 5;
1051 1.1 christos
1052 1.1 christos /* Extend the sign. */
1053 1.1 christos int signbit = 1 << (11 - 1);
1054 1.1 christos value = (value ^ signbit) - signbit;
1055 1.1 christos
1056 1.1 christos return value;
1057 1.1 christos }
1058 1.1 christos #endif /* EXTRACT_SIMM11_A32_13_S */
1059 1.1 christos
1060 1.1 christos #ifndef INSERT_UIMM7_13_S
1061 1.1 christos #define INSERT_UIMM7_13_S
1062 1.1 christos /* mask = 0000000022220111
1063 1.1 christos insn = 01010bbbUUUU1uuu. */
1064 1.4 christos static unsigned long long
1065 1.4 christos insert_uimm7_13_s (unsigned long long insn ATTRIBUTE_UNUSED,
1066 1.4 christos long long int value ATTRIBUTE_UNUSED,
1067 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
1068 1.1 christos {
1069 1.1 christos
1070 1.1 christos insn |= ((value >> 0) & 0x0007) << 0;
1071 1.1 christos insn |= ((value >> 3) & 0x000f) << 4;
1072 1.1 christos
1073 1.1 christos return insn;
1074 1.1 christos }
1075 1.1 christos #endif /* INSERT_UIMM7_13_S */
1076 1.1 christos
1077 1.1 christos #ifndef EXTRACT_UIMM7_13_S
1078 1.1 christos #define EXTRACT_UIMM7_13_S
1079 1.1 christos /* mask = 0000000022220111. */
1080 1.4 christos static long long int
1081 1.4 christos extract_uimm7_13_s (unsigned long long insn ATTRIBUTE_UNUSED,
1082 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
1083 1.1 christos {
1084 1.1 christos unsigned value = 0;
1085 1.1 christos
1086 1.1 christos value |= ((insn >> 0) & 0x0007) << 0;
1087 1.1 christos value |= ((insn >> 4) & 0x000f) << 3;
1088 1.1 christos
1089 1.1 christos return value;
1090 1.1 christos }
1091 1.1 christos #endif /* EXTRACT_UIMM7_13_S */
1092 1.1 christos
1093 1.1 christos #ifndef INSERT_UIMM6_A16_21
1094 1.1 christos #define INSERT_UIMM6_A16_21
1095 1.1 christos /* mask = 00000000000000000000011111000000
1096 1.1 christos insn = 00101bbb01001100RBBBRuuuuuAAAAAA. */
1097 1.4 christos static unsigned long long
1098 1.4 christos insert_uimm6_a16_21 (unsigned long long insn ATTRIBUTE_UNUSED,
1099 1.4 christos long long int value ATTRIBUTE_UNUSED,
1100 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
1101 1.1 christos {
1102 1.1 christos if (value & 0x01)
1103 1.1 christos *errmsg = _("Target address is not 16bit aligned.");
1104 1.1 christos
1105 1.1 christos insn |= ((value >> 1) & 0x001f) << 6;
1106 1.1 christos
1107 1.1 christos return insn;
1108 1.1 christos }
1109 1.1 christos #endif /* INSERT_UIMM6_A16_21 */
1110 1.1 christos
1111 1.1 christos #ifndef EXTRACT_UIMM6_A16_21
1112 1.1 christos #define EXTRACT_UIMM6_A16_21
1113 1.1 christos /* mask = 00000000000000000000011111000000. */
1114 1.4 christos static long long int
1115 1.4 christos extract_uimm6_a16_21 (unsigned long long insn ATTRIBUTE_UNUSED,
1116 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
1117 1.1 christos {
1118 1.1 christos unsigned value = 0;
1119 1.1 christos
1120 1.1 christos value |= ((insn >> 6) & 0x001f) << 1;
1121 1.1 christos
1122 1.1 christos return value;
1123 1.1 christos }
1124 1.1 christos #endif /* EXTRACT_UIMM6_A16_21 */
1125 1.1 christos
1126 1.1 christos #ifndef INSERT_UIMM7_11_S
1127 1.1 christos #define INSERT_UIMM7_11_S
1128 1.1 christos /* mask = 0000022200011110
1129 1.1 christos insn = 11000UUU110uuuu0. */
1130 1.4 christos static unsigned long long
1131 1.4 christos insert_uimm7_11_s (unsigned long long insn ATTRIBUTE_UNUSED,
1132 1.4 christos long long int value ATTRIBUTE_UNUSED,
1133 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
1134 1.1 christos {
1135 1.1 christos
1136 1.1 christos insn |= ((value >> 0) & 0x000f) << 1;
1137 1.1 christos insn |= ((value >> 4) & 0x0007) << 8;
1138 1.1 christos
1139 1.1 christos return insn;
1140 1.1 christos }
1141 1.1 christos #endif /* INSERT_UIMM7_11_S */
1142 1.1 christos
1143 1.1 christos #ifndef EXTRACT_UIMM7_11_S
1144 1.1 christos #define EXTRACT_UIMM7_11_S
1145 1.1 christos /* mask = 0000022200011110. */
1146 1.4 christos static long long int
1147 1.4 christos extract_uimm7_11_s (unsigned long long insn ATTRIBUTE_UNUSED,
1148 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
1149 1.1 christos {
1150 1.1 christos unsigned value = 0;
1151 1.1 christos
1152 1.1 christos value |= ((insn >> 1) & 0x000f) << 0;
1153 1.1 christos value |= ((insn >> 8) & 0x0007) << 4;
1154 1.1 christos
1155 1.1 christos return value;
1156 1.1 christos }
1157 1.1 christos #endif /* EXTRACT_UIMM7_11_S */
1158 1.1 christos
1159 1.1 christos #ifndef INSERT_UIMM7_A16_20
1160 1.1 christos #define INSERT_UIMM7_A16_20
1161 1.1 christos /* mask = 00000000000000000000111111000000
1162 1.1 christos insn = 00100RRR111010000RRRuuuuuu1QQQQQ. */
1163 1.4 christos static unsigned long long
1164 1.4 christos insert_uimm7_a16_20 (unsigned long long insn ATTRIBUTE_UNUSED,
1165 1.4 christos long long int value ATTRIBUTE_UNUSED,
1166 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
1167 1.1 christos {
1168 1.1 christos if (value & 0x01)
1169 1.1 christos *errmsg = _("Target address is not 16bit aligned.");
1170 1.1 christos
1171 1.1 christos insn |= ((value >> 1) & 0x003f) << 6;
1172 1.1 christos
1173 1.1 christos return insn;
1174 1.1 christos }
1175 1.1 christos #endif /* INSERT_UIMM7_A16_20 */
1176 1.1 christos
1177 1.1 christos #ifndef EXTRACT_UIMM7_A16_20
1178 1.1 christos #define EXTRACT_UIMM7_A16_20
1179 1.1 christos /* mask = 00000000000000000000111111000000. */
1180 1.4 christos static long long int
1181 1.4 christos extract_uimm7_a16_20 (unsigned long long insn ATTRIBUTE_UNUSED,
1182 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
1183 1.1 christos {
1184 1.1 christos unsigned value = 0;
1185 1.1 christos
1186 1.1 christos value |= ((insn >> 6) & 0x003f) << 1;
1187 1.1 christos
1188 1.1 christos return value;
1189 1.1 christos }
1190 1.1 christos #endif /* EXTRACT_UIMM7_A16_20 */
1191 1.1 christos
1192 1.1 christos #ifndef INSERT_SIMM13_A16_20
1193 1.1 christos #define INSERT_SIMM13_A16_20
1194 1.1 christos /* mask = 00000000000000000000111111222222
1195 1.1 christos insn = 00100RRR101010000RRRssssssSSSSSS. */
1196 1.4 christos static unsigned long long
1197 1.4 christos insert_simm13_a16_20 (unsigned long long insn ATTRIBUTE_UNUSED,
1198 1.4 christos long long int value ATTRIBUTE_UNUSED,
1199 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
1200 1.1 christos {
1201 1.1 christos if (value & 0x01)
1202 1.1 christos *errmsg = _("Target address is not 16bit aligned.");
1203 1.1 christos
1204 1.1 christos insn |= ((value >> 1) & 0x003f) << 6;
1205 1.1 christos insn |= ((value >> 7) & 0x003f) << 0;
1206 1.1 christos
1207 1.1 christos return insn;
1208 1.1 christos }
1209 1.1 christos #endif /* INSERT_SIMM13_A16_20 */
1210 1.1 christos
1211 1.1 christos #ifndef EXTRACT_SIMM13_A16_20
1212 1.1 christos #define EXTRACT_SIMM13_A16_20
1213 1.1 christos /* mask = 00000000000000000000111111222222. */
1214 1.4 christos static long long int
1215 1.4 christos extract_simm13_a16_20 (unsigned long long insn ATTRIBUTE_UNUSED,
1216 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
1217 1.1 christos {
1218 1.1 christos int value = 0;
1219 1.1 christos
1220 1.1 christos value |= ((insn >> 6) & 0x003f) << 1;
1221 1.1 christos value |= ((insn >> 0) & 0x003f) << 7;
1222 1.1 christos
1223 1.1 christos /* Extend the sign. */
1224 1.1 christos int signbit = 1 << (13 - 1);
1225 1.1 christos value = (value ^ signbit) - signbit;
1226 1.1 christos
1227 1.1 christos return value;
1228 1.1 christos }
1229 1.1 christos #endif /* EXTRACT_SIMM13_A16_20 */
1230 1.1 christos
1231 1.1 christos #ifndef INSERT_UIMM8_8_S
1232 1.1 christos #define INSERT_UIMM8_8_S
1233 1.1 christos /* mask = 0000000011111111
1234 1.1 christos insn = 11011bbbuuuuuuuu. */
1235 1.4 christos static unsigned long long
1236 1.4 christos insert_uimm8_8_s (unsigned long long insn ATTRIBUTE_UNUSED,
1237 1.4 christos long long int value ATTRIBUTE_UNUSED,
1238 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
1239 1.1 christos {
1240 1.1 christos
1241 1.1 christos insn |= ((value >> 0) & 0x00ff) << 0;
1242 1.1 christos
1243 1.1 christos return insn;
1244 1.1 christos }
1245 1.1 christos #endif /* INSERT_UIMM8_8_S */
1246 1.1 christos
1247 1.1 christos #ifndef EXTRACT_UIMM8_8_S
1248 1.1 christos #define EXTRACT_UIMM8_8_S
1249 1.1 christos /* mask = 0000000011111111. */
1250 1.4 christos static long long int
1251 1.4 christos extract_uimm8_8_s (unsigned long long insn ATTRIBUTE_UNUSED,
1252 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
1253 1.1 christos {
1254 1.1 christos unsigned value = 0;
1255 1.1 christos
1256 1.1 christos value |= ((insn >> 0) & 0x00ff) << 0;
1257 1.1 christos
1258 1.1 christos return value;
1259 1.1 christos }
1260 1.1 christos #endif /* EXTRACT_UIMM8_8_S */
1261 1.1 christos
1262 1.1 christos #ifndef INSERT_UIMM6_5_S
1263 1.1 christos #define INSERT_UIMM6_5_S
1264 1.1 christos /* mask = 0000011111100000
1265 1.1 christos insn = 01111uuuuuu11111. */
1266 1.4 christos static unsigned long long
1267 1.4 christos insert_uimm6_5_s (unsigned long long insn ATTRIBUTE_UNUSED,
1268 1.4 christos long long int value ATTRIBUTE_UNUSED,
1269 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
1270 1.1 christos {
1271 1.1 christos
1272 1.1 christos insn |= ((value >> 0) & 0x003f) << 5;
1273 1.1 christos
1274 1.1 christos return insn;
1275 1.1 christos }
1276 1.1 christos #endif /* INSERT_UIMM6_5_S */
1277 1.1 christos
1278 1.1 christos #ifndef EXTRACT_UIMM6_5_S
1279 1.1 christos #define EXTRACT_UIMM6_5_S
1280 1.1 christos /* mask = 0000011111100000. */
1281 1.4 christos static long long int
1282 1.4 christos extract_uimm6_5_s (unsigned long long insn ATTRIBUTE_UNUSED,
1283 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
1284 1.1 christos {
1285 1.1 christos unsigned value = 0;
1286 1.1 christos
1287 1.1 christos value |= ((insn >> 5) & 0x003f) << 0;
1288 1.1 christos
1289 1.1 christos return value;
1290 1.1 christos }
1291 1.1 christos #endif /* EXTRACT_UIMM6_5_S */
1292 1.1 christos
1293 1.1 christos #ifndef INSERT_UIMM6_AXX_
1294 1.1 christos #define INSERT_UIMM6_AXX_
1295 1.1 christos /* mask = 00000000000000000000000000000000
1296 1.1 christos insn = 00110bbb11100001100001100001QQQQ. */
1297 1.1 christos static ATTRIBUTE_UNUSED unsigned
1298 1.4 christos insert_uimm6_axx_ (unsigned long long insn ATTRIBUTE_UNUSED,
1299 1.4 christos long long int value ATTRIBUTE_UNUSED,
1300 1.1 christos const char **errmsg ATTRIBUTE_UNUSED)
1301 1.1 christos {
1302 1.1 christos if (value & 0x3f)
1303 1.1 christos *errmsg = _("Target address is not 512bit aligned.");
1304 1.1 christos
1305 1.1 christos return insn;
1306 1.1 christos }
1307 1.1 christos #endif /* INSERT_UIMM6_AXX_ */
1308 1.1 christos
1309 1.1 christos #ifndef EXTRACT_UIMM6_AXX_
1310 1.1 christos #define EXTRACT_UIMM6_AXX_
1311 1.1 christos /* mask = 00000000000000000000000000000000. */
1312 1.1 christos static ATTRIBUTE_UNUSED int
1313 1.4 christos extract_uimm6_axx_ (unsigned long long insn ATTRIBUTE_UNUSED,
1314 1.6 christos bool *invalid ATTRIBUTE_UNUSED)
1315 1.1 christos {
1316 1.1 christos unsigned value = 0;
1317 1.1 christos
1318 1.1 christos return value;
1319 1.1 christos }
1320 1.1 christos #endif /* EXTRACT_UIMM6_AXX_ */
1321