comparison mc-code-i64.c @ 931:2ed46e515c55

linux 64 ptr cache
author kono
date Sun, 13 Apr 2014 17:46:30 +0900
parents 96c53f76b360
children da35b4de1f9f
comparison
equal deleted inserted replaced
930:e4b2a7cce237 931:2ed46e515c55
529 #define __DEC128_MANT_DIG__ 34\n\ 529 #define __DEC128_MANT_DIG__ 34\n\
530 #define __LDBL_MIN_10_EXP__ (-4931)\n\ 530 #define __LDBL_MIN_10_EXP__ (-4931)\n\
531 #define __SIZEOF_LONG_LONG__ 8\n\ 531 #define __SIZEOF_LONG_LONG__ 8\n\
532 #define __LDBL_DIG__ 18\n\ 532 #define __LDBL_DIG__ 18\n\
533 #define __GNUC_GNU_INLINE__ 1\n\ 533 #define __GNUC_GNU_INLINE__ 1\n\
534 <<<<<<< local
535 #define __extension__\n\ 534 #define __extension__\n\
536 =======
537 #define __extension__ \n\
538 >>>>>>> other
539 " 535 "
540 #endif 536 #endif
541 // extension is certainly wrong 537 // extension is certainly wrong
542 538
543 539
1118 if (is_pointer_reg(ireg)) { 1114 if (is_pointer_reg(ireg)) {
1119 free_register(ireg); 1115 free_register(ireg);
1120 ireg = 0; 1116 ireg = 0;
1121 } 1117 }
1122 i = reg==USING_REG?creg:reg; 1118 i = reg==USING_REG?creg:reg;
1123 #ifdef __APPLE__
1124 if (regs[i]==PTRC_REG) clear_ptr_cache_reg(i); 1119 if (regs[i]==PTRC_REG) clear_ptr_cache_reg(i);
1125 #endif
1126 if (!i||!ireg||!is_data_reg(i)) { 1120 if (!i||!ireg||!is_data_reg(i)) {
1127 if (!ireg) { 1121 if (!ireg) {
1128 ireg = get_data_register(); 1122 ireg = get_data_register();
1129 } 1123 }
1130 i = ireg; 1124 i = ireg;
1164 static void 1158 static void
1165 set_ireg(int reg,int mode) 1159 set_ireg(int reg,int mode)
1166 { 1160 {
1167 if (!is_int_reg(reg)) error(-1); 1161 if (!is_int_reg(reg)) error(-1);
1168 if (reg!=creg) { 1162 if (reg!=creg) {
1169 #ifdef __APPLE__
1170 if (regs[reg]==PTRC_REG) 1163 if (regs[reg]==PTRC_REG)
1171 clear_ptr_cache_reg(reg); 1164 clear_ptr_cache_reg(reg);
1172 #endif
1173 if (ireg && reg!=ireg ) { 1165 if (ireg && reg!=ireg ) {
1174 clear_ptr_cache_reg(ireg); 1166 clear_ptr_cache_reg(ireg);
1175 if (regs[ireg]!=REG_VAR) free_register(ireg); 1167 if (regs[ireg]!=REG_VAR) free_register(ireg);
1176 if (mode) { 1168 if (mode) {
1177 printf("\tmovq %s,%s\n",reg_name_q[ireg],reg_name_q[reg]); 1169 printf("\tmovq %s,%s\n",reg_name_q[ireg],reg_name_q[reg]);
1236 extern void 1228 extern void
1237 emit_reinit() 1229 emit_reinit()
1238 { 1230 {
1239 /* called for each file */ 1231 /* called for each file */
1240 output_mode = -1; 1232 output_mode = -1;
1241 #ifdef __APPLE__
1242 init_ptr_cache(); 1233 init_ptr_cache();
1243 #endif
1244 } 1234 }
1245 1235
1246 1236
1247 char * 1237 char *
1248 register_name(int i,int byte) 1238 register_name(int i,int byte)
1284 regs_line[i]=glineno; 1274 regs_line[i]=glineno;
1285 regs[i]=1; /* そのレジスタを使うことを宣言し */ 1275 regs[i]=1; /* そのレジスタを使うことを宣言し */
1286 return i; /* その場所を表す番号を返す */ 1276 return i; /* その場所を表す番号を返す */
1287 } 1277 }
1288 } 1278 }
1289 #ifdef __APPLE__
1290 /* PTR_CACHE をつぶす */ 1279 /* PTR_CACHE をつぶす */
1291 if ((i=last_ptr_cache())) { 1280 if ((i=last_ptr_cache())) {
1292 clear_ptr_cache_reg(i); 1281 clear_ptr_cache_reg(i);
1293 regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ 1282 regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */
1294 regs_line[i]=glineno; 1283 regs_line[i]=glineno;
1295 return i; /* その場所を表す番号を返す */ 1284 return i; /* その場所を表す番号を返す */
1296 } 1285 }
1297 #endif
1298 /* search register stack */ 1286 /* search register stack */
1299 for(i=0;i<reg_sp;i++) { 1287 for(i=0;i<reg_sp;i++) {
1300 if ((reg=reg_stack[i])>=0) { 1288 if ((reg=reg_stack[i])>=0) {
1301 code_assign_lvar( 1289 code_assign_lvar(
1302 (j=new_lvar(SIZE_OF_LONGLONG)),reg,0); 1290 (j=new_lvar(SIZE_OF_LONGLONG)),reg,0);
1318 regs[i]=1; /* そのレジスタを使うことを宣言し */ 1306 regs[i]=1; /* そのレジスタを使うことを宣言し */
1319 regs_line[i]=glineno; 1307 regs_line[i]=glineno;
1320 return i; /* その場所を表す番号を返す */ 1308 return i; /* その場所を表す番号を返す */
1321 } 1309 }
1322 } 1310 }
1323 #ifdef __APPLE__
1324 /* PTR_CACHE をつぶす */ 1311 /* PTR_CACHE をつぶす */
1325 while ((i=last_ptr_cache())) { 1312 while ((i=last_ptr_cache())) {
1326 clear_ptr_cache_reg(i); 1313 clear_ptr_cache_reg(i);
1327 if (is_data_reg(i)) { 1314 if (is_data_reg(i)) {
1328 regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ 1315 regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */
1329 regs_line[i]=glineno; 1316 regs_line[i]=glineno;
1330 return i; /* その場所を表す番号を返す */ 1317 return i; /* その場所を表す番号を返す */
1331 } 1318 }
1332 } 1319 }
1333 #endif
1334 /* search register stack */ 1320 /* search register stack */
1335 for(i=0;i<reg_sp;i++) { 1321 for(i=0;i<reg_sp;i++) {
1336 if (is_data_reg(i) && (reg=reg_stack[i])>=0) { 1322 if (is_data_reg(i) && (reg=reg_stack[i])>=0) {
1337 code_dassign_lvar( 1323 code_dassign_lvar(
1338 (j=new_lvar(SIZE_OF_DOUBLE)),reg,0); 1324 (j=new_lvar(SIZE_OF_DOUBLE)),reg,0);
1352 } 1338 }
1353 1339
1354 extern void 1340 extern void
1355 use_ptr_cache(int r) 1341 use_ptr_cache(int r)
1356 { 1342 {
1357 #ifdef __APPLE__
1358 regs[r]=PTRC_REG; 1343 regs[r]=PTRC_REG;
1359 #else
1360 error(-1);
1361 #endif
1362 } 1344 }
1363 1345
1364 extern void 1346 extern void
1365 code_ptr_cache_def(int r,NMTBL *nptr) 1347 code_ptr_cache_def(int r,NMTBL *nptr)
1366 { 1348 {
1349 char *rrn = register_name(r,0);
1367 #ifdef __APPLE__ 1350 #ifdef __APPLE__
1368 char *rrn = register_name(r,0);
1369 if (nptr->sc==STATIC && !(is_code(nptr)||is_function(nptr))) { 1351 if (nptr->sc==STATIC && !(is_code(nptr)||is_function(nptr))) {
1370 printf("\tleaq _%s(%%rip),%s\n",nptr->nm, rrn); 1352 printf("\tleaq _%s(%%rip),%s\n",nptr->nm, rrn);
1371 } else { 1353 } else {
1372 printf("\tmovq _%s@GOTPCREL(%%rip),%s\n", 1354 printf("\tmovq _%s@GOTPCREL(%%rip),%s\n",
1373 nptr->nm, rrn); 1355 nptr->nm, rrn);
1374 } 1356 }
1357 printf("\tleaq _%s,%s\n",nptr->nm, rrn);
1375 #else 1358 #else
1376 error(-1); 1359 printf("\tleaq %s,%s\n",nptr->nm, rrn);
1377 #endif 1360 #endif
1378 } 1361 }
1379 1362
1380 /* 1363 /*
1381 */ 1364 */
1688 if (dots) { 1671 if (dots) {
1689 // %al の値によって float を適切にloadする必要がある sigh... 1672 // %al の値によって float を適切にloadする必要がある sigh...
1690 func_reg_arg_size = 1673 func_reg_arg_size =
1691 MAX_INPUT_REGISTER_VAR*SIZE_OF_LONGLONG + 1674 MAX_INPUT_REGISTER_VAR*SIZE_OF_LONGLONG +
1692 MAX_INPUT_DREGISTER_VAR*SIZE_OF_DOUBLE; 1675 MAX_INPUT_DREGISTER_VAR*SIZE_OF_DOUBLE;
1693 #ifndef __APPLE__
1694 // printf(".set %s%d, %d\n",lpfx, arg_offset_label,
1695 // arg_offset_v+ arg_offset);
1696 #endif
1697 } 1676 }
1698 code_save_input_registers(dots, func_reg_arg_size ); 1677 code_save_input_registers(dots, func_reg_arg_size );
1699 arg_offset_v = func_reg_arg_size; 1678 arg_offset_v = func_reg_arg_size;
1700 } 1679 }
1701 } 1680 }
1804 } 1783 }
1805 1784
1806 void 1785 void
1807 code_label(int labelno) 1786 code_label(int labelno)
1808 { 1787 {
1809 #ifdef __APPLE__
1810 clear_ptr_cache(); 1788 clear_ptr_cache();
1811 #endif
1812 // printf("\t.align 4\n");
1813 printf("_%d:\n",labelno); 1789 printf("_%d:\n",labelno);
1814 } 1790 }
1815 1791
1816 void 1792 void
1817 code_gvar(int e1,int creg) { 1793 code_gvar(int e1,int creg) {
1820 #ifdef __APPLE__ 1796 #ifdef __APPLE__
1821 if (nptr->sc==STATIC && !(is_code(nptr)||is_function(nptr))) { 1797 if (nptr->sc==STATIC && !(is_code(nptr)||is_function(nptr))) {
1822 printf("\tleaq _%s+%d(%%rip),%s\n", nptr->nm,cadr(e1),register_name(creg,0)); 1798 printf("\tleaq _%s+%d(%%rip),%s\n", nptr->nm,cadr(e1),register_name(creg,0));
1823 return; 1799 return;
1824 } 1800 }
1801 #endif
1825 int r = get_ptr_cache(nptr); 1802 int r = get_ptr_cache(nptr);
1826 if (cadr(e1)) { 1803 if (cadr(e1)) {
1827 printf("\tleaq %d(%s),%s\n", cadr(e1),register_name(r,0), 1804 printf("\tleaq %d(%s),%s\n", cadr(e1),register_name(r,0),
1828 register_name(creg,0)); 1805 register_name(creg,0));
1829 } else { 1806 } else {
1830 printf("\tmovq %s,%s\n", register_name(r,0), register_name(creg,0)); 1807 printf("\tmovq %s,%s\n", register_name(r,0), register_name(creg,0));
1831 } 1808 }
1832 #else
1833 if (cadr(e1)) {
1834 printf("\tmovq $%s+%d,%s\n",nptr->nm,cadr(e1),
1835 register_name(creg,0));
1836 } else {
1837 printf("\tmovq $%s,%s\n",nptr->nm,register_name(creg,0));
1838 }
1839 #endif
1840 1809
1841 } 1810 }
1842 1811
1843 void 1812 void
1844 code_rgvar(int e1,int creg) { 1813 code_rgvar(int e1,int creg) {
1845 use_int(creg); 1814 use_int(creg);
1846 if (car(e1)==URGVAR) { 1815 if (car(e1)==URGVAR) {
1847 code_crgvar(e1,creg,0,SIZE_OF_INT); 1816 code_crgvar(e1,creg,0,SIZE_OF_INT);
1848 return; 1817 return;
1849 } 1818 }
1819 #ifdef __APPLE__
1850 NMTBL *nptr = ncaddr(e1); 1820 NMTBL *nptr = ncaddr(e1);
1851 #ifdef __APPLE__
1852 if (nptr->sc==STATIC && !(is_code(nptr)||is_function(nptr))) { 1821 if (nptr->sc==STATIC && !(is_code(nptr)||is_function(nptr))) {
1853 printf("\tmovl _%s+%d(%%rip),%s\n", nptr->nm,cadr(e1),register_name(creg,SIZE_OF_INT)); 1822 printf("\tmovl _%s+%d(%%rip),%s\n", nptr->nm,cadr(e1),register_name(creg,SIZE_OF_INT));
1854 return; 1823 return;
1855 } 1824 }
1825 #endif
1856 int r = get_ptr_cache(ncaddr(e1)); 1826 int r = get_ptr_cache(ncaddr(e1));
1857 if (cadr(e1)) { 1827 if (cadr(e1)) {
1858 printf("\tmovl %d(%s),%s\n", cadr(e1),register_name(r,0), 1828 printf("\tmovl %d(%s),%s\n", cadr(e1),register_name(r,0),
1859 register_name(creg,SIZE_OF_INT)); 1829 register_name(creg,SIZE_OF_INT));
1860 } else { 1830 } else {
1861 printf("\tmovl (%s),%s\n", register_name(r,0), register_name(creg,SIZE_OF_INT)); 1831 printf("\tmovl (%s),%s\n", register_name(r,0), register_name(creg,SIZE_OF_INT));
1862 } 1832 }
1863 #else
1864 if (cadr(e1)) {
1865 printf("\tmovl %s+%d,%s\n",nptr->nm,cadr(e1),
1866 register_name(creg,SIZE_OF_INT));
1867 } else
1868 printf("\tmovl %s,%s\n",nptr->nm,register_name(creg,SIZE_OF_INT));
1869 #endif
1870
1871 } 1833 }
1872 1834
1873 static char * 1835 static char *
1874 cload(int sign,int sz) { 1836 cload(int sign,int sz) {
1875 return sz==1?(sign?"movsbq":"movzbq"): 1837 return sz==1?(sign?"movsbq":"movzbq"):
1889 #ifdef __APPLE__ 1851 #ifdef __APPLE__
1890 if (nptr->sc==STATIC && !(is_code(nptr)||is_function(nptr))) { 1852 if (nptr->sc==STATIC && !(is_code(nptr)||is_function(nptr))) {
1891 printf("\t%s _%s+%d(%%rip),%s\n", cload(sign,sz),nptr->nm,cadr(e1),register_name(creg,regu(sign,sz,0))); 1853 printf("\t%s _%s+%d(%%rip),%s\n", cload(sign,sz),nptr->nm,cadr(e1),register_name(creg,regu(sign,sz,0)));
1892 return; 1854 return;
1893 } 1855 }
1856 #endif
1894 int r = get_ptr_cache(ncaddr(e1)); 1857 int r = get_ptr_cache(ncaddr(e1));
1895 if (cadr(e1)) { 1858 if (cadr(e1)) {
1896 printf("\t%s %d(%s),%s\n", cload(sign,sz),cadr(e1),register_name(r,0), 1859 printf("\t%s %d(%s),%s\n", cload(sign,sz),cadr(e1),register_name(r,0),
1897 register_name(creg,regu(sign,sz,0))); 1860 register_name(creg,regu(sign,sz,0)));
1898 } else { 1861 } else {
1899 printf("\t%s (%s),%s\n", cload(sign,sz), 1862 printf("\t%s (%s),%s\n", cload(sign,sz),
1900 register_name(r,0), register_name(creg,regu(sign,sz,0))); 1863 register_name(r,0), register_name(creg,regu(sign,sz,0)));
1901 } 1864 }
1902 #else
1903 if (cadr(e1)) {
1904 printf("\t%s %s+%d,%s\n",cload(sign,sz),
1905 nptr->nm,cadr(e1),register_name(creg,regu(sign,sz,0)));
1906 } else
1907 printf("\t%s %s,%s\n",cload(sign,sz),
1908 nptr->nm,register_name(creg,regu(sign,sz,0)));
1909 #endif
1910
1911 } 1865 }
1912 1866
1913 1867
1914 void 1868 void
1915 code_lvar(int e2,int creg) { 1869 code_lvar(int e2,int creg) {
1981 if (n->sc==STATIC) { 1935 if (n->sc==STATIC) {
1982 printf("\tleaq _%s(%%rip),%s\n", n->nm, 1936 printf("\tleaq _%s(%%rip),%s\n", n->nm,
1983 register_name(creg,0)); 1937 register_name(creg,0));
1984 return; 1938 return;
1985 } 1939 }
1940 #endif
1986 int r = get_ptr_cache(n); 1941 int r = get_ptr_cache(n);
1987 printf("\tmovq %s,%s\n", register_name(r,0), register_name(creg,0)); 1942 printf("\tmovq %s,%s\n", register_name(r,0), register_name(creg,0));
1988 #else
1989 printf("\tmovq $%s,%s\n",n->nm,register_name(creg,0));
1990 #endif
1991 } 1943 }
1992 1944
1993 void 1945 void
1994 code_label_value(int label,int reg) { 1946 code_label_value(int label,int reg) {
1995 use_int(reg); 1947 use_int(reg);
2154 } 2106 }
2155 2107
2156 void 2108 void
2157 code_cmp_crgvar(int e1,int reg,int sz,int label,int cond) { 2109 code_cmp_crgvar(int e1,int reg,int sz,int label,int cond) {
2158 use_int(reg); 2110 use_int(reg);
2159 #ifdef __APPLE__
2160 int r = get_ptr_cache(ncaddr(e1)); 2111 int r = get_ptr_cache(ncaddr(e1));
2161 if (cadr(e1)) { 2112 if (cadr(e1)) {
2162 if (sz==1) 2113 if (sz==1)
2163 printf("\tcmpb $0,%d(%s)\n",cadr(e1),register_name(r,0)); 2114 printf("\tcmpb $0,%d(%s)\n",cadr(e1),register_name(r,0));
2164 else if (sz==SIZE_OF_SHORT) 2115 else if (sz==SIZE_OF_SHORT)
2167 if (sz==1) 2118 if (sz==1)
2168 printf("\tcmpb $0,(%s)\n",register_name(r,0)); 2119 printf("\tcmpb $0,(%s)\n",register_name(r,0));
2169 else if (sz==SIZE_OF_SHORT) 2120 else if (sz==SIZE_OF_SHORT)
2170 printf("\tcmpw $0,(%s)\n",register_name(r,0)); 2121 printf("\tcmpw $0,(%s)\n",register_name(r,0));
2171 } 2122 }
2172 #else
2173 if (cadr(e1)) {
2174 if (sz==1)
2175 printf("\tcmpb $0,%s+%d\n",(ncaddr(e1))->nm,cadr(e1));
2176 else if (sz==SIZE_OF_SHORT)
2177 printf("\tcmpw $0,%s+%d\n",(ncaddr(e1))->nm,cadr(e1));
2178 } else {
2179 if (sz==1)
2180 printf("\tcmpb $0,%s\n",(ncaddr(e1))->nm);
2181 else if (sz==SIZE_OF_SHORT)
2182 printf("\tcmpw $0,%s\n",(ncaddr(e1))->nm);
2183 }
2184 #endif
2185 jcond(label,cond); 2123 jcond(label,cond);
2186 } 2124 }
2187 2125
2188 2126
2189 void 2127 void
2199 2137
2200 2138
2201 void 2139 void
2202 code_cmp_rgvar(int e1,int reg,int label,int cond) { 2140 code_cmp_rgvar(int e1,int reg,int label,int cond) {
2203 use_int(reg); 2141 use_int(reg);
2204 #ifdef __APPLE__
2205 int r = get_ptr_cache(ncaddr(e1)); 2142 int r = get_ptr_cache(ncaddr(e1));
2206 if (cadr(e1)) 2143 if (cadr(e1))
2207 printf("\tcmpl $0,%d(%s)\n",cadr(e1),register_name(r,0)); 2144 printf("\tcmpl $0,%d(%s)\n",cadr(e1),register_name(r,0));
2208 else 2145 else
2209 printf("\tcmpl $0,(%s)\n",register_name(r,0)); 2146 printf("\tcmpl $0,(%s)\n",register_name(r,0));
2210 #else
2211 if (cadr(e1))
2212 printf("\tcmpl $0,%s+%d\n",(ncaddr(e1))->nm,cadr(e1));
2213 else
2214 printf("\tcmpl $0,%s\n",(ncaddr(e1))->nm);
2215 #endif
2216 jcond(label,cond); 2147 jcond(label,cond);
2217 } 2148 }
2218 2149
2219 2150
2220 void 2151 void
2915 2846
2916 void 2847 void
2917 code_assign_gvar(int e2,int creg,int byte) { 2848 code_assign_gvar(int e2,int creg,int byte) {
2918 if (byte && byte <SIZE_OF_INT) { use_data_reg(creg,1); 2849 if (byte && byte <SIZE_OF_INT) { use_data_reg(creg,1);
2919 } else { use_int(creg); } 2850 } else { use_int(creg); }
2920 #ifdef __APPLE__
2921 int r = get_ptr_cache(ncaddr(e2)); 2851 int r = get_ptr_cache(ncaddr(e2));
2922 if (cadr(e2)) 2852 if (cadr(e2))
2923 printf("\t%s %s,%d(%s)\n",move(byte),register_name(creg,byte), 2853 printf("\t%s %s,%d(%s)\n",move(byte),register_name(creg,byte),
2924 cadr(e2),register_name(r,0)); 2854 cadr(e2),register_name(r,0));
2925 else 2855 else
2926 printf("\t%s %s,(%s)\n",move(byte),register_name(creg,byte), 2856 printf("\t%s %s,(%s)\n",move(byte),register_name(creg,byte),
2927 register_name(r,0)); 2857 register_name(r,0));
2928 #else
2929 if (cadr(e2))
2930 printf("\t%s %s,%s+%d\n",move(byte),register_name(creg,byte),(ncaddr(e2))->nm,cadr(e2));
2931 else
2932 printf("\t%s %s,%s\n",move(byte),register_name(creg,byte),(ncaddr(e2))->nm);
2933 #endif
2934 } 2858 }
2935 2859
2936 void 2860 void
2937 code_assign_lvar(int e2,int creg,int byte) { 2861 code_assign_lvar(int e2,int creg,int byte) {
2938 if (byte && byte <SIZE_OF_INT) { use_data_reg(creg,1); 2862 if (byte && byte <SIZE_OF_INT) { use_data_reg(creg,1);
3061 break; 2985 break;
3062 case DIV: 2986 case DIV:
3063 case UDIV: 2987 case UDIV:
3064 case MOD: 2988 case MOD:
3065 case UMOD: 2989 case UMOD:
3066 #ifdef __APPLE__
3067 if (regs[REG_EDX]==PTRC_REG) 2990 if (regs[REG_EDX]==PTRC_REG)
3068 clear_ptr_cache_reg(REG_EDX); 2991 clear_ptr_cache_reg(REG_EDX);
3069 #endif
3070 use_register(reg,REG_EAX,1); 2992 use_register(reg,REG_EAX,1);
3071 if (oreg==REG_EAX) oreg=reg; 2993 if (oreg==REG_EAX) oreg=reg;
3072 if (oreg==REG_EDX) { 2994 if (oreg==REG_EDX) {
3073 use_register(oreg,REG_ECX,1); 2995 use_register(oreg,REG_ECX,1);
3074 oreg = REG_ECX; 2996 oreg = REG_ECX;
4301 } 4223 }
4302 4224
4303 void code_drgvar(int e2,int d,int freg) 4225 void code_drgvar(int e2,int d,int freg)
4304 { 4226 {
4305 use_float(d,freg); 4227 use_float(d,freg);
4306 #ifdef __APPLE__
4307 int r = get_ptr_cache(ncaddr(e2)); 4228 int r = get_ptr_cache(ncaddr(e2));
4308 if (cadr(e2)) 4229 if (cadr(e2))
4309 printf("\t%s %d(%s),%s\n",fload(d),cadr(e2),register_name(r,0),fregister_name(freg)); 4230 printf("\t%s %d(%s),%s\n",fload(d),cadr(e2),register_name(r,0),fregister_name(freg));
4310 else 4231 else
4311 printf("\t%s (%s),%s\n",fload(d),register_name(r,0),fregister_name(freg)); 4232 printf("\t%s (%s),%s\n",fload(d),register_name(r,0),fregister_name(freg));
4312 #else
4313 if (cadr(e2))
4314 printf("\t%s %s+%d,%s\n",fload(d),(ncaddr(e2))->nm,cadr(e2),fregister_name(freg));
4315 else
4316 printf("\t%s %s,%s\n",fload(d),(ncaddr(e2))->nm,fregister_name(freg));
4317 #endif
4318 } 4233 }
4319 4234
4320 4235
4321 void code_drlvar(int e2,int d,int freg) 4236 void code_drlvar(int e2,int d,int freg)
4322 { 4237 {
4328 { 4243 {
4329 char *db = d?"d":"s"; 4244 char *db = d?"d":"s";
4330 use_float(d,reg); 4245 use_float(d,reg);
4331 char *f = fregister_name(reg); 4246 char *f = fregister_name(reg);
4332 int t = get_dregister(d); 4247 int t = get_dregister(d);
4333 #ifdef __APPLE__
4334 int r = get_ptr_cache(ncaddr(e2)); 4248 int r = get_ptr_cache(ncaddr(e2));
4335 if (cadr(e2)) 4249 if (cadr(e2))
4336 printf("\tmovs%s %d(%s),%s\n",db,cadr(e2),register_name(r,0),f); 4250 printf("\tmovs%s %d(%s),%s\n",db,cadr(e2),register_name(r,0),f);
4337 else 4251 else
4338 printf("\tmovs%s (%s),%s\n",db,register_name(r,0),f); 4252 printf("\tmovs%s (%s),%s\n",db,register_name(r,0),f);
4339 #else
4340 if (cadr(e2))
4341 printf("\tmovs%s %s+%d,%s\n",db,(ncaddr(e2))->nm,cadr(e2),f);
4342 else
4343 printf("\tmovs%s %s,%s\n",db,(ncaddr(e2))->nm,f);
4344 #endif
4345 printf("\txorp%s %s,%s\n",db,f,fregister_name(t)); 4253 printf("\txorp%s %s,%s\n",db,f,fregister_name(t));
4346 printf("\tucomis%s %s,%s\n",db,f,fregister_name(t)); 4254 printf("\tucomis%s %s,%s\n",db,f,fregister_name(t));
4347 free_register(t); 4255 free_register(t);
4348 jcond(label,cond); 4256 jcond(label,cond);
4349 } 4257 }
4453 } else { 4361 } else {
4454 float_one_f_lib_used=1; 4362 float_one_f_lib_used=1;
4455 one = &float_one_f; 4363 one = &float_one_f;
4456 } 4364 }
4457 char *grn=fregister_name(g); 4365 char *grn=fregister_name(g);
4458 #ifdef __APPLE__
4459 int r = get_ptr_cache(one); 4366 int r = get_ptr_cache(one);
4460 char *drn=register_name(r,0); 4367 char *drn=register_name(r,0);
4461 printf("\tmovs%s 0(%s),%s\n",d?"d":"s",drn,grn); 4368 printf("\tmovs%s 0(%s),%s\n",d?"d":"s",drn,grn);
4462 #else
4463 printf("\tmovs%s %s,%s\n",d?"d":"s",one->nm,grn);
4464 #endif
4465 return g; 4369 return g;
4466 } 4370 }
4467 4371
4468 void 4372 void
4469 code_dpreinc(int e1,int e2,int d,int reg) { 4373 code_dpreinc(int e1,int e2,int d,int reg) {
4637 4541
4638 void 4542 void
4639 code_cmp_dregister(int e2,int d,int label,int cond) 4543 code_cmp_dregister(int e2,int d,int label,int cond)
4640 { 4544 {
4641 use_float(d,e2); 4545 use_float(d,e2);
4642 #ifdef __APPLE__
4643 if (regs[REG_EAX]==PTRC_REG) 4546 if (regs[REG_EAX]==PTRC_REG)
4644 clear_ptr_cache_reg(REG_EAX); 4547 clear_ptr_cache_reg(REG_EAX);
4645 #endif
4646 int tmp = get_dregister(d); 4548 int tmp = get_dregister(d);
4647 char *n = fregister_name(tmp); 4549 char *n = fregister_name(tmp);
4648 char *c = fregister_name(creg); 4550 char *c = fregister_name(creg);
4649 char *sd = d?"d":"s"; 4551 char *sd = d?"d":"s";
4650 printf("\txorp%s %s,%s\n",sd,n,n); 4552 printf("\txorp%s %s,%s\n",sd,n,n);
4763 } 4665 }
4764 4666
4765 void code_cmp_lrgvar(int e1,int e2,int label,int cond) 4667 void code_cmp_lrgvar(int e1,int e2,int label,int cond)
4766 { 4668 {
4767 use_longlong(e2); 4669 use_longlong(e2);
4768 #ifdef __APPLE__
4769 int r = get_ptr_cache(ncaddr(e1)); 4670 int r = get_ptr_cache(ncaddr(e1));
4770 if (cadr(e1)) 4671 if (cadr(e1))
4771 printf("\tcmpq $0,%d(%s)\n",cadr(e1),register_name(r,0)); 4672 printf("\tcmpq $0,%d(%s)\n",cadr(e1),register_name(r,0));
4772 else 4673 else
4773 printf("\tcmpq $0,(%s)\n",register_name(r,0)); 4674 printf("\tcmpq $0,(%s)\n",register_name(r,0));
4774 #else
4775 if (cadr(e1))
4776 printf("\tcmpq $0,%s+%d\n",(ncaddr(e1))->nm,cadr(e1));
4777 else
4778 printf("\tcmpq $0,%s\n",(ncaddr(e1))->nm);
4779 #endif
4780 jcond(label,cond); 4675 jcond(label,cond);
4781 } 4676 }
4782 4677
4783 void code_cmp_lrlvar(int e1,int e2,int label,int cond) 4678 void code_cmp_lrlvar(int e1,int e2,int label,int cond)
4784 { 4679 {
5084 printf("\tsubl\t$%d,%s\n",min,crnl); 4979 printf("\tsubl\t$%d,%s\n",min,crnl);
5085 printf("\tcmpl\t$%d,%s\n",max-min,crnl); 4980 printf("\tcmpl\t$%d,%s\n",max-min,crnl);
5086 printf("\tja\t_%d\n",dlabel); 4981 printf("\tja\t_%d\n",dlabel);
5087 // this assumes 32bit offset, but it may too small 4982 // this assumes 32bit offset, but it may too small
5088 if (delta==1) { 4983 if (delta==1) {
5089 #ifdef __APPLE__
5090 printf("\tleaq\t_%d(%%rip),%%rbx\n",l); 4984 printf("\tleaq\t_%d(%%rip),%%rbx\n",l);
5091 printf("\tmovslq\t(%%rbx,%s,4),%s\n",crn,crn); 4985 printf("\tmovslq\t(%%rbx,%s,4),%s\n",crn,crn);
5092 printf("\taddq\t%%rbx,%s\n",crn); 4986 printf("\taddq\t%%rbx,%s\n",crn);
5093 printf("\tjmp\t*%s\n",crn); 4987 printf("\tjmp\t*%s\n",crn);
5094 #else
5095 printf("\tjmp\t*_%d(,%s,8)\n",l,crn);
5096 #endif
5097 return; 4988 return;
5098 } 4989 }
5099 #ifdef __APPLE__
5100 if (regs[REG_EAX]==PTRC_REG) 4990 if (regs[REG_EAX]==PTRC_REG)
5101 clear_ptr_cache_reg(REG_EAX); 4991 clear_ptr_cache_reg(REG_EAX);
5102 #endif
5103 use_register(creg,REG_EAX,1); 4992 use_register(creg,REG_EAX,1);
5104 crn = "%rax"; 4993 crn = "%rax";
5105 4994
5106 switch(delta) { 4995 switch(delta) {
5107 case 2: 4996 case 2:
5108 printf("\tmovl\t$1,%%edx\n"); 4997 printf("\tmovl\t$1,%%edx\n");
5109 printf("\tandl\t%%eax,%%edx\n"); 4998 printf("\tandl\t%%eax,%%edx\n");
5110 printf("\tjne\t_%d\n",dlabel); 4999 printf("\tjne\t_%d\n",dlabel);
5111 #ifdef __APPLE__
5112 printf("\tleaq\t_%d(%%rip),%%rbx\n",l); 5000 printf("\tleaq\t_%d(%%rip),%%rbx\n",l);
5113 printf("\tmovslq\t(%%rbx,%s,2),%s\n",crn,crn); 5001 printf("\tmovslq\t(%%rbx,%s,2),%s\n",crn,crn);
5114 printf("\taddq\t%%rbx,%s\n",crn); 5002 printf("\taddq\t%%rbx,%s\n",crn);
5115 printf("\tjmp\t*%s\n",crn); 5003 printf("\tjmp\t*%s\n",crn);
5116 #else
5117 printf("\tjmp\t*_%d(,%%eax,4)\n",l);
5118 #endif
5119 break; 5004 break;
5120 case 4: 5005 case 4:
5121 printf("\tmovl\t$3,%%edx\n"); 5006 printf("\tmovl\t$3,%%edx\n");
5122 printf("\tandl\t%%eax,%%edx\n"); 5007 printf("\tandl\t%%eax,%%edx\n");
5123 printf("\tjne\t_%d\n",dlabel); 5008 printf("\tjne\t_%d\n",dlabel);
5124 #ifdef __APPLE__
5125 printf("\tleaq\t_%d(%%rip),%%rbx\n",l); 5009 printf("\tleaq\t_%d(%%rip),%%rbx\n",l);
5126 printf("\tmovslq\t(%%rbx,%s),%s\n",crn,crn); 5010 printf("\tmovslq\t(%%rbx,%s),%s\n",crn,crn);
5127 printf("\taddq\t%%rbx,%s\n",crn); 5011 printf("\taddq\t%%rbx,%s\n",crn);
5128 printf("\tjmp\t*%s\n",crn); 5012 printf("\tjmp\t*%s\n",crn);
5129 #else
5130 printf("\tjmp\t*_%d(,%%eax,2)\n",l);
5131 #endif
5132 break; 5013 break;
5133 default: 5014 default:
5134 printf("\tmovl $%d,%%ecx\n",delta); 5015 printf("\tmovl $%d,%%ecx\n",delta);
5135 printf("\txor %%edx,%%edx\n\tdivl %%ecx\n"); 5016 printf("\txor %%edx,%%edx\n\tdivl %%ecx\n");
5136 printf("\tandl\t%%edx,%%edx\n"); 5017 printf("\tandl\t%%edx,%%edx\n");
5137 printf("\tjne\t_%d\n",dlabel); 5018 printf("\tjne\t_%d\n",dlabel);
5138 #ifdef __APPLE__
5139 printf("\tleaq\t_%d(%%rip),%%rbx\n",l); 5019 printf("\tleaq\t_%d(%%rip),%%rbx\n",l);
5140 printf("\tmovslq\t(%%rbx,%s,4),%s\n",crn,crn); 5020 printf("\tmovslq\t(%%rbx,%s,4),%s\n",crn,crn);
5141 printf("\taddq\t%%rbx,%s\n",crn); 5021 printf("\taddq\t%%rbx,%s\n",crn);
5142 printf("\tjmp\t*%s\n",crn); 5022 printf("\tjmp\t*%s\n",crn);
5143 #else
5144 printf("\tjmp\t*_%d(,%%rax,8)\n",l);
5145 #endif
5146 break; 5023 break;
5147 } 5024 }
5148 5025
5149 } 5026 }
5150 5027
5151 void 5028 void
5152 code_table_open(int l) 5029 code_table_open(int l)
5153 { 5030 {
5154 output_mode=DATA_EMIT_MODE; 5031 output_mode=DATA_EMIT_MODE;
5155 #ifdef __APPLE__
5156 printf(" \t.align 2\n"); 5032 printf(" \t.align 2\n");
5157 #else
5158 printf(" \t.section\t.rodata\n\t.align 4\n");
5159 #endif
5160 fwddef(l); 5033 fwddef(l);
5161 } 5034 }
5162 5035
5163 void 5036 void
5164 code_table_value(int label,int table_top) 5037 code_table_value(int label,int table_top)
5165 { 5038 {
5166 #ifdef __APPLE__
5167 printf("\t.long _%d-_%d\n",label,table_top); 5039 printf("\t.long _%d-_%d\n",label,table_top);
5168 #else
5169 printf("\t.quad _%d\n",label);
5170 #endif
5171 } 5040 }
5172 5041
5173 void 5042 void
5174 code_table_close() 5043 code_table_close()
5175 { 5044 {