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