2 * ARMv4 code generator for TCC
4 * Copyright (c) 2003 Daniel Glöckner
6 * Based on i386-gen.c by Fabrice Bellard
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 /* number of available registers */
26 /* a register can belong to several classes. The classes must be
27 sorted from more general to more precise (see gv2() code which does
28 assumptions on it). */
29 #define RC_INT 0x0001 /* generic integer register */
30 #define RC_FLOAT 0x0002 /* generic float register */
40 #define RC_IRET RC_R0 /* function return: integer register */
41 #define RC_LRET RC_R1 /* function return: second integer register */
42 #define RC_FRET RC_F0 /* function return: float register */
44 /* pretty names for the registers */
57 int reg_classes
[NB_REGS
] = {
58 /* r0 */ RC_INT
| RC_R0
,
59 /* r1 */ RC_INT
| RC_R1
,
60 /* r2 */ RC_INT
| RC_R2
,
61 /* r3 */ RC_INT
| RC_R3
,
62 /* r12 */ RC_INT
| RC_R12
,
63 /* f0 */ RC_FLOAT
| RC_F0
,
64 /* f1 */ RC_FLOAT
| RC_F1
,
65 /* f2 */ RC_FLOAT
| RC_F2
,
66 /* f3 */ RC_FLOAT
| RC_F3
,
69 static int two2mask(int a
,int b
) {
70 return (reg_classes
[a
]|reg_classes
[b
])&~(RC_INT
|RC_FLOAT
);
73 static int regmask(int r
) {
74 return reg_classes
[r
]&~(RC_INT
|RC_FLOAT
);
77 /* return registers for function */
78 #define REG_IRET TREG_R0 /* single word int return register */
79 #define REG_LRET TREG_R1 /* second word return register (for long long) */
80 #define REG_FRET TREG_F0 /* float return register */
82 /* defined if function parameters must be evaluated in reverse order */
83 #define INVERT_FUNC_PARAMS
85 /* defined if structures are passed as pointers. Otherwise structures
86 are directly pushed on stack. */
87 //#define FUNC_STRUCT_PARAM_AS_PTR
89 /* pointer size, in bytes */
92 /* long double size and alignment, in bytes */
93 #define LDOUBLE_SIZE 8
94 #define LDOUBLE_ALIGN 4
95 /* maximum alignment (for aligned attribute support) */
98 #define CHAR_IS_UNSIGNED
100 /******************************************************/
103 #define EM_TCC_TARGET EM_ARM
105 /* relocation type for 32 bit data relocation */
106 #define R_DATA_32 R_ARM_ABS32
107 #define R_JMP_SLOT R_ARM_JUMP_SLOT
108 #define R_COPY R_ARM_COPY
110 #define ELF_START_ADDR 0x00008000
111 #define ELF_PAGE_SIZE 0x1000
113 /******************************************************/
114 static unsigned long func_sub_sp_offset
,last_itod_magic
;
116 void o(unsigned long i
)
118 /* this is a good place to start adding big-endian support*/
122 if (!cur_text_section
)
123 error("compiler error! This happens f.ex. if the compiler\n"
124 "can't evaluate constant expressions outside of a function.");
125 if (ind1
> cur_text_section
->data_allocated
)
126 section_realloc(cur_text_section
, ind1
);
127 cur_text_section
->data
[ind
++] = i
&255;
129 cur_text_section
->data
[ind
++] = i
&255;
131 cur_text_section
->data
[ind
++] = i
&255;
133 cur_text_section
->data
[ind
++] = i
;
136 static unsigned long stuff_const(unsigned long op
,unsigned long c
)
139 unsigned long nc
,negop
;
148 case 0x1A00000: //mov
149 case 0x1E00000: //mvn
156 return (op
&0xF010F000)|((op
>>16)&0xF)|0x1E00000;
160 return (op
&0xF010F000)|((op
>>16)&0xF)|0x1A00000;
161 case 0x1C00000: //bic
166 case 0x1800000: //orr
168 return (op
&0xFFF0FFFF)|0x1E00000;
174 if(c
<256) /* catch undefined <<32 */
177 m
=(0xff>>i
)|(0xff<<(32-i
));
179 return op
|(i
<<7)|(c
<<i
)|(c
>>(32-i
));
189 void stuff_const_harder(unsigned long op
,unsigned long v
) {
195 unsigned long a
[16],nv
,no
,o2
,n2
;
198 o2
=(op
&0xfff0ffff)|((op
&0xf000)<<4);;
200 a
[i
]=(a
[i
-1]>>2)|(a
[i
-1]<<30);
202 for(j
=i
+4;i
<13+i
;i
++)
203 if((v
&(a
[i
]|a
[j
]))==v
) {
204 o(stuff_const(op
,v
&a
[i
]));
205 o(stuff_const(o2
,v
&a
[j
]));
212 for(j
=i
+4;i
<13+i
;i
++)
213 if((nv
&(a
[i
]|a
[j
]))==nv
) {
214 o(stuff_const(no
,nv
&a
[i
]));
215 o(stuff_const(n2
,nv
&a
[j
]));
220 for(k
=j
+4;k
<13+i
;i
++)
221 if((v
&(a
[i
]|a
[j
]|a
[k
]))==v
) {
222 o(stuff_const(op
,v
&a
[i
]));
223 o(stuff_const(o2
,v
&a
[j
]));
224 o(stuff_const(o2
,v
&a
[k
]));
231 for(k
=j
+4;k
<13+i
;i
++)
232 if((nv
&(a
[i
]|a
[j
]|a
[k
]))==nv
) {
233 o(stuff_const(no
,nv
&a
[i
]));
234 o(stuff_const(n2
,nv
&a
[j
]));
235 o(stuff_const(n2
,nv
&a
[k
]));
238 o(stuff_const(op
,v
&a
[0]));
239 o(stuff_const(o2
,v
&a
[4]));
240 o(stuff_const(o2
,v
&a
[8]));
241 o(stuff_const(o2
,v
&a
[12]));
245 unsigned long encbranch(int pos
,int addr
,int fail
)
249 if(addr
>=0x1000000 || addr
<-0x1000000) {
251 error("FIXME: function bigger than 32MB");
254 return 0x0A000000|(addr
&0xffffff);
257 int decbranch(int pos
)
260 x
=*(int *)(cur_text_section
->data
+ pos
);
267 /* output a symbol and patch all calls to it */
268 void gsym_addr(int t
, int a
)
273 x
=(unsigned long *)(cur_text_section
->data
+ t
);
276 *x
=0xE1A00000; // nop
279 *x
|= encbranch(lt
,a
,1);
289 static unsigned long fpr(int r
)
291 if(r
<TREG_F0
|| r
>TREG_F3
)
292 error("compiler error! register %i is no fp register\n",r
);
296 static unsigned long intr(int r
)
300 if((r
<0 || r
>4) && r
!=14)
301 error("compiler error! register %i is no int register\n",r
);
305 static void calcaddr(unsigned long *base
,int *off
,int *sgn
,int maxoff
,unsigned shift
)
307 if(*off
>maxoff
|| *off
&((1<<shift
)-1)) {
314 y
=stuff_const(x
,*off
&~maxoff
);
320 y
=stuff_const(x
,(*off
+maxoff
)&~maxoff
);
324 *off
=((*off
+maxoff
)&~maxoff
)-*off
;
327 stuff_const_harder(x
,*off
&~maxoff
);
332 static unsigned long mapcc(int cc
)
357 error("unexpected condition code");
361 static int negcc(int cc
)
386 error("unexpected condition code");
390 /* load 'r' from value 'sv' */
391 void load(int r
, SValue
*sv
)
393 int v
, ft
, fc
, fr
, sign
;
410 unsigned long base
=0xB; // fp
413 v1
.r
= VT_LOCAL
| VT_LVAL
;
415 load(base
=14 /* lr */, &v1
);
418 } else if(v
== VT_CONST
) {
426 } else if(v
< VT_CONST
) {
433 calcaddr(&base
,&fc
,&sign
,1020,2);
437 #if LDOUBLE_SIZE == 8
438 if ((ft
& VT_BTYPE
) != VT_FLOAT
)
441 if ((ft
& VT_BTYPE
) == VT_DOUBLE
)
443 else if ((ft
& VT_BTYPE
) == VT_LDOUBLE
)
446 o(op
|(fpr(r
)<<12)|(fc
>>2)|(base
<<16));
447 } else if((ft
& VT_TYPE
) == VT_BYTE
|| (ft
& VT_BTYPE
) == VT_SHORT
) {
448 calcaddr(&base
,&fc
,&sign
,255,0);
450 if ((ft
& VT_BTYPE
) == VT_SHORT
)
452 if ((ft
& VT_UNSIGNED
) == 0)
456 o(op
|(intr(r
)<<12)|(base
<<16)|((fc
&0xf0)<<4)|(fc
&0xf));
458 calcaddr(&base
,&fc
,&sign
,4095,0);
462 if ((ft
& VT_BTYPE
) == VT_BYTE
)
464 o(op
|(intr(r
)<<12)|fc
|(base
<<16));
470 op
=stuff_const(0xE3A00000|(intr(r
)<<12),sv
->c
.ul
);
471 if (fr
& VT_SYM
|| !op
) {
472 o(0xE59F0000|(intr(r
)<<12));
475 greloc(cur_text_section
, sv
->sym
, ind
, R_ARM_ABS32
);
480 } else if (v
== VT_LOCAL
) {
481 op
=stuff_const(0xE28B0000|(intr(r
)<<12),sv
->c
.ul
);
482 if (fr
& VT_SYM
|| !op
) {
483 o(0xE59F0000|(intr(r
)<<12));
485 if(fr
& VT_SYM
) // needed ?
486 greloc(cur_text_section
, sv
->sym
, ind
, R_ARM_ABS32
);
488 o(0xE08B0000|(intr(r
)<<12)|intr(r
));
492 } else if(v
== VT_CMP
) {
493 o(mapcc(sv
->c
.ul
)|0x3A00001|(intr(r
)<<12));
494 o(mapcc(negcc(sv
->c
.ul
))|0x3A00000|(intr(r
)<<12));
496 } else if (v
== VT_JMP
|| v
== VT_JMPI
) {
499 o(0xE3A00000|(intr(r
)<<12)|t
);
502 o(0xE3A00000|(intr(r
)<<12)|(t
^1));
504 } else if (v
< VT_CONST
) {
506 o(0xEE008180|(fpr(r
)<<12)|fpr(v
));
508 o(0xE1A00000|(intr(r
)<<12)|intr(v
));
512 error("load unimplemented!");
515 /* store register 'r' in lvalue 'v' */
516 void store(int r
, SValue
*sv
)
519 int v
, ft
, fc
, fr
, sign
;
534 if (fr
& VT_LVAL
|| fr
== VT_LOCAL
) {
535 unsigned long base
=0xb;
540 } else if(v
== VT_CONST
) {
551 calcaddr(&base
,&fc
,&sign
,1020,2);
555 #if LDOUBLE_SIZE == 8
556 if ((ft
& VT_BTYPE
) != VT_FLOAT
)
559 if ((ft
& VT_BTYPE
) == VT_DOUBLE
)
561 if ((ft
& VT_BTYPE
) == VT_LDOUBLE
)
564 o(op
|(fpr(r
)<<12)|(fc
>>2)|(base
<<16));
566 } else if((ft
& VT_BTYPE
) == VT_SHORT
) {
567 calcaddr(&base
,&fc
,&sign
,255,0);
571 o(op
|(intr(r
)<<12)|(base
<<16)|((fc
&0xf0)<<4)|(fc
&0xf));
573 calcaddr(&base
,&fc
,&sign
,4095,0);
577 if ((ft
& VT_BTYPE
) == VT_BYTE
)
579 o(op
|(intr(r
)<<12)|fc
|(base
<<16));
584 error("store unimplemented");
587 static void gadd_sp(int val
)
589 stuff_const_harder(0xE28DD000,val
);
592 /* 'is_jmp' is '1' if it is a jump */
593 static void gcall_or_jmp(int is_jmp
)
596 if ((vtop
->r
& (VT_VALMASK
| VT_LVAL
)) == VT_CONST
) {
599 x
=encbranch(ind
,ind
+vtop
->c
.ul
,0);
601 if (vtop
->r
& VT_SYM
) {
602 /* relocation case */
603 greloc(cur_text_section
, vtop
->sym
, ind
, R_ARM_PC24
);
605 put_elf_reloc(symtab_section
, cur_text_section
, ind
, R_ARM_PC24
, 0);
606 o(x
|(is_jmp
?0xE0000000:0xE1000000));
609 o(0xE28FE004); // add lr,pc,#4
610 o(0xE51FF004); // ldr pc,[pc,#-4]
611 if (vtop
->r
& VT_SYM
)
612 greloc(cur_text_section
, vtop
->sym
, ind
, R_ARM_ABS32
);
616 /* otherwise, indirect call */
619 o(0xE1A0E00F); // mov lr,pc
620 o(0xE1A0F000|intr(r
)); // mov pc,r
624 /* Generate function call. The function address is pushed first, then
625 all the parameters in call order. This functions pops all the
626 parameters and the function address. */
627 void gfunc_call(int nb_args
)
629 int size
, align
, r
, args_size
, i
;
631 signed char plan
[4][2]={{-1,-1},{-1,-1},{-1,-1},{-1,-1}};
632 int todo
=0xf, keep
, plan2
[4]={0,0,0,0};
634 r
= vtop
->r
& VT_VALMASK
;
635 if (r
== VT_CMP
|| (r
& ~1) == VT_JMP
)
638 for(i
= nb_args
; i
-- && args_size
< 16 ;) {
639 if ((vtop
[-i
].type
.t
& VT_BTYPE
) == VT_STRUCT
) {
640 size
= type_size(&vtop
[-i
].type
, &align
);
641 size
= (size
+ 3) & ~3;
643 } else if ((vtop
[-i
].type
.t
& VT_BTYPE
) == VT_FLOAT
)
645 else if ((vtop
[-i
].type
.t
& VT_BTYPE
) == VT_DOUBLE
)
647 else if ((vtop
[-i
].type
.t
& VT_BTYPE
) == VT_LDOUBLE
)
648 args_size
+= LDOUBLE_SIZE
;
650 plan
[nb_args
-1-i
][0]=args_size
/4;
652 if ((vtop
[-i
].type
.t
& VT_BTYPE
) == VT_LLONG
&& args_size
< 16) {
653 plan
[nb_args
-1-i
][1]=args_size
/4;
658 args_size
= keep
= 0;
659 for(i
= 0;i
< nb_args
; i
++) {
661 if ((vtop
->type
.t
& VT_BTYPE
) == VT_STRUCT
) {
662 size
= type_size(&vtop
->type
, &align
);
663 /* align to stack align size */
664 size
= (size
+ 3) & ~3;
665 /* allocate the necessary size on stack */
667 /* generate structure store */
669 o(0xE1A0000D|(intr(r
)<<12));
670 vset(&vtop
->type
, r
| VT_LVAL
, 0);
675 } else if (is_float(vtop
->type
.t
)) {
676 r
=fpr(gv(RC_FLOAT
))<<12;
677 if ((vtop
->type
.t
& VT_BTYPE
) == VT_FLOAT
)
679 else if ((vtop
->type
.t
& VT_BTYPE
) == VT_DOUBLE
)
689 o(0xED2D0100|r
|(size
>>2));
694 /* simple type (currently always same size) */
695 /* XXX: implicit cast ? */
697 if ((vtop
->type
.t
& VT_BTYPE
) == VT_LLONG
) {
700 if(nb_args
-i
<5 && plan
[nb_args
-i
-1][1]!=-1) {
701 s
=regmask(plan
[nb_args
-i
-1][1]);
702 todo
&=~(1<<plan
[nb_args
-i
-1][1]);
706 o(0xE52D0004|(intr(r
)<<12)); /* str r,[sp,#-4]! */
716 if(nb_args
-i
<5 && plan
[nb_args
-i
-1][0]!=-1) {
717 s
=regmask(plan
[nb_args
-i
-1][0]);
718 todo
&=~(1<<plan
[nb_args
-i
-1][0]);
722 o(0xE52D0004|(intr(r
)<<12)); /* str r,[sp,#-4]! */
735 save_regs(keep
); /* save used temporary registers */
756 func_sym
= vtop
->type
.ref
;
763 /* generate function prolog of type 't' */
764 void gfunc_prolog(CType
*func_type
)
767 int n
,addr
,size
,align
;
769 sym
= func_type
->ref
;
774 if((func_vt
.t
& VT_BTYPE
) == VT_STRUCT
) {
779 for(sym2
=sym
->next
;sym2
&& n
<4;sym2
=sym2
->next
) {
780 size
= type_size(&sym2
->type
, &align
);
781 size
= (size
+ 3) & ~3;
784 o(0xE1A0C00D); /* mov ip,sp */
785 if(func_type
->ref
->c
== FUNC_ELLIPSIS
)
790 o(0xE92D0000|((1<<n
)-1)); /* save r0-r4 on stack if needed */
792 o(0xE92D5800); /* save fp, ip, lr*/
793 o(0xE1A0B00D); /* mov fp,sp */
794 func_sub_sp_offset
= ind
;
795 o(0xE1A00000); /* nop, leave space for stack adjustment */
796 while ((sym
= sym
->next
)) {
799 sym_push(sym
->v
& ~SYM_FIELD
, type
, VT_LOCAL
| VT_LVAL
, addr
);
800 size
= type_size(type
, &align
);
801 size
= (size
+ 3) & ~3;
808 /* generate function epilog */
809 void gfunc_epilog(void)
812 o(0xE89BA800); /* restore fp, sp, pc */
814 x
=stuff_const(0xE24DD000, (-loc
+ 3) & -4); /* sub sp,sp,# */
816 *(unsigned long *)(cur_text_section
->data
+ func_sub_sp_offset
) = x
;
820 o(0xE59FC004); /* ldr ip,[pc+4] */
821 o(0xE04DD00C); /* sub sp,sp,ip */
822 o(0xE1A0F00E); /* mov pc,lr */
824 *(unsigned long *)(cur_text_section
->data
+ func_sub_sp_offset
) = 0xE1000000|encbranch(func_sub_sp_offset
,addr
,1);
829 /* generate a jump to a label */
834 o(0xE0000000|encbranch(r
,t
,1));
838 /* generate a jump to a fixed address */
839 void gjmp_addr(int a
)
844 /* generate a test. set 'inv' to invert test. Stack entry is popped */
845 int gtst(int inv
, int t
)
849 v
= vtop
->r
& VT_VALMASK
;
852 op
=mapcc(inv
?negcc(vtop
->c
.i
):vtop
->c
.i
);
853 op
|=encbranch(r
,t
,1);
856 } else if (v
== VT_JMP
|| v
== VT_JMPI
) {
857 if ((v
& 1) == inv
) {
868 x
= (unsigned long *)(cur_text_section
->data
+ lp
);
870 *x
|= encbranch(lp
,t
,1);
879 if (is_float(vtop
->type
.t
)) {
881 o(0xEE90F118|fpr(r
)<<16);
885 } else if ((vtop
->r
& (VT_VALMASK
| VT_LVAL
| VT_SYM
)) == VT_CONST
) {
886 /* constant jmp optimization */
887 if ((vtop
->c
.i
!= 0) != inv
)
891 o(0xE3300000|(intr(v
)<<16));
901 /* generate an integer binary operation */
905 unsigned long opc
,r
,fr
;
913 case TOK_ADDC1
: /* add with carry generation */
921 case TOK_SUBC1
: /* sub with carry generation */
925 case TOK_ADDC2
: /* add with carry use */
929 case TOK_SUBC2
: /* sub with carry use */
950 o(0xE0000090|(intr(r
)<<16)|(intr(r
)<<8)|intr(fr
));
983 r
=intr(vtop
[-1].r2
=get_reg(RC_INT
));
985 vtop
[-1].r
=get_reg_ex(RC_INT
,regmask(c
));
987 o(0xE0800090|(r
<<16)|(intr(vtop
->r
)<<12)|(intr(c
)<<8)|intr(vtop
[1].r
));
995 if((vtop
[-1].r
& (VT_VALMASK
| VT_LVAL
| VT_SYM
)) == VT_CONST
) {
996 if(opc
== 4 || opc
== 5 || opc
== 0xc) {
998 opc
|=2; // sub -> rsb
1001 if ((vtop
->r
& VT_VALMASK
) == VT_CMP
||
1002 (vtop
->r
& (VT_VALMASK
& ~1)) == VT_JMP
)
1007 opc
=0xE0000000|(opc
<<20)|(c
<<16);
1008 if((vtop
->r
& (VT_VALMASK
| VT_LVAL
| VT_SYM
)) == VT_CONST
) {
1010 x
=stuff_const(opc
|0x2000000,vtop
->c
.i
);
1012 r
=intr(vtop
[-1].r
=get_reg_ex(RC_INT
,regmask(vtop
[-1].r
)));
1017 fr
=intr(gv(RC_INT
));
1018 r
=intr(vtop
[-1].r
=get_reg_ex(RC_INT
,two2mask(vtop
->r
,vtop
[-1].r
)));
1022 if (op
>= TOK_ULT
&& op
<= TOK_GT
) {
1028 opc
=0xE1A00000|(opc
<<5);
1029 if ((vtop
->r
& VT_VALMASK
) == VT_CMP
||
1030 (vtop
->r
& (VT_VALMASK
& ~1)) == VT_JMP
)
1036 if ((vtop
->r
& (VT_VALMASK
| VT_LVAL
| VT_SYM
)) == VT_CONST
) {
1037 fr
=intr(vtop
[-1].r
=get_reg_ex(RC_INT
,regmask(vtop
[-1].r
)));
1038 c
= vtop
->c
.i
& 0x1f;
1039 o(opc
|(c
<<7)|(fr
<<12));
1041 fr
=intr(gv(RC_INT
));
1042 c
=intr(vtop
[-1].r
=get_reg_ex(RC_INT
,two2mask(vtop
->r
,vtop
[-1].r
)));
1043 o(opc
|(c
<<12)|(fr
<<8)|0x10);
1048 vpush_global_sym(&func_old_type
, func
);
1055 error("gen_opi %i unimplemented!",op
);
1059 static int is_fconst()
1063 if((vtop
->r
& (VT_VALMASK
| VT_LVAL
| VT_SYM
)) != VT_CONST
)
1065 if (vtop
->type
.t
== VT_FLOAT
)
1067 else if (vtop
->type
.t
== VT_DOUBLE
)
1097 /* generate a floating point operation 'v = t1 op t2' instruction. The
1098 two operands are guaranted to have the same floating point type */
1099 void gen_opf(int op
)
1103 //fputs("gen_opf\n",stderr);
1109 #if LDOUBLE_SIZE == 8
1110 if ((vtop
->type
.t
& VT_BTYPE
) != VT_FLOAT
)
1113 if ((vtop
->type
.t
& VT_BTYPE
) == VT_DOUBLE
)
1115 else if ((vtop
->type
.t
& VT_BTYPE
) == VT_LDOUBLE
)
1126 r
=fpr(gv(RC_FLOAT
));
1133 r2
=fpr(gv(RC_FLOAT
));
1142 r
=fpr(gv(RC_FLOAT
));
1144 } else if(c1
&& c1
<=0xf) {
1147 r
=fpr(gv(RC_FLOAT
));
1152 r
=fpr(gv(RC_FLOAT
));
1154 r2
=fpr(gv(RC_FLOAT
));
1163 r
=fpr(gv(RC_FLOAT
));
1168 r2
=fpr(gv(RC_FLOAT
));
1176 r
=fpr(gv(RC_FLOAT
));
1178 } else if(c1
&& c1
<=0xf) {
1181 r
=fpr(gv(RC_FLOAT
));
1186 r
=fpr(gv(RC_FLOAT
));
1188 r2
=fpr(gv(RC_FLOAT
));
1192 if(op
>= TOK_ULT
&& op
<= TOK_GT
) {
1193 x
|=0xd0f110; // cmfe
1199 fputs("unsigned comparision on floats?\n",stderr
);
1215 x
&=~0x400000; // cmfe -> cmf
1236 // bug (intention?) in Linux FPU emulator
1237 // doesn't set carry if equal
1240 else if(op
==TOK_UGE
)
1243 r
=fpr(gv(RC_FLOAT
));
1250 r2
=fpr(gv(RC_FLOAT
));
1252 vtop
[-1].r
= VT_CMP
;
1255 error("unknown fp op %x!\n",op
);
1259 if(vtop
[-1].r
== VT_CMP
)
1265 vtop
[-1].r
=get_reg_ex(RC_FLOAT
,two2mask(vtop
[-1].r
,c1
));
1269 o(x
|(r
<<16)|(c1
<<12)|r2
);
1272 /* convert integers to fp 't' type. Must handle 'int', 'unsigned int'
1273 and 'long long' cases. */
1274 void gen_cvt_itof(int t
)
1277 bt
=vtop
->type
.t
& VT_BTYPE
;
1278 if(bt
== VT_INT
|| bt
== VT_SHORT
|| bt
== VT_BYTE
) {
1280 r2
=fpr(vtop
->r
=get_reg(RC_FLOAT
));
1281 o(0xEE000190|(r2
<<16)|(r
<<12));
1282 if((vtop
->type
.t
& (VT_UNSIGNED
|VT_BTYPE
)) == (VT_UNSIGNED
|VT_INT
)) {
1284 o(0xE3500000|(r
<<12));
1285 r
=fpr(get_reg(RC_FLOAT
));
1286 if(last_itod_magic
) {
1287 off
=ind
+8-last_itod_magic
;
1292 o(0xBD1F8100|(r
<<12)|off
);
1295 last_itod_magic
=ind
;
1299 o(0xBE000180|(r2
<<16)|(r2
<<12)|r
);
1302 } else if(bt
== VT_LLONG
) {
1304 if(vtop
->type
.t
& VT_UNSIGNED
)
1308 vpush_global_sym(&func_old_type
, func
);
1315 error("unimplemented gen_cvt_itof %x!",vtop
->type
.t
);
1318 /* convert fp to int 't' type */
1319 void gen_cvt_ftoi(int t
)
1324 r2
=vtop
->type
.t
& VT_BTYPE
;
1328 func
=TOK___fixunssfsi
;
1329 else if(r2
== VT_DOUBLE
)
1330 func
=TOK___fixunsdfsi
;
1331 else if(r2
== VT_LDOUBLE
)
1332 #if LDOUBLE_SIZE == 8
1333 func
=TOK___fixunsdfsi
;
1335 func
=TOK___fixunsxfsi
;
1338 r
=fpr(gv(RC_FLOAT
));
1339 r2
=intr(vtop
->r
=get_reg(RC_INT
));
1340 o(0xEE100170|(r2
<<12)|r
);
1343 } else if(t
== VT_LLONG
) { // unsigned handled in gen_cvt_ftoi1
1346 else if(r2
== VT_DOUBLE
)
1348 else if(r2
== VT_LDOUBLE
)
1349 #if LDOUBLE_SIZE == 8
1356 vpush_global_sym(&func_old_type
, func
);
1361 vtop
->r2
= REG_LRET
;
1365 error("unimplemented gen_cvt_ftoi!");
1368 /* convert from one floating point type to another */
1369 void gen_cvt_ftof(int t
)
1371 /* all we have to do on i386 and ARM is to put the float in a register */
1375 /* computed goto support */
1382 /* end of ARM code generator */
1383 /*************************************************************/