Debian Codegraph @

arch/arm/local2.c

raw symbols SCIP
1 /* $Id: local2.c,v 1.41 2021/09/04 10:38:37 gmcgarry Exp $ */
2 /*
3 * Copyright (c) 2007 Gregory McGarry ([email protected]).
4 * Copyright (c) 2003 Anders Magnusson ([email protected]).
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include <assert.h>
31 #include <ctype.h>
32 #include <string.h>
33 #include <stdlib.h>
34
35 #include "pass2.h"
36
37 extern void defalign(int);
38
39 #define exname(x) x
40
41 char *rnames[] = {
42 "r0", "r1", "r2", "r3","r4","r5", "r6", "r7",
43 "r8", "r9", "r10", "fp", "ip", "sp", "lr", "pc",
44 "r0r1", "r1r2", "r2r3", "r3r4", "r4r5", "r5r6",
45 "r6r7", "r7r8", "r8r9", "r9r10",
46 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
47 };
48
49 /*
50 * Handling of integer constants. We have 8 bits + an even
51 * number of rotates available as a simple immediate.
52 * If a constant isn't trivially representable, use an ldr
53 * and a subsequent sequence of orr operations.
54 */
55
56 static int
57 trepresent(const unsigned int val)
58 {
59 int i;
60 #define rotate_left(v, n) (v << n | v >> (32 - n))
61
62 for (i = 0; i < 32; i += 2)
63 if (rotate_left(val, i) <= 0xff)
64 return 1;
65 return 0;
66 }
67
68 /*
69 * Return values are:
70 * 0 - output constant as is (should be covered by trepresent() above)
71 * 1 - 4 generate 1-4 instructions as needed.
72 */
73 static int
74 encode_constant(int constant, int *values)
75 {
76 int tmp = constant;
77 int i = 0;
78 int first_bit, value;
79
80 while (tmp) {
81 first_bit = ffs(tmp);
82 first_bit -= 1; /* ffs indexes from 1, not 0 */
83 first_bit &= ~1; /* must use even bit offsets */
84
85 value = tmp & (0xff << first_bit);
86 values[i++] = value;
87 tmp &= ~value;
88 }
89 return i;
90 }
91
92 #if 0
93 static void
94 load_constant(NODE *p)
95 {
96 int v = p->n_lval & 0xffffffff;
97 int reg = DECRA(p->n_reg, 1);
98
99 load_constant_into_reg(reg, v);
100 }
101 #endif
102
103 static void
104 load_constant_into_reg(int reg, int v)
105 {
106 if (trepresent(v))
107 printf("\tmov %s,#%d\n", rnames[reg], v);
108 else if (trepresent(-v))
109 printf("\tmvn %s,#%d\n", rnames[reg], -v);
110 else {
111 int vals[4], nc, i;
112
113 nc = encode_constant(v, vals);
114 for (i = 0; i < nc; i++) {
115 if (i == 0) {
116 printf("\tmov %s,#%d" COM "load constant %d\n",
117 rnames[reg], vals[i], v);
118 } else {
119 printf("\torr %s,%s,#%d\n",
120 rnames[reg], rnames[reg], vals[i]);
121 }
122 }
123 }
124 }
125
126 static TWORD ftype;
127
128 /*
129 * calculate stack size and offsets
130 */
131 static int
132 offcalc(struct interpass_prolog *ipp)
133 {
134 int addto;
135
136 #ifdef PCC_DEBUG
137 if (x2debug)
138 printf("offcalc: p2maxautooff=%d\n", p2maxautooff);
139 #endif
140
141 addto = p2maxautooff;
142
143 #if 0
144 addto += 7;
145 addto &= ~7;
146 #endif
147
148 #ifdef PCC_DEBUG
149 if (x2debug)
150 printf("offcalc: addto=%d\n", addto);
151 #endif
152
153 addto -= AUTOINIT / SZCHAR;
154
155 return addto;
156 }
157
158 void
159 prologue(struct interpass_prolog *ipp)
160 {
161 int addto;
162 int vals[4], nc, i;
163
164 #ifdef PCC_DEBUG
165 if (x2debug)
166 printf("prologue: type=%d, lineno=%d, name=%s, vis=%d, ipptype=%d, autos=%d, tmpnum=%d, lblnum=%d\n",
167 ipp->ipp_ip.type,
168 ipp->ipp_ip.lineno,
169 ipp->ipp_name,
170 ipp->ipp_vis,
171 ipp->ipp_type,
172 ipp->ipp_autos,
173 ipp->ip_tmpnum,
174 ipp->ip_lblnum);
175 #endif
176
177 ftype = ipp->ipp_type;
178
179 /*
180 * We here know what register to save and how much to
181 * add to the stack.
182 */
183 addto = offcalc(ipp);
184
185 printf("\tsub %s,%s,#%d\n", rnames[SP], rnames[SP], 16);
186 printf("\tmov %s,%s\n", rnames[IP], rnames[SP]);
187 printf("\tstmfd %s!,{%s,%s,%s,%s}\n", rnames[SP], rnames[FP],
188 rnames[IP], rnames[LR], rnames[PC]);
189 printf("\tsub %s,%s,#4\n", rnames[FP], rnames[IP]);
190
191 if (addto == 0)
192 return;
193
194 if (trepresent(addto)) {
195 printf("\tsub %s,%s,#%d\n", rnames[SP], rnames[SP], addto);
196 } else {
197 nc = encode_constant(addto, vals);
198 for (i = 0; i < nc; i++)
199 printf("\tsub %s,%s,#%d\n",
200 rnames[SP], rnames[SP], vals[i]);
201 }
202 }
203
204 void
205 eoftn(struct interpass_prolog *ipp)
206 {
207 if (ipp->ipp_ip.ip_lbl == 0)
208 return; /* no code needs to be generated */
209
210 /* struct return needs special treatment */
211 if (ftype == STRTY || ftype == UNIONTY) {
212 assert(0);
213 } else {
214 printf("\tldmea %s,{%s,%s,%s}\n", rnames[FP], rnames[FP],
215 rnames[SP], rnames[PC]);
216 printf("\tadd %s,%s,#%d\n", rnames[SP], rnames[SP], 16);
217 }
218 printf("\t.size %s,.-%s\n", exname(ipp->ipp_name),
219 exname(ipp->ipp_name));
220 }
221
222
223 /*
224 * these mnemonics match the order of the preprocessor decls
225 * EQ, NE, LE, LT, GE, GT, ULE, ULT, UGE, UGT
226 */
227
228 static char *
229 ccbranches[] = {
230 "beq", /* branch if equal */
231 "bne", /* branch if not-equal */
232 "ble", /* branch if less-than-or-equal */
233 "blt", /* branch if less-than */
234 "bge", /* branch if greater-than-or-equal */
235 "bgt", /* branch if greater-than */
236 /* what should these be ? */
237 "bls", /* branch if lower-than-or-same */
238 "blo", /* branch if lower-than */
239 "bhs", /* branch if higher-than-or-same */
240 "bhi", /* branch if higher-than */
241 };
242
243 /*
244 * add/sub/...
245 *
246 * Param given:
247 */
248 void
249 hopcode(int f, int o)
250 {
251 char *str;
252
253 switch (o) {
254 case PLUS:
255 str = "add";
256 break;
257 case MINUS:
258 str = "sub";
259 break;
260 case AND:
261 str = "and";
262 break;
263 case OR:
264 str = "orr";
265 break;
266 case ER:
267 str = "eor";
268 break;
269 default:
270 comperr("hopcode2: %d", o);
271 str = 0; /* XXX gcc */
272 }
273 printf("%s%c", str, f);
274 }
275
276 /*
277 * Return type size in bytes. Used by R2REGS, arg 2 to offset().
278 */
279 int
280 tlen(NODE *p)
281 {
282 switch(p->n_type) {
283 case CHAR:
284 case UCHAR:
285 return(1);
286
287 case SHORT:
288 case USHORT:
289 return(SZSHORT/SZCHAR);
290
291 case DOUBLE:
292 return(SZDOUBLE/SZCHAR);
293
294 case INT:
295 case UNSIGNED:
296 case LONG:
297 case ULONG:
298 return(SZINT/SZCHAR);
299
300 case LONGLONG:
301 case ULONGLONG:
302 return SZLONGLONG/SZCHAR;
303
304 default:
305 if (!ISPTR(p->n_type))
306 comperr("tlen type %d not pointer");
307 return SZPOINT(p->n_type)/SZCHAR;
308 }
309 }
310
311 /*
312 * Emit code to compare two longlong numbers.
313 */
314 static void
315 twollcomp(NODE *p)
316 {
317 int o = p->n_op;
318 int s = getlab2();
319 int e = p->n_label;
320 int cb1, cb2;
321
322 if (o >= ULE)
323 o -= (ULE-LE);
324 switch (o) {
325 case NE:
326 cb1 = 0;
327 cb2 = NE;
328 break;
329 case EQ:
330 cb1 = NE;
331 cb2 = 0;
332 break;
333 case LE:
334 case LT:
335 cb1 = GT;
336 cb2 = LT;
337 break;
338 case GE:
339 case GT:
340 cb1 = LT;
341 cb2 = GT;
342 break;
343
344 default:
345 cb1 = cb2 = 0; /* XXX gcc */
346 }
347 if (p->n_op >= ULE)
348 cb1 += 4, cb2 += 4;
349 expand(p, 0, "\tcmp UR,UL" COM "compare 64-bit values (upper)\n");
350 if (cb1) cbgen(cb1, s);
351 if (cb2) cbgen(cb2, e);
352 expand(p, 0, "\tcmp AR,AL" COM "(and lower)\n");
353 cbgen(p->n_op, e);
354 deflab(s);
355 }
356
357 int
358 fldexpand(NODE *p, int cookie, char **cp)
359 {
360 CONSZ val;
361 int shft;
362
363 if (p->n_op == ASSIGN)
364 p = p->n_left;
365
366 if (features(FEATURE_BIGENDIAN))
367 shft = SZINT - UPKFSZ(p->n_rval) - UPKFOFF(p->n_rval);
368 else
369 shft = UPKFOFF(p->n_rval);
370
371 switch (**cp) {
372 case 'S':
373 printf("#%d", UPKFSZ(p->n_rval));
374 break;
375 case 'H':
376 printf("#%d", shft);
377 break;
378 case 'M':
379 case 'N':
380 val = (CONSZ)1 << UPKFSZ(p->n_rval);
381 --val;
382 val <<= shft;
383 printf("%lld", (**cp == 'M' ? val : ~val) & 0xffffffff);
384 break;
385 default:
386 comperr("fldexpand");
387 }
388 return 1;
389 }
390
391
392 /*
393 * Structure assignment.
394 */
395 static void
396 stasg(NODE *p)
397 {
398 NODE *l = p->n_left;
399 int val = getlval(l);
400
401 /* R0 = dest, R1 = src, R2 = len */
402 load_constant_into_reg(R2, attr_find(p->n_ap, ATTR_P2STRUCT)->iarg(0));
403 if (l->n_op == OREG) {
404 if (R2TEST(regno(l))) {
405 int r = regno(l);
406 printf("\tadd %s,%s,lsl #%d\n",
407 rnames[R0], rnames[R2UPK2(r)], R2UPK3(r));
408 printf("\tadd %s,%s,%s\n", rnames[R0], rnames[R0],
409 rnames[R2UPK1(r)]);
410 } else {
411 if (trepresent(val)) {
412 printf("\tadd %s,%s,#%d\n",
413 rnames[R0], rnames[regno(l)], val);
414 } else {
415 load_constant_into_reg(R0, val);
416 printf("\tadd %s,%s,%s\n", rnames[R0],
417 rnames[R0], rnames[regno(l)]);
418 }
419 }
420 } else if (l->n_op == NAME) {
421 cerror("not implemented");
422 }
423
424 printf("\tbl %s\n", exname("memcpy"));
425 }
426
427 static void
428 shiftop(NODE *p)
429 {
430 NODE *r = p->n_right;
431 TWORD ty = p->n_type;
432 char *shifttype;
433
434 if (p->n_op == LS && r->n_op == ICON && getlval(r) < 32) {
435 expand(p, INBREG, "\tmov A1,AL,lsr ");
436 printf("#" CONFMT COM "64-bit left-shift\n", 32 - getlval(r));
437 expand(p, INBREG, "\tmov U1,UL,asl AR\n");
438 expand(p, INBREG, "\torr U1,U1,A1\n");
439 expand(p, INBREG, "\tmov A1,AL,asl AR\n");
440 } else if (p->n_op == LS && r->n_op == ICON && getlval(r) < 64) {
441 expand(p, INBREG, "\tmov A1,#0" COM "64-bit left-shift\n");
442 expand(p, INBREG, "\tmov U1,AL");
443 if (getlval(r) - 32 != 0)
444 printf(",asl #" CONFMT, getlval(r) - 32);
445 printf("\n");
446 } else if (p->n_op == LS && r->n_op == ICON) {
447 expand(p, INBREG, "\tmov A1,#0" COM "64-bit left-shift\n");
448 expand(p, INBREG, "\tmov U1,#0\n");
449 } else if (p->n_op == RS && r->n_op == ICON && getlval(r) < 32) {
450 expand(p, INBREG, "\tmov U1,UL,asl ");
451 printf("#" CONFMT COM "64-bit right-shift\n", 32 - getlval(r));
452 expand(p, INBREG, "\tmov A1,AL,lsr AR\n");
453 expand(p, INBREG, "\torr A1,A1,U1\n");
454 if (ty == LONGLONG)
455 expand(p, INBREG, "\tmov U1,UL,asr AR\n");
456 else
457 expand(p, INBREG, "\tmov U1,UL,lsr AR\n");
458 } else if (p->n_op == RS && r->n_op == ICON && getlval(r) < 64) {
459 if (ty == LONGLONG) {
460 expand(p, INBREG, "\tmvn U1,#1" COM "64-bit right-shift\n");
461 expand(p, INBREG, "\tmov A1,UL");
462 shifttype = "asr";
463 }else {
464 expand(p, INBREG, "\tmov U1,#0" COM "64-bit right-shift\n");
465 expand(p, INBREG, "\tmov A1,UL");
466 shifttype = "lsr";
467 }
468 if (getlval(r) - 32 != 0)
469 printf(",%s #" CONFMT, shifttype, getlval(r) - 32);
470 printf("\n");
471 } else if (p->n_op == RS && r->n_op == ICON) {
472 expand(p, INBREG, "\tmov A1,#0" COM "64-bit right-shift\n");
473 expand(p, INBREG, "\tmov U1,#0\n");
474 }
475 }
476
477 /*
478 * http://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html#Soft-float-library-routines
479 */
480 static void
481 fpemul(NODE *p)
482 {
483 NODE *l = p->n_left;
484 char *ch = NULL;
485
486 if (p->n_op == PLUS && p->n_type == FLOAT) ch = "addsf3";
487 else if (p->n_op == PLUS && p->n_type == DOUBLE) ch = "adddf3";
488 else if (p->n_op == PLUS && p->n_type == LDOUBLE) ch = "adddf3";
489
490 else if (p->n_op == MINUS && p->n_type == FLOAT) ch = "subsf3";
491 else if (p->n_op == MINUS && p->n_type == DOUBLE) ch = "subdf3";
492 else if (p->n_op == MINUS && p->n_type == LDOUBLE) ch = "subdf3";
493
494 else if (p->n_op == MUL && p->n_type == FLOAT) ch = "mulsf3";
495 else if (p->n_op == MUL && p->n_type == DOUBLE) ch = "muldf3";
496 else if (p->n_op == MUL && p->n_type == LDOUBLE) ch = "muldf3";
497
498 else if (p->n_op == DIV && p->n_type == FLOAT) ch = "divsf3";
499 else if (p->n_op == DIV && p->n_type == DOUBLE) ch = "divdf3";
500 else if (p->n_op == DIV && p->n_type == LDOUBLE) ch = "divdf3";
501
502 else if (p->n_op == UMINUS && p->n_type == FLOAT) ch = "negsf2";
503 else if (p->n_op == UMINUS && p->n_type == DOUBLE) ch = "negdf2";
504 else if (p->n_op == UMINUS && p->n_type == LDOUBLE) ch = "negdf2";
505
506 else if (p->n_op == EQ && l->n_type == FLOAT) ch = "eqsf2";
507 else if (p->n_op == EQ && l->n_type == DOUBLE) ch = "eqdf2";
508 else if (p->n_op == EQ && l->n_type == LDOUBLE) ch = "eqdf2";
509
510 else if (p->n_op == NE && l->n_type == FLOAT) ch = "nesf2";
511 else if (p->n_op == NE && l->n_type == DOUBLE) ch = "nedf2";
512 else if (p->n_op == NE && l->n_type == LDOUBLE) ch = "nedf2";
513
514 else if (p->n_op == GE && l->n_type == FLOAT) ch = "gesf2";
515 else if (p->n_op == GE && l->n_type == DOUBLE) ch = "gedf2";
516 else if (p->n_op == GE && l->n_type == LDOUBLE) ch = "gedf2";
517
518 else if (p->n_op == LE && l->n_type == FLOAT) ch = "lesf2";
519 else if (p->n_op == LE && l->n_type == DOUBLE) ch = "ledf2";
520 else if (p->n_op == LE && l->n_type == LDOUBLE) ch = "ledf2";
521
522 else if (p->n_op == GT && l->n_type == FLOAT) ch = "gtsf2";
523 else if (p->n_op == GT && l->n_type == DOUBLE) ch = "gtdf2";
524 else if (p->n_op == GT && l->n_type == LDOUBLE) ch = "gtdf2";
525
526 else if (p->n_op == LT && l->n_type == FLOAT) ch = "ltsf2";
527 else if (p->n_op == LT && l->n_type == DOUBLE) ch = "ltdf2";
528 else if (p->n_op == LT && l->n_type == LDOUBLE) ch = "ltdf2";
529
530 else if (p->n_op == SCONV && p->n_type == FLOAT) {
531 if (l->n_type == DOUBLE) ch = "truncdfsf2";
532 else if (l->n_type == LDOUBLE) ch = "truncdfsf2";
533 else if (l->n_type == ULONGLONG) ch = "floatunsdisf";
534 else if (l->n_type == LONGLONG) ch = "floatdisf";
535 else if (l->n_type == LONG) ch = "floatsisf";
536 else if (l->n_type == ULONG) ch = "floatunsisf";
537 else if (l->n_type == INT) ch = "floatsisf";
538 else if (l->n_type == UNSIGNED) ch = "floatunsisf";
539 } else if (p->n_op == SCONV && p->n_type == DOUBLE) {
540 if (l->n_type == FLOAT) ch = "extendsfdf2";
541 else if (l->n_type == LDOUBLE) ch = "trunctfdf2";
542 else if (l->n_type == ULONGLONG) ch = "floatunsdidf";
543 else if (l->n_type == LONGLONG) ch = "floatdidf";
544 else if (l->n_type == LONG) ch = "floatsidf";
545 else if (l->n_type == ULONG) ch = "floatunsidf";
546 else if (l->n_type == INT) ch = "floatsidf";
547 else if (l->n_type == UNSIGNED) ch = "floatunsidf";
548 } else if (p->n_op == SCONV && p->n_type == LDOUBLE) {
549 if (l->n_type == FLOAT) ch = "extendsfdf2";
550 else if (l->n_type == DOUBLE) ch = "extenddftd2";
551 else if (l->n_type == ULONGLONG) ch = "floatunsdidf";
552 else if (l->n_type == LONGLONG) ch = "floatdidf";
553 else if (l->n_type == LONG) ch = "floatsidf";
554 else if (l->n_type == ULONG) ch = "floatunsidf";
555 else if (l->n_type == INT) ch = "floatsidf";
556 else if (l->n_type == UNSIGNED) ch = "floatunsidf";
557 } else if (p->n_op == SCONV && p->n_type == ULONGLONG) {
558 if (l->n_type == FLOAT) ch = "fixunssfdi";
559 else if (l->n_type == DOUBLE) ch = "fixunsdfdi";
560 else if (l->n_type == LDOUBLE) ch = "fixunsdfdi";
561 } else if (p->n_op == SCONV && p->n_type == LONGLONG) {
562 if (l->n_type == FLOAT) ch = "fixsfdi";
563 else if (l->n_type == DOUBLE) ch = "fixdfdi";
564 else if (l->n_type == LDOUBLE) ch = "fixdfdi";
565 } else if (p->n_op == SCONV && p->n_type == LONG) {
566 if (l->n_type == FLOAT) ch = "fixsfsi";
567 else if (l->n_type == DOUBLE) ch = "fixdfsi";
568 else if (l->n_type == LDOUBLE) ch = "fixdfsi";
569 } else if (p->n_op == SCONV && p->n_type == ULONG) {
570 if (l->n_type == FLOAT) ch = "fixunssfdi";
571 else if (l->n_type == DOUBLE) ch = "fixunsdfdi";
572 else if (l->n_type == LDOUBLE) ch = "fixunsdfdi";
573 } else if (p->n_op == SCONV && p->n_type == INT) {
574 if (l->n_type == FLOAT) ch = "fixsfsi";
575 else if (l->n_type == DOUBLE) ch = "fixdfsi";
576 else if (l->n_type == LDOUBLE) ch = "fixdfsi";
577 } else if (p->n_op == SCONV && p->n_type == UNSIGNED) {
578 if (l->n_type == FLOAT) ch = "fixunssfsi";
579 else if (l->n_type == DOUBLE) ch = "fixunsdfsi";
580 else if (l->n_type == LDOUBLE) ch = "fixunsdfsi";
581 }
582
583 if (ch == NULL) comperr("ZF: op=0x%x (%d)\n", p->n_op, p->n_op);
584
585 printf("\tbl __%s" COM "softfloat operation\n", exname(ch));
586
587 if (p->n_op >= EQ && p->n_op <= GT)
588 printf("\tcmp %s,#0\n", rnames[R0]);
589 }
590
591
592 /*
593 * http://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html#Integer-library-routines
594 */
595
596 static void
597 emul(NODE *p)
598 {
599 char *ch = NULL;
600
601 if (p->n_op == LS && DEUNSIGN(p->n_type) == LONGLONG) ch = "ashldi3";
602 else if (p->n_op == LS && DEUNSIGN(p->n_type) == LONG) ch = "ashlsi3";
603 else if (p->n_op == LS && DEUNSIGN(p->n_type) == INT) ch = "ashlsi3";
604
605 else if (p->n_op == RS && p->n_type == ULONGLONG) ch = "lshrdi3";
606 else if (p->n_op == RS && p->n_type == ULONG) ch = "lshrsi3";
607 else if (p->n_op == RS && p->n_type == UNSIGNED) ch = "lshrsi3";
608
609 else if (p->n_op == RS && p->n_type == LONGLONG) ch = "ashrdi3";
610 else if (p->n_op == RS && p->n_type == LONG) ch = "ashrsi3";
611 else if (p->n_op == RS && p->n_type == INT) ch = "ashrsi3";
612
613 else if (p->n_op == DIV && p->n_type == LONGLONG) ch = "divdi3";
614 else if (p->n_op == DIV && p->n_type == LONG) ch = "divsi3";
615 else if (p->n_op == DIV && p->n_type == INT) ch = "divsi3";
616
617 else if (p->n_op == DIV && p->n_type == ULONGLONG) ch = "udivdi3";
618 else if (p->n_op == DIV && p->n_type == ULONG) ch = "udivsi3";
619 else if (p->n_op == DIV && p->n_type == UNSIGNED) ch = "udivsi3";
620
621 else if (p->n_op == MOD && p->n_type == LONGLONG) ch = "moddi3";
622 else if (p->n_op == MOD && p->n_type == LONG) ch = "modsi3";
623 else if (p->n_op == MOD && p->n_type == INT) ch = "modsi3";
624
625 else if (p->n_op == MOD && p->n_type == ULONGLONG) ch = "umoddi3";
626 else if (p->n_op == MOD && p->n_type == ULONG) ch = "umodsi3";
627 else if (p->n_op == MOD && p->n_type == UNSIGNED) ch = "umodsi3";
628
629 else if (p->n_op == MUL && p->n_type == LONGLONG) ch = "muldi3";
630 else if (p->n_op == MUL && p->n_type == LONG) ch = "mulsi3";
631 else if (p->n_op == MUL && p->n_type == INT) ch = "mulsi3";
632
633 else if (p->n_op == UMINUS && p->n_type == LONGLONG) ch = "negdi2";
634 else if (p->n_op == UMINUS && p->n_type == LONG) ch = "negsi2";
635 else if (p->n_op == UMINUS && p->n_type == INT) ch = "negsi2";
636
637 else ch = 0, comperr("ZE");
638 printf("\tbl __%s" COM "emulated operation\n", exname(ch));
639 }
640
641 static void
642 halfword(NODE *p)
643 {
644 NODE *r = getlr(p, 'R');
645 NODE *l = getlr(p, 'L');
646 int idx0 = 0, idx1 = 1;
647 CONSZ lval;
648
649 if (features(FEATURE_BIGENDIAN)) {
650 idx0 = 1;
651 idx1 = 0;
652 }
653
654 if (p->n_op == ASSIGN && r->n_op == OREG) {
655 /* load */
656 lval = getlval(r);
657 expand(p, 0, "\tldrb A1,");
658 printf("[%s,#" CONFMT "]\n", rnames[r->n_rval], lval+idx0);
659 expand(p, 0, "\tldrb AL,");
660 printf("[%s,#" CONFMT "]\n", rnames[r->n_rval], lval+idx1);
661 expand(p, 0, "\torr AL,A1,AL,asl #8\n");
662 } else if (p->n_op == ASSIGN && l->n_op == OREG) {
663 /* store */
664 lval = getlval(l);
665 expand(p, 0, "\tstrb AR,");
666 printf("[%s,#" CONFMT "]\n", rnames[l->n_rval], lval+idx0);
667 expand(p, 0, "\tmov A1,AR,asr #8\n");
668 expand(p, 0, "\tstrb A1,");
669 printf("[%s,#" CONFMT "]\n", rnames[l->n_rval], lval+idx1);
670 } else if (p->n_op == SCONV || p->n_op == UMUL) {
671 /* load */
672 lval = getlval(l);
673 expand(p, 0, "\tldrb A1,");
674 printf("[%s,#" CONFMT "]\n", rnames[l->n_rval], lval+idx0);
675 expand(p, 0, "\tldrb A2,");
676 printf("[%s,#" CONFMT "]\n", rnames[l->n_rval], lval+idx1);
677 expand(p, 0, "\torr A1,A1,A2,asl #8\n");
678 } else if (p->n_op == NAME || p->n_op == ICON || p->n_op == OREG) {
679 /* load */
680 lval = getlval(p);
681 expand(p, 0, "\tldrb A1,");
682 printf("[%s,#" CONFMT "]\n", rnames[p->n_rval], lval+idx0);
683 expand(p, 0, "\tldrb A2,");
684 printf("[%s,#" CONFMT "]\n", rnames[p->n_rval], lval+idx1);
685 expand(p, 0, "\torr A1,A1,A2,asl #8\n");
686 } else {
687 comperr("halfword");
688 }
689 }
690
691 static void
692 bfext(NODE *p)
693 {
694 int sz;
695
696 if (ISUNSIGNED(p->n_right->n_type))
697 return;
698 sz = 32 - UPKFSZ(p->n_left->n_rval);
699
700 expand(p, 0, "\tmov AD,AD,asl ");
701 printf("#%d\n", sz);
702 expand(p, 0, "\tmov AD,AD,asr ");
703 printf("#%d\n", sz);
704 }
705
706 static int
707 argsiz(NODE *p)
708 {
709 TWORD t = p->n_type;
710
711 if (t < LONGLONG || t == FLOAT || t > BTMASK)
712 return 4;
713 if (t == LONGLONG || t == ULONGLONG)
714 return 8;
715 if (t == DOUBLE || t == LDOUBLE)
716 return 8;
717 if (t == STRTY || t == UNIONTY)
718 return attr_find(p->n_ap, ATTR_P2STRUCT)->iarg(0);
719 comperr("argsiz");
720 return 0;
721 }
722
723 void
724 zzzcode(NODE *p, int c)
725 {
726 int pr;
727
728 switch (c) {
729
730 case 'B': /* bit-field sign extension */
731 bfext(p);
732 break;
733
734 case 'C': /* remove from stack after subroutine call */
735 pr = p->n_qual;
736 #if 0
737 if (p->n_op == STCALL || p->n_op == USTCALL)
738 pr += 4;
739 #endif
740 if (p->n_op == UCALL)
741 return; /* XXX remove ZC from UCALL */
742 if (pr > 0)
743 printf("\tadd %s,%s,#%d\n", rnames[SP], rnames[SP], pr);
744 break;
745
746 case 'D': /* Long long comparision */
747 twollcomp(p);
748 break;
749
750 case 'E': /* print out emulated ops */
751 emul(p);
752 break;
753
754 case 'F': /* print out emulated floating-point ops */
755 fpemul(p);
756 break;
757
758 case 'H': /* do halfword access */
759 halfword(p);
760 break;
761
762 case 'I': /* init constant */
763 if (p->n_name[0] != '\0')
764 comperr("named init");
765 load_constant_into_reg(DECRA(p->n_reg, 1),
766 getlval(p) & 0xffffffff);
767 break;
768
769 case 'J': /* init longlong constant */
770 load_constant_into_reg(DECRA(p->n_reg, 1) - R0R1,
771 getlval(p) & 0xffffffff);
772 load_constant_into_reg(DECRA(p->n_reg, 1) - R0R1 + 1,
773 (getlval(p) >> 32));
774 break;
775
776 case 'O': /* 64-bit left and right shift operators */
777 shiftop(p);
778 break;
779
780 case 'Q': /* emit struct assign */
781 stasg(p);
782 break;
783
784 default:
785 comperr("zzzcode %c", c);
786 }
787 }
788
789 /*ARGSUSED*/
790 int
791 rewfld(NODE *p)
792 {
793 return(1);
794 }
795
796 /*
797 * Does the bitfield shape match?
798 */
799 int
800 flshape(NODE *p)
801 {
802 int o = p->n_op;
803
804 if (o == OREG || o == REG || o == NAME)
805 return SRDIR; /* Direct match */
806 if (o == UMUL && shumul(p->n_left, SOREG))
807 return SROREG; /* Convert into oreg */
808 return SRREG; /* put it into a register */
809 }
810
811 /* INTEMP shapes must not contain any temporary registers */
812 /* XXX should this go away now? */
813 int
814 shtemp(NODE *p)
815 {
816 return 0;
817 #if 0
818 int r;
819
820 if (p->n_op == STARG )
821 p = p->n_left;
822
823 switch (p->n_op) {
824 case REG:
825 return (!istreg(p->n_rval));
826
827 case OREG:
828 r = p->n_rval;
829 if (R2TEST(r)) {
830 if (istreg(R2UPK1(r)))
831 return(0);
832 r = R2UPK2(r);
833 }
834 return (!istreg(r));
835
836 case UMUL:
837 p = p->n_left;
838 return (p->n_op != UMUL && shtemp(p));
839 }
840
841 if (optype(p->n_op) != LTYPE)
842 return(0);
843 return(1);
844 #endif
845 }
846
847 void
848 adrcon(CONSZ val)
849 {
850 printf("#" CONFMT, val);
851 }
852
853 void
854 conput(FILE *fp, NODE *p)
855 {
856 char *s;
857 int val = getlval(p);
858
859 switch (p->n_op) {
860 case ICON:
861 #if 0
862 if (p->n_sp)
863 printf(" [class=%d,level=%d] ", p->n_sp->sclass, p->n_sp->slevel);
864 #endif
865 #ifdef notdef /* ICON cannot ever use sp here */
866 /* If it does, it's a giant bug */
867 if (p->n_sp == NULL || (
868 (p->n_sp->sclass == STATIC && p->n_sp->slevel > 0)))
869 s = p->n_name;
870 else
871 s = exname(p->n_name);
872 #else
873 s = p->n_name;
874 #endif
875
876 if (*s != '\0') {
877 fprintf(fp, "%s", s);
878 if (val > 0)
879 fprintf(fp, "+%d", val);
880 else if (val < 0)
881 fprintf(fp, "-%d", -val);
882 } else
883 fprintf(fp, "#" CONFMT, (CONSZ)val);
884 return;
885
886 default:
887 comperr("illegal conput, p %p", p);
888 }
889 }
890
891 /*ARGSUSED*/
892 void
893 insput(NODE *p)
894 {
895 comperr("insput");
896 }
897
898 /*
899 * Write out the upper address, like the upper register of a 2-register
900 * reference, or the next memory location.
901 */
902 void
903 upput(NODE *p, int size)
904 {
905
906 size /= SZCHAR;
907 switch (p->n_op) {
908 case REG:
909 printf("%s", rnames[p->n_rval-R0R1+1]);
910 break;
911
912 case NAME:
913 case OREG:
914 setlval(p, getlval(p) + size);
915 adrput(stdout, p);
916 setlval(p, getlval(p) - size);
917 break;
918 case ICON:
919 printf("#" CONFMT, getlval(p) >> 32);
920 break;
921 default:
922 comperr("upput bad op %d size %d", p->n_op, size);
923 }
924 }
925
926 void
927 adrput(FILE *io, NODE *p)
928 {
929 int r;
930 /* output an address, with offsets, from p */
931
932 if (p->n_op == FLD)
933 p = p->n_left;
934
935 switch (p->n_op) {
936
937 case NAME:
938 if (p->n_name[0] != '\0') {
939 fputs(p->n_name, io);
940 if (getlval(p) != 0)
941 fprintf(io, "+%lld", getlval(p));
942 } else
943 fprintf(io, "#" CONFMT, getlval(p));
944 return;
945
946 case OREG:
947 r = p->n_rval;
948 if (R2TEST(r))
949 fprintf(io, "[%s, %s, lsl #%d]",
950 rnames[R2UPK1(r)],
951 rnames[R2UPK2(r)],
952 R2UPK3(r));
953 else
954 fprintf(io, "[%s,#%d]", rnames[p->n_rval], (int)getlval(p));
955 return;
956
957 case ICON:
958 /* addressable value of the constant */
959 conput(io, p);
960 return;
961
962 case REG:
963 switch (p->n_type) {
964 case DOUBLE:
965 case LDOUBLE:
966 if (features(FEATURE_HARDFLOAT)) {
967 fprintf(io, "%s", rnames[p->n_rval]);
968 break;
969 }
970 /* FALLTHROUGH */
971 case LONGLONG:
972 case ULONGLONG:
973 fprintf(io, "%s", rnames[p->n_rval-R0R1]);
974 break;
975 default:
976 fprintf(io, "%s", rnames[p->n_rval]);
977 }
978 return;
979
980 default:
981 comperr("illegal address, op %d, node %p", p->n_op, p);
982 return;
983
984 }
985 }
986
987 /* printf conditional and unconditional branches */
988 void
989 cbgen(int o, int lab)
990 {
991 if (o < EQ || o > UGT)
992 comperr("bad conditional branch: %s", opst[o]);
993 printf("\t%s " LABFMT COM "conditional branch\n",
994 ccbranches[o-EQ], lab);
995 }
996
997 /*
998 * The arm can only address 4k to get a NAME, so there must be some
999 * rewriting here. Strategy:
1000 * For first 1000 nodes found, print out the word directly.
1001 * For the following 1000 nodes, group them together in asm statements
1002 * and create a jump over.
1003 * For the last <1000 statements, print out the words last.
1004 */
1005 struct addrsymb {
1006 SLIST_ENTRY(addrsymb) link;
1007 char *name; /* symbol name */
1008 int num; /* symbol offset */
1009 char *str; /* replace label */
1010 };
1011 SLIST_HEAD(, addrsymb) aslist;
1012 static struct interpass *ipbase;
1013 static int prtnumber, nodcnt, notfirst;
1014 #define PRTLAB ".LY%d" /* special for here */
1015
1016 static struct interpass *
1017 anode(char *p)
1018 {
1019 extern int thisline;
1020 struct interpass *ip = tmpalloc(sizeof(struct interpass));
1021
1022 ip->ip_asm = p;
1023 ip->type = IP_ASM;
1024 ip->lineno = thisline;
1025 return ip;
1026 }
1027
1028 static void
1029 flshlab(void)
1030 {
1031 struct interpass *ip;
1032 struct addrsymb *el;
1033 int lab = prtnumber++;
1034 char *c;
1035
1036 if (SLIST_FIRST(&aslist) == NULL)
1037 return;
1038
1039 snprintf(c = tmpalloc(32), 32, "\tb " PRTLAB "\n", lab);
1040 ip = anode(c);
1041 DLIST_INSERT_BEFORE(ipbase, ip, qelem);
1042
1043 SLIST_FOREACH(el, &aslist, link) {
1044 /* insert each node as asm */
1045 int l = 32+strlen(el->name);
1046 c = tmpalloc(l);
1047 if (el->num)
1048 snprintf(c, l, "%s:\n\t.word %s+%d\n",
1049 el->str, el->name, el->num);
1050 else
1051 snprintf(c, l, "%s:\n\t.word %s\n", el->str, el->name);
1052 ip = anode(c);
1053 DLIST_INSERT_BEFORE(ipbase, ip, qelem);
1054 }
1055 /* generate asm label */
1056 snprintf(c = tmpalloc(32), 32, PRTLAB ":\n", lab);
1057 ip = anode(c);
1058 DLIST_INSERT_BEFORE(ipbase, ip, qelem);
1059 }
1060
1061 static void
1062 prtaddr(NODE *p, void *arg)
1063 {
1064 NODE *l = p->n_left;
1065 struct addrsymb *el;
1066 int found = 0;
1067 int lab;
1068
1069 nodcnt++;
1070
1071 if (p->n_op == ASSIGN && p->n_right->n_op == ICON &&
1072 p->n_right->n_name[0] != '\0') {
1073 /* named constant */
1074 p = p->n_right;
1075
1076 /* Restore addrof */
1077 l = mklnode(NAME, getlval(p), 0, 0);
1078 l->n_name = p->n_name;
1079 p->n_left = l;
1080 p->n_op = ADDROF;
1081 }
1082
1083 if (p->n_op != ADDROF || l->n_op != NAME)
1084 return;
1085
1086 /* if we passed 1k nodes printout list */
1087 if (nodcnt > 1000) {
1088 if (notfirst)
1089 flshlab();
1090 SLIST_INIT(&aslist);
1091 notfirst = 1;
1092 nodcnt = 0;
1093 }
1094
1095 /* write address to byte stream */
1096
1097 SLIST_FOREACH(el, &aslist, link) {
1098 if (el->num == getlval(l) && el->name[0] == l->n_name[0] &&
1099 strcmp(el->name, l->n_name) == 0) {
1100 found = 1;
1101 break;
1102 }
1103 }
1104
1105 if (!found) {
1106 /* we know that this is text segment */
1107 lab = prtnumber++;
1108 if (nodcnt <= 1000 && notfirst == 0) {
1109 if (getlval(l))
1110 printf(PRTLAB ":\n\t.word %s+%lld\n",
1111 lab, l->n_name, getlval(l));
1112 else
1113 printf(PRTLAB ":\n\t.word %s\n",
1114 lab, l->n_name);
1115 }
1116 el = tmpalloc(sizeof(struct addrsymb));
1117 el->num = getlval(l);
1118 el->name = l->n_name;
1119 el->str = tmpalloc(32);
1120 snprintf(el->str, 32, PRTLAB, lab);
1121 SLIST_INSERT_LAST(&aslist, el, link);
1122 }
1123
1124 nfree(l);
1125 p->n_op = NAME;
1126 setlval(p, 0);
1127 p->n_name = el->str;
1128 }
1129
1130 void
1131 myreader(struct interpass *ipole)
1132 {
1133 struct interpass *ip;
1134
1135 SLIST_INIT(&aslist);
1136 notfirst = nodcnt = 0;
1137
1138 DLIST_FOREACH(ip, ipole, qelem) {
1139 switch (ip->type) {
1140 case IP_NODE:
1141 lineno = ip->lineno;
1142 ipbase = ip;
1143 walkf(ip->ip_node, prtaddr, 0);
1144 break;
1145 case IP_EPILOG:
1146 ipbase = ip;
1147 if (notfirst)
1148 flshlab();
1149 break;
1150 default:
1151 break;
1152 }
1153 }
1154 if (x2debug)
1155 printip(ipole);
1156 }
1157
1158 /*
1159 * Remove some PCONVs after OREGs are created.
1160 */
1161 static void
1162 pconv2(NODE *p, void *arg)
1163 {
1164 NODE *q;
1165
1166 if (p->n_op == PLUS) {
1167 if (p->n_type == (PTR+SHORT) || p->n_type == (PTR+USHORT)) {
1168 if (p->n_right->n_op != ICON)
1169 return;
1170 if (p->n_left->n_op != PCONV)
1171 return;
1172 if (p->n_left->n_left->n_op != OREG)
1173 return;
1174 q = p->n_left->n_left;
1175 nfree(p->n_left);
1176 p->n_left = q;
1177 /*
1178 * This will be converted to another OREG later.
1179 */
1180 }
1181 }
1182 }
1183
1184 void
1185 mycanon(NODE *p)
1186 {
1187 walkf(p, pconv2, 0);
1188 }
1189
1190 void
1191 myoptim(struct interpass *ipp)
1192 {
1193 }
1194
1195 /*
1196 * Register move: move contents of register 's' to register 'r'.
1197 */
1198 void
1199 rmove(int s, int d, TWORD t)
1200 {
1201 switch (t) {
1202 case DOUBLE:
1203 case LDOUBLE:
1204 if (features(FEATURE_HARDFLOAT)) {
1205 printf("\tfmr %s,%s" COM "rmove\n",
1206 rnames[d], rnames[s]);
1207 break;
1208 }
1209 /* FALLTHROUGH */
1210 case LONGLONG:
1211 case ULONGLONG:
1212 #define LONGREG(x, y) rnames[(x)-(R0R1-(y))]
1213 if (s == d+1) {
1214 /* dh = sl, copy low word first */
1215 printf("\tmov %s,%s" COM "rmove\n",
1216 LONGREG(d,0), LONGREG(s,0));
1217 printf("\tmov %s,%s\n",
1218 LONGREG(d,1), LONGREG(s,1));
1219 } else {
1220 /* copy high word first */
1221 printf("\tmov %s,%s" COM "rmove\n",
1222 LONGREG(d,1), LONGREG(s,1));
1223 printf("\tmov %s,%s\n",
1224 LONGREG(d,0), LONGREG(s,0));
1225 }
1226 #undef LONGREG
1227 break;
1228 case FLOAT:
1229 if (features(FEATURE_HARDFLOAT)) {
1230 printf("\tmr %s,%s" COM "rmove\n",
1231 rnames[d], rnames[s]);
1232 break;
1233 }
1234 /* FALLTHROUGH */
1235 default:
1236 printf("\tmov %s,%s" COM "rmove\n", rnames[d], rnames[s]);
1237 }
1238 }
1239
1240 /*
1241 * Can we assign a register from class 'c', given the set
1242 * of number of assigned registers in each class 'r'.
1243 *
1244 * On ARM, we have:
1245 * 11 CLASSA registers (32-bit hard registers)
1246 * 10 CLASSB registers (64-bit composite registers)
1247 * 8 or 32 CLASSC registers (floating-point)
1248 *
1249 * There is a problem calculating the available composite registers
1250 * (ie CLASSB). The algorithm below assumes that given any two
1251 * registers, we can make a composite register. But this isn't true
1252 * here (or with other targets), since the number of combinations
1253 * of register pairs could become very large. Additionally,
1254 * having so many combinations really isn't so practical, since
1255 * most register pairs cannot be used to pass function arguments.
1256 * Consequently, when there is pressure composite registers,
1257 * "beenhere" compilation failures are common.
1258 *
1259 * [We need to know which registers are allocated, not simply
1260 * the number in each class]
1261 */
1262 int
1263 COLORMAP(int c, int *r)
1264 {
1265 int num = 0; /* number of registers used */
1266
1267 #if 0
1268 static const char classes[] = { 'X', 'A', 'B', 'C', 'D' };
1269 printf("COLORMAP: requested class %c\n", classes[c]);
1270 printf("COLORMAP: class A: %d\n", r[CLASSA]);
1271 printf("COLORMAP: class B: %d\n", r[CLASSB]);
1272 #endif
1273
1274 switch (c) {
1275 case CLASSA:
1276 num += r[CLASSA];
1277 num += 2*r[CLASSB];
1278 return num < 11;
1279 case CLASSB:
1280 num += 2*r[CLASSB];
1281 num += r[CLASSA];
1282 return num < 6; /* XXX see comments above */
1283 case CLASSC:
1284 num += r[CLASSC];
1285 if (features(FEATURE_FPA))
1286 return num < 8;
1287 else if (features(FEATURE_VFP))
1288 return num < 8;
1289 else
1290 cerror("colormap 1");
1291 }
1292 cerror("colormap 2");
1293 return 0; /* XXX gcc */
1294 }
1295
1296 /*
1297 * Return a class suitable for a specific type.
1298 */
1299 int
1300 gclass(TWORD t)
1301 {
1302 if (t == DOUBLE || t == LDOUBLE) {
1303 if (features(FEATURE_HARDFLOAT))
1304 return CLASSC;
1305 else
1306 return CLASSB;
1307 }
1308 if (t == FLOAT) {
1309 if (features(FEATURE_HARDFLOAT))
1310 return CLASSC;
1311 else
1312 return CLASSA;
1313 }
1314 if (DEUNSIGN(t) == LONGLONG)
1315 return CLASSB;
1316 return CLASSA;
1317 }
1318
1319 int
1320 retreg(int t)
1321 {
1322 int c = gclass(t);
1323 if (c == CLASSB)
1324 return R0R1;
1325 else if (c == CLASSC)
1326 return F0;
1327 return R0;
1328 }
1329
1330 /*
1331 * Calculate argument sizes.
1332 */
1333 void
1334 lastcall(NODE *p)
1335 {
1336 NODE *op = p;
1337 int size = 0;
1338
1339 p->n_qual = 0;
1340 if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
1341 return;
1342 for (p = p->n_right; p->n_op == CM; p = p->n_left)
1343 size += argsiz(p->n_right);
1344 size += argsiz(p);
1345 op->n_qual = size - 16; /* XXX */
1346 }
1347
1348 /*
1349 * Special shapes.
1350 */
1351 int
1352 special(NODE *p, int shape)
1353 {
1354 return SRNOPE;
1355 }
1356
1357 /*
1358 * default to ARMv2
1359 */
1360 #ifdef TARGET_BIG_ENDIAN
1361 #define DEFAULT_FEATURES FEATURE_BIGENDIAN | FEATURE_MUL
1362 #else
1363 #define DEFAULT_FEATURES FEATURE_MUL
1364 #endif
1365
1366 static int fset = DEFAULT_FEATURES;
1367
1368 /*
1369 * Target-dependent command-line options.
1370 */
1371 void
1372 mflags(char *str)
1373 {
1374 if (strcasecmp(str, "little-endian") == 0) {
1375 fset &= ~FEATURE_BIGENDIAN;
1376 } else if (strcasecmp(str, "big-endian") == 0) {
1377 fset |= FEATURE_BIGENDIAN;
1378 } else if (strcasecmp(str, "fpe=fpa") == 0) {
1379 fset &= ~(FEATURE_VFP | FEATURE_FPA);
1380 fset |= FEATURE_FPA;
1381 } else if (strcasecmp(str, "fpe=vfp") == 0) {
1382 fset &= ~(FEATURE_VFP | FEATURE_FPA);
1383 fset |= FEATURE_VFP;
1384 } else if (strcasecmp(str, "fpe=vfpv3-d16") == 0) {
1385 fset &= ~(FEATURE_VFP | FEATURE_FPA);
1386 fset |= FEATURE_VFP;
1387 } else if (strcasecmp(str, "soft-float") == 0) {
1388 fset &= ~(FEATURE_VFP | FEATURE_FPA);
1389 } else if (strcasecmp(str, "arch=armv1") == 0) {
1390 fset &= ~FEATURE_HALFWORDS;
1391 fset &= ~FEATURE_EXTEND;
1392 fset &= ~FEATURE_MUL;
1393 fset &= ~FEATURE_MULL;
1394 fset &= ~FEATURE_DIV;
1395 } else if (strcasecmp(str, "arch=armv2") == 0) {
1396 fset &= ~FEATURE_HALFWORDS;
1397 fset &= ~FEATURE_EXTEND;
1398 fset |= FEATURE_MUL;
1399 fset &= ~FEATURE_MULL;
1400 fset &= ~FEATURE_DIV;
1401 } else if (strcasecmp(str, "arch=armv2a") == 0) {
1402 fset &= ~FEATURE_HALFWORDS;
1403 fset &= ~FEATURE_EXTEND;
1404 fset |= FEATURE_MUL;
1405 fset &= ~FEATURE_MULL;
1406 fset &= ~FEATURE_DIV;
1407 } else if (strcasecmp(str, "arch=armv3") == 0) {
1408 fset &= ~FEATURE_HALFWORDS;
1409 fset &= ~FEATURE_EXTEND;
1410 fset |= FEATURE_MUL;
1411 fset &= ~FEATURE_MULL;
1412 fset &= ~FEATURE_DIV;
1413 } else if (strcasecmp(str, "arch=armv4") == 0) {
1414 fset |= FEATURE_HALFWORDS;
1415 fset &= ~FEATURE_EXTEND;
1416 fset |= FEATURE_MUL;
1417 fset |= FEATURE_MULL;
1418 fset &= ~FEATURE_DIV;
1419 } else if (strcasecmp(str, "arch=armv4t") == 0) {
1420 fset |= FEATURE_HALFWORDS;
1421 fset &= ~FEATURE_EXTEND;
1422 fset |= FEATURE_MUL;
1423 fset |= FEATURE_MULL;
1424 fset &= ~FEATURE_DIV;
1425 } else if (strcasecmp(str, "arch=armv4tej") == 0) {
1426 fset |= FEATURE_HALFWORDS;
1427 fset &= ~FEATURE_EXTEND;
1428 fset |= FEATURE_MUL;
1429 fset |= FEATURE_MULL;
1430 fset &= ~FEATURE_DIV;
1431 } else if (strcasecmp(str, "arch=armv5") == 0) {
1432 fset |= FEATURE_HALFWORDS;
1433 fset &= ~FEATURE_EXTEND;
1434 fset |= FEATURE_MUL;
1435 fset |= FEATURE_MULL;
1436 fset &= ~FEATURE_DIV;
1437 } else if (strcasecmp(str, "arch=armv5te") == 0) {
1438 fset |= FEATURE_HALFWORDS;
1439 fset &= ~FEATURE_EXTEND;
1440 fset |= FEATURE_MUL;
1441 fset |= FEATURE_MULL;
1442 fset &= ~FEATURE_DIV;
1443 } else if (strcasecmp(str, "arch=armv5tej") == 0) {
1444 fset |= FEATURE_HALFWORDS;
1445 fset &= ~FEATURE_EXTEND;
1446 fset |= FEATURE_MUL;
1447 fset |= FEATURE_MULL;
1448 fset &= ~FEATURE_DIV;
1449 } else if (strcasecmp(str, "arch=armv6") == 0) {
1450 fset |= FEATURE_HALFWORDS;
1451 fset |= FEATURE_EXTEND;
1452 fset |= FEATURE_MUL;
1453 fset |= FEATURE_MULL;
1454 fset &= ~FEATURE_DIV;
1455 } else if (strcasecmp(str, "arch=armv6t2") == 0) {
1456 fset |= FEATURE_HALFWORDS;
1457 fset |= FEATURE_EXTEND;
1458 fset |= FEATURE_MUL;
1459 fset |= FEATURE_MULL;
1460 fset &= ~FEATURE_DIV;
1461 } else if (strcasecmp(str, "arch=armv6kz") == 0) {
1462 fset |= FEATURE_HALFWORDS;
1463 fset |= FEATURE_EXTEND;
1464 fset |= FEATURE_MUL;
1465 fset |= FEATURE_MULL;
1466 fset &= ~FEATURE_DIV;
1467 } else if (strcasecmp(str, "arch=armv6k") == 0) {
1468 fset |= FEATURE_HALFWORDS;
1469 fset |= FEATURE_EXTEND;
1470 fset |= FEATURE_MUL;
1471 fset |= FEATURE_MULL;
1472 fset &= ~FEATURE_DIV;
1473 } else if (strcasecmp(str, "arch=armv7") == 0) {
1474 fset |= FEATURE_HALFWORDS;
1475 fset |= FEATURE_EXTEND;
1476 fset |= FEATURE_MUL;
1477 fset |= FEATURE_MULL;
1478 fset |= FEATURE_DIV;
1479 } else if (strcasecmp(str, "arch=armv7-m") == 0 || strcasecmp(str, "arch=armv7e-m") == 0) {
1480 fset |= FEATURE_HALFWORDS;
1481 fset |= FEATURE_EXTEND;
1482 fset |= FEATURE_MUL;
1483 fset |= FEATURE_MULL;
1484 fset |= FEATURE_DIV;
1485 } else if (strcasecmp(str, "arch=armv7-a") == 0) {
1486 fset |= FEATURE_HALFWORDS;
1487 fset |= FEATURE_EXTEND;
1488 fset |= FEATURE_MUL;
1489 fset |= FEATURE_MULL;
1490 fset &= ~FEATURE_DIV;
1491 } else {
1492 fprintf(stderr, "unknown m option '%s'\n", str);
1493 exit(1);
1494 }
1495 }
1496
1497 int
1498 features(int mask)
1499 {
1500 if (mask == FEATURE_HARDFLOAT)
1501 return ((fset & mask) != 0);
1502 return ((fset & mask) == mask);
1503 }
1504
1505 /*
1506 * Define the current location as an internal label.
1507 */
1508 void
1509 deflab(int label)
1510 {
1511 printf(LABFMT ":\n", label);
1512 }
1513
1514 /*
1515 * Do something target-dependent for xasm arguments.
1516 * Supposed to find target-specific constraints and rewrite them.
1517 */
1518 int
1519 myxasm(struct interpass *ip, NODE *p)
1520 {
1521 return 0;
1522 }