Mercurial > hg > CbC > old > device
annotate mc-code-powerpc.c @ 908:0df95413f583
minor fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 09 Apr 2014 11:44:01 +0900 (2014-04-09) |
parents | 8bdd5061cb8f |
children | 485f13206916 |
rev | line source |
---|---|
326 | 1 /* Micro-C Code Generation Part for Power PC (Mac OS X) */ |
607 | 2 |
3 /* | |
4 ************************************************************************ | |
5 ** Copyright (C) 2006 Shinji Kono | |
724 | 6 ** 連絡先: 琉球大学情報工学科 河野 真治 |
7 ** (E-Mail Address: kono@ie.u-ryukyu.ac.jp) | |
607 | 8 ** |
724 | 9 ** このソースのいかなる複写,改変,修正も許諾します。ただし、 |
10 ** その際には、誰が貢献したを示すこの部分を残すこと。 | |
11 ** 再配布や雑誌の付録などの問い合わせも必要ありません。 | |
12 ** 営利利用も上記に反しない範囲で許可します。 | |
13 ** バイナリの配布の際にはversion messageを保存することを条件とします。 | |
14 ** このプログラムについては特に何の保証もしない、悪しからず。 | |
607 | 15 ** |
16 ** Everyone is permitted to do anything on this program | |
17 ** including copying, modifying, improving, | |
18 ** as long as you don't try to pretend that you wrote it. | |
19 ** i.e., the above copyright notice has to appear in all copies. | |
20 ** Binary distribution requires original version messages. | |
21 ** You don't have to ask before copying, redistribution or publishing. | |
22 ** THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. | |
23 *********************************************************************** | |
24 */ | |
89 | 25 |
327 | 26 #include <stdio.h> |
89 | 27 #include "mc.h" |
327 | 28 #include "mc-parse.h" |
93 | 29 #include "mc-code.h" |
89 | 30 #include "mc-codegen.h" |
31 | |
615 | 32 #include "mc-include.c" |
324 | 33 |
664 | 34 // #undef __APPLE__ |
662 | 35 |
327 | 36 static |
667 | 37 char *init_src0 = |
38 #ifdef __APPLE__ | |
39 "\ | |
313 | 40 #define __ppc__ 1\n\ |
41 #define __BIG_ENDIAN__ 1\n\ | |
42 #define __STDC__ 1\n\ | |
469 | 43 #define __GNUC__ 1\n\ |
526 | 44 #define __inline inline\n\ |
45 #define __inline__ inline\n\ | |
313 | 46 #define __builtin_va_list int\n\ |
47 #define __builtin_va_start(ap,arg) ap=(((int)(&arg))+sizeof(arg))\n\ | |
48 #define __builtin_va_arg(ap,type) (*((type *)ap)++)\n\ | |
49 #define alloca __builtin_alloca\n\ | |
616 | 50 #define __FLT_MIN__ 1.17549435e-38F\n\ |
51 #define __DBL_MIN__ 2.2250738585072014e-308\n\ | |
52 #define __LDBL_MIN__ 2.00416836000897277799610805135016e-292L\n\ | |
636 | 53 " |
667 | 54 #else |
55 "\ | |
56 #define __inline inline\n\ | |
57 #define __extension__\n\ | |
58 #define __const const\n\ | |
59 #define __inline__ inline\n\ | |
809 | 60 typedef struct __builtin_va_list { \\\n\ |
61 long long_last; \\\n\ | |
62 long float_first; \\\n\ | |
63 long float_last; \\\n\ | |
64 long stack_top; \\\n\ | |
65 long arg; \\\n\ | |
66 long top; \\\n\ | |
67 } __builtin_va_list; \\\n\ | |
68 \\\n\ | |
69 #define __builtin_va_start(__ap0,v) \\\n\ | |
70 { \\\n\ | |
71 __builtin_va_list *__ap = &__ap0; \\\n\ | |
72 long __top = __ap->top = (long)&__my_va_list; \\\n\ | |
73 __ap->long_last = __top +32; \\\n\ | |
74 __ap->float_first = __ap->long_last; \\\n\ | |
75 __ap->stack_top = __top+32+64+8; \\\n\ | |
76 long __adr = (long)(&v) + sizeof(v); \\\n\ | |
77 if (__adr >= __ap->stack_top) __ap->arg = __ap->float_first = __adr; \\\n\ | |
78 if (__builtin_types_compatible_p(typeof(v),double)) \\\n\ | |
79 __ap->float_first = __adr; \\\n\ | |
80 __ap->arg = __adr; \\\n\ | |
81 } \\\n\ | |
82 \n\ | |
83 #define __builtin_va_arg(__ap0,type) ({ \\\n\ | |
84 __builtin_va_list *__ap = &__ap0; \\\n\ | |
85 long __arg; \\\n\ | |
86 if (__builtin_types_compatible_p(type,double) \\\n\ | |
87 && __ap->float_first < __ap->stack_top) { \\\n\ | |
88 __arg = __ap->float_first; \\\n\ | |
89 __ap->float_first = __ap->float_first+8; \\\n\ | |
90 if (__ap->float_first==__ap->float_last) \\\n\ | |
91 __ap->float_first = __ap->stack_top;\\\n\ | |
92 } else { \\\n\ | |
880 | 93 if (__builtin_types_compatible_p(type,long long)) { \\\n\ |
809 | 94 if (__ap->arg==__ap->top+4) __ap->arg += 4; \\\n\ |
880 | 95 __arg = __ap->arg; \\\n\ |
96 __ap->arg += 8; \\\n\ | |
809 | 97 if (__ap->arg==__ap->top+16+16) \\\n\ |
880 | 98 __ap->arg = __ap->stack_top; \\\n\ |
99 } else { \\\n\ | |
100 __arg = __ap->arg; \\\n\ | |
101 __ap->arg = __ap->arg+sizeof(type); \\\n\ | |
102 if (__ap->arg==__ap->long_last) \\\n\ | |
103 __ap->arg = __ap->stack_top; \\\n\ | |
104 } \\\n\ | |
809 | 105 } \\\n\ |
106 *((type *)(__arg)); \\\n\ | |
107 }) \\\n\ | |
108 \n" | |
109 | |
110 "// #define __builtin_va_arg(ap,type) (*((type *)__builtin_va_next((type),&ap)))\n\ | |
667 | 111 #define alloca __builtin_alloca\n\ |
112 #define __DBL_MIN_EXP__ (-1021)\n\ | |
113 #define __FLT_MIN__ 1.17549435e-38F\n\ | |
114 #define __CHAR_BIT__ 8\n\ | |
115 #define __WCHAR_MAX__ 2147483647\n\ | |
116 #define __DBL_DENORM_MIN__ 4.9406564584124654e-324\n\ | |
117 #define __FLT_EVAL_METHOD__ 0\n\ | |
118 #define __DBL_MIN_10_EXP__ (-307)\n\ | |
119 #define __FINITE_MATH_ONLY__ 0\n\ | |
120 #define __GNUC_PATCHLEVEL__ 0\n\ | |
121 #define __SHRT_MAX__ 32767\n\ | |
122 #define __LDBL_MAX__ 1.79769313486231580793728971405301e+308L\n\ | |
123 #define __UINTMAX_TYPE__ long long unsigned int\n\ | |
124 #define __linux 1\n\ | |
125 #define __CHAR_UNSIGNED__ 1\n\ | |
126 #define __LDBL_MAX_EXP__ 1024\n\ | |
127 #define __linux__ 1\n\ | |
128 #define __SCHAR_MAX__ 127\n\ | |
129 #define __USER_LABEL_PREFIX__ \n\ | |
130 #define __STDC_HOSTED__ 1\n\ | |
131 #define __LDBL_HAS_INFINITY__ 1\n\ | |
132 #define __DBL_DIG__ 15\n\ | |
133 #define __FLT_EPSILON__ 1.19209290e-7F\n\ | |
134 #define _CALL_SYSV 1\n\ | |
135 #define __LDBL_MIN__ 2.00416836000897277799610805135016e-292L\n\ | |
136 #define __unix__ 1\n\ | |
137 #define __DECIMAL_DIG__ 33\n\ | |
138 #define __gnu_linux__ 1\n\ | |
139 #define __LDBL_HAS_QUIET_NAN__ 1\n\ | |
140 #define __GNUC__ 4\n\ | |
141 #define __DBL_MAX__ 1.7976931348623157e+308\n\ | |
142 #define __DBL_HAS_INFINITY__ 1\n\ | |
143 #define __DBL_MAX_EXP__ 1024\n\ | |
144 #define __LONG_LONG_MAX__ 9223372036854775807LL\n\ | |
145 #define __PPC__ 1\n\ | |
146 #define __GXX_ABI_VERSION 1002\n\ | |
147 #define __FLT_MIN_EXP__ (-125)\n\ | |
148 #define __DBL_MIN__ 2.2250738585072014e-308\n\ | |
149 #define __DBL_HAS_QUIET_NAN__ 1\n\ | |
150 #define __REGISTER_PREFIX__ \n\ | |
151 #define __NO_INLINE__ 1\n\ | |
152 #define _ARCH_PPC 1\n\ | |
153 #define __FLT_MANT_DIG__ 24\n\ | |
154 #define __VERSION__ \"mc-powerpc\"\n\ | |
155 #define __BIG_ENDIAN__ 1\n\ | |
156 #define __powerpc__ 1\n\ | |
157 #define unix 1\n\ | |
158 #define __SIZE_TYPE__ unsigned int\n\ | |
159 #define __ELF__ 1\n\ | |
160 #define __FLT_RADIX__ 2\n\ | |
161 #define __LDBL_EPSILON__ 4.94065645841246544176568792868221e-324L\n\ | |
162 #define __GNUC_RH_RELEASE__ 3\n\ | |
163 #define __LDBL_DIG__ 31\n\ | |
164 #define __FLT_HAS_QUIET_NAN__ 1\n\ | |
165 #define __FLT_MAX_10_EXP__ 38\n\ | |
166 #define __LONG_MAX__ 2147483647L\n\ | |
167 #define __FLT_HAS_INFINITY__ 1\n\ | |
168 #define __unix 1\n\ | |
169 #define _BIG_ENDIAN 1\n\ | |
170 #define linux 1\n\ | |
171 #define __PPC 1\n\ | |
172 #define __LDBL_MANT_DIG__ 106\n\ | |
173 #define __WCHAR_TYPE__ long int\n\ | |
174 #define __FLT_DIG__ 6\n\ | |
175 #define __powerpc 1\n\ | |
176 #define __INT_MAX__ 2147483647\n\ | |
177 #define __LONG_DOUBLE_128__ 1\n\ | |
178 #define __FLT_MAX_EXP__ 128\n\ | |
179 #define __DBL_MANT_DIG__ 53\n\ | |
180 #define __WINT_TYPE__ unsigned int\n\ | |
181 #define __LDBL_MIN_EXP__ (-968)\n\ | |
182 #define __LDBL_MAX_10_EXP__ 308\n\ | |
183 #define __DBL_EPSILON__ 2.2204460492503131e-16\n\ | |
184 #define PPC 1\n\ | |
185 #define powerpc 1\n\ | |
186 #define __INTMAX_MAX__ 9223372036854775807LL\n\ | |
187 #define __FLT_DENORM_MIN__ 1.40129846e-45F\n\ | |
188 #define __FLT_MAX__ 3.40282347e+38F\n\ | |
189 #define __FLT_MIN_10_EXP__ (-37)\n\ | |
190 #define __INTMAX_TYPE__ long long int\n\ | |
191 #define __GNUC_MINOR__ 1\n\ | |
192 #define __DBL_MAX_10_EXP__ 308\n\ | |
193 #define __LDBL_DENORM_MIN__ 4.94065645841246544176568792868221e-324L\n\ | |
194 #define __STDC__ 1\n\ | |
195 #define __PTRDIFF_TYPE__ int\n\ | |
196 #define __LDBL_MIN_10_EXP__ (-291)\n\ | |
197 " | |
198 #endif | |
636 | 199 #ifdef __APPLE__ |
200 "#define __APPLE__ 1\n" | |
201 #endif | |
202 ; | |
313 | 203 |
89 | 204 #define TEXT_EMIT_MODE 0 |
205 #define DATA_EMIT_MODE 1 | |
206 #define RODATA_EMIT_MODE 2 | |
207 | |
221 | 208 static void ld_indexx(int byte, int n, int xreg,int reg,int sign); |
93 | 209 static void local_table(void); |
221 | 210 static void shift(char *op, int creg,int reg); |
444 | 211 static int push_struct(int e4,int t,int arg); |
518 | 212 static void ascii(char *s); |
213 | |
662 | 214 #ifdef __APPLE__ |
215 static char lpfx[] = "L_"; | |
216 static char npfx[] = "_"; | |
217 #else | |
218 static char lpfx[] = ".LC"; | |
219 static char npfx[] = ""; | |
220 #endif | |
93 | 221 |
555 | 222 int eval_order = NORMAL; |
341 | 223 |
221 | 224 static int creg; |
225 | |
89 | 226 static int output_mode = TEXT_EMIT_MODE; |
340 | 227 int data_alignment = 0; |
89 | 228 |
229 static int code_disp_label; | |
111 | 230 static int code_setup; |
116 | 231 static int r1_offset_label; |
232 static int lvar_offset_label; | |
313 | 233 static int max_func_arg_label; |
672 | 234 #ifndef __APPLE__ |
235 static int arg_offset_label; | |
236 #endif | |
676 | 237 static int arg_offset_v = 0; |
116 | 238 |
239 static int reg_save; | |
240 static int freg_save; | |
241 | |
205 | 242 static int freg,ireg,lreg; |
147 | 243 |
238 | 244 int code_lassop_p = 1; |
245 | |
245 | 246 #define SIZE_OF_INT 4 |
247 #define SIZE_OF_SHORT 2 | |
248 #define SIZE_OF_FLOAT 4 | |
249 #define SIZE_OF_DOUBLE 8 | |
250 #define SIZE_OF_LONGLONG 8 | |
251 #define ENDIAN 1 | |
411 | 252 #define ENDIAN_L 1 |
253 #define ENDIAN_D 1 | |
245 | 254 |
205 | 255 static int reg_sp; /* REGister Stack-Pointer */ |
724 | 256 static int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ |
138 | 257 |
258 /* floating point registers */ | |
259 | |
205 | 260 static int freg_sp; /* floating point REGister Stack-Pointer */ |
724 | 261 static int freg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ |
89 | 262 |
206 | 263 static int lreg_sp; /* longlong REGister Stack-Pointer */ |
724 | 264 static int lreg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ |
206 | 265 |
667 | 266 #ifdef __APPLE__ |
577 | 267 #define REG_sp 1 |
268 #define REG_fp 30 | |
119 | 269 #define REG_VAR_BASE 29 |
130 | 270 #define REG_VAR_MIN 18 |
119 | 271 #define MIN_TMP_REG 3 |
130 | 272 #define MAX_TMP_REG 11 |
119 | 273 |
274 #define FREG_VAR_BASE 31 | |
130 | 275 #define FREG_VAR_MIN 20 |
119 | 276 #define MIN_TMP_FREG 1 |
130 | 277 #define MAX_TMP_FREG 14 |
667 | 278 #else |
279 #define REG_sp 1 | |
280 #define REG_fp 31 | |
281 #define REG_VAR_BASE 29 | |
282 #define REG_VAR_MIN 18 | |
283 #define MIN_TMP_REG 3 | |
284 #define MAX_TMP_REG 11 | |
285 | |
286 #define FREG_VAR_BASE 31 | |
287 #define FREG_VAR_MIN 20 | |
288 #define MIN_TMP_FREG 1 | |
289 #define MAX_TMP_FREG 9 | |
290 #endif | |
119 | 291 |
724 | 292 int MAX_REGISTER=30; /* PowerPCのレジスタを10個まで使う*/ |
122 | 293 int MAX_FREGISTER=31; |
724 | 294 #define REAL_MAX_REGISTER 32 /* PowerPCのレジスタが32ということ*/ |
295 #define REAL_MAX_FREGISTER 32 /* PowerPCのレジスタが32ということ*/ | |
207 | 296 #define REAL_MAX_LREGISTER 16 |
119 | 297 |
145 | 298 #define FREG_OFFSET REAL_MAX_REGISTER |
207 | 299 #define LREG_OFFSET (REAL_MAX_REGISTER+REAL_MAX_FREGISTER) |
300 | |
301 #define RET_REGISTER 3 | |
302 #define RET_FREGISTER (1+FREG_OFFSET) | |
222 | 303 #define RET_LREGISTER_H 3 /* high word */ |
207 | 304 #define RET_LREGISTER_L 4 /* low word */ |
305 #define RET_LREGISTER LREG_OFFSET | |
145 | 306 |
122 | 307 int MAX_INPUT_REGISTER_VAR = 11-MIN_TMP_REG; |
308 int MAX_CODE_INPUT_REGISTER_VAR = 11-MIN_TMP_REG; | |
667 | 309 int MAX_INPUT_DREGISTER_VAR = MAX_TMP_FREG-MIN_TMP_FREG; |
310 int MAX_INPUT_FREGISTER_VAR = MAX_TMP_FREG-MIN_TMP_FREG; | |
311 int MAX_CODE_INPUT_DREGISTER_VAR = MAX_TMP_FREG-MIN_TMP_FREG; | |
312 int MAX_CODE_INPUT_FREGISTER_VAR = MAX_TMP_FREG-MIN_TMP_FREG; | |
119 | 313 |
207 | 314 static int powerpc_regs[REAL_MAX_REGISTER+REAL_MAX_FREGISTER+ |
315 REAL_MAX_LREGISTER]; | |
316 static int regv_h0[REAL_MAX_LREGISTER]; | |
317 static int regv_l0[REAL_MAX_LREGISTER]; | |
211 | 318 #define regv_h(i) regv_h0[(i)-LREG_OFFSET] |
319 #define regv_l(i) regv_l0[(i)-LREG_OFFSET] | |
205 | 320 |
321 static int *regs = powerpc_regs; | |
119 | 322 |
207 | 323 #define CREG_REGISTER (MAX_TMP_REG) |
324 #define FREG_FREGISTER (MAX_TMP_FREG+FREG_OFFSET) | |
325 #define LREG_LREGISTER (MAX_TMP_REG+LREG_OFFSET) | |
206 | 326 |
327 | |
119 | 328 static int max_reg_var, max_freg_var; |
329 | |
805
362b0258b4db
fix func_disp_offset in PS3
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
804
diff
changeset
|
330 #ifdef __APPLE__ |
119 | 331 static char *reg_name[] = { |
332 "r0","r1","r2","r3","r4","r5","r6","r7","r8","r9", | |
333 "r10","r11","r12","r13","r14","r15","r16","r17","r18","r19", | |
334 "r20","r21","r22","r23","r24","r25","r26","r27","r28","r29", | |
145 | 335 "r30","r31", |
119 | 336 "f0","f1","f2","f3","f4","f5","f6","f7","f8","f9", |
337 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19", | |
338 "f20","f21","f22","f23","f24","f25","f26","f27","f28","f29", | |
339 "f30","f31" | |
340 }; | |
805
362b0258b4db
fix func_disp_offset in PS3
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
804
diff
changeset
|
341 #else |
660 | 342 // PS3 (PowerPC Fedora Core) |
343 static char *reg_name[] = { | |
805
362b0258b4db
fix func_disp_offset in PS3
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
804
diff
changeset
|
344 "r0","r1","r2","r3","r4","r5","r6","r7","r8","r9", |
362b0258b4db
fix func_disp_offset in PS3
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
804
diff
changeset
|
345 "r10","r11","r12","r13","r14","r15","r16","r17","r18","r19", |
362b0258b4db
fix func_disp_offset in PS3
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
804
diff
changeset
|
346 "r20","r21","r22","r23","r24","r25","r26","r27","r28","r29", |
362b0258b4db
fix func_disp_offset in PS3
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
804
diff
changeset
|
347 "r30","r31", |
660 | 348 "0","1","2","3","4","5","6","7","8","9", |
349 "10","11","12","13","14","15","16","17","18","19", | |
350 "20","21","22","23","24","25","26","27","28","29", | |
351 "30","31" | |
352 }; | |
353 #endif | |
119 | 354 |
716 | 355 #define round4(i) align(i,4) |
356 #define round16(i) align(i,16) | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
357 |
207 | 358 #define register_name(i) reg_name[i] |
359 #define fregister_name(i) reg_name[i] | |
360 #define lregister_name_low(i) reg_name[regv_l(i)] | |
210 | 361 #define lregister_name_high(i) reg_name[regv_h(i)] |
207 | 362 |
431 | 363 #define DEBUG_REG 1 |
364 #if DEBUG_REG | |
467 | 365 char *rn(int i) { return register_name(i); } |
366 char *fn(int i) { return fregister_name(i); } | |
367 char *lln(int i) { return lregister_name_low(i); } | |
368 char *lhn(int i) { return lregister_name_high(i); } | |
369 int ll(int i) { return regv_l(i); } | |
370 int lh(int i) { return regv_h(i); } | |
431 | 371 #endif |
221 | 372 |
207 | 373 #define is_int_reg(i) (0<=i&&i<REAL_MAX_REGISTER) |
374 #define is_float_reg(i) (REAL_MAX_REGISTER<=i&&i<REAL_MAX_FREGISTER+REAL_MAX_REGISTER) | |
375 #define is_longlong_reg(i) (LREG_OFFSET<=i&&i<LREG_OFFSET+REAL_MAX_LREGISTER) | |
147 | 376 |
221 | 377 #define use_int(reg) if (reg==USE_CREG) reg=use_int0() |
378 static | |
379 int use_int0() { | |
380 int i = creg; | |
233 | 381 if (!i||!ireg||!is_int_reg(i)) { |
880 | 382 if (lreg) { if (regs[lreg]!=REG_VAR) free_register(lreg); lreg = 0; } |
383 if (!ireg) ireg = get_register(); | |
384 // else if (ireg!=i) free_register(i); | |
385 i = ireg; | |
205 | 386 } |
207 | 387 if (!regs[i]) regs[i]=USING_REG; |
221 | 388 creg = i; |
147 | 389 return i; |
390 } | |
391 | |
222 | 392 #if LONGLONG_CODE |
393 #define use_longlong(reg) if (reg==USE_CREG) reg=use_longlong0() | |
394 | |
395 static | |
396 int use_longlong0() { | |
397 int i = creg; | |
398 if (!is_longlong_reg(i)) { | |
880 | 399 if (ireg) { if (regs[ireg]!=REG_VAR) free_register(ireg); ireg=0; } |
400 if (!lreg||!regs[lreg]) lreg = get_lregister(); | |
401 // else if (lreg!=i) free_register(i); | |
402 i = lreg; | |
222 | 403 } |
404 if (!regv_l(i)) regv_l(i) = get_register(); | |
405 if (!regv_h(i)) regv_h(i) = get_register(); | |
406 if (!regs[i]) regs[i]=USING_REG; | |
407 if (!regs[regv_l(i)]) regs[regv_l(i)]=USING_REG; | |
408 if (!regs[regv_h(i)]) regs[regv_h(i)]=USING_REG; | |
409 creg = i; | |
410 return i; | |
411 } | |
412 #endif | |
413 | |
414 | |
221 | 415 #if FLOAT_CODE |
416 #define use_float(d,reg) if (reg==USE_CREG) reg=d?use_double0():use_float0() | |
417 static | |
418 int use_float0() { | |
419 int i = creg; | |
207 | 420 if (!is_float_reg(i)) { |
880 | 421 if (lreg) { if (regs[lreg]!=REG_VAR) free_register(lreg); lreg = 0; } |
422 if (!freg) freg = get_dregister(0); | |
423 else if (freg!=i) if (regs[i]!=REG_VAR) free_register(i); | |
424 i = freg; | |
207 | 425 } |
426 if (!regs[i]) regs[i]=USING_REG; | |
221 | 427 creg = i; |
147 | 428 return i; |
429 } | |
221 | 430 static |
431 int use_double0() { | |
432 int i = creg; | |
207 | 433 if (!is_float_reg(i)) { |
880 | 434 if (lreg) { if (regs[lreg]!=REG_VAR) free_register(lreg); lreg = 0; } |
435 if (!freg) freg = get_dregister(1); | |
436 else if (freg!=i) if (regs[i]!=REG_VAR) free_register(i); | |
437 i = freg; | |
207 | 438 } |
439 if (!regs[i]) regs[i]=USING_REG; | |
221 | 440 creg = i; |
147 | 441 return i; |
442 } | |
221 | 443 #endif |
444 | |
195 | 445 |
446 #if FLOAT_CODE | |
663 | 447 #ifdef __APPLE__ |
119 | 448 static |
348 | 449 NMTBL float_zero = {"_float_zero",0,STATIC,FLOAT,0}; |
119 | 450 static |
348 | 451 NMTBL float_one = {"_float_one",0,STATIC,FLOAT,0}; |
663 | 452 #else |
453 static | |
454 NMTBL float_zero = {"__float_zero",0,STATIC,FLOAT,0}; | |
455 static | |
456 NMTBL float_one = {"__float_one",0,STATIC,FLOAT,0}; | |
457 #endif | |
119 | 458 |
459 | |
460 static char * fload(int d); | |
461 static int code_d1(double d); | |
462 static int code_d2(double d); | |
195 | 463 #endif |
206 | 464 #if LONGLONG_CODE |
465 static int code_l1(long long ll); | |
466 static int code_l2(long long ll); | |
467 #endif | |
195 | 468 |
305
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
304
diff
changeset
|
469 static void code_save_input_registers(int dots); |
207 | 470 static void set_ireg(int,int); |
119 | 471 static void set_freg(int,int); |
195 | 472 static void set_lreg(int,int); |
287 | 473 static void jcond(int l, char cond); |
431 | 474 static void register_usage(char *s); |
475 | |
119 | 476 |
153 | 477 static int max_func_args; |
478 static int my_func_args; | |
119 | 479 #define ARG_LVAR_OFFSET 0x10000000 |
480 | |
126 | 481 /* |
89 | 482 |
97 | 483 r0 return value etc. |
484 r3-r10 input register | |
326 | 485 r22-r29 saved register variable (input register for code segment) |
89 | 486 r30 stack pointer |
487 r31 0 | |
488 r1 frame pointer | |
97 | 489 |
490 f0 return value etc. | |
491 f1-r8 input register | |
492 f24-f31 saved register variable | |
116 | 493 |
672 | 494 function call stack frame (Mac OS X) |
375 | 495 <-------r1_offset------------------------------> |
672 | 496 r30 |
375 | 497 <------------lvar_offset0------> |
672 | 498 <--lvar_offset--> r1 |
116 | 499 r+ +------------+---+---------------+----------+--------------+----+ - |
122 | 500 callee arg xx register save local caller arg xx |
245 | 501 reg_save disp max_func_args*SIZE_OF_INT |
119 | 502 lvar>0 lvar<0 lvar>0x1000 0000 |
127 | 503 |
672 | 504 function call stack frame (PS3) |
676 | 505 <---------------r1_offset------------------------------> |
506 r30--> | |
507 <--arg_offset--> | |
508 xxx<----------lvar_offset--> <----r1 | |
509 r+ +------+---+------+---------------+----------+--------------+----+ - | |
672 | 510 callee arg reg arg register save local caller arg xx |
511 reg_save disp max_func_args*SIZE_OF_INT | |
512 lvar>0 lvar<0 lvar>0x1000 0000 | |
513 | |
514 | |
127 | 515 code segment stack frame |
516 | |
724 | 517 * gotoを呼び出した関数のr1 ! r1(goto前のr1) |
128 | 518 # * r30 <---r1_offset---------> r1 |
127 | 519 r+ +----------+--+----------+----------------+-----------+----------+----+ |
520 cousin arg xx reg save !callee arg !code local caller arg xx | |
521 r20-r29 lvar>0 lvar<0 lvar>0x1000 000 | |
522 f20-f31 <-my_func_args--><--disp-----><-max_func_arg-> | |
245 | 523 *SIZE_OF_INT *SIZE_OF_INT |
127 | 524 |
89 | 525 */ |
667 | 526 |
527 | |
528 #ifdef __APPLE__ | |
529 | |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
530 #define arg_offset 24 |
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
531 #define arg_offset1 24 |
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
532 |
230 | 533 #define func_disp_offset 68 |
672 | 534 #define func_disp_offset1 16 |
803 | 535 #define code_disp_offset0 (-4) |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
536 |
667 | 537 #else |
538 | |
672 | 539 #define arg_offset (8) |
676 | 540 #define arg_offset0 (8) |
672 | 541 #define arg_offset1 (8) |
542 | |
805
362b0258b4db
fix func_disp_offset in PS3
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
804
diff
changeset
|
543 #define func_disp_offset (12) |
362b0258b4db
fix func_disp_offset in PS3
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
804
diff
changeset
|
544 #define code_disp_offset0 (-4) |
667 | 545 |
546 #endif | |
547 | |
803 | 548 int disp_offset = -4; |
667 | 549 |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
550 #define CODE_LVAR(l) ((l)+code_disp_offset0) |
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
551 #define CODE_CALLER_ARG(l) ((l)+arg_offset1) |
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
552 #define FUNC_LVAR(l) ((l)+disp_offset) |
676 | 553 #ifdef __APPLE__ |
672 | 554 #define CALLEE_ARG(l) ((l)+arg_offset) |
676 | 555 #else |
556 #define CALLEE_ARG(l) ((l)+arg_offset+((l>=arg_offset_v)?arg_offset0:0)) | |
557 #endif | |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
558 #define CALLER_ARG(l) ((l)+arg_offset1) |
89 | 559 |
647 | 560 |
116 | 561 void |
562 code_offset_set() | |
563 { | |
126 | 564 #if 0 |
121 | 565 int l; |
126 | 566 #endif |
647 | 567 int lvar_offsetv = |
880 | 568 round16(-disp+max_func_args*SIZE_OF_INT)+func_disp_offset; |
676 | 569 int r1_offsetv = round16(lvar_offsetv-reg_save); |
647 | 570 |
662 | 571 printf(".set %s%d,%d\n",lpfx,lvar_offset_label,r1_offsetv-lvar_offsetv); |
577 | 572 if (r1_offsetv-lvar_offsetv > 65000) error(-1); |
880 | 573 // too large function arguments? |
662 | 574 printf(".set %s%d,%d\n",lpfx,r1_offset_label,r1_offsetv); |
313 | 575 if (max_func_arg_label) { |
880 | 576 printf(".set %s%d,%d\n",lpfx,max_func_arg_label, |
577 round16(max_func_args*SIZE_OF_INT)+24); | |
578 max_func_arg_label = 0; | |
313 | 579 } |
580 | |
417 | 581 #if 0 |
468 | 582 printf("## reg_save %d\n",reg_save); |
583 printf("## function %s\n",fnptr->nm); | |
121 | 584 l = ARG_LVAR_OFFSET; |
468 | 585 printf("## offset call0\t%d\n",CALLER_ARG); |
245 | 586 l = ARG_LVAR_OFFSET+max_func_args*SIZE_OF_INT; |
468 | 587 printf("## offset calln\t%d %d\n",CALLER_ARG,max_func_args*SIZE_OF_INT); |
121 | 588 l = disp; |
468 | 589 printf("## offset lvarn\t%d %d\n",FUNC_LVAR+lvar_offsetv,disp); |
121 | 590 l = 0; |
468 | 591 printf("## offset lvar0\t%d\n",FUNC_LVAR+lvar_offsetv); |
121 | 592 l = -reg_save; |
468 | 593 printf("## offset regs\t%d\n",FUNC_LVAR+lvar_offsetv); |
594 printf("## offset r1off\t%d\n",r1_offsetv); | |
121 | 595 l = 0; |
468 | 596 printf("## offset carg0\t%d\n",CALLEE_ARG+r1_offsetv); |
121 | 597 l = my_func_args; |
468 | 598 printf("## offset cargn\t%d %d\n",CALLEE_ARG+r1_offsetv,my_func_args); |
126 | 599 #endif |
116 | 600 } |
111 | 601 |
375 | 602 static int large_offset_reg; |
119 | 603 |
660 | 604 #ifdef __APPLE__ |
605 | |
119 | 606 static void |
375 | 607 lvar(int l) |
116 | 608 { |
375 | 609 char *rn; |
610 if (!large_offset_reg) { | |
880 | 611 if (is_code(fnptr)) { |
612 if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ | |
613 printf("lo16(%d)(r1)\n",CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); | |
614 } else | |
615 printf("lo16(%d)(r30)\n",CODE_LVAR(l)); | |
616 } else if (l<0) { /* local variable */ | |
617 printf("lo16(%d)(r30)\n",FUNC_LVAR(l)); | |
618 } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ | |
619 printf("lo16(%d)(r1)\n",CALLER_ARG(l-ARG_LVAR_OFFSET)); | |
620 } else { /* callee's arguments */ | |
621 printf("lo16(%d+%s%d)(r30)\n",CALLEE_ARG(l),lpfx,lvar_offset_label); | |
622 } | |
375 | 623 } else { |
624 rn = register_name(large_offset_reg); | |
544 | 625 if (is_code(fnptr)) { |
375 | 626 if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
627 printf("lo16(%d)(%s)\n",CODE_CALLER_ARG(l-ARG_LVAR_OFFSET),rn); |
375 | 628 } else |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
629 printf("lo16(%d)(%s)\n",CODE_LVAR(l),rn); |
375 | 630 } else if (l<0) { /* local variable */ |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
631 printf("lo16(%d)(%s)\n",FUNC_LVAR(l),rn); |
375 | 632 } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
633 printf("lo16(%d)(%s)\n",CALLER_ARG(l-ARG_LVAR_OFFSET),rn); |
375 | 634 } else { /* callee's arguments */ |
662 | 635 printf("lo16(%d+%s%d)(%s)\n",CALLEE_ARG(l),lpfx,lvar_offset_label,rn); |
375 | 636 } |
637 free_register(large_offset_reg); | |
116 | 638 } |
639 } | |
111 | 640 |
119 | 641 /* if size of local variables / input variables is more then 64k, |
642 lo16 does not work. We have to use ha16 also. But we can't know | |
643 the exact size in one path compile. We may safely use lvar16ha | |
326 | 644 if disp or max_func_args > 32k. Of course this is redundant for |
119 | 645 smaller offset. But who cares who use very large local variables? |
646 */ | |
96 | 647 |
375 | 648 #define LARGE_OFFSET(l) (l<-32000||l>32000) |
95 | 649 |
119 | 650 static void |
375 | 651 lvar_intro(int l) |
119 | 652 { |
375 | 653 char *rn; |
654 large_offset_reg=0; | |
544 | 655 if (is_code(fnptr)) { |
375 | 656 if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
657 if (LARGE_OFFSET(CODE_CALLER_ARG(l-ARG_LVAR_OFFSET))) { |
375 | 658 rn=register_name(large_offset_reg=get_register()); |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
659 printf("\taddis %s,r1,ha16(%d)\n",rn, |
880 | 660 CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); |
375 | 661 } |
662 } else { | |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
663 if (LARGE_OFFSET(CODE_LVAR(l))) { |
375 | 664 rn=register_name(large_offset_reg=get_register()); |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
665 printf("\taddis %s,r30,ha16(%d)\n",rn,CODE_LVAR(l)); |
375 | 666 } |
667 } | |
119 | 668 } else if (l<0) { /* local variable */ |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
669 if (LARGE_OFFSET(FUNC_LVAR(l))) { |
375 | 670 rn=register_name(large_offset_reg=get_register()); |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
671 printf("\taddis %s,r30,ha16(%d)\n",rn,FUNC_LVAR(l)); |
375 | 672 } |
125 | 673 } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
674 if (LARGE_OFFSET(CALLER_ARG(l-ARG_LVAR_OFFSET))) { |
375 | 675 rn=register_name(large_offset_reg=get_register()); |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
676 printf("\taddis %s,r1,ha16(%d)\n",rn,CALLER_ARG(l-ARG_LVAR_OFFSET)); |
375 | 677 } |
119 | 678 } else { /* callee's arguments */ |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
679 if (LARGE_OFFSET(CALLEE_ARG(l))) { |
375 | 680 rn=register_name(large_offset_reg=get_register()); |
662 | 681 printf("\taddis %s,r30,ha16(%d+%s%d)\n", |
880 | 682 rn,CALLEE_ARG(l),lpfx,lvar_offset_label); |
375 | 683 } |
119 | 684 } |
685 } | |
89 | 686 |
660 | 687 #else /* PS3 */ |
688 | |
689 static void | |
690 lvar(int l) | |
691 { | |
692 char *rn; | |
693 if (!large_offset_reg) { | |
880 | 694 if (is_code(fnptr)) { |
695 if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ | |
696 printf("%d@l(1)\n",CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); | |
697 } else | |
698 printf("%d@l(%d)\n",CODE_LVAR(l),REG_fp); | |
699 } else if (l<0) { /* local variable */ | |
700 printf("%d@l(%d)\n",FUNC_LVAR(l),REG_fp); | |
701 } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ | |
702 printf("%d@l(1)\n",CALLER_ARG(l-ARG_LVAR_OFFSET)); | |
703 } else { /* callee's arguments */ | |
672 | 704 printf("%d+%s%d@l(%d)\n",CALLEE_ARG(l),lpfx,lvar_offset_label,REG_fp) ; |
880 | 705 } |
660 | 706 } else { |
707 rn = register_name(large_offset_reg); | |
708 if (is_code(fnptr)) { | |
709 if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ | |
710 printf("%d@l(%s)\n",CODE_CALLER_ARG(l-ARG_LVAR_OFFSET),rn); | |
711 } else | |
712 printf("%d@l(%s)\n",CODE_LVAR(l),rn); | |
713 } else if (l<0) { /* local variable */ | |
714 printf("%d@l(%s)\n",FUNC_LVAR(l),rn); | |
715 } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ | |
716 printf("%d@l(%s)\n",CALLER_ARG(l-ARG_LVAR_OFFSET),rn); | |
717 } else { /* callee's arguments */ | |
662 | 718 printf("%d+%s%d@l(%s)\n",CALLEE_ARG(l),lpfx,lvar_offset_label,rn); |
660 | 719 } |
720 free_register(large_offset_reg); | |
721 } | |
722 } | |
723 | |
724 /* if size of local variables / input variables is more then 64k, | |
725 lo16 does not work. We have to use ha16 also. But we can't know | |
726 the exact size in one path compile. We may safely use lvar16ha | |
727 if disp or max_func_args > 32k. Of course this is redundant for | |
728 smaller offset. But who cares who use very large local variables? | |
729 */ | |
730 | |
731 #define LARGE_OFFSET(l) (l<-32000||l>32000) | |
732 | |
733 static void | |
734 lvar_intro(int l) | |
735 { | |
736 char *rn; | |
737 large_offset_reg=0; | |
738 if (is_code(fnptr)) { | |
739 if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ | |
740 if (LARGE_OFFSET(CODE_CALLER_ARG(l-ARG_LVAR_OFFSET))) { | |
741 rn=register_name(large_offset_reg=get_register()); | |
673 | 742 printf("\taddis %s,1,%d@ha\n",rn, |
880 | 743 CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); |
660 | 744 } |
745 } else { | |
746 if (LARGE_OFFSET(CODE_LVAR(l))) { | |
747 rn=register_name(large_offset_reg=get_register()); | |
673 | 748 printf("\taddis %s,%d,%d@ha\n",rn,REG_fp,CODE_LVAR(l)); |
660 | 749 } |
750 } | |
751 } else if (l<0) { /* local variable */ | |
752 if (LARGE_OFFSET(FUNC_LVAR(l))) { | |
753 rn=register_name(large_offset_reg=get_register()); | |
673 | 754 printf("\taddis %s,%d,%d@ha\n",rn,REG_fp,FUNC_LVAR(l)); |
660 | 755 } |
756 } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ | |
757 if (LARGE_OFFSET(CALLER_ARG(l-ARG_LVAR_OFFSET))) { | |
758 rn=register_name(large_offset_reg=get_register()); | |
673 | 759 printf("\taddis %s,1,%d@ha\n",rn,CALLER_ARG(l-ARG_LVAR_OFFSET)); |
660 | 760 } |
761 } else { /* callee's arguments */ | |
762 if (LARGE_OFFSET(CALLEE_ARG(l))) { | |
763 rn=register_name(large_offset_reg=get_register()); | |
673 | 764 printf("\taddis %s,%d,%d+%s%d@ha\n", |
672 | 765 rn,REG_fp,CALLEE_ARG(l),lpfx,lvar_offset_label); |
660 | 766 } |
767 } | |
768 } | |
769 #endif | |
89 | 770 |
119 | 771 void |
221 | 772 code_lvar(int e2,int reg) { |
773 use_int(reg); | |
119 | 774 lvar_intro(e2); |
221 | 775 printf("\tla %s,",register_name(reg)); |
119 | 776 lvar(e2); |
777 } | |
95 | 778 |
89 | 779 void |
780 code_init(void) | |
781 { | |
327 | 782 /* called only once */ |
783 | |
784 init_src = init_src0; | |
785 size_of_int = SIZE_OF_INT; | |
715 | 786 size_of_pointer = SIZE_OF_INT; |
327 | 787 size_of_short = SIZE_OF_SHORT; |
788 size_of_float = SIZE_OF_FLOAT; | |
789 size_of_double = SIZE_OF_DOUBLE; | |
790 size_of_longlong = SIZE_OF_LONGLONG; | |
791 endian = ENDIAN; | |
717 | 792 struct_align = size_of_int; |
327 | 793 |
207 | 794 regv_l(RET_LREGISTER) = RET_LREGISTER_L; |
795 regv_h(RET_LREGISTER) = RET_LREGISTER_H; | |
89 | 796 } |
797 | |
327 | 798 extern void |
799 emit_reinit() | |
800 { | |
801 /* called for each file */ | |
328 | 802 /* heap is initialized here, setup ptr cache free list */ |
605 | 803 output_mode = -1; |
328 | 804 init_ptr_cache(); |
327 | 805 } |
806 | |
89 | 807 void |
808 gexpr_code_init(void){ | |
96 | 809 } |
810 | |
147 | 811 void |
812 code_gexpr(int e){ | |
590 | 813 if ((is_int_reg(creg))&®s[creg]==REG_VAR) |
814 creg = ireg = 0; | |
815 else if (is_float_reg(creg)&®s[creg]==REG_VAR) | |
816 creg = lreg = 0; | |
817 else if (is_longlong_reg(creg)&®s[creg]==REG_VAR) | |
818 creg = lreg = 0; | |
819 // if (is_int_reg(creg) && creg!=ireg) error(-1); | |
147 | 820 } |
821 | |
676 | 822 /* |
823 set variable storage type and offset | |
824 save register contents to our stack | |
825 for & operator | |
826 */ | |
89 | 827 |
109 | 828 void |
794
032dc03be02e
i64 arg_register in inline mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
784
diff
changeset
|
829 code_arg_register(NMTBL *fnptr, int in) |
109 | 830 { |
137 | 831 int args = fnptr->dsp; |
832 NMTBL *n; | |
833 int reg_var = 0; | |
834 int freg_var = 0; | |
835 int type; | |
836 int reg; | |
207 | 837 int i; |
137 | 838 int is_code0 = is_code(fnptr); |
305
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
304
diff
changeset
|
839 int dots; |
676 | 840 arg_offset_v = 0; |
825
425768eb5e9e
code segment fix for non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
809
diff
changeset
|
841 int offset = 0; |
305
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
304
diff
changeset
|
842 |
809 | 843 function_type(fnptr->ty,&dots); |
844 | |
845 if (dots && (in || !parse_mode)) { | |
846 type = INT; | |
847 mode = LDECL; | |
848 stmode = 0; | |
849 n = def(lsearch("__my_va_list",0),0); | |
880 | 850 n->dsp = 0; // first argument |
809 | 851 } |
794
032dc03be02e
i64 arg_register in inline mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
784
diff
changeset
|
852 if (in) return; |
032dc03be02e
i64 arg_register in inline mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
784
diff
changeset
|
853 |
137 | 854 while (args) { |
855 /* process in reverse order */ | |
712 | 856 n = ncadddr(args); |
137 | 857 type = n->ty; |
880 | 858 int sz = size(type); |
825
425768eb5e9e
code segment fix for non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
809
diff
changeset
|
859 offset = code_arg_alignment(offset,n,type,sz,is_code0); |
137 | 860 if (scalar(type)) { |
861 if ((reg = get_input_register_var(reg_var,n,is_code0))) { | |
862 n->sc = REGISTER; | |
207 | 863 n->dsp = cadr(reg); |
864 regs[n->dsp]= INPUT_REG; | |
137 | 865 reg_var++; |
880 | 866 arg_offset_v += (caddr(args)=SIZE_OF_INT); |
137 | 867 } |
138 | 868 } else if (type==FLOAT) { |
869 if ((reg = get_input_dregister_var(freg_var,n,is_code0,0))) { | |
870 n->sc = DREGISTER; | |
207 | 871 n->dsp = cadr(reg); |
872 regs[n->dsp]= INPUT_REG; | |
138 | 873 freg_var++; |
880 | 874 arg_offset_v += (caddr(args)=size(type)); |
138 | 875 } |
876 } else if (type==DOUBLE) { | |
877 if ((reg = get_input_dregister_var(freg_var,n,is_code0,1))) { | |
137 | 878 n->sc = DREGISTER; |
207 | 879 n->dsp = cadr(reg); |
880 regs[n->dsp]= INPUT_REG; | |
137 | 881 freg_var++; |
880 | 882 arg_offset_v += (caddr(args)=size(type)); |
205 | 883 } |
884 } else if (type==LONGLONG||type==ULONGLONG) { | |
885 if ((reg = get_input_lregister_var(reg_var,n,is_code0))) { | |
886 n->sc = LREGISTER; | |
207 | 887 n->dsp = cadr(reg); |
888 regs[i=n->dsp]= INPUT_REG; | |
889 regs[regv_l(i)]= INPUT_REG; | |
890 regs[regv_h(i)]= INPUT_REG; | |
205 | 891 reg_var+=2; |
880 | 892 arg_offset_v += (caddr(args)=size(type)); |
137 | 893 } |
894 } | |
895 args = cadr(args); | |
896 } | |
672 | 897 if (is_function(fnptr)) { |
898 #ifndef __APPLE__ | |
880 | 899 if (dots) { |
900 arg_offset_v = | |
901 MAX_INPUT_REGISTER_VAR*SIZE_OF_INT + | |
902 MAX_INPUT_DREGISTER_VAR*SIZE_OF_DOUBLE; | |
903 } | |
904 printf(".set %s%d, %d\n",lpfx, arg_offset_label, | |
905 arg_offset_v+ arg_offset); | |
906 #endif | |
907 code_save_input_registers(dots); | |
672 | 908 } |
109 | 909 } |
910 | |
208 | 911 |
89 | 912 int |
210 | 913 get_register(void) |
724 | 914 { /* 使われていないレジスタを調べる */ |
219 | 915 int i,j,reg; |
96 | 916 for(i=MAX_TMP_REG;i>MIN_TMP_REG;i--) { |
880 | 917 if (regs[i]) continue; /* 使われている */ |
918 regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ | |
919 return i; /* その場所を表す番号を返す */ | |
724 | 920 } |
921 /* PTR_CACHE をつぶす */ | |
341 | 922 if ((i=last_ptr_cache())) { |
880 | 923 clear_ptr_cache_reg(i); |
924 regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ | |
925 return i; /* その場所を表す番号を返す */ | |
96 | 926 } |
927 /* search register stack */ | |
928 for(i=0;i<reg_sp;i++) { | |
880 | 929 if ((reg=reg_stack[i])>=0) { |
96 | 930 code_assign_lvar( |
245 | 931 (j=new_lvar(SIZE_OF_INT)),reg,0); |
219 | 932 reg_stack[i]= j-REG_LVAR_OFFSET; |
880 | 933 return reg; |
934 } | |
89 | 935 } |
206 | 936 #if LONGLONG_CODE |
937 /* search register stack */ | |
938 for(i=0;i<lreg_sp;i++) { | |
880 | 939 if ((reg=lreg_stack[i])>=0) { |
219 | 940 code_lassign_lvar( |
245 | 941 (j=new_lvar(SIZE_OF_LONGLONG)),reg); |
219 | 942 lreg_stack[i]= j-REG_LVAR_OFFSET; |
880 | 943 free_register(reg); |
944 return get_register(); | |
945 } | |
206 | 946 } |
947 #endif | |
130 | 948 for(i=0;i<REG_VAR_BASE-REG_VAR_MIN;i++) { |
949 reg =REG_VAR_BASE-i; | |
724 | 950 if (! regs[reg]) { /* 使われていないなら */ |
951 regs[reg]=USING_REG; /* そのレジスタを使うことを宣言し */ | |
880 | 952 if (i>max_reg_var) max_reg_var=i; |
953 return reg; /* その場所を表す番号を返す */ | |
130 | 954 } |
955 } | |
724 | 956 /* 空いている場所がないなら、エラー (いったい誰が使ってるの?) */ |
528 | 957 error(RGERR); return creg; |
89 | 958 } |
959 | |
210 | 960 #if 0 |
208 | 961 int |
962 get_register(void) | |
963 { | |
964 int i = get_register0(); | |
468 | 965 printf("## get_register %d\n",i); |
208 | 966 return i; |
967 } | |
210 | 968 #endif |
208 | 969 |
93 | 970 int |
971 pop_register(void) | |
724 | 972 { /* レジスタから値を取り出す */ |
93 | 973 return reg_stack[--reg_sp]; |
974 } | |
975 | |
195 | 976 #if FLOAT_CODE |
96 | 977 int |
210 | 978 get_dregister(int d) |
724 | 979 { /* 使われていないレジスタを調べる */ |
103 | 980 int i,reg; |
145 | 981 for(i=MAX_TMP_FREG+FREG_OFFSET;i>MIN_TMP_FREG+FREG_OFFSET;i--) { |
880 | 982 if (regs[i]) continue; /* 使われている */ |
983 regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ | |
984 return i; /* その場所を表す番号を返す */ | |
102 | 985 } |
96 | 986 /* search register stack */ |
987 for(i=0;i<freg_sp;i++) { | |
880 | 988 if ((reg=freg_stack[i])>=0) { |
96 | 989 code_dassign_lvar( |
245 | 990 (freg_stack[i]=new_lvar(SIZE_OF_DOUBLE)),reg,1); |
96 | 991 freg_stack[i]= freg_stack[i]-REG_LVAR_OFFSET; |
880 | 992 return reg; |
993 } | |
96 | 994 } |
130 | 995 for(i=0;i<FREG_VAR_BASE-REG_VAR_MIN;i++) { |
145 | 996 reg =FREG_VAR_BASE-i+FREG_OFFSET; |
724 | 997 if (! regs[reg]) { /* 使われていないなら */ |
998 regs[reg]=USING_REG; /* そのレジスタを使うことを宣言し */ | |
880 | 999 if (i>max_freg_var) max_freg_var=i; |
1000 return reg; /* その場所を表す番号を返す */ | |
130 | 1001 } |
1002 } | |
724 | 1003 /* 空いている場所がないなら、エラー (いったい誰が使ってるの?) */ |
98 | 1004 error(REG_ERR); return freg; |
96 | 1005 } |
1006 | |
210 | 1007 #if 0 |
208 | 1008 int |
1009 get_dregister(int d) | |
1010 { | |
1011 int i = get_dregister0(d); | |
468 | 1012 printf("## get_dregister %d\n",i); |
208 | 1013 return i; |
1014 } | |
210 | 1015 #endif |
208 | 1016 |
96 | 1017 int |
97 | 1018 pop_fregister(void) |
724 | 1019 { /* レジスタから値を取り出す */ |
96 | 1020 return freg_stack[--freg_sp]; |
1021 } | |
195 | 1022 #endif |
1023 | |
530 | 1024 |
195 | 1025 int |
207 | 1026 get_lregister0() |
1027 { | |
1028 int i; | |
1029 for(i=LREG_OFFSET+1;i<REAL_MAX_LREGISTER+LREG_OFFSET;i++) { | |
880 | 1030 if (regs[i]==0) { |
1031 return i; | |
1032 } | |
207 | 1033 } |
1034 return -1; | |
1035 } | |
1036 | |
530 | 1037 static int |
1038 get_lregister1(int n,int m) | |
1039 { | |
1040 int i; | |
1041 #if 1 | |
1042 for(i=LREG_OFFSET;i<REAL_MAX_LREGISTER+LREG_OFFSET;i++) { | |
880 | 1043 if (regv_l(i)==n && regv_h(i)==m) { |
1044 return i; | |
1045 } | |
530 | 1046 } |
1047 #endif | |
1048 return get_lregister0(); | |
1049 } | |
1050 | |
1051 | |
1052 static void | |
1053 cleanup_lregister0() | |
1054 { | |
1055 int i; | |
536 | 1056 // we should not have this, but powerpc's function |
1057 // lost some input register variables. | |
530 | 1058 #if 1 |
1059 for(i=LREG_OFFSET+1;i<REAL_MAX_LREGISTER+LREG_OFFSET;i++) { | |
880 | 1060 if (regs[i]) { |
1061 if(!regv_l(i) && !regv_h(i)) { | |
1062 regs[i]=0; | |
1063 // printf("## cleanup lreg 0 %d\n",i); | |
1064 } else if(!regs[regv_l(i)] && !regs[regv_h(i)]) { | |
1065 free_register(i); | |
1066 // printf("## cleanup lreg 1 %d\n",i); | |
1067 } | |
1068 } | |
530 | 1069 } |
1070 #endif | |
1071 } | |
1072 | |
207 | 1073 int |
205 | 1074 get_lregister() |
1075 { | |
207 | 1076 int h,l,i; |
1077 i = get_lregister0(); | |
1078 if (i==-1) return -1; | |
220 | 1079 h = get_register(); |
1080 if (h==-1) return -1; | |
1081 regv_h(i) = h; | |
1082 l = get_register(); | |
590 | 1083 if (l==-1) { |
880 | 1084 if (regs[h]!=REG_VAR) free_register(h); |
1085 if (regs[i]!=REG_VAR) free_register(i); | |
1086 return -1; | |
590 | 1087 } |
220 | 1088 regv_l(i) = l; |
590 | 1089 if (!regs[i]) regs[i]=USING_REG; |
530 | 1090 // printf("## get_lregister %d %s %s\n",i, lregister_name_high(i), lregister_name_low(i)); |
220 | 1091 return i; |
205 | 1092 } |
1093 | |
1094 int | |
195 | 1095 get_lregister_var(NMTBL *n) |
1096 { | |
207 | 1097 int i,j,ll; |
206 | 1098 int max_reg_var_save=max_reg_var; |
207 | 1099 ll = get_lregister0(); |
255 | 1100 if (ll==-1) goto not_found; |
207 | 1101 if (regs[ll]==0) { |
880 | 1102 for(i=0;i<REG_VAR_BASE-REG_VAR_MIN;i++) { |
1103 if (! regs[REG_VAR_BASE-i]) { /* 使われていないなら */ | |
1104 /* そのレジスタを使うことを宣言し */ | |
1105 regs[REG_VAR_BASE-i]=USING_REG; | |
1106 if (i>max_reg_var) max_reg_var=i; | |
1107 for(j=0;j<REG_VAR_BASE-REG_VAR_MIN;j++) { | |
1108 if (! regs[REG_VAR_BASE-j]) { | |
1109 /* 使われていないなら */ | |
1110 /* そのレジスタを使うことを宣言し */ | |
1111 regs[REG_VAR_BASE-j]=REG_VAR; | |
1112 if (j>max_reg_var) max_reg_var=j; | |
1113 /* その場所を表す番号を返す */ | |
1114 regs[ll]=REG_VAR; | |
1115 regv_l(ll) = REG_VAR_BASE-j; | |
1116 regv_h(ll) = REG_VAR_BASE-i; | |
1117 return list3n(LREGISTER,ll,n); | |
1118 } | |
1119 } | |
1120 /* ひとつしかなかった */ | |
1121 regs[REG_VAR_BASE-i]=0; | |
1122 max_reg_var=max_reg_var_save; | |
1123 goto not_found; | |
1124 } | |
1125 } | |
206 | 1126 } |
207 | 1127 not_found: |
711 | 1128 return list3n(LVAR,new_lvar(SIZE_OF_LONGLONG),0); |
195 | 1129 } |
96 | 1130 |
93 | 1131 void |
1132 emit_pop_free(int xreg) | |
1133 { | |
590 | 1134 if (xreg>=0 && xreg!=creg && regs[xreg]!=REG_VAR) |
880 | 1135 free_register(xreg); |
93 | 1136 } |
1137 | |
211 | 1138 void |
1139 | |
724 | 1140 free_register(int i) { /* いらなくなったレジスタを開放 */ |
590 | 1141 // printf("## free_register %d\n",i); |
207 | 1142 if (is_longlong_reg(i)) { |
880 | 1143 regs[regv_l(i)]=0; |
1144 regs[regv_h(i)]=0; | |
206 | 1145 } |
530 | 1146 regs[i]=0; |
96 | 1147 } |
1148 | |
341 | 1149 extern void |
1150 use_ptr_cache(int r) | |
1151 { | |
1152 regs[r]=PTRC_REG; | |
1153 } | |
1154 | |
89 | 1155 int |
138 | 1156 get_input_dregister_var(int i,NMTBL *n,int is_code,int d) |
99 | 1157 { |
126 | 1158 if (is_code) { |
880 | 1159 if(!(i<FREG_VAR_BASE-FREG_VAR_MIN)) return 0; |
1160 i = FREG_VAR_BASE-i+FREG_OFFSET; | |
126 | 1161 } else { |
880 | 1162 if (i<0||i>=MAX_INPUT_DREGISTER_VAR) return 0; |
1163 i = i+MIN_TMP_FREG+FREG_OFFSET; | |
126 | 1164 } |
711 | 1165 return list3n(DREGISTER,i,n); |
205 | 1166 } |
1167 | |
1168 int | |
1169 get_input_lregister_var(int i,NMTBL *n,int is_code) | |
1170 { | |
207 | 1171 int ll; |
1172 if (i!=-1) { | |
880 | 1173 if (is_code) { |
1174 if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0; | |
1175 i = REG_VAR_BASE-i; | |
1176 } else { | |
1177 if (i<0||i>=MAX_INPUT_REGISTER_VAR) return 0; | |
674 | 1178 #ifndef __APPLE__ |
673 | 1179 if (i%2==1) i++; |
674 | 1180 #endif |
880 | 1181 i = i+MIN_TMP_REG; |
1182 } | |
1183 ll = get_lregister1(i,i+1); | |
411 | 1184 #if ENDIAN_L==0 |
880 | 1185 regv_l(ll)=i; |
1186 regv_h(ll)=i+1; | |
411 | 1187 #else |
880 | 1188 regv_h(ll)=i; |
1189 regv_l(ll)=i+1; | |
411 | 1190 #endif |
207 | 1191 } else { error(-1); ll=LREG_OFFSET+2; } |
711 | 1192 return list3n(LREGISTER,ll,n); |
99 | 1193 } |
1194 | |
1195 int | |
126 | 1196 get_input_register_var(int i,NMTBL *n,int is_code) |
99 | 1197 { |
126 | 1198 if (is_code) { |
880 | 1199 if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0; |
1200 i = REG_VAR_BASE-i; | |
126 | 1201 } else { |
880 | 1202 if (i<0||i>=MAX_INPUT_REGISTER_VAR) return 0; |
1203 i = i+MIN_TMP_REG; | |
135 | 1204 } |
711 | 1205 return list3n(REGISTER,i,n); |
135 | 1206 } |
1207 | |
145 | 1208 /* double register case? */ |
1209 | |
135 | 1210 int |
1211 get_input_register_var_1(int i,NMTBL *n,int is_code) | |
1212 { | |
1213 if (is_code) { | |
880 | 1214 if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0; |
1215 i = REG_VAR_BASE-i; | |
135 | 1216 } else { |
880 | 1217 if (i<0||i>=MAX_INPUT_REGISTER_VAR+1) return 0; |
1218 i = i+MIN_TMP_REG; | |
126 | 1219 } |
711 | 1220 return list3n(REGISTER,i,n); |
99 | 1221 } |
1222 | |
1223 int | |
137 | 1224 free_register_count(int d) |
103 | 1225 { |
1226 int i,count,fcount; | |
1227 fcount = count = 0; | |
1228 for(i=0;i<MAX_REGISTER;i++) { | |
205 | 1229 if (! regs[i]) count++; |
103 | 1230 } |
1231 for(i=0;i<MAX_FREGISTER;i++) { | |
205 | 1232 if (! regs[i+FREG_OFFSET]) fcount++; |
103 | 1233 } |
468 | 1234 printf("## free reg %d freg %d\n",count,fcount); |
137 | 1235 return d?fcount:count; |
103 | 1236 } |
1237 | |
205 | 1238 #if 0 |
1239 static int | |
89 | 1240 register_full(void) |
1241 { | |
1242 int i; | |
1243 for(i=0;i<MAX_REGISTER;i++) { | |
880 | 1244 if (! regs[i]) { |
1245 return 0; | |
1246 } | |
89 | 1247 } |
1248 return 1; | |
1249 } | |
205 | 1250 #endif |
89 | 1251 |
1252 void | |
1253 free_all_register(void) | |
1254 { | |
1255 int i; | |
468 | 1256 // printf("## free_all register\n"); |
206 | 1257 #if LONGLONG_CODE |
226 | 1258 for(i=0;i<REAL_MAX_LREGISTER;i++) { |
880 | 1259 regs[i+LREG_OFFSET]=0; |
1260 regv_l(i+LREG_OFFSET) = 0; | |
1261 regv_h(i+LREG_OFFSET) = 0; | |
226 | 1262 } |
206 | 1263 lreg = 0; |
222 | 1264 // set_lreg(LREG_LREGISTER,0); |
206 | 1265 #endif |
205 | 1266 for(i=0;i<MAX_REGISTER;i++) { regs[i]=0; } |
1267 for(i=0;i<MAX_FREGISTER;i++) { regs[i+FREG_OFFSET]=0; } | |
195 | 1268 #if FLOAT_CODE |
138 | 1269 freg = get_dregister(1); |
195 | 1270 set_freg(FREG_FREGISTER,0); |
1271 #endif | |
1272 ireg = creg = get_register(); | |
207 | 1273 set_ireg(CREG_REGISTER,0); |
89 | 1274 return; |
1275 } | |
1276 | |
345 | 1277 extern int |
1278 code_register_overlap(int s,int t) | |
1279 { | |
1280 switch(car(s)) { | |
1281 case REGISTER: | |
880 | 1282 switch(car(t)) { |
1283 case DREGISTER: case FREGISTER: break; | |
1284 case REGISTER: | |
1285 if(cadr(s)==cadr(t)) return 1; | |
1286 break; | |
1287 case LREGISTER: | |
1288 if(cadr(s)==regv_l(cadr(t))) return 1; | |
1289 if(cadr(s)==regv_h(cadr(t))) return 1; | |
1290 break; | |
1291 } | |
1292 break; | |
345 | 1293 case DREGISTER: |
1294 case FREGISTER: | |
880 | 1295 switch(car(t)) { |
1296 case REGISTER: case LREGISTER: break; | |
1297 case DREGISTER: case FREGISTER: | |
1298 if(cadr(s)==cadr(t)) return 1; | |
1299 break; | |
1300 } | |
1301 break; | |
345 | 1302 case LREGISTER: |
880 | 1303 switch(car(t)) { |
1304 case DREGISTER: case FREGISTER: break; | |
1305 case REGISTER: | |
1306 if(cadr(t)==regv_l(cadr(s))) return 1; | |
1307 if(cadr(t)==regv_h(cadr(s))) return 1; | |
1308 break; | |
1309 case LREGISTER: | |
1310 if(regv_l(cadr(t))==regv_l(cadr(s))) return 1; | |
1311 if(regv_l(cadr(t))==regv_h(cadr(s))) return 1; | |
1312 if(regv_h(cadr(t))==regv_l(cadr(s))) return 1; | |
1313 if(regv_h(cadr(t))==regv_h(cadr(s))) return 1; | |
1314 break; | |
1315 } | |
1316 break; | |
345 | 1317 } |
1318 return 0; | |
1319 } | |
1320 | |
531 | 1321 // int lreg_count; |
530 | 1322 |
89 | 1323 void |
1324 register_usage(char *s) | |
1325 { | |
207 | 1326 #if 1 |
273 | 1327 int i,j; |
1328 #endif | |
1329 #define USAGE_MAX 4 | |
1330 if (!lsrc) return; | |
467 | 1331 printf("## %d: %s:",lineno,s); |
273 | 1332 if (ireg) printf(" creg=%s",register_name(ireg)); |
1333 if (freg) printf(" freg=%s",fregister_name(freg)); | |
1334 if (lreg) printf(" lreg=%s,%s",lregister_name_high(lreg), | |
880 | 1335 lregister_name_low(lreg)); |
273 | 1336 #if 1 |
1337 for(j=0,i=0;i<MAX_REGISTER;i++) if (regs[i]) j++; | |
1338 if (j>USAGE_MAX) { | |
880 | 1339 printf("\n## regs(%d):",j); |
1340 for(i=0;i<MAX_REGISTER;i++) { printf("%d",regs[i]); } | |
273 | 1341 } |
1342 if (reg_sp>0) { | |
880 | 1343 printf(" stack "); |
1344 for(i=reg_sp;i>0;i--) { | |
1345 if(reg_stack[i-1]>=0) { | |
1346 printf(" %s",register_name(reg_stack[i-1])); | |
273 | 1347 } else |
880 | 1348 printf(",%d",reg_stack[i-1]); |
1349 } | |
273 | 1350 } |
1351 for(j=0,i=0;i<MAX_FREGISTER;i++) if (regs[i+FREG_OFFSET]) j++; | |
1352 if (j>USAGE_MAX) { | |
880 | 1353 printf("\n## freg(%d):",j); |
1354 for(i=0;i<MAX_FREGISTER;i++) { printf("%d",regs[i+FREG_OFFSET]); } | |
273 | 1355 } |
1356 if (freg_sp>0) { | |
880 | 1357 printf(" fstack "); |
1358 for(i=freg_sp;i>0;i--) { | |
1359 if(freg_stack[i-1]>=0) { | |
1360 printf(" %s",fregister_name(freg_stack[i-1])); | |
273 | 1361 } else |
880 | 1362 printf(",%d",freg_stack[i-1]); |
1363 } | |
273 | 1364 } |
1365 | |
1366 for(j=0,i=0;i<REAL_MAX_LREGISTER;i++) if (regs[i+LREG_OFFSET]) j++; | |
531 | 1367 // lreg_count = j; |
273 | 1368 if (j>USAGE_MAX) { |
880 | 1369 printf("\n## lreg(%d):",j); |
1370 for(i=0;i<REAL_MAX_LREGISTER;i++) { printf("%d",regs[i+LREG_OFFSET]); } | |
530 | 1371 #if 0 |
880 | 1372 for(i=0;i<REAL_MAX_LREGISTER;i++) { |
1373 if (regs[i+LREG_OFFSET] && regv_l(i+LREG_OFFSET)) | |
1374 printf(" %s-%s", lregister_name_high(i+LREG_OFFSET),lregister_name_low(i+LREG_OFFSET)); | |
1375 else if (regv_l(i+LREG_OFFSET)) | |
1376 printf(" *%s-%s", lregister_name_high(i+LREG_OFFSET),lregister_name_low(i+LREG_OFFSET)); | |
1377 } | |
530 | 1378 #endif |
273 | 1379 } |
1380 if (lreg_sp>0) { | |
880 | 1381 printf(" lstack "); |
1382 for(i=lreg_sp;i>0;i--) { | |
1383 if(lreg_stack[i-1]>=0) { | |
1384 printf(" %s",lregister_name_high(lreg_stack[i-1])); | |
1385 printf(",%s",lregister_name_low(lreg_stack[i-1])); | |
273 | 1386 } else |
880 | 1387 printf(",%d",lreg_stack[i-1]); |
1388 } | |
273 | 1389 } |
1390 #endif | |
1391 printf("\n"); | |
1392 } | |
1393 | |
211 | 1394 void |
1395 | |
89 | 1396 gexpr_init(void) |
1397 { | |
1398 while(reg_sp > 0) { | |
880 | 1399 error(-1); |
1400 free_register(reg_stack[--reg_sp]); | |
89 | 1401 } |
148 | 1402 while(freg_sp > 0) { |
880 | 1403 error(-1); |
1404 free_register(freg_stack[--freg_sp]); | |
148 | 1405 } |
206 | 1406 while(lreg_sp > 0) { |
880 | 1407 error(-1); |
1408 free_register(lreg_stack[--lreg_sp]); | |
206 | 1409 } |
221 | 1410 use_int0(); |
516 | 1411 text_mode(0); |
89 | 1412 gexpr_code_init(); |
1413 register_usage("gexpr_init"); | |
1414 } | |
1415 | |
1416 | |
211 | 1417 void |
1418 | |
89 | 1419 emit_init(void) |
1420 { | |
327 | 1421 /* called before each declaration */ |
1422 | |
89 | 1423 free_all_register(); |
110 | 1424 max_reg_var=-1; max_freg_var=-1; |
89 | 1425 reg_sp = 0; |
123 | 1426 freg_sp = 0; |
89 | 1427 } |
1428 | |
97 | 1429 |
89 | 1430 int |
105 | 1431 get_register_var(NMTBL *n) |
89 | 1432 { |
1433 int i; | |
99 | 1434 for(i=0;i<REG_VAR_BASE-REG_VAR_MIN;i++) { |
880 | 1435 if (! regs[REG_VAR_BASE-i]) { /* 使われていないなら */ |
1436 /* そのレジスタを使うことを宣言し */ | |
1437 regs[REG_VAR_BASE-i]=REG_VAR; | |
1438 if (i>max_reg_var) max_reg_var=i; | |
1439 /* その場所を表す番号を返す */ | |
1440 return list3n(REGISTER,REG_VAR_BASE-i,n); | |
1441 } | |
96 | 1442 } |
711 | 1443 return list3n(LVAR,new_lvar(SIZE_OF_INT),0); |
96 | 1444 } |
1445 | |
1446 int | |
138 | 1447 get_dregister_var(NMTBL *n,int d) |
96 | 1448 { |
1449 int i; | |
148 | 1450 for(i=0;i<FREG_VAR_BASE-FREG_VAR_MIN;i++) { |
724 | 1451 if (! regs[FREG_VAR_BASE-i+FREG_OFFSET]) { /* 使われていないなら */ |
1452 regs[FREG_VAR_BASE-i+FREG_OFFSET]=REG_VAR; /*そのレジスタを使うことを宣言し*/ | |
880 | 1453 if (i>max_freg_var) max_freg_var=i; |
1454 /* その場所を表す番号を返す */ | |
1455 return list3n(DREGISTER, | |
1456 FREG_VAR_BASE-i+FREG_OFFSET,n); | |
89 | 1457 } |
1458 } | |
711 | 1459 return list3n(LVAR,new_lvar(SIZE_OF_DOUBLE),0); |
89 | 1460 } |
1461 | |
426 | 1462 int |
107 | 1463 emit_push() |
89 | 1464 { |
426 | 1465 int new_reg,old=creg; |
221 | 1466 if (!is_int_reg(creg)) error(-1); |
102 | 1467 if (reg_sp>MAX_MAX) error(-1); |
724 | 1468 new_reg = get_register(); /* 絶対に取れる */ |
590 | 1469 if (new_reg==creg) error(-1); // freed creg |
724 | 1470 reg_stack[reg_sp++] = creg; /* push するかわりにレジスタを使う */ |
147 | 1471 ireg = creg = new_reg; |
590 | 1472 if (!regs[creg]) regs[creg]=USING_REG; |
426 | 1473 return old; |
89 | 1474 } |
1475 | |
1476 int | |
93 | 1477 emit_pop(int type) |
89 | 1478 { |
112 | 1479 int xreg,reg; |
97 | 1480 xreg=pop_register(); |
1481 if (xreg<= -REG_LVAR_OFFSET) { | |
880 | 1482 reg = get_register(); |
119 | 1483 code_rlvar(REG_LVAR_OFFSET+xreg,reg); |
880 | 1484 free_lvar(REG_LVAR_OFFSET+xreg); |
1485 xreg = reg; | |
97 | 1486 } |
89 | 1487 return xreg; |
1488 } | |
1489 | |
660 | 1490 #ifdef __APPLE__ |
100
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
1491 static int code_base; |
660 | 1492 #endif |
89 | 1493 |
341 | 1494 extern void |
1495 code_ptr_cache_def(int r,NMTBL *nptr) | |
89 | 1496 { |
341 | 1497 char *rrn = register_name(r); |
660 | 1498 #ifdef __APPLE__ |
544 | 1499 if (nptr->sc==STATIC && !(is_code(nptr)||is_function(nptr))) { |
880 | 1500 printf("\taddis %s,r31,ha16(_%s-L_%d)\n", |
1501 rrn,nptr->nm,code_base); | |
1502 printf("\tla %s,lo16(_%s-L_%d)(%s)\n", | |
1503 rrn,nptr->nm,code_base,rrn); | |
109 | 1504 } else { |
880 | 1505 printf("\taddis %s,r31,ha16(L_%s$non_lazy_ptr-L_%d)\n", |
1506 rrn,nptr->nm,code_base); | |
1507 printf("\tlwz %s,lo16(L_%s$non_lazy_ptr-L_%d)(%s)\n", | |
1508 rrn,nptr->nm,code_base,rrn); | |
109 | 1509 } |
660 | 1510 #else |
1511 printf("\tlis %s,%s@ha\n", | |
880 | 1512 rrn,nptr->nm); |
660 | 1513 printf("\tla %s,%s@l(%s)\n", |
880 | 1514 rrn,nptr->nm,rrn); |
660 | 1515 #endif |
89 | 1516 } |
1517 | |
245 | 1518 static char *cload(int sz) { return sz==1?"lbz":sz==SIZE_OF_SHORT?"lhz":"lwz"; } |
1519 static char *cstore(int sz) { return sz==1?"stb":sz==SIZE_OF_SHORT?"sth":"stw"; } | |
230 | 1520 |
1521 static void | |
1522 cext(int sign,int sz,int reg) | |
1523 { | |
1524 char *crn = register_name(reg); | |
1525 if (sign) { | |
880 | 1526 if (sz==1) |
1527 printf("\textsb %s,%s\n",crn,crn); | |
1528 else if (sz==SIZE_OF_SHORT) | |
1529 printf("\textsh %s,%s\n",crn,crn); | |
230 | 1530 } else { |
880 | 1531 if (sz==1) |
1532 printf("\trlwinm %s,%s,0,0xff\n",crn,crn); | |
1533 else if (sz==SIZE_OF_SHORT) | |
1534 printf("\trlwinm %s,%s,0,0xffff\n",crn,crn); | |
230 | 1535 } |
1536 } | |
1537 | |
168 | 1538 |
89 | 1539 void |
92 | 1540 code_label(int labelno) |
1541 { | |
1542 clear_ptr_cache(); | |
662 | 1543 printf("%s%d:\n",lpfx,labelno); |
92 | 1544 } |
1545 | |
367 | 1546 static void |
1547 code_add(int reg,int offset,int r) | |
1548 { | |
1549 char *crn = register_name(reg); | |
1550 char *rrn = register_name(r); | |
1551 if (offset==0) { | |
880 | 1552 if(r!=reg) |
1553 printf("\tmr %s,%s\n",crn,rrn); | |
375 | 1554 } else if (LARGE_OFFSET(offset)) { |
660 | 1555 #ifdef __APPLE__ |
880 | 1556 printf("\tla %s,lo16(%d)(%s)\n",crn,offset,rrn); |
1557 printf("\taddis %s,%s,ha16(%d)\n",crn,crn,offset); | |
660 | 1558 #else |
880 | 1559 printf("\tla %s,%d@l(%s)\n",crn,offset,rrn); |
1560 printf("\taddis %s,%s,%d@ha\n",crn,crn,offset); | |
660 | 1561 #endif |
367 | 1562 } else |
880 | 1563 printf("\taddi %s,%s,%d\n",crn,rrn,offset); |
367 | 1564 } |
1565 | |
1566 static void | |
1567 code_ld(char *ld,int reg,int offset,int r) | |
1568 { | |
1569 char *crn = register_name(reg); | |
1570 char *rrn = register_name(r); | |
375 | 1571 if (LARGE_OFFSET(offset)) { |
660 | 1572 #ifdef __APPLE__ |
880 | 1573 printf("\taddis %s,%s,ha16(%d)\n",crn,rrn,offset); |
1574 printf("\t%s %s,lo16(%d)(%s)\n",ld,crn,offset,crn); | |
660 | 1575 #else |
880 | 1576 printf("\taddis %s,%s,%d@ha\n",crn,rrn,offset); |
1577 printf("\t%s %s,%d@l(%s)\n",ld,crn,offset,crn); | |
660 | 1578 #endif |
367 | 1579 } else |
880 | 1580 printf("\t%s %s,%d(%s)\n",ld,crn,offset,rrn); |
367 | 1581 } |
1582 | |
1583 static void | |
1584 code_ldf(char *ld,char *crn,int offset,int r) | |
1585 { | |
1586 char *rrn = register_name(r); | |
1587 int reg; | |
1588 char *lrn; | |
1589 if (offset<-32768||32767<offset) { | |
880 | 1590 lrn = register_name(reg = get_register()); |
660 | 1591 #ifdef __APPLE__ |
880 | 1592 printf("\taddis %s,%s,ha16(%d)\n",lrn,rrn,offset); |
1593 printf("\t%s %s,lo16(%d)(%s)\n",ld,crn,offset,lrn); | |
660 | 1594 #else |
880 | 1595 printf("\taddis %s,%s,%d@ha\n",lrn,rrn,offset); |
1596 printf("\t%s %s,%d@l(%s)\n",ld,crn,offset,lrn); | |
1597 #endif | |
1598 free_register(reg); | |
367 | 1599 } else |
880 | 1600 printf("\t%s %s,%d(%s)\n",ld,crn,offset,rrn); |
367 | 1601 } |
1602 | |
92 | 1603 void |
221 | 1604 code_gvar(int e1,int reg) { |
1605 use_int(reg); | |
711 | 1606 code_add(reg,cadr(e1),get_ptr_cache(ncaddr(e1))); |
89 | 1607 return; |
1608 } | |
1609 | |
1610 void | |
221 | 1611 code_rgvar(int e1,int reg) { |
1612 use_int(reg); | |
711 | 1613 code_ld("lwz",reg,cadr(e1),get_ptr_cache(ncaddr(e1))); |
89 | 1614 } |
1615 | |
1616 void | |
221 | 1617 code_crgvar(int e1,int reg,int sign,int sz){ |
1618 use_int(reg); | |
711 | 1619 code_ld(cload(sz),reg,cadr(e1),get_ptr_cache(ncaddr(e1))); |
230 | 1620 cext(sign,sz,reg); |
89 | 1621 } |
1622 | |
165 | 1623 |
1624 | |
89 | 1625 void |
221 | 1626 code_register(int e2,int reg) { |
1627 use_int(reg); | |
1628 if (reg!=e2) | |
880 | 1629 printf("\tmr %s,%s\n",register_name(reg),register_name(e2)); |
89 | 1630 } |
1631 | |
353 | 1632 extern void |
1633 code_i2c(int reg) | |
1634 { | |
1635 use_int(reg); | |
1636 cext(1,1,reg); | |
1637 } | |
1638 | |
1639 extern void | |
1640 code_i2s(int reg) | |
1641 { | |
1642 use_int(reg); | |
1643 cext(1,SIZE_OF_SHORT,reg); | |
1644 } | |
1645 | |
1646 extern void | |
1647 code_u2uc(int reg) | |
1648 { | |
1649 use_int(reg); | |
1650 cext(0,1,reg); | |
1651 } | |
1652 | |
1653 extern void | |
1654 code_u2us(int reg) | |
1655 { | |
1656 use_int(reg); | |
1657 cext(0,SIZE_OF_SHORT,reg); | |
1658 } | |
89 | 1659 |
1660 void | |
95 | 1661 code_rlvar(int e2,int reg) { |
221 | 1662 use_int(reg); |
119 | 1663 lvar_intro(e2); |
1664 printf("\tlwz %s,",register_name(reg)); | |
1665 lvar(e2); | |
89 | 1666 } |
1667 | |
1668 void | |
165 | 1669 code_crlvar(int e2,int reg,int sign,int sz) { |
221 | 1670 use_int(reg); |
119 | 1671 lvar_intro(e2); |
165 | 1672 printf("\t%s %s,",cload(sz),register_name(reg)); |
119 | 1673 lvar(e2); |
230 | 1674 cext(sign,sz,reg); |
89 | 1675 } |
1676 | |
1677 void | |
221 | 1678 code_fname(NMTBL *n,int reg) { |
89 | 1679 int r; |
221 | 1680 use_int(reg); |
109 | 1681 r = get_ptr_cache(n); |
221 | 1682 if(r!=reg) |
880 | 1683 printf("\tmr %s,%s\n",register_name(reg),register_name(r)); |
89 | 1684 return; |
1685 } | |
1686 | |
363 | 1687 void |
1688 code_label_value(int label,int reg) { | |
1689 char *crn; | |
1690 use_int(reg); | |
1691 crn = register_name(reg); | |
662 | 1692 #ifdef __APPLE__ |
363 | 1693 printf("\taddis %s,r31,ha16(L_%d-L_%d)\n",crn,label,code_base); |
1694 printf("\tla %s,lo16(L_%d-L_%d)(%s)\n",crn,label,code_base,crn); | |
660 | 1695 #else |
1696 printf("\tlis %s,.LC%d@ha\n",crn,label); | |
1697 printf("\tla %s,.LC%d@l(%s)\n",crn,label,crn); | |
1698 #endif | |
363 | 1699 return; |
1700 } | |
89 | 1701 |
1702 void | |
221 | 1703 code_const(int e2,int reg) { |
1704 char *crn; | |
1705 use_int(reg); | |
1706 crn = register_name(reg); | |
527 | 1707 // printf("## 0x%08x\n",e2); |
660 | 1708 #ifdef __APPLE__ |
89 | 1709 if (-32768<e2&&e2<32768) |
880 | 1710 printf("\tli %s,%d\n",crn,e2); |
599 | 1711 else if ((e2&0xffff)==0) |
880 | 1712 printf("\tlis %s,ha16(%d)\n",crn,e2); |
89 | 1713 else { |
880 | 1714 printf("\tlis %s,ha16(%d)\n",crn,e2); |
1715 printf("\taddi %s,%s,lo16(%d)\n",crn,crn,e2); | |
89 | 1716 } |
660 | 1717 #else |
1718 if (-32768<e2&&e2<32768) | |
880 | 1719 printf("\tli %s,%d\n",crn,e2); |
660 | 1720 else if ((e2&0xffff)==0) |
880 | 1721 printf("\tlis %s,%d@ha\n",crn,e2); |
660 | 1722 else { |
880 | 1723 printf("\tlis %s,%d@ha\n",crn,e2); |
1724 printf("\taddi %s,%s,%d@l\n",crn,crn,e2); | |
660 | 1725 } |
1726 #endif | |
89 | 1727 } |
1728 | |
1729 void | |
107 | 1730 code_neg(int creg) { |
221 | 1731 use_int(creg); |
93 | 1732 printf("\tneg %s,%s\n", register_name(creg), register_name(creg)); |
89 | 1733 } |
1734 | |
1735 | |
1736 void | |
107 | 1737 code_not(int creg) { |
221 | 1738 use_int(creg); |
89 | 1739 printf("\tnor %s,%s,%s\n", |
880 | 1740 register_name(creg), register_name(creg),register_name(creg)); |
89 | 1741 } |
1742 | |
1743 | |
1744 void | |
107 | 1745 code_lnot(int creg) { |
221 | 1746 use_int(creg); |
660 | 1747 #ifdef __APPLE__ |
89 | 1748 printf("\tsubfic r0,%s,0\n", register_name(creg)); |
1749 printf("\tadde %s,r0,%s\n", register_name(creg),register_name(creg)); | |
660 | 1750 #else |
1751 printf("\tsubfic 0,%s,0\n", register_name(creg)); | |
1752 printf("\tadde %s,0,%s\n", register_name(creg),register_name(creg)); | |
1753 #endif | |
89 | 1754 } |
1755 | |
1756 void | |
168 | 1757 code_preinc(int e1,int e2,int dir,int sign,int sz,int reg) { |
89 | 1758 char *xrn,*drn; |
1759 if (car(e2)==REGISTER) { | |
880 | 1760 use_int(reg); |
1761 printf("\taddi %s,%s,%d\n", | |
1762 register_name(cadr(e2)),register_name(cadr(e2)), dir); | |
1763 if (use && cadr(e2)!=reg) | |
1764 printf("\tmr %s,%s\n",register_name(reg),register_name(cadr(e2))); | |
1765 return; | |
89 | 1766 } |
1767 g_expr(e2); | |
221 | 1768 if (!is_int_reg(creg)) error(-1); |
89 | 1769 xrn = register_name(creg); |
221 | 1770 if (reg==USE_CREG) { |
880 | 1771 reg=get_register(); if (!reg) error(-1); |
1772 drn = register_name(reg); | |
1773 set_ireg(reg,0); | |
221 | 1774 } else { |
880 | 1775 drn = register_name(reg); |
221 | 1776 } |
168 | 1777 printf("\t%s %s,0(%s)\n",cload(sz),drn,xrn); |
231 | 1778 if (use) cext(sign,sz,reg); |
168 | 1779 printf("\taddi %s,%s,%d\n",drn,drn,dir); |
1780 printf("\t%s %s,0(%s)\n",cstore(sz),drn,xrn); | |
89 | 1781 } |
1782 | |
1783 | |
1784 void | |
168 | 1785 code_postinc(int e1,int e2,int dir,int sign,int sz,int reg) { |
89 | 1786 char *xrn,*crn,*nrn; |
231 | 1787 int nreg; |
89 | 1788 if (car(e2)==REGISTER) { |
880 | 1789 use_int(reg); |
1790 if (use) | |
1791 printf("\tmr %s,%s\n",register_name(reg),register_name(cadr(e2))); | |
1792 printf("\taddi %s,%s,%d\n", | |
1793 register_name(cadr(e2)),register_name(cadr(e2)),dir); | |
1794 return; | |
89 | 1795 } |
1796 g_expr(e2); | |
221 | 1797 if (!is_int_reg(creg)) error(-1); |
89 | 1798 crn = register_name(creg); |
1799 nreg=get_register(); if (!nreg) error(-1); | |
1800 nrn = register_name(nreg); | |
221 | 1801 if (reg==USE_CREG) { |
880 | 1802 reg=get_register(); if (!reg) error(-1); |
1803 xrn = register_name(reg); | |
1804 set_ireg(reg,0); | |
221 | 1805 } else { |
880 | 1806 xrn = register_name(reg); |
221 | 1807 } |
168 | 1808 printf("\t%s %s,0(%s)\n",cload(sz),xrn,crn); |
230 | 1809 if (use) cext(sign,sz,reg); |
168 | 1810 printf("\taddi %s,%s,%d\n",nrn,xrn,dir); |
1811 printf("\t%s %s,0(%s)\n",cstore(sz),nrn,crn); | |
89 | 1812 free_register(nreg); |
1813 } | |
1814 | |
1815 | |
1816 void | |
107 | 1817 code_return(int creg) { |
662 | 1818 |
221 | 1819 use_int(creg); |
660 | 1820 code_label_value(retcont,creg); |
89 | 1821 } |
1822 | |
577 | 1823 #define R1SAVE 0 |
89 | 1824 |
1825 void | |
107 | 1826 code_environment(int creg) { |
126 | 1827 /* save frame pointer */ |
221 | 1828 use_int(creg); |
128 | 1829 #if R1SAVE |
660 | 1830 printf("\tlwz %s,0(%s)\n",register_name(creg),register_name(1)); |
128 | 1831 #else |
667 | 1832 printf("\tmr %s,%s\n",register_name(creg),register_name(REG_fp)); |
577 | 1833 // int l = 0; |
1834 // printf("\tla %s,",register_name(creg)); | |
1835 // printf("lo16(%d+L_%d)(r30)\n",FUNC_LVAR,lvar_offset_label); | |
128 | 1836 #endif |
89 | 1837 } |
1838 | |
288 | 1839 static int rexpr_bool(int e1,int reg); |
1840 | |
1841 #if FLOAT_CODE | |
1842 static int drexpr_bool(int e1,int reg); | |
1843 #endif | |
1844 | |
1845 #if LONGLONG_CODE | |
1846 static int lrexpr_bool(int e1,int reg) | |
1847 { | |
1848 return 0; | |
1849 } | |
1850 #endif | |
1851 | |
1852 | |
1853 | |
89 | 1854 void |
221 | 1855 code_bool(int e1,int reg) { |
89 | 1856 char *xrn; |
1857 int e2,e3; | |
288 | 1858 |
1859 if (rexpr_bool(e1,reg)) return; | |
1860 #if FLOAT_CODE | |
1861 else if (drexpr_bool(e1,reg)) return; | |
1862 #endif | |
1863 #if LONGLONG_CODE | |
1864 else if (lrexpr_bool(e1,reg)) return; | |
1865 #endif | |
1866 | |
89 | 1867 b_expr(e1,1,e2=fwdlabel(),1); /* including > < ... */ |
289 | 1868 if (use) { |
880 | 1869 use_int(reg); |
1870 xrn = register_name(reg); | |
1871 printf("\tli %s,0\n",xrn); | |
1872 jmp(e3=fwdlabel()); | |
1873 fwddef(e2); | |
1874 printf("\tli %s,1\n",xrn); | |
1875 fwddef(e3); | |
289 | 1876 } else { |
880 | 1877 fwddef(e2); |
289 | 1878 } |
89 | 1879 } |
1880 | |
433 | 1881 #define code_gt(cond) (cond?"gt":"le") |
1882 | |
1883 #define code_ugt(cond) (cond?"gt":"le") | |
1884 | |
1885 #define code_ge(cond) (cond?"ge":"lt") | |
1886 | |
1887 #define code_uge(cond) (cond?"ge":"lt") | |
1888 | |
1889 #define code_eq(cond) (cond?"eq":"ne") | |
89 | 1890 |
569 | 1891 static int cmpflag = 7; |
280 | 1892 |
1893 static void | |
1894 inc_cmpflag() | |
1895 { | |
569 | 1896 // gcc use cmpflag 4 and 7, and gcc4 believes flag 4 is preserved. |
673 | 1897 do { |
880 | 1898 cmpflag = (cmpflag+1)%8; |
673 | 1899 } while (cmpflag!=4 && cmpflag!=7); |
280 | 1900 } |
1901 | |
662 | 1902 #ifdef __APPLE__ |
1903 static | |
1904 char *crname_[] = { "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7" }; | |
1905 #else | |
1906 static | |
1907 char *crname_[] = { "0", "1", "2", "3", "4", "5", "6", "7" }; | |
1908 #endif | |
1909 #define crname(d) (crname_[d]) | |
1910 | |
89 | 1911 void |
287 | 1912 code_cmp_crgvar(int e1,int reg,int sz,int label,int cond) { |
221 | 1913 use_int(reg); |
711 | 1914 code_ld(cload(sz),reg,cadr(e1),get_ptr_cache(ncaddr(e1))); |
432 | 1915 cext(0,sz,reg); |
291 | 1916 inc_cmpflag(); |
662 | 1917 printf("\tcmpwi %s,%s,0\n",crname(cmpflag),register_name(reg)); |
287 | 1918 jcond(label,cond); |
89 | 1919 } |
1920 | |
1921 | |
1922 void | |
287 | 1923 code_cmp_crlvar(int e2,int reg, int sz,int label,int cond) { |
221 | 1924 char *crn; |
1925 use_int(reg); | |
1926 crn = register_name(reg); | |
119 | 1927 lvar_intro(e2); |
167 | 1928 printf("\t%s %s,",cload(sz),crn); |
160 | 1929 lvar(e2); |
230 | 1930 cext(0,sz,reg); |
287 | 1931 code_cmp_register(reg,label,cond); |
160 | 1932 } |
1933 | |
89 | 1934 |
1935 void | |
287 | 1936 code_cmp_rgvar(int e1,int reg,int label,int cond) { |
221 | 1937 use_int(reg); |
711 | 1938 code_ld("lwz",reg,cadr(e1),get_ptr_cache(ncaddr(e1))); |
287 | 1939 code_cmp_register(reg,label,cond); |
89 | 1940 } |
1941 | |
1942 | |
1943 void | |
287 | 1944 code_cmp_rlvar(int e2,int reg,int label,int cond) { |
221 | 1945 char *crn; |
1946 use_int(reg); | |
1947 crn = register_name(reg); | |
119 | 1948 lvar_intro(e2); |
1949 printf("\tlwz %s,",crn); | |
1950 lvar(e2); | |
287 | 1951 code_cmp_register(reg,label,cond); |
89 | 1952 } |
1953 | |
1954 | |
1955 void | |
287 | 1956 code_cmp_register(int e2,int label,int cond) { |
221 | 1957 use_int(e2); |
291 | 1958 inc_cmpflag(); |
662 | 1959 printf("\tcmpwi %s,%s,0\n",crname(cmpflag),register_name(e2)); |
287 | 1960 jcond(label,cond); |
89 | 1961 } |
1962 | |
1963 | |
1964 void | |
107 | 1965 code_string(int e1,int creg) |
89 | 1966 { |
95 | 1967 int lb; |
711 | 1968 NMTBL *n = ncaddr(e1); |
560 | 1969 if ((lb=attr_value(n,LABEL))) { |
1970 // already defined | |
1971 return code_label_value(lb,creg) ; | |
1972 } | |
221 | 1973 |
1974 use_int(creg); | |
319 | 1975 lb = emit_string_label(); |
560 | 1976 ascii(n->nm); |
89 | 1977 if (output_mode==TEXT_EMIT_MODE) { |
880 | 1978 printf(".text\n"); |
89 | 1979 } else { |
880 | 1980 text_mode(0); |
89 | 1981 } |
660 | 1982 code_label_value(lb,creg); |
560 | 1983 set_attr(n,LABEL,lb); |
89 | 1984 } |
1985 | |
778
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
1986 |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
1987 void |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
1988 emit_strings(NMTBL *n) |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
1989 { |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
1990 int l = emit_string_label(); |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
1991 int i; |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
1992 for(i = n->dsp; i; i = cadr(i)) { |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
1993 ascii(scaddr(i)); |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
1994 } |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
1995 emit_label(l); |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
1996 } |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
1997 |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
1998 void |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
1999 code_strings(int e2,int reg) |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
2000 { |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
2001 int l = emit_string_label(); |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
2002 int i; |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
2003 for(i = e2; i; i = cadr(i)) { |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
2004 ascii(scaddr(i)); |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
2005 } |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
2006 if (output_mode==TEXT_EMIT_MODE) { |
880 | 2007 printf(".text\n"); |
778
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
2008 } else { |
880 | 2009 text_mode(0); |
778
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
2010 } |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
2011 code_label_value(l,reg); |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
2012 } |
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
739
diff
changeset
|
2013 |
89 | 2014 #define MAX_COPY_LEN 20 |
417 | 2015 // #define MAX_COPY_LEN 10 |
89 | 2016 |
211 | 2017 void |
89 | 2018 emit_copy(int from,int to,int length,int offset,int value,int det) |
2019 { | |
221 | 2020 char *frn; |
2021 char *trn; | |
89 | 2022 char *drn; |
125 | 2023 char *memmove = "memmove"; |
556 | 2024 int l; |
95 | 2025 int dreg = get_register(); if (!dreg) error(-1); |
221 | 2026 |
880 | 2027 drn = register_name(dreg); |
221 | 2028 use_int(from); |
2029 use_int(to); | |
880 | 2030 frn = register_name(from); |
2031 trn = register_name(to); | |
89 | 2032 |
2033 /* length <0 means upward direction copy */ | |
2034 switch (length) { | |
880 | 2035 case 0: break; |
89 | 2036 case 1: case -1: |
880 | 2037 printf("\tlbz %s,%d(%s)\n",drn,offset,frn); |
2038 printf("\tstb %s,%d(%s)\n",drn,offset,trn); | |
2039 break; | |
89 | 2040 case 2: case -2: |
880 | 2041 printf("\tlhz %s,%d(%s)\n",drn,offset,frn); |
2042 printf("\tsth %s,%d(%s)\n",drn,offset,trn); | |
2043 break; | |
89 | 2044 case 4: case -4: |
880 | 2045 printf("\tlwz %s,%d(%s)\n",drn,offset,frn); |
2046 printf("\tstw %s,%d(%s)\n",drn,offset,trn); | |
2047 break; | |
89 | 2048 default: |
880 | 2049 if (length <0) { |
2050 if (length >= -MAX_COPY_LEN) { | |
2051 free_register(dreg); dreg = 0; | |
2052 for(;length<=-4;length+=4,offset-=4) | |
2053 emit_copy(from,to,-4,offset-4,0,det); | |
2054 for(;length<=-2;length+=2,offset-=2) | |
2055 emit_copy(from,to,-2,offset-2,0,det); | |
2056 if(length<0) | |
2057 emit_copy(from,to,length,offset-1,0,det); | |
2058 break; | |
2059 } | |
2060 } else if (length <=MAX_COPY_LEN) { | |
2061 free_register(dreg); dreg = 0; | |
2062 for(;length>=4;length-=4,offset+=4) | |
2063 emit_copy(from,to,4,offset,0,det); | |
2064 for(;length>=2;length-=2,offset+=2) | |
2065 emit_copy(from,to,2,offset,0,det); | |
2066 if(length>0) | |
2067 emit_copy(from,to,length,offset,0,det); | |
2068 break; | |
2069 } | |
2070 clear_ptr_cache(); | |
2071 code_save_stacks(); | |
556 | 2072 |
2073 l = list3(3,0,to); | |
2074 l = list3(4,l,from); | |
2075 parallel_rassign(l); | |
2076 | |
660 | 2077 #ifdef __APPLE__ |
880 | 2078 printf("\tli r5,%d\n",length>0?length:-length); |
2079 /* offset should be ignored */ | |
125 | 2080 /* overrap must be allowed */ |
880 | 2081 printf("\tbl L_%s$stub\n",memmove); |
660 | 2082 #else |
880 | 2083 printf("\tli 5,%d\n",length>0?length:-length); |
2084 /* offset should be ignored */ | |
660 | 2085 /* overrap must be allowed */ |
880 | 2086 printf("\tbl %s\n",memmove); |
2087 #endif | |
2088 extern_define(memmove,0,FUNCTION,1); | |
2089 set_ireg(RET_REGISTER,0); | |
2090 //if (creg!=to) { | |
2091 // free_register(to); to = creg; | |
2092 //} | |
2093 break; | |
89 | 2094 } |
2095 if (value) { | |
2096 /* creg must point top of the destination data */ | |
2097 /* this code is necessary for the value of assignment or function call */ | |
2098 /* otherwise we don't need this */ | |
880 | 2099 if(creg!=to) { |
2100 free_register(to); | |
2101 // set_ireg(to,1); | |
2102 } | |
89 | 2103 } |
583 | 2104 if (dreg) free_register(dreg); |
89 | 2105 } |
2106 | |
2107 int | |
444 | 2108 push_struct(int e4,int t,int arg) |
89 | 2109 { |
95 | 2110 int length,count; |
119 | 2111 int dreg,sreg; char *drn,*crn,*srn; |
89 | 2112 g_expr(e4); |
221 | 2113 if (!is_int_reg(creg)) error(-1); |
89 | 2114 length=size(t); |
245 | 2115 if(length%SIZE_OF_INT) { |
880 | 2116 length += SIZE_OF_INT - (length%SIZE_OF_INT); |
89 | 2117 } |
95 | 2118 dreg = get_register(); if (!dreg) error(-1); |
89 | 2119 drn = register_name(dreg); |
119 | 2120 crn = register_name(creg); |
125 | 2121 if (length<MAX_COPY_LEN) { |
880 | 2122 sreg = get_register(); if (!sreg) error(-1); |
2123 srn = register_name(sreg); | |
2124 code_lvar(cadr(arg),dreg); | |
2125 for(count=0;count<length;count+=SIZE_OF_INT) { | |
2126 printf("\tlwz %s,%d(%s)\n",srn,count,crn); | |
2127 printf("\tstw %s,%d(%s)\n",srn,count,drn); | |
2128 } | |
2129 free_register(sreg); | |
2130 free_register(dreg); | |
2131 return length/SIZE_OF_INT; | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2132 } else { |
880 | 2133 code_lvar(cadr(arg),dreg); |
2134 /* downward direction copy */ | |
2135 emit_copy(creg,dreg,length,0,0,1); | |
89 | 2136 } |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2137 free_register(dreg); |
245 | 2138 return length/SIZE_OF_INT; |
89 | 2139 } |
2140 | |
655 | 2141 static void |
207 | 2142 set_ireg(int reg,int mode) |
104 | 2143 { |
207 | 2144 if (!is_int_reg(reg)) error(-1); |
104 | 2145 if (reg!=creg) { |
880 | 2146 clear_ptr_cache_reg(reg); |
2147 if (ireg && reg!=ireg ) { | |
2148 clear_ptr_cache_reg(ireg); | |
2149 if (regs[ireg]!=REG_VAR) free_register(ireg); | |
2150 if (mode) { | |
2151 printf("\tmr %s,%s\n",register_name(reg),register_name(ireg)); | |
2152 } | |
2153 } | |
2154 if (regs[creg]!=REG_VAR) { | |
2155 clear_ptr_cache_reg(creg); | |
2156 free_register(creg); | |
2157 } | |
2158 if (creg==lreg) lreg = 0; | |
2159 regs[reg]=USING_REG; | |
104 | 2160 } |
206 | 2161 creg = ireg = reg; |
104 | 2162 } |
2163 | |
655 | 2164 static void |
104 | 2165 set_freg(int reg,int mode) |
2166 { | |
207 | 2167 if (!is_float_reg(reg)) error(-1); |
147 | 2168 if (reg!=creg) { |
880 | 2169 if (freg && reg!=freg) { |
2170 free_register(freg); | |
2171 if (mode) { | |
2172 printf("\tfmr %s,%s\n",fregister_name(reg),fregister_name(freg)); | |
2173 } | |
2174 } | |
2175 // if (creg!=ireg) free_register(creg); | |
2176 regs[reg]=USING_REG; | |
104 | 2177 } |
206 | 2178 creg = freg = reg; |
195 | 2179 } |
2180 | |
655 | 2181 static void |
195 | 2182 set_lreg(int reg,int mode) |
2183 { | |
222 | 2184 if (reg==RET_LREGISTER) { |
880 | 2185 regv_l(reg) = RET_LREGISTER_L; |
2186 regv_h(reg) = RET_LREGISTER_H; | |
222 | 2187 } |
207 | 2188 if (!is_longlong_reg(reg)) error(-1); |
206 | 2189 if (reg!=creg) { |
880 | 2190 if (lreg) { |
2191 if (reg!=lreg) { | |
2192 if (mode) { | |
2193 printf("\tmr %s,%s\n", | |
2194 lregister_name_low(reg),lregister_name_low(lreg)); | |
2195 printf("\tmr %s,%s\n", | |
2196 lregister_name_high(reg),lregister_name_high(lreg)); | |
2197 } | |
2198 free_register(lreg); | |
2199 } | |
2200 if (lreg==creg) creg=0; | |
2201 } | |
2202 if (creg) free_register(creg); | |
2203 regs[reg]=USING_REG; | |
2204 clear_ptr_cache_reg(regv_l(reg)); | |
2205 regs[regv_l(reg)]=USING_REG; | |
2206 clear_ptr_cache_reg(regv_h(reg)); | |
2207 regs[regv_h(reg)]=USING_REG; | |
2208 creg = lreg = reg; | |
206 | 2209 } |
104 | 2210 } |
2211 | |
655 | 2212 static void |
217 | 2213 set_lreg_operand(int reg,int mode) |
216 | 2214 { |
326 | 2215 // save_stack,clear_ptr_cache is assumed |
217 | 2216 if (!is_longlong_reg(reg)) { error(-1); return; } |
2217 if (mode) { | |
880 | 2218 if (regv_l(reg)!=3) |
2219 printf("\tmr %s,%s\n", register_name(3),lregister_name_high(reg)); | |
2220 if (regv_l(reg)!=4) | |
2221 printf("\tmr %s,%s\n", register_name(4),lregister_name_low(reg)); | |
255 | 2222 } |
2223 } | |
2224 | |
655 | 2225 static void |
255 | 2226 set_lreg_operand1(int reg,int mode) |
2227 { | |
326 | 2228 // save_stack,clear_ptr_cache is assumed |
255 | 2229 if (!is_longlong_reg(reg)) { error(-1); return; } |
2230 if (mode) { | |
880 | 2231 if (regv_l(reg)!=5) |
2232 printf("\tmr %s,%s\n", register_name(5),lregister_name_high(reg)); | |
2233 if (regv_l(reg)!=6) | |
2234 printf("\tmr %s,%s\n", register_name(6),lregister_name_low(reg)); | |
217 | 2235 } |
216 | 2236 } |
2237 | |
655 | 2238 static void |
207 | 2239 use_reg(int arg) |
104 | 2240 { |
468 | 2241 // printf("## use reg %d\n",arg); |
208 | 2242 if (arg<0||arg> REAL_MAX_REGISTER+REAL_MAX_FREGISTER+ REAL_MAX_LREGISTER) |
880 | 2243 error(-1); |
223 | 2244 clear_ptr_cache_reg(arg); |
207 | 2245 regs[arg]=USING_REG; |
2246 if (is_longlong_reg(arg)) { | |
880 | 2247 clear_ptr_cache_reg(regv_l(arg)); |
2248 regs[regv_l(arg)]=USING_REG; | |
2249 clear_ptr_cache_reg(regv_h(arg)); | |
2250 regs[regv_h(arg)]=USING_REG; | |
206 | 2251 } |
104 | 2252 } |
2253 | |
676 | 2254 /* |
2255 store input argument into stack | |
2256 we need this always because of one path compiler | |
2257 */ | |
655 | 2258 static void |
305
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
304
diff
changeset
|
2259 code_save_input_registers(int dots) |
105 | 2260 { |
119 | 2261 int args; |
2262 NMTBL *n; | |
2263 int reg; | |
2264 int tag; | |
676 | 2265 // int lvar; |
119 | 2266 int t; |
2267 /* fnptr->dsp=list4(type,fnptr->dsp,(int)n,0); */ | |
2268 int reg_offset = 0; | |
2269 int offset = 0; | |
305
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
304
diff
changeset
|
2270 int reg_var = 0; |
825
425768eb5e9e
code segment fix for non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
809
diff
changeset
|
2271 if (!parse_mode && dots) { |
425768eb5e9e
code segment fix for non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
809
diff
changeset
|
2272 int stype = type; int smode = mode; |
425768eb5e9e
code segment fix for non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
809
diff
changeset
|
2273 type = INT; |
425768eb5e9e
code segment fix for non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
809
diff
changeset
|
2274 mode = LDECL; |
425768eb5e9e
code segment fix for non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
809
diff
changeset
|
2275 stmode = 0; |
425768eb5e9e
code segment fix for non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
809
diff
changeset
|
2276 // lsearch defines local name |
425768eb5e9e
code segment fix for non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
809
diff
changeset
|
2277 NMTBL *n = def(lsearch("__my_va_list",0),0); |
425768eb5e9e
code segment fix for non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
809
diff
changeset
|
2278 n->dsp = offset; |
425768eb5e9e
code segment fix for non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
809
diff
changeset
|
2279 type = stype; mode = smode; |
425768eb5e9e
code segment fix for non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
809
diff
changeset
|
2280 } |
425768eb5e9e
code segment fix for non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
809
diff
changeset
|
2281 |
119 | 2282 |
2283 for(args = fnptr->dsp;args;args = cadr(args)) { | |
880 | 2284 n = ncadddr(args); |
2285 tag = n->sc; | |
2286 reg = n->dsp; | |
2287 if (!n||n==&null_nptr) error(REG_ERR); | |
2288 if (tag==REGISTER) { | |
2289 n->dsp = offset; | |
2290 offset+=SIZE_OF_INT; | |
2291 t = INT; | |
2292 reg += reg_offset; /* for duplicated floating point argument */ | |
2293 reg_var++; | |
2294 } else if (tag==DREGISTER) { | |
2295 n->dsp = offset; | |
2296 t = n->ty; | |
672 | 2297 #ifdef __APPLE__ |
880 | 2298 if(t==FLOAT) { offset+=SIZE_OF_FLOAT; reg_offset+=1; } |
2299 else if(t==DOUBLE) { offset+=SIZE_OF_DOUBLE; reg_offset+=2; } | |
2300 else error(-1); | |
2301 reg_var += 2; | |
672 | 2302 #else |
880 | 2303 if(t==FLOAT) { offset+=SIZE_OF_FLOAT; } |
2304 else if(t==DOUBLE) { offset+=SIZE_OF_DOUBLE; } | |
2305 else error(-1); | |
2306 #endif | |
2307 } else if (tag==LREGISTER) { | |
2308 n->dsp = offset; | |
2309 t = n->ty; | |
2310 offset+=SIZE_OF_LONGLONG; | |
2311 reg_offset+=2; | |
2312 reg_var += 2; | |
2313 } else { | |
2314 // n->dsp = offset; this is no allowed becase of arg reorder | |
2315 offset += size(n->ty); | |
2316 continue; | |
2317 } | |
2318 n->sc = LVAR; | |
2319 g_expr_u(assign_expr0( | |
2320 list3n(LVAR,n->dsp,0),list3n(tag,reg,n),n->ty,t)); | |
2321 if (tag==REGISTER||tag==DREGISTER||tag==FREGISTER||tag==LREGISTER) { | |
2322 free_register(reg); | |
2323 } | |
119 | 2324 } |
305
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
304
diff
changeset
|
2325 if (dots) { |
880 | 2326 while ((reg = get_input_register_var(reg_var,0,0))) { |
2327 g_expr_u(assign_expr0( | |
2328 list3n(LVAR,offset,0),reg,INT,INT)); | |
2329 offset+=SIZE_OF_INT; | |
2330 reg_var++; | |
2331 } | |
673 | 2332 #ifndef __APPLE__ |
880 | 2333 int skip = fwdlabel(); |
2334 int freg_var = 0; | |
2335 printf("\tbne 1,%s%d\n",lpfx,skip); | |
2336 while ((reg = get_input_dregister_var(freg_var,0,0,1))) { | |
2337 g_expr_u(assign_expr0( | |
2338 list3n(LVAR,offset,0),reg,DOUBLE,DOUBLE)); | |
2339 offset+=SIZE_OF_DOUBLE; | |
2340 freg_var++; | |
2341 } | |
2342 fwddef(skip); | |
673 | 2343 #endif |
305
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
304
diff
changeset
|
2344 } |
121 | 2345 my_func_args = offset; |
105 | 2346 } |
2347 | |
449 | 2348 int |
228 | 2349 not_simple_p(int e3) |
223 | 2350 { |
450
eaf9e2746c83
parallel assign for simple expr. (too complex solution)
kono
parents:
449
diff
changeset
|
2351 switch (e3) { |
880 | 2352 case FUNCTION: case CONV: case LCALL: case STASS: |
2353 case LLSHIFT: case LULSHIFT: case LRSHIFT: case LURSHIFT: | |
2354 case LDIV: case LUDIV: case LMOD: case LUMOD: case LASSOP: case ALLOCA: | |
2355 case INLINE: | |
450
eaf9e2746c83
parallel assign for simple expr. (too complex solution)
kono
parents:
449
diff
changeset
|
2356 return 1; |
eaf9e2746c83
parallel assign for simple expr. (too complex solution)
kono
parents:
449
diff
changeset
|
2357 } |
eaf9e2746c83
parallel assign for simple expr. (too complex solution)
kono
parents:
449
diff
changeset
|
2358 return 0; |
223 | 2359 } |
2360 | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2361 static int |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2362 simple_arg(int e3) |
108 | 2363 { |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2364 return !contains_p(e3,not_simple_p); |
108 | 2365 } |
2366 | |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
2367 #define caller_arg_offset_v(arg) (ARG_LVAR_OFFSET+(arg)*SIZE_OF_INT) |
111 | 2368 |
715 | 2369 /* |
2370 use input register as current register | |
724 | 2371 なんで、こんなに複雑なんだ? |
880 | 2372 むしろ、INPUT_REG みたいな mark をいれたら? |
715 | 2373 */ |
2374 | |
655 | 2375 static void |
233 | 2376 use_input_reg(int reg,int mode) |
2377 { | |
2378 if (is_int_reg(reg)) { | |
880 | 2379 if (ireg&® == ireg) { |
2380 if (creg==ireg) creg = 0; | |
2381 ireg = 0; | |
2382 } | |
2383 if (lreg) { | |
2384 // free_regsiter(lreg) でいいんじゃないの? | |
2385 if (regv_l(lreg)==reg) { | |
2386 regs[lreg]=0; | |
2387 if (regv_h(lreg)>reg&®s[regv_h(lreg)]==USING_REG) { | |
2388 free_register(regv_h(lreg)); | |
2389 } | |
2390 if (creg==lreg) creg = ireg; | |
2391 free_register(lreg); | |
2392 lreg = 0; | |
2393 } else if (regv_h(lreg)==reg) { | |
2394 regs[lreg]=0; | |
2395 if (regv_h(lreg)>reg&®s[regv_l(lreg)]==USING_REG) { | |
2396 free_register(regv_l(lreg)); | |
2397 } | |
2398 if (creg==lreg) creg = ireg; | |
2399 free_register(lreg); | |
2400 lreg = 0; | |
2401 } | |
2402 } | |
233 | 2403 } else if (is_longlong_reg(reg)) { |
880 | 2404 use_input_reg(regv_h(reg),mode); |
2405 use_input_reg(regv_l(reg),mode); | |
233 | 2406 } else if (is_float_reg(reg)) { |
880 | 2407 if (freg&® == freg) { |
2408 if (creg==freg) creg = ireg; | |
2409 freg = 0; | |
2410 } | |
233 | 2411 } |
2412 if (mode) use_reg(reg); | |
2413 } | |
2414 | |
271 | 2415 static int |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2416 compute_complex_arg(int e3,int reg_arg_list,int arg) { |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2417 int t=caddr(e3); |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2418 int e4 = car(e3); |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2419 reg_arg_list = list2(arg,reg_arg_list); |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2420 if (car(arg)==REGISTER||car(arg)==DREGISTER|| |
880 | 2421 car(arg)==FREGISTER||car(arg)==LREGISTER) |
2422 use_input_reg(cadr(arg),1); | |
709 | 2423 g_expr_u(assign_expr0(arg,e4,t,t)); |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2424 car(e3) = arg; |
271 | 2425 return reg_arg_list; |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2426 } |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2427 |
667 | 2428 |
2429 #ifdef __APPLE__ | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2430 static void |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2431 increment_function_arg(int e3,int *pnargs,int *preg_arg,int *pfreg_arg) { |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2432 int nargs=0,reg_arg=0,freg_arg=0; |
487 | 2433 int t=type_value(caddr(e3)); |
331 | 2434 if (t>=0&&(car(t)==BIT_FIELD)) { |
880 | 2435 t = type_value(cadr(t)); |
331 | 2436 } |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2437 if(scalar(t)) { |
880 | 2438 nargs ++ ; reg_arg++; |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2439 } else if (t==LONGLONG||t==ULONGLONG) { |
880 | 2440 nargs ++ ; reg_arg++; |
2441 nargs ++ ; reg_arg++; | |
475 | 2442 } else if (t==FLOAT) { |
880 | 2443 if (*preg_arg<MAX_INPUT_REGISTER_VAR) { |
2444 reg_arg += 1; | |
2445 } | |
2446 freg_arg++; | |
2447 nargs += size(t)/SIZE_OF_INT; | |
475 | 2448 } else if (t==DOUBLE) { |
880 | 2449 if (*preg_arg<MAX_INPUT_REGISTER_VAR) { |
2450 reg_arg += 2; | |
2451 } | |
2452 nargs += size(t)/SIZE_OF_INT; | |
2453 freg_arg++; | |
638 | 2454 } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) { |
880 | 2455 nargs += round4(size(t))/SIZE_OF_INT; |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2456 } else { |
880 | 2457 error(TYERR); |
2458 nargs ++ ; | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2459 } |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2460 *pnargs += nargs; |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2461 *preg_arg += reg_arg; |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2462 *pfreg_arg += freg_arg; |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2463 } |
667 | 2464 #else |
2465 static void | |
2466 increment_function_arg(int e3,int *pnargs,int *preg_arg,int *pfreg_arg) { | |
2467 int nargs=0,reg_arg=0,freg_arg=0; | |
2468 int t=type_value(caddr(e3)); | |
2469 if (t>=0&&(car(t)==BIT_FIELD)) { | |
880 | 2470 t = type_value(cadr(t)); |
667 | 2471 } |
2472 if(scalar(t)) { | |
880 | 2473 reg_arg++; |
2474 if (*preg_arg>=MAX_INPUT_REGISTER_VAR) nargs ++ ; | |
667 | 2475 } else if (t==LONGLONG||t==ULONGLONG) { |
672 | 2476 if (*preg_arg%2==1) reg_arg++; // alignment |
2477 if (*pnargs%2==1) nargs++; // alignment | |
880 | 2478 reg_arg++; reg_arg++; |
2479 if (*preg_arg+1>=MAX_INPUT_REGISTER_VAR) nargs += 2; | |
667 | 2480 } else if (t==FLOAT) { |
880 | 2481 freg_arg++; |
2482 if (*pfreg_arg>=MAX_INPUT_DREGISTER_VAR) nargs += size(t)/SIZE_OF_INT; | |
667 | 2483 } else if (t==DOUBLE) { |
880 | 2484 freg_arg++; |
2485 if (*pfreg_arg>=MAX_INPUT_DREGISTER_VAR) nargs += round4(size(t))/SIZE_OF_INT; | |
667 | 2486 } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) { |
880 | 2487 nargs += round4(size(t))/SIZE_OF_INT; |
667 | 2488 } else { |
880 | 2489 error(TYERR); |
2490 nargs ++ ; | |
667 | 2491 } |
2492 *pnargs += nargs; | |
2493 *preg_arg += reg_arg; | |
2494 *pfreg_arg += freg_arg; | |
2495 } | |
2496 #endif | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2497 |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2498 #define AS_SAVE 1 |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2499 #define AS_ARG 0 |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2500 |
676 | 2501 /* |
2502 set storage type of caller's arguments | |
2503 register or stack | |
2504 this muse corprate with code_arg_register(); | |
2505 if AS_SAVE is set, register variable (or temporary local variable) | |
2506 is used. | |
2507 */ | |
2508 | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2509 static int |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2510 get_input_arg(int t,int mode,int nargs,int reg_arg,int freg_arg) |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2511 { |
487 | 2512 t = type_value(t); |
331 | 2513 if (t>=0&&(car(t)==BIT_FIELD)) { |
880 | 2514 t = type_value(cadr(t)); |
331 | 2515 } |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2516 if(scalar(t)) { |
880 | 2517 if (mode==AS_SAVE) { |
2518 return get_register_var(0); | |
2519 } else if (reg_arg>=MAX_INPUT_REGISTER_VAR) { | |
2520 return list3n(LVAR,caller_arg_offset_v(nargs),0); | |
2521 } else { | |
2522 int e = get_input_register_var(reg_arg,0,0); | |
843 | 2523 clear_ptr_cache_reg(cadr(e)); |
880 | 2524 return e; |
2525 } | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2526 } else if (t==LONGLONG||t==ULONGLONG) { |
880 | 2527 if (mode==AS_SAVE) { |
2528 return get_lregister_var(0); | |
2529 } else if (reg_arg+1>=MAX_INPUT_REGISTER_VAR) { | |
2530 return list3n(LVAR,caller_arg_offset_v(nargs),0); | |
2531 } else { | |
2532 int e = get_input_lregister_var(reg_arg,0,0); | |
843 | 2533 clear_ptr_cache_reg(regv_l(cadr(e))); |
2534 clear_ptr_cache_reg(regv_h(cadr(e))); | |
880 | 2535 return e; |
2536 } | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2537 } else if (t==FLOAT) { |
880 | 2538 if (mode==AS_SAVE) { |
2539 return get_dregister_var(0,0); | |
2540 } else if (freg_arg>=MAX_INPUT_DREGISTER_VAR) { | |
2541 return list3n(LVAR,caller_arg_offset_v(nargs),0); | |
2542 } else | |
2543 return get_input_dregister_var(freg_arg,0,0,0); | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2544 } else if (t==DOUBLE) { |
880 | 2545 if (mode==AS_SAVE) { |
2546 return get_dregister_var(0,1); | |
2547 } else if (freg_arg>=MAX_INPUT_DREGISTER_VAR) { | |
2548 return list3n(LVAR,caller_arg_offset_v(nargs),0); | |
2549 } else | |
2550 return get_input_dregister_var(freg_arg,0,0,1); | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2551 } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) { |
880 | 2552 if (mode==AS_SAVE) { |
2553 return get_register_var(0); | |
2554 } else | |
2555 return list3n(LVAR,caller_arg_offset_v(nargs),0); | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2556 } else { |
880 | 2557 error(-1); |
2558 return get_register_var(0); | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2559 } |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2560 } |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2561 |
108 | 2562 int |
89 | 2563 function(int e1) |
2564 { | |
667 | 2565 int e2,e3,e4,e5,nargs,t,r0; |
104 | 2566 int arg,reg_arg,freg_arg,arg_assign; |
136
069960078249
remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents:
135
diff
changeset
|
2567 int dots; |
111 | 2568 int reg_arg_list=0,ret_type,special_lvar; |
127 | 2569 NMTBL *fn = 0; |
108 | 2570 int jmp = 0; |
2571 char *jrn; | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2572 int complex_; |
569 | 2573 int pnargs=0,preg_arg=0,pfreg_arg=0; |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2574 int stargs; |
95 | 2575 |
111 | 2576 special_lvar = -1; |
305
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
304
diff
changeset
|
2577 ret_type = function_type(cadddr(e1),&dots); |
313 | 2578 if (caddr(cadddr(e1))==0) dots=1; |
108 | 2579 |
285 | 2580 arg_assign = 0; |
108 | 2581 e2 = cadr(e1); |
880 | 2582 if (car(e2) == FNAME) { |
2583 fn=ncaddr(e2); | |
2584 } else { | |
285 | 2585 if (car(e2)==INDIRECT) e2=cadr(e2); // (*func)(i) case |
880 | 2586 jmp = get_register_var(0); |
2587 if (car(jmp)!=REGISTER) error(-1); | |
2588 reg_arg_list = list2(jmp,reg_arg_list); | |
285 | 2589 if (!simple_arg(e2)) { |
2590 g_expr_u(assign_expr0(jmp,e2,INT,INT)); | |
2591 } else | |
880 | 2592 arg_assign = list2(assign_expr0(jmp,e2,INT,INT),arg_assign); |
108 | 2593 } |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2594 /* first we execute complex argument to avoid interaction with |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2595 input variables */ |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2596 stargs = 0; |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2597 complex_ = 0; |
259 | 2598 nargs = reg_arg = freg_arg = 0; |
880 | 2599 for (e3 = e1 = reverse0(caddr(e1)); e3; e3 = cadr(e3)) { |
2600 t=caddr(e3); | |
2601 if ((e5= !simple_arg(car(e3)))) { | |
2602 if (complex_) { | |
2603 arg = get_input_arg(caddr(complex_),AS_SAVE, | |
2604 pnargs,preg_arg,pfreg_arg); | |
2605 reg_arg_list = compute_complex_arg(complex_,reg_arg_list,arg); | |
2606 } | |
2607 pnargs=nargs;preg_arg=reg_arg;pfreg_arg=freg_arg; | |
2608 complex_ = e3; | |
2609 } | |
2610 if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) { | |
2611 // The struct should be pushed after complex arguments. | |
2612 if (e5) { // compute address only, complex_ is me now. Clear it. | |
2613 complex_ = 0; | |
2614 e4 = car(e3); | |
901
8bdd5061cb8f
RSTRUCT removal (at last)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
880
diff
changeset
|
2615 if (car(e4)==INDIRECT) e4 = cadr(e4); |
880 | 2616 if (!simple_arg(e4)) { |
2617 // Calculate complex struct address here. | |
2618 // If simple, leave it. | |
2619 arg = get_register_var(0); | |
2620 g_expr_u(assign_expr0(arg,e4,INT,INT)); | |
2621 car(e3)=arg; | |
2622 reg_arg_list = list2(arg,reg_arg_list); | |
2623 if (car(arg)==REGISTER) use_input_reg(cadr(arg),1); | |
408 | 2624 else car(e3) = rvalue_t(arg,INT); |
880 | 2625 } |
2626 } | |
2627 stargs = list4(e3,stargs,nargs,reg_arg); | |
2628 } | |
2629 increment_function_arg(e3,&nargs,®_arg,&freg_arg); | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2630 } |
108 | 2631 |
99 | 2632 /* now all input register vars are free */ |
108 | 2633 code_save_stacks(); |
222 | 2634 // set_lreg(LREG_LREGISTER,0); |
221 | 2635 set_freg(FREG_FREGISTER,0); |
207 | 2636 set_ireg(CREG_REGISTER,0); |
108 | 2637 |
268 | 2638 // Struct arguments need emit_copy. it destructs 3 input registers. |
326 | 2639 // But it returns no value on a register. So calculate it here. |
268 | 2640 // We cannot do this in the previous loop, because the copied struct may be |
326 | 2641 // override by other complex arguments. But before this we have to check |
268 | 2642 // complex_. |
2643 | |
2644 if (stargs) { | |
2645 if (complex_) { | |
2646 arg = get_input_arg(caddr(complex_),AS_SAVE, | |
2647 pnargs,preg_arg,pfreg_arg); | |
271 | 2648 reg_arg_list = compute_complex_arg(complex_,reg_arg_list,arg); |
268 | 2649 } |
2650 for(stargs=reverse0(stargs);stargs;stargs = cadr(stargs)) { | |
2651 e3 = car(stargs); | |
2652 e4 = car(e3); | |
2653 t = caddr(e3); | |
2654 arg = get_input_arg(t,AS_ARG,caddr(stargs),cadddr(stargs),0); | |
444 | 2655 push_struct(e4,t,arg); |
268 | 2656 car(e3)=0; // done |
2657 } | |
2658 } else { | |
880 | 2659 // last complex argument can use input register |
2660 if (complex_) { | |
2661 arg = get_input_arg(caddr(complex_),AS_ARG,pnargs,preg_arg,pfreg_arg); | |
2662 reg_arg_list = compute_complex_arg(complex_,reg_arg_list,arg); | |
2663 } | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2664 } |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2665 |
285 | 2666 nargs = reg_arg = freg_arg = 0; |
268 | 2667 // calc stack arguments first, it may requires extra registers, |
2668 // and we can still use input registers now. | |
259 | 2669 for (e3 = e1; e3; |
880 | 2670 increment_function_arg(e3,&nargs,®_arg,&freg_arg), |
2671 e3 = cadr(e3)) { | |
2672 if (!(e4=car(e3))) continue; | |
2673 t=caddr(e3); | |
2674 arg = get_input_arg(t,AS_ARG,nargs,reg_arg,freg_arg); | |
2675 if (car(arg)!=LVAR) continue; | |
2676 g_expr_u(assign_expr0(arg,e4,t,t)); | |
2677 if (t==LONGLONG||t==ULONGLONG) { | |
2678 if (reg_arg+1==MAX_INPUT_REGISTER_VAR) { | |
2679 // half register, half memory case | |
2680 arg_assign = list2( | |
2681 assign_expr0(r0=get_input_register_var(reg_arg,0,0), | |
2682 arg,INT,INT), | |
2683 arg_assign); | |
2684 use_input_reg(cadr(r0),1); | |
2685 } | |
2686 } | |
2687 car(e3)=0; // done | |
259 | 2688 } |
2689 nargs = reg_arg = freg_arg = 0; | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
257
diff
changeset
|
2690 for (e3 = e1; e3; |
880 | 2691 increment_function_arg(e3,&nargs,®_arg,&freg_arg), |
2692 e3 = cadr(e3)) { | |
2693 if (!(e4=car(e3))) continue; | |
2694 t=type_value(caddr(e3)); | |
2695 arg = get_input_arg(t,AS_ARG,nargs,reg_arg,freg_arg); | |
2696 if(scalar(t)) { | |
2697 reg_arg_list = list2(arg,reg_arg_list); | |
2698 /* protect from input register free */ | |
2699 if (car(arg)==REGISTER) { | |
843 | 2700 set_ireg(cadr(arg),0); |
880 | 2701 g_expr_u(assign_expr0(arg,e4,t,t)); |
2702 use_input_reg(cadr(arg),1); | |
2703 } else | |
2704 g_expr_u(assign_expr0(arg,e4,t,t)); | |
2705 } else if (t==LONGLONG||t==ULONGLONG) { | |
2706 if (reg_arg+1==MAX_INPUT_REGISTER_VAR) { | |
2707 // half register, half memory case | |
2708 // put whole long long anyway | |
2709 arg_assign = list2( | |
2710 assign_expr0(r0=get_input_register_var(reg_arg,0,0), | |
2711 arg,INT,INT), | |
2712 arg_assign); | |
2713 use_input_reg(cadr(r0),1); | |
2714 reg_arg_list = list2(r0,reg_arg_list); | |
2715 } else { | |
2716 if (car(arg)==LREGISTER) { | |
2717 use_input_reg(cadr(arg),1); | |
2718 } | |
2719 } | |
2720 reg_arg_list = list2(arg,reg_arg_list); | |
2721 g_expr_u(assign_expr0(arg,e4,t,t)); | |
2722 } else if (t==DOUBLE||t==FLOAT) { | |
667 | 2723 #ifdef __APPLE__ |
880 | 2724 if (reg_arg<MAX_INPUT_REGISTER_VAR) { |
2725 /* sigh... | |
326 | 2726 printf requires floating value in integer registers |
119 | 2727 */ |
880 | 2728 if (dots) { |
2729 int r1; | |
2730 if (car(e4)==DRLVAR) { | |
2731 special_lvar = cadr(e4); | |
2732 e5 = list3n(LVAR,special_lvar,0); | |
2733 } else { | |
2734 special_lvar = new_lvar(SIZE_OF_DOUBLE); | |
2735 g_expr(assign_expr0( | |
2736 (e5=list3n(LVAR,special_lvar,0)),e4,DOUBLE,t)); | |
2737 reg_arg_list = list2(e5,reg_arg_list); | |
2738 e4 = list2(DREGISTER,freg); | |
2739 /* freg should not change until XXX */ | |
2740 } | |
2741 r0=get_input_register_var(reg_arg,0,0); | |
2742 r1 = reg_arg+1+MIN_TMP_REG; | |
2743 if (regs[r1]==PTRC_REG) | |
2744 clear_ptr_cache_reg(list2(REGISTER,r1)); | |
2745 /* else if (regs[r1]) error(-1); */ | |
2746 r1=get_input_register_var_1(reg_arg+1,0,0); | |
2747 use_input_reg(cadr(r0),1); /* protect from input register free */ | |
2748 use_input_reg(cadr(r1),1); /* protect from input register free */ | |
2749 reg_arg_list = list2(r0,reg_arg_list); | |
2750 reg_arg_list = list2(r1,reg_arg_list); | |
2751 arg_assign = list2( assign_expr0(r0,e5,INT,INT), arg_assign); | |
2752 arg_assign = list2( assign_expr0(r1, | |
2753 list3n(LVAR,special_lvar+SIZE_OF_INT,0), | |
2754 INT,INT), arg_assign); | |
2755 } | |
2756 } | |
2757 if (dots && (freg_arg*8+reg_arg*4)>=32 && freg_arg<MAX_INPUT_DREGISTER_VAR) { | |
2758 /* | |
326 | 2759 it requires integer register and floating register and |
496 | 2760 stack value. |
119 | 2761 */ |
880 | 2762 arg_assign = list2( |
2763 assign_expr0(list3n(LVAR,caller_arg_offset_v(nargs),0), | |
2764 get_input_dregister_var(freg_arg,0,0,1),t,t), | |
2765 arg_assign); | |
2766 } | |
2767 #endif | |
2768 reg_arg_list = list2(arg,reg_arg_list); | |
2769 if (car(arg)==DREGISTER) { | |
845 | 2770 set_freg(cadr(arg),0); |
880 | 2771 g_expr_u(assign_expr0(arg,e4,t,t)); |
2772 use_input_reg(cadr(arg),1); | |
2773 } else | |
2774 g_expr_u(assign_expr0(arg,e4,t,t)); | |
2775 } | |
2776 // structs are finished | |
89 | 2777 } |
116 | 2778 if (max_func_args<nargs) max_func_args=nargs; |
104 | 2779 for(;arg_assign;arg_assign=cadr(arg_assign)) { |
880 | 2780 g_expr_u(car(arg_assign)); |
104 | 2781 } |
96 | 2782 clear_ptr_cache(); |
667 | 2783 #ifndef __APPLE__ |
673 | 2784 if (dots) { |
880 | 2785 if (freg_arg) { |
2786 // variadic function has floating value in register | |
2787 printf("\tcreqv 6,6,6\n"); | |
2788 } else { | |
2789 // printf("\tcrxor 6,6,6\n"); // for value in stack | |
2790 } | |
2791 } | |
2792 #endif | |
2793 if (car(e2) == FNAME) { | |
660 | 2794 #ifdef __APPLE__ |
880 | 2795 printf("\tbl\tL_%s$stub\n",fn->nm); |
660 | 2796 #else |
880 | 2797 printf("\tbl\t%s\n",fn->nm); |
660 | 2798 #endif |
89 | 2799 } else { |
108 | 2800 jrn = register_name(cadr(jmp)); |
89 | 2801 printf("\tmtctr %s\n",jrn); |
2802 printf("\tbctrl\n"); | |
2803 } | |
716 | 2804 free_register_var(reg_arg_list); |
105 | 2805 if (ret_type==DOUBLE||ret_type==FLOAT) { |
880 | 2806 set_freg(RET_FREGISTER,0); |
206 | 2807 } else if (ret_type==ULONGLONG||ret_type==LONGLONG) { |
880 | 2808 set_lreg(RET_LREGISTER,0); |
2809 use_reg(RET_LREGISTER); | |
105 | 2810 } else if (ret_type==VOID) { |
96 | 2811 } else { |
880 | 2812 set_ireg(RET_REGISTER,0); |
96 | 2813 } |
530 | 2814 cleanup_lregister0(); |
105 | 2815 return ret_type; |
89 | 2816 } |
2817 | |
2818 void | |
313 | 2819 code_alloca(int e1,int reg) |
2820 { | |
2821 char *crn,*grn; | |
2822 int g; | |
672 | 2823 |
2824 if (!is_const(e1)) { | |
2825 g_expr(list3(BAND,list3(ADD,e1,list2(CONST,15)),list2(CONST,~15))); | |
2826 use_int(reg); | |
2827 } else { | |
2828 use_int(reg); | |
2829 code_const(round16(cadr(e1)),reg); | |
2830 } | |
313 | 2831 use_int(reg); |
2832 g = get_register(); | |
2833 crn = register_name(reg); | |
2834 grn = register_name(g); | |
2835 // printf("\trlwinm r0,%s,0,0,27\n",crn); | |
672 | 2836 #ifdef R1SAVE |
660 | 2837 printf("\tlwz %s,0(%s)\n",grn,register_name(1)); |
313 | 2838 printf("\tneg %s,%s\n",crn,crn); |
660 | 2839 printf("\tstwux %s,%s,%s\n",grn,register_name(1),crn); |
672 | 2840 #else |
2841 printf("\tlwz %s,0(%s)\n",grn,register_name(1)); | |
2842 printf("\tneg %s,%s\n",crn,crn); | |
2843 printf("\tstwux %s,%s,%s\n",grn,register_name(1),crn); | |
2844 #endif | |
313 | 2845 // printf("\tstw %s,0(r1)\n",grn); |
2846 if (!max_func_arg_label) max_func_arg_label = fwdlabel(); | |
660 | 2847 #ifdef __APPLE__ |
313 | 2848 printf("\taddis r1,r1,ha16(L_%d)\n",max_func_arg_label); |
2849 printf("\taddi %s,r1,lo16(L_%d)\n",crn,max_func_arg_label); | |
660 | 2850 #else |
2851 printf("\taddis 1,1,.LC%d@ha\n",max_func_arg_label); | |
2852 printf("\taddi %s,1,.LC%d@l\n",crn,max_func_arg_label); | |
2853 #endif | |
313 | 2854 free_register(g); |
2855 } | |
2856 | |
2857 void | |
89 | 2858 code_frame_pointer(int e3) { |
221 | 2859 use_int(e3); |
128 | 2860 #if R1SAVE |
660 | 2861 printf("\tmr %s,%s\n",register_name(1),register_name(e3)); |
128 | 2862 #else |
667 | 2863 printf("\tmr %s,%s\n",register_name(REG_fp),register_name(e3)); |
128 | 2864 #endif |
89 | 2865 } |
2866 | |
577 | 2867 int |
2868 code_frame_pointer_register() | |
2869 { | |
2870 return list2(REGISTER,REG_fp); | |
2871 } | |
89 | 2872 |
2873 void | |
2874 code_fix_frame_pointer(int disp_offset) { | |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
2875 #if 0 |
128 | 2876 printf("\tla r30,"); |
578
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
2877 printf("lo16(%d)(r30)\n",FUNC_LVAR(0)-CODE_LVAR(0)); |
dbde3b869a0f
try to remove code_fix_frame_pointer(); PowerPC fixed.
kono
parents:
577
diff
changeset
|
2878 #endif |
89 | 2879 } |
2880 | |
2881 void | |
2882 code_jmp(char *s) { | |
128 | 2883 max_reg_var = REG_VAR_BASE-REG_VAR_MIN; |
2884 max_freg_var = FREG_VAR_BASE-FREG_VAR_MIN; | |
660 | 2885 #ifdef __APPLE__ |
89 | 2886 printf("\tb L_%s$stub\n",s); |
660 | 2887 #else |
2888 printf("\tb %s\n",s); | |
2889 #endif | |
283 | 2890 control=0; |
89 | 2891 } |
2892 | |
2893 | |
2894 void | |
2895 code_indirect_jmp(int e2) { | |
128 | 2896 max_reg_var = REG_VAR_BASE-REG_VAR_MIN; |
2897 max_freg_var = FREG_VAR_BASE-FREG_VAR_MIN; | |
221 | 2898 use_int(e2); |
89 | 2899 printf("\tmtctr %s\n",register_name(e2)); |
2900 printf("\tbctr\n"); | |
283 | 2901 control=0; |
89 | 2902 } |
2903 | |
660 | 2904 static void |
2905 code_add_op(char *op, char *crn, int offset, char *rrn) | |
2906 { | |
2907 #ifdef __APPLE__ | |
2908 if (LARGE_OFFSET(offset)) { | |
2909 printf("\taddis %s,%s,ha16(%d)\n",crn,crn,offset); | |
2910 } | |
662 | 2911 printf("\t%s %s,lo16(%d)(%s)\n",op,crn,offset,rrn); |
660 | 2912 #else |
2913 if (LARGE_OFFSET(offset)) { | |
2914 printf("\taddis %s,%s,%d@ha\n",crn,crn,offset); | |
2915 } | |
662 | 2916 printf("\t%s %s,%d@l(%s)\n",op,crn,offset,rrn); |
660 | 2917 #endif |
2918 } | |
2919 | |
355 | 2920 void |
2921 code_rindirect(int e1, int reg,int offset, int sign,int sz) | |
196 | 2922 { |
221 | 2923 char *crn,*rrn; |
196 | 2924 g_expr(e1); |
221 | 2925 if (!is_int_reg(creg)) error(-1); |
196 | 2926 crn=register_name(creg); |
221 | 2927 use_int(reg); |
2928 rrn=register_name(reg); | |
660 | 2929 code_add_op(cload(sz),rrn,offset,crn); |
355 | 2930 cext(sign,sz,reg); |
89 | 2931 } |
2932 | |
196 | 2933 #if FLOAT_CODE |
2934 int | |
221 | 2935 code_drindirect(int e1, int reg,int offset, int d) |
196 | 2936 { |
2937 char *crn; | |
2938 g_expr(e1); | |
221 | 2939 if (!is_int_reg(creg)) error(-1); |
196 | 2940 crn=register_name(creg); |
221 | 2941 use_float(d,reg); |
660 | 2942 code_add_op(fload(d),fregister_name(reg),offset,crn); |
375 | 2943 |
206 | 2944 return d?DOUBLE:FLOAT; |
196 | 2945 } |
2946 #endif | |
2947 | |
440 | 2948 #if LONGLONG_CODE |
660 | 2949 |
2950 | |
269 | 2951 static void |
2952 lload(int creg,int reg,int offset) | |
2953 { | |
2954 char *crn = register_name(creg); | |
660 | 2955 #ifdef __APPLE__ |
375 | 2956 if (LARGE_OFFSET(offset)) { |
880 | 2957 printf("\taddis %s,%s,ha16(%d)\n",crn,crn,offset); |
375 | 2958 } |
411 | 2959 #if ENDIAN_L==0 |
2960 if (creg!=regv_l(reg)) { | |
880 | 2961 printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_low(reg),offset,crn); |
2962 printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_high(reg),offset+SIZE_OF_INT,crn); | |
411 | 2963 } else { |
880 | 2964 printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_high(reg),offset+SIZE_OF_INT,crn); |
2965 printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_low(reg),offset,crn); | |
411 | 2966 } |
2967 #else | |
269 | 2968 if (creg!=regv_h(reg)) { |
880 | 2969 printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_high(reg),offset,crn); |
2970 printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); | |
269 | 2971 } else { |
880 | 2972 printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); |
2973 printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_high(reg),offset,crn); | |
269 | 2974 } |
411 | 2975 #endif |
660 | 2976 #else |
2977 if (LARGE_OFFSET(offset)) { | |
880 | 2978 printf("\taddis %s,%s,%d@ha\n",crn,crn,offset); |
660 | 2979 } |
2980 #if ENDIAN_L==0 | |
2981 if (creg!=regv_l(reg)) { | |
880 | 2982 printf("\tlwz %s,%d@l(%s)\n",lregister_name_low(reg),offset,crn); |
2983 printf("\tlwz %s,%d@l(%s)\n",lregister_name_high(reg),offset+SIZE_OF_INT,crn); | |
660 | 2984 } else { |
880 | 2985 printf("\tlwz %s,%d@l(%s)\n",lregister_name_high(reg),offset+SIZE_OF_INT,crn); |
2986 printf("\tlwz %s,%d@l(%s)\n",lregister_name_low(reg),offset,crn); | |
660 | 2987 } |
2988 #else | |
2989 if (creg!=regv_h(reg)) { | |
880 | 2990 printf("\tlwz %s,%d@l(%s)\n",lregister_name_high(reg),offset,crn); |
2991 printf("\tlwz %s,%d@l(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); | |
660 | 2992 } else { |
880 | 2993 printf("\tlwz %s,%d@l(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); |
2994 printf("\tlwz %s,%d@l(%s)\n",lregister_name_high(reg),offset,crn); | |
660 | 2995 } |
2996 #endif | |
2997 | |
2998 #endif | |
269 | 2999 } |
3000 | |
196 | 3001 int |
221 | 3002 code_lrindirect(int e1, int reg, int offset, int us) |
196 | 3003 { |
3004 char *crn; | |
222 | 3005 int creg0; |
3006 | |
196 | 3007 g_expr(e1); |
221 | 3008 if (!is_int_reg(creg)) error(-1); |
222 | 3009 crn=register_name(creg0=creg); |
221 | 3010 use_longlong(reg); |
269 | 3011 lload(creg0,reg,offset); |
206 | 3012 return us?ULONGLONG:LONGLONG; |
196 | 3013 } |
3014 #endif | |
3015 | |
89 | 3016 void |
103 | 3017 code_assign_gvar(int e2,int creg,int byte) { |
221 | 3018 use_int(creg); |
367 | 3019 code_ldf(cstore(byte),register_name(creg),cadr(e2), |
880 | 3020 get_ptr_cache(ncaddr(e2))); |
89 | 3021 } |
3022 | |
3023 void | |
103 | 3024 code_assign_lvar(int e2,int creg,int byte) { |
90 | 3025 char *crn; |
221 | 3026 use_int(creg); |
90 | 3027 crn=register_name(creg); |
119 | 3028 lvar_intro(e2); |
660 | 3029 printf("\t%s %s,",cstore(byte),crn); |
165 | 3030 lvar(e2); |
89 | 3031 } |
3032 | |
3033 void | |
111 | 3034 code_assign_register(int e2,int byte,int creg) { |
221 | 3035 use_int(creg); |
104 | 3036 if (e2!=creg) |
880 | 3037 printf("\tmr %s,%s\n",register_name(e2),register_name(creg)); |
89 | 3038 } |
3039 | |
3040 void | |
118 | 3041 code_assign(int e2,int byte,int creg) { |
233 | 3042 char *drn; |
221 | 3043 char *crn; |
233 | 3044 use_int(e2); |
3045 drn=register_name(e2); | |
221 | 3046 use_int(creg); |
3047 crn=register_name(creg); | |
95 | 3048 |
367 | 3049 printf("\t%s %s,0(%s)\n",cstore(byte),crn,drn); |
89 | 3050 } |
3051 | |
3052 | |
3053 void | |
221 | 3054 code_register_assop(int e2,int reg, int op,int byte) { |
3055 // reg <= reg(e2) op=reg | |
3056 use_int(reg); | |
3057 tosop(op,e2,reg); | |
89 | 3058 } |
3059 | |
3060 void | |
221 | 3061 code_assop(int op,int creg, int byte,int sign) { |
590 | 3062 int xreg; |
3063 // (*pop()) op = creg | |
3064 // creg should be ecx | |
3065 | |
3066 use_int(creg); | |
3067 xreg = emit_pop(0); /* pop e3 value */ | |
3068 emit_push(); | |
3069 ld_indexx(byte,0,creg,ireg,sign); | |
3070 tosop(op,ireg,xreg); | |
3071 emit_pop_free(xreg); | |
3072 xreg = emit_pop(0); /* pop e3 value */ | |
3073 printf("\t%s %s,0(%s)\n",cstore(byte), | |
880 | 3074 register_name(ireg),register_name(xreg)); |
590 | 3075 emit_pop_free(xreg); |
594 | 3076 } |
3077 | |
3078 int | |
3079 tosop_operand_safe_p(int op) | |
3080 { | |
3081 return 1; | |
89 | 3082 } |
3083 | |
3084 void | |
221 | 3085 tosop(int op,int creg,int oreg) |
89 | 3086 { |
221 | 3087 int dx = -1; |
252 | 3088 int ox = -1; |
95 | 3089 char *orn,*crn,*drn; |
221 | 3090 // creg = creg op oreg |
3091 | |
3092 use_int(creg); | |
103 | 3093 if(oreg==-1) { |
880 | 3094 error(-1); |
103 | 3095 } else if (oreg<= -REG_LVAR_OFFSET) { |
880 | 3096 ox = get_register(); if (ox<0) error(-1); |
252 | 3097 code_rlvar(oreg+REG_LVAR_OFFSET,ox); |
590 | 3098 free_lvar(oreg+REG_LVAR_OFFSET); |
880 | 3099 oreg = ox; |
103 | 3100 } |
3101 | |
89 | 3102 switch(op) { |
3103 case LSHIFT: | |
3104 case ULSHIFT: | |
880 | 3105 shift("slw",creg,oreg); |
3106 if(ox!=-1) free_register(ox); | |
3107 return; | |
89 | 3108 case RSHIFT: |
880 | 3109 shift("sraw",creg,oreg); |
3110 if(ox!=-1) free_register(ox); | |
3111 return; | |
89 | 3112 case URSHIFT: |
880 | 3113 shift("srw",creg,oreg); |
3114 if(ox!=-1) free_register(ox); | |
3115 return; | |
89 | 3116 } |
93 | 3117 orn = register_name(oreg); |
89 | 3118 crn = register_name(creg); |
3119 switch(op) { | |
3120 case ADD: | |
880 | 3121 printf("\tadd %s,%s,%s\n",crn,crn,orn); |
3122 break; | |
89 | 3123 case SUB: |
880 | 3124 printf("\tsub %s,%s,%s\n",crn,crn,orn); |
3125 break; | |
112 | 3126 case CMP: |
880 | 3127 inc_cmpflag(); |
3128 printf("\tcmpw %s,%s,%s\n",crname(cmpflag),crn,orn); | |
3129 break; | |
280 | 3130 case UCMP: |
880 | 3131 inc_cmpflag(); |
3132 printf("\tcmplw %s,%s,%s\n",crname(cmpflag),crn,orn); | |
3133 break; | |
89 | 3134 case BAND: |
880 | 3135 printf("\tand %s,%s,%s\n",crn,crn,orn); |
3136 break; | |
89 | 3137 case EOR: |
880 | 3138 printf("\txor %s,%s,%s\n",crn,crn,orn); |
3139 break; | |
89 | 3140 case BOR: |
880 | 3141 printf("\tor %s,%s,%s\n",crn,crn,orn); |
3142 break; | |
89 | 3143 case MUL: |
880 | 3144 printf("\tmullw %s,%s,%s\n",crn,crn,orn); |
3145 break; | |
89 | 3146 case UMUL: |
880 | 3147 printf("\tmullw %s,%s,%s\n",crn,crn,orn); |
3148 break; | |
89 | 3149 case DIV: |
880 | 3150 printf("\tdivw %s,%s,%s\n",crn,crn,orn); |
3151 break; | |
89 | 3152 case UDIV: |
880 | 3153 printf("\tdivwu %s,%s,%s\n",crn,crn,orn); |
3154 break; | |
89 | 3155 case MOD: |
880 | 3156 dx=get_register(); |
3157 drn = register_name(dx); | |
3158 printf("\tdivw %s,%s,%s\n",drn,crn,orn); | |
3159 printf("\tmullw %s,%s,%s\n",drn,drn,orn); | |
3160 printf("\tsubf %s,%s,%s\n",crn,drn,crn); | |
3161 break; | |
89 | 3162 case UMOD: |
880 | 3163 dx=get_register(); |
3164 drn = register_name(dx); | |
3165 printf("\tdivwu %s,%s,%s\n",drn,crn,orn); | |
3166 printf("\tmullw %s,%s,%s\n",drn,drn,orn); | |
3167 printf("\tsubf %s,%s,%s\n",crn,drn,crn); | |
3168 break; | |
112 | 3169 default: |
880 | 3170 error(-1); |
89 | 3171 } |
221 | 3172 if(dx!=-1) free_register(dx); |
252 | 3173 if(ox!=-1) free_register(ox); |
89 | 3174 } |
3175 | |
189 | 3176 int |
3177 code_const_op_p(int op,int v) | |
3178 { | |
240 | 3179 if (car(v)!=CONST) return 0; |
366 | 3180 if (op==DIV||op==UDIV) return ilog(v); |
3181 if (op==BAND||op==MOD||op==UMOD) return 0; | |
240 | 3182 v = cadr(v); |
214 | 3183 return (-32766<v&&v<32767); |
189 | 3184 } |
3185 | |
211 | 3186 void |
221 | 3187 oprtc(int op,int creg, int v) |
189 | 3188 { |
221 | 3189 char *crn; |
366 | 3190 int l; |
221 | 3191 use_int(creg); |
3192 crn = register_name(creg); | |
240 | 3193 v = cadr(v); |
221 | 3194 |
189 | 3195 switch(op) { |
3196 case LSHIFT: | |
3197 case ULSHIFT: | |
880 | 3198 printf("\tslwi %s,%s,%d\n",crn,crn,v); |
3199 return; | |
366 | 3200 case DIV: |
880 | 3201 v = ilog(v); |
189 | 3202 case RSHIFT: |
880 | 3203 printf("\tsrawi %s,%s,%d\n",crn,crn,v); |
3204 return; | |
366 | 3205 case UDIV: |
880 | 3206 v = ilog(v); |
189 | 3207 case URSHIFT: |
880 | 3208 printf("\tsrwi %s,%s,%d\n",crn,crn,v); |
3209 return; | |
189 | 3210 case ADD: |
660 | 3211 #ifdef __APPLE__ |
880 | 3212 printf("\taddi %s,%s,lo16(%d)\n",crn,crn,v); |
660 | 3213 #else |
880 | 3214 printf("\taddi %s,%s,%d@l\n",crn,crn,v); |
3215 #endif | |
3216 break; | |
189 | 3217 case SUB: |
660 | 3218 #ifdef __APPLE__ |
880 | 3219 printf("\taddi %s,%s,lo16(-%d)\n",crn,crn,v); |
660 | 3220 #else |
880 | 3221 printf("\taddi %s,%s,-%d@l\n",crn,crn,v); |
3222 #endif | |
3223 break; | |
189 | 3224 case CMP: |
880 | 3225 inc_cmpflag(); |
660 | 3226 #ifdef __APPLE__ |
880 | 3227 printf("\tcmpwi %s,%s,lo16(%d)\n",crname(cmpflag),crn,v); |
660 | 3228 #else |
880 | 3229 printf("\tcmpwi %s,%s,%d@l\n",crname(cmpflag),crn,v); |
3230 #endif | |
3231 break; | |
354 | 3232 case UCMP: |
880 | 3233 inc_cmpflag(); |
660 | 3234 #ifdef __APPLE__ |
880 | 3235 printf("\tcmplwi %s,%s,lo16(%d)\n",crname(cmpflag),crn,v); |
660 | 3236 #else |
880 | 3237 printf("\tcmplwi %s,%s,%d@l\n",crname(cmpflag),crn,v); |
3238 #endif | |
3239 break; | |
189 | 3240 case EOR: |
660 | 3241 #ifdef __APPLE__ |
880 | 3242 printf("\txori %s,%s,lo16(%d)\n",crn,crn,v); |
660 | 3243 #else |
880 | 3244 printf("\txori %s,%s,%d@l\n",crn,crn,v); |
3245 #endif | |
3246 break; | |
189 | 3247 case BOR: |
660 | 3248 #ifdef __APPLE__ |
880 | 3249 printf("\tori %s,%s,lo16(%d)\n",crn,crn,v); |
660 | 3250 #else |
880 | 3251 printf("\tori %s,%s,%d@l\n",crn,crn,v); |
3252 #endif | |
3253 break; | |
189 | 3254 case MUL: |
3255 case UMUL: | |
880 | 3256 if ((l=ilog(v))) { |
3257 printf("\tslwi %s,%s,%d\n",crn,crn,l); | |
3258 } else | |
660 | 3259 #ifdef __APPLE__ |
880 | 3260 printf("\tmulli %s,%s,lo16(%d)\n",crn,crn,v); |
660 | 3261 #else |
880 | 3262 printf("\tmulli %s,%s,%d@l\n",crn,crn,v); |
3263 #endif | |
3264 break; | |
189 | 3265 default: |
880 | 3266 error(-1); |
189 | 3267 } |
3268 } | |
89 | 3269 |
3270 void | |
221 | 3271 shift(char *op, int creg, int reg) |
89 | 3272 { |
221 | 3273 char *crn; |
93 | 3274 char *rrn = register_name(reg); |
221 | 3275 use_int(creg); |
3276 crn = register_name(creg); | |
186 | 3277 printf("\t%s %s,%s,%s\n",op,crn,crn,rrn); |
89 | 3278 } |
3279 | |
3280 void | |
221 | 3281 ld_indexx(int byte, int n, int xreg,int creg, int sign) |
880 | 3282 { |
221 | 3283 char *crn; |
3284 use_int(creg); | |
3285 crn = register_name(creg); | |
246 | 3286 printf("\t%s %s,%d(%s)\n",cload(byte),register_name(creg),n, |
880 | 3287 register_name(xreg)); |
246 | 3288 cext(sign,byte,creg); |
89 | 3289 } |
3290 | |
95 | 3291 int |
3292 code_csvalue() | |
3293 { | |
458 | 3294 return glist2(REGISTER,creg); |
95 | 3295 } |
3296 | |
89 | 3297 void |
287 | 3298 code_cmpdimm(int e, int csreg,int label,int cond) |
89 | 3299 { |
415 | 3300 int reg,regsv; |
89 | 3301 /* used in dosiwtch() */ |
291 | 3302 inc_cmpflag(); |
3303 if (-32767<e&&e<32767) { | |
880 | 3304 printf("\tcmpwi %s,%s,%d\n",crname(cmpflag),register_name(csreg),e); |
3305 jcond(label,cond); | |
291 | 3306 } else { |
880 | 3307 regsv = regs[csreg]; regs[csreg]=USING_REG; |
3308 reg = get_register(); | |
3309 regs[csreg]= regsv; | |
3310 code_const(e,reg); | |
3311 printf("\tcmpw %s,%s,%s\n",crname(cmpflag),register_name(csreg),register_name(reg)); | |
3312 jcond(label,cond); | |
3313 free_register(reg); | |
291 | 3314 } |
89 | 3315 } |
3316 | |
3317 void | |
3318 code_opening(char *filename) | |
3319 { | |
3320 printf("\t.file \"%s\"\n",filename); | |
108 | 3321 /* printf("\t.version\t\"01.01\"\n"); */ |
804 | 3322 printf("cbc_compiled.:\n"); |
605 | 3323 // printf(".text\n"); |
804 | 3324 #ifndef __APPLE__ |
3325 printf( | |
3326 " .set r0,0\n" | |
3327 " .set r1,1\n" | |
3328 " .set r2,2\n" | |
3329 " .set r3,3\n" | |
3330 " .set r4,4\n" | |
3331 " .set r5,5\n" | |
3332 " .set r6,6\n" | |
3333 " .set r7,7\n" | |
3334 " .set r8,8\n" | |
3335 " .set r9,9\n" | |
3336 " .set r10,10\n" | |
3337 " .set r11,11\n" | |
3338 " .set r12,12\n" | |
3339 " .set r13,13\n" | |
3340 " .set r14,14\n" | |
3341 " .set r15,15\n" | |
3342 " .set r16,16\n" | |
3343 " .set r17,17\n" | |
3344 " .set r18,18\n" | |
3345 " .set r19,19\n" | |
3346 " .set r20,20\n" | |
3347 " .set r21,21\n" | |
3348 " .set r22,22\n" | |
3349 " .set r23,23\n" | |
3350 " .set r24,24\n" | |
3351 " .set r25,25\n" | |
3352 " .set r26,26\n" | |
3353 " .set r27,27\n" | |
3354 " .set r28,28\n" | |
3355 " .set r29,29\n" | |
3356 " .set r30,30\n" | |
3357 " .set r31,31\n" | |
3358 ); | |
3359 #endif | |
3360 | |
89 | 3361 } |
3362 | |
288 | 3363 #define CRBITSIZ 4 |
3364 | |
3365 static int | |
3366 rexpr_bool(int e1,int reg) | |
3367 { | |
3368 int t,flag=-1,eq=-1,neg=-1; | |
3369 char *rn; | |
3370 switch(car(e1)) { | |
3371 case GT: t=INT; flag = 2; break; | |
3372 case UGT: t=0; flag = 2; break; | |
3373 case GE: t=INT; flag = 2; eq=3; break; | |
3374 case UGE: t=0; flag = 2; eq=3; break; | |
3375 case LT: t=INT; flag = 1; break; | |
3376 case ULT: t=0; flag = 1; break; | |
3377 case LE: t=INT; flag = 1; eq=3; break; | |
3378 case ULE: t=0; flag = 1; eq=3; break; | |
3379 case EQ: t=INT; flag = 3; break; | |
289 | 3380 case NEQ: t=INT; flag = 3; neg=3; break; |
288 | 3381 default: return 0; |
3382 } | |
3383 g_expr(list3((t==INT?CMP:UCMP),cadr(e1),caddr(e1))); | |
3384 use_int(reg); | |
3385 rn = register_name(reg); | |
289 | 3386 t = CRBITSIZ*cmpflag; |
288 | 3387 if (eq>0) { |
880 | 3388 printf("\tcror %d,%d,%d\n",t+flag-1,t+eq-1,t+flag-1); |
289 | 3389 } |
3390 if (neg>0) { | |
880 | 3391 neg = t+neg-1, |
3392 printf("\tcrnor %d,%d,%d\n",neg,neg,neg); | |
288 | 3393 } |
3394 printf("\tmfcr %s\n",rn); | |
289 | 3395 printf("\trlwinm %s,%s,%d,1\n",rn,rn,t+flag); |
288 | 3396 return 1; |
3397 } | |
3398 | |
438
626d705471d5
Unexecuted code in conditional. Lazy jmp code generation.
kono
parents:
436
diff
changeset
|
3399 int |
280 | 3400 rexpr(int e1, int l1, int cond,int t) |
89 | 3401 { |
569 | 3402 char *s=0; |
433 | 3403 switch(car(e1)+BNOT*(!cond)) { |
3404 case GT: s=code_gt(1); break; | |
3405 case UGT: s=code_ugt(1); break; | |
3406 case GE: s=code_ge(1); break; | |
3407 case UGE: s=code_uge(1); break; | |
3408 case LT: s=code_ge(!1); break; | |
3409 case ULT: s=code_uge(!1);break; | |
3410 case LE: s=code_gt(!1); break; | |
3411 case ULE: s=code_ugt(!1);break; | |
3412 case EQ: s=code_eq(1); break; | |
3413 case NEQ: s=code_eq(!1); break; | |
3414 case GT+BNOT: s=code_gt(0); break; | |
3415 case UGT+BNOT: s=code_ugt(0); break; | |
3416 case GE+BNOT: s=code_ge(0); break; | |
3417 case UGE+BNOT: s=code_uge(0); break; | |
3418 case LT+BNOT: s=code_ge(!0); break; | |
3419 case ULT+BNOT: s=code_uge(!0);break; | |
3420 case LE+BNOT: s=code_gt(!0); break; | |
3421 case ULE+BNOT: s=code_ugt(!0);break; | |
3422 case EQ+BNOT: s=code_eq(0); break; | |
3423 case NEQ+BNOT: s=code_eq(!0); break; | |
280 | 3424 default: error(-1); |
3425 } | |
3426 g_expr(list3((t==INT?CMP:UCMP),cadr(e1),caddr(e1))); | |
662 | 3427 printf("\tb%s %s,%s%d\n",s,crname(cmpflag),lpfx,l1); |
438
626d705471d5
Unexecuted code in conditional. Lazy jmp code generation.
kono
parents:
436
diff
changeset
|
3428 return l1; |
89 | 3429 } |
3430 | |
287 | 3431 static void |
89 | 3432 jcond(int l, char cond) |
3433 { | |
297 | 3434 if (cond==LT) { |
880 | 3435 printf("\tb%s %s,%s%d\n",code_ge(0),crname(cmpflag),lpfx,l); |
297 | 3436 } else if (cond==1||cond==0) { |
880 | 3437 printf("\tb%s %s,%s%d\n",cond?"ne":"eq",crname(cmpflag),lpfx,l); |
297 | 3438 } else error(-1); |
89 | 3439 } |
3440 | |
3441 void | |
3442 jmp(int l) | |
3443 { | |
662 | 3444 printf("\tb\t%s%d\n",lpfx,l); |
89 | 3445 } |
3446 | |
327 | 3447 extern void |
456 | 3448 code_comment(char *s) |
89 | 3449 { |
307 | 3450 printf("## %s",s); |
89 | 3451 } |
3452 | |
3453 void | |
3454 code_enter(char *name) | |
3455 { | |
660 | 3456 #ifdef __APPLE__ |
100
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3457 if (output_mode!=TEXT_EMIT_MODE) |
880 | 3458 text_mode(0); |
100
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3459 else |
880 | 3460 printf("\t.align 2\n"); |
89 | 3461 if (stmode!=STATIC) |
880 | 3462 printf(".globl _%s\n",name); |
126 | 3463 #ifdef DOT_SIZE |
89 | 3464 printf("\t.type\t%s,@function\n",name); |
126 | 3465 #endif |
101 | 3466 printf("_%s:\n",name); |
100
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3467 code_disp_label=fwdlabel(); |
417 | 3468 #if 0 |
128 | 3469 printf("\tla r1,lo16(L_%d)(r30)\n",code_disp_label); |
417 | 3470 #else |
3471 printf("\tla r1,lo16(L_%d)(r30)\n",code_disp_label); | |
3472 printf("\taddis r1,r1,ha16(L_%d)\n",code_disp_label); | |
3473 #endif | |
126 | 3474 printf("\tbcl 20,31,L_%d\n",code_base = fwdlabel()); |
3475 fwddef(code_base); | |
3476 printf("\tmflr r31\n"); | |
119 | 3477 max_func_args = 0; |
489 | 3478 clear_ptr_cache(); |
660 | 3479 #else |
3480 if (output_mode!=TEXT_EMIT_MODE) | |
880 | 3481 text_mode(0); |
660 | 3482 else |
880 | 3483 printf("\t.align 2\n"); |
660 | 3484 if (stmode!=STATIC) |
880 | 3485 printf(".globl %s\n",name); |
660 | 3486 #ifdef DOT_SIZE |
3487 printf("\t.type\t%s,@function\n",name); | |
3488 #endif | |
3489 printf("%s:\n",name); | |
3490 code_disp_label=fwdlabel(); | |
3491 #if 0 | |
3492 printf("\tla r1,lo16(L_%d)(r30)\n",code_disp_label); | |
3493 #else | |
672 | 3494 printf("\tla 1,%s%d@l(31)\n",lpfx,code_disp_label); |
3495 printf("\taddis 1,1,%s%d@ha\n",lpfx,code_disp_label); | |
660 | 3496 #endif |
3497 max_func_args = 0; | |
3498 clear_ptr_cache(); | |
3499 #endif | |
89 | 3500 } |
3501 | |
3502 | |
3503 void | |
3504 code_enter1(int args) | |
3505 { | |
222 | 3506 // set_lreg(LREG_LREGISTER,0); |
207 | 3507 set_ireg(CREG_REGISTER,0); |
106 | 3508 set_freg(FREG_FREGISTER,0); |
89 | 3509 } |
3510 | |
3511 void | |
3512 code_leave(char *name) | |
3513 { | |
128 | 3514 int r1_offsetv; |
245 | 3515 disp&= -SIZE_OF_INT; |
603 | 3516 r1_offsetv = -disp+max_func_args*SIZE_OF_INT -code_disp_offset0 +8+32+48; |
660 | 3517 #ifdef __APPLE__ |
128 | 3518 printf(".set L_%d,%d\n",code_disp_label,-r1_offsetv); |
417 | 3519 if (max_func_arg_label) { |
880 | 3520 printf(".set L_%d,%d\n",max_func_arg_label,max_func_args*SIZE_OF_INT+24); |
3521 max_func_arg_label = 0; | |
417 | 3522 } |
660 | 3523 #else |
3524 printf(".set .LC%d,%d\n",code_disp_label,-r1_offsetv); | |
3525 if (max_func_arg_label) { | |
880 | 3526 printf(".set .LC%d,%d\n",max_func_arg_label,max_func_args*SIZE_OF_INT+24); |
3527 max_func_arg_label = 0; | |
660 | 3528 } |
3529 #endif | |
89 | 3530 local_table(); |
208 | 3531 // free_all_register(); |
89 | 3532 } |
3533 | |
3534 void | |
3535 enter(char *name) | |
3536 { | |
660 | 3537 #ifdef __APPLE__ |
100
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3538 if (output_mode!=TEXT_EMIT_MODE) |
880 | 3539 text_mode(0); |
100
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3540 else |
880 | 3541 printf("\t.align 2\n"); |
89 | 3542 if (stmode!=STATIC) |
880 | 3543 printf(".globl %s%s\n",npfx,name); |
108 | 3544 /* |
100
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3545 printf("\t.type\t%s,@function\n",name); |
108 | 3546 */ |
662 | 3547 printf("%s%s:\n",npfx,name); |
100
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3548 code_setup=fwdlabel(); |
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3549 printf("\tmflr r0\n"); |
102 | 3550 printf("\tbl L_%d\n",code_setup); |
100
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3551 code_base=fwdlabel(); |
111 | 3552 fwddef(code_base); |
116 | 3553 r1_offset_label = fwdlabel(); |
3554 lvar_offset_label = fwdlabel(); | |
375 | 3555 #if 0 |
3556 printf("\taddi r30,r1,lo16(-L_%d)\n",lvar_offset_label); | |
116 | 3557 printf("\tstwu r1,lo16(-L_%d)(r1)\n",r1_offset_label); |
375 | 3558 // printf("\tmr r30,r1\n"); |
3559 #else | |
3560 printf("\taddi r30,r1,lo16(-L_%d)\n",lvar_offset_label); | |
3561 printf("\tlis r31,ha16(-L_%d)\n",r1_offset_label); | |
3562 printf("\taddi r31,r31,lo16(-L_%d)\n",r1_offset_label); | |
3563 printf("\tstwux r1,r1,r31\n"); | |
3564 #endif | |
100
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3565 printf("\tmflr r31\n"); |
660 | 3566 #else |
3567 if (output_mode!=TEXT_EMIT_MODE) | |
880 | 3568 text_mode(0); |
660 | 3569 else |
880 | 3570 printf("\t.align 2\n"); |
660 | 3571 if (stmode!=STATIC) |
880 | 3572 printf(".globl %s%s\n",npfx,name); |
660 | 3573 /* |
3574 printf("\t.type\t%s,@function\n",name); | |
3575 */ | |
3576 printf("%s:\n",name); | |
805
362b0258b4db
fix func_disp_offset in PS3
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
804
diff
changeset
|
3577 control = 1; |
660 | 3578 code_setup=fwdlabel(); |
672 | 3579 arg_offset_label = fwdlabel(); |
660 | 3580 printf("\tmflr 0\n"); |
672 | 3581 printf("\tstwu %d,-%s%d@l(%d)\n",1,lpfx,arg_offset_label,1); |
660 | 3582 printf("\tbl .LC%d\n",code_setup); |
3583 r1_offset_label = fwdlabel(); | |
3584 lvar_offset_label = fwdlabel(); | |
667 | 3585 |
672 | 3586 printf("\tmr %d,1\n",REG_fp); |
3587 printf("\taddi %d,1,-%s%d@l\n",REG_fp,lpfx,lvar_offset_label); | |
667 | 3588 printf("\tlis %d,-%s%d@ha\n",30,lpfx,r1_offset_label); |
672 | 3589 printf("\taddi %d,%d,-%s%d@l\n",30,30,lpfx,r1_offset_label); |
667 | 3590 printf("\tstwux 1,1,%d\n",30); |
660 | 3591 #endif |
116 | 3592 max_func_args = 0; |
489 | 3593 clear_ptr_cache(); |
89 | 3594 } |
3595 | |
3596 void | |
3597 enter1() | |
3598 { | |
516 | 3599 text_mode(0); |
208 | 3600 // set_lreg(LREG_LREGISTER,0); |
207 | 3601 set_ireg(CREG_REGISTER,0); |
106 | 3602 set_freg(FREG_FREGISTER,0); |
100
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3603 } |
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3604 |
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3605 int |
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3606 reg_save_offset() |
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3607 { |
108 | 3608 return -( |
880 | 3609 (REAL_MAX_REGISTER-(REG_VAR_BASE-max_reg_var))*SIZE_OF_INT+ |
3610 (REAL_MAX_FREGISTER-(FREG_VAR_BASE-max_freg_var))*SIZE_OF_DOUBLE | |
3611 ); | |
89 | 3612 } |
3613 | |
3614 void | |
450
eaf9e2746c83
parallel assign for simple expr. (too complex solution)
kono
parents:
449
diff
changeset
|
3615 code_label_call(int l) |
eaf9e2746c83
parallel assign for simple expr. (too complex solution)
kono
parents:
449
diff
changeset
|
3616 { |
660 | 3617 #ifdef __APPLE__ |
880 | 3618 printf("\tbl\tL_%d\n",l); |
660 | 3619 #else |
880 | 3620 printf("\tbl\t.LC%d\n",l); |
660 | 3621 #endif |
450
eaf9e2746c83
parallel assign for simple expr. (too complex solution)
kono
parents:
449
diff
changeset
|
3622 } |
eaf9e2746c83
parallel assign for simple expr. (too complex solution)
kono
parents:
449
diff
changeset
|
3623 |
eaf9e2746c83
parallel assign for simple expr. (too complex solution)
kono
parents:
449
diff
changeset
|
3624 void |
eaf9e2746c83
parallel assign for simple expr. (too complex solution)
kono
parents:
449
diff
changeset
|
3625 code_ret() |
eaf9e2746c83
parallel assign for simple expr. (too complex solution)
kono
parents:
449
diff
changeset
|
3626 { |
880 | 3627 printf("\tblr\n"); |
450
eaf9e2746c83
parallel assign for simple expr. (too complex solution)
kono
parents:
449
diff
changeset
|
3628 } |
eaf9e2746c83
parallel assign for simple expr. (too complex solution)
kono
parents:
449
diff
changeset
|
3629 |
663 | 3630 #ifndef __APPLE__ |
3631 static int saveFP_used=0; | |
3632 static char *saveFP_lib[] = { | |
3633 ".saveFP: stfd 14,-144(1)", | |
3634 " stfd 15,-136(1)", | |
3635 " stfd 16,-128(1)", | |
3636 " stfd 17,-120(1)", | |
3637 " stfd 18,-112(1)", | |
3638 " stfd 19,-104(1)", | |
3639 " stfd 20,-96(1)", | |
3640 " stfd 21,-88(1)", | |
3641 " stfd 22,-80(1)", | |
3642 " stfd 23,-72(1)", | |
3643 " stfd 24,-64(1)", | |
3644 " stfd 25,-56(1)", | |
3645 " stfd 26,-48(1)", | |
3646 " stfd 27,-40(1)", | |
3647 " stfd 28,-32(1)", | |
3648 " stfd 29,-24(1)", | |
672 | 3649 " stfd 31,-16(1)", |
3650 " stfd 30,-8(1)", | |
676 | 3651 " stw 0,4(1)", |
663 | 3652 " blr", |
672 | 3653 ".restFP: ", |
3654 " lfd 14,-144(1)", | |
663 | 3655 " lfd 15,-136(1)", |
3656 " lfd 16,-128(1)", | |
3657 " lfd 17,-120(1)", | |
3658 " lfd 18,-112(1)", | |
3659 " lfd 19,-104(1)", | |
3660 " lfd 20,-96(1)", | |
3661 " lfd 21,-88(1)", | |
3662 " lfd 22,-80(1)", | |
3663 " lfd 23,-72(1)", | |
3664 " lfd 24,-64(1)", | |
3665 " lfd 25,-56(1)", | |
3666 " lfd 26,-48(1)", | |
3667 " lfd 27,-40(1)", | |
3668 " lfd 28,-32(1)", | |
3669 " lfd 29,-24(1)", | |
672 | 3670 " lwz 0,4(1)", |
3671 " lfd 31,-16(1)", | |
3672 " lwz 1,0(1)", | |
663 | 3673 " mtlr 0", |
672 | 3674 " blr", |
663 | 3675 0 |
3676 }; | |
3677 #endif | |
3678 | |
726 | 3679 static void |
3680 make_return_continuation() | |
3681 { | |
3682 #if R1SAVE | |
880 | 3683 retcont1 = fwdlabel(); |
3684 #endif | |
3685 fwddef(retcont); | |
3686 if (cadr(fnptr->ty)==FLOAT||cadr(fnptr->ty)==DOUBLE) { | |
3687 printf("\tfmr %s,%s\n",fregister_name(1),fregister_name(31)); | |
3688 printf("\tmr %s,%s\n",register_name(30),register_name(28)); | |
3689 } else if (cadr(fnptr->ty)>0&&( | |
3690 car(cadr(fnptr->ty))==STRUCT || | |
3691 car(cadr(fnptr->ty))==UNION)) { | |
3692 int sz = size(cadr(fnptr->ty)); | |
726 | 3693 #ifdef __APPLE__ |
880 | 3694 printf("\tli r7,%d\n",sz); |
3695 printf("\tsubl r6,r7,r30\n"); | |
3696 printf("\tlwz r3,lo16(%d)(r30)\n",(my_func_args-1)*SIZE_OF_INT); | |
3697 // emit_copy(6,3,sz,0,1,1); | |
726 | 3698 #else |
880 | 3699 printf("\tli 7,%d\n",sz); |
3700 printf("\tsubl 6,7,%d\n",REG_fp); | |
3701 printf("\tlwz 3,%d@l(%d)\n",(my_func_args-1)*SIZE_OF_INT,REG_fp); | |
3702 // emit_copy(6,3,sz,0,1,1); | |
3703 #endif | |
3704 printf("\tmr %s,%s\n",register_name(30),register_name(28)); | |
3705 } else if (cadr(fnptr->ty)!=VOID) { | |
3706 printf("\tmr %s,%s\n",register_name(3),register_name(29)); | |
3707 printf("\tmr %s,%s\n",register_name(30),register_name(28)); | |
3708 } | |
726 | 3709 #if R1SAVE |
880 | 3710 jmp(retcont1); |
726 | 3711 #else |
3712 #endif | |
3713 } | |
3714 | |
450
eaf9e2746c83
parallel assign for simple expr. (too complex solution)
kono
parents:
449
diff
changeset
|
3715 void |
89 | 3716 leave(int control, char *name) |
3717 { | |
577 | 3718 #if R1SAVE |
726 | 3719 int retcont1=0; |
577 | 3720 #else |
3721 #endif | |
128 | 3722 |
3723 if (max_freg_var>=0 && max_freg_var<=3) max_freg_var=3; | |
3724 reg_save = reg_save_offset(); | |
111 | 3725 |
100
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3726 if (control) { |
880 | 3727 code_set_return_register(1); |
89 | 3728 } |
126 | 3729 if (retcont) { |
880 | 3730 if (control) jmp(retlabel); |
3731 make_return_continuation(); | |
126 | 3732 } |
89 | 3733 fwddef(retlabel); |
577 | 3734 #if R1SAVE |
662 | 3735 printf("\tlwz %s,0(%s)\n",register_name(1),register_name(1)); |
128 | 3736 if (retcont) { |
880 | 3737 fwddef(retcont1); |
128 | 3738 } |
577 | 3739 #else |
662 | 3740 #ifdef __APPLE__ |
577 | 3741 printf("\taddi r1,r30,lo16(L_%d)\n",lvar_offset_label); |
662 | 3742 #else |
672 | 3743 printf("\taddi 1,%d,%s%d@l\n",REG_fp,lpfx,lvar_offset_label); |
662 | 3744 #endif |
577 | 3745 #endif |
110 | 3746 if (max_freg_var>=0) { |
663 | 3747 #ifdef __APPLE__ |
880 | 3748 printf("\tlmw r%d,%d(%s)\n", |
3749 REG_VAR_BASE-max_reg_var,reg_save,register_name(1)); | |
3750 freg_save = 72-(REAL_MAX_FREGISTER-(FREG_VAR_BASE-max_freg_var))*4; | |
3751 printf("\tb restFP+%d ; restore f%d-f31\n", | |
3752 freg_save, | |
3753 FREG_VAR_BASE-max_freg_var); | |
662 | 3754 #else |
880 | 3755 printf("\tlmw %d,%d(%s)\n", |
3756 REG_VAR_BASE-max_reg_var,reg_save,register_name(1)); | |
3757 freg_save = 72-(REAL_MAX_FREGISTER-(FREG_VAR_BASE-max_freg_var))*4; | |
3758 printf("\tb .restFP+%d # restore f%d-f31\n", | |
3759 freg_save, | |
3760 FREG_VAR_BASE-max_freg_var); | |
662 | 3761 #endif |
100
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3762 } else { |
662 | 3763 #ifdef __APPLE__ |
880 | 3764 printf("\tlwz r0,8(r1)\n"); |
3765 printf("\tmtlr r0\n"); | |
3766 printf("\tlmw r%d,%d(r1)\n", | |
3767 REG_VAR_BASE-max_reg_var,reg_save); | |
662 | 3768 #else |
880 | 3769 printf("\tlmw %d,%d(1)\n", |
3770 REG_VAR_BASE-max_reg_var,reg_save); | |
3771 printf("\tlwz %s,4(1)\n",register_name(0)); | |
3772 printf("\tlwz 1,0(1)\n"); | |
3773 printf("\tmtlr %s\n",register_name(0)); | |
3774 #endif | |
3775 code_ret(); | |
100
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3776 } |
89 | 3777 |
245 | 3778 disp &= -SIZE_OF_INT; |
100
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3779 fwddef(code_setup); |
672 | 3780 #ifdef __APPLE__ |
662 | 3781 printf("\tstmw %s,%d(%s)\n", |
880 | 3782 register_name(REG_VAR_BASE-max_reg_var),reg_save,register_name(1)); |
662 | 3783 printf("\tstw %s,8(%s)\n",register_name(0),register_name(1)); |
672 | 3784 #else |
3785 printf("\tstmw %s,%d(%s)\n", | |
880 | 3786 register_name(REG_VAR_BASE-max_reg_var),reg_save,register_name(1)); |
672 | 3787 printf("\tstw %s,4(%s)\n",register_name(0),register_name(1)); |
3788 #endif | |
663 | 3789 if (max_freg_var>=0) { |
664 | 3790 #ifdef __APPLE__ |
880 | 3791 printf("\tb saveFP+%d ; save f%d-f31\n", |
3792 freg_save, | |
3793 FREG_VAR_BASE-max_freg_var); | |
662 | 3794 #else |
880 | 3795 saveFP_used = 1; |
3796 printf("\tb .saveFP+%d # save f%d-f31\n", | |
3797 freg_save, | |
3798 FREG_VAR_BASE-max_freg_var); | |
662 | 3799 #endif |
663 | 3800 } else { |
880 | 3801 printf("\tblr\n"); |
110 | 3802 } |
100
a9e6f2a2946f
Wrote all code for PowerPC and no compile error. Let's fix all bugs...
kono
parents:
99
diff
changeset
|
3803 |
116 | 3804 code_offset_set(); |
89 | 3805 local_table(); |
3806 labelno++; | |
208 | 3807 // free_all_register(); |
89 | 3808 } |
3809 | |
3810 | |
705 | 3811 int |
107 | 3812 code_set_return_register(int mode) { |
111 | 3813 if (cadr(fnptr->ty)==DOUBLE||cadr(fnptr->ty)==FLOAT) { |
880 | 3814 set_freg(RET_FREGISTER,mode); |
3815 return freg; | |
206 | 3816 } else if (cadr(fnptr->ty)==LONGLONG||cadr(fnptr->ty)==ULONGLONG) { |
880 | 3817 set_lreg(RET_LREGISTER,mode); |
3818 return lreg; | |
147 | 3819 } else if (cadr(fnptr->ty)==VOID) { |
880 | 3820 return 0; |
103 | 3821 } else { |
880 | 3822 set_ireg(RET_REGISTER,mode); |
3823 return ireg; | |
103 | 3824 } |
89 | 3825 } |
3826 | |
187 | 3827 int |
3828 code_get_fixed_creg(int reg,int type) { | |
3829 return creg; | |
3830 } | |
3831 | |
89 | 3832 void |
187 | 3833 code_set_fixed_creg(int reg,int mode,int type) { |
108 | 3834 if (type==FLOAT||type==DOUBLE) { |
880 | 3835 set_freg(reg,mode); |
206 | 3836 } else if (type==LONGLONG||type==ULONGLONG) { |
880 | 3837 set_lreg(reg,mode); |
3838 // use_reg(reg); | |
108 | 3839 } else { |
880 | 3840 set_ireg(reg,mode); |
108 | 3841 } |
107 | 3842 } |
3843 | |
3844 void | |
89 | 3845 gen_gdecl(char *n, int gpc) |
3846 { | |
102 | 3847 /* |
89 | 3848 if (stmode!=STATIC) |
880 | 3849 printf(".globl _%s\n",n); |
102 | 3850 */ |
89 | 3851 } |
3852 | |
340 | 3853 extern void |
3854 ascii(char *s) | |
3855 { | |
517 | 3856 cstring_mode(); |
662 | 3857 #ifdef __APPLE__ |
340 | 3858 printf("\t.ascii \""); |
662 | 3859 #else |
3860 printf("\t.string \""); | |
3861 #endif | |
340 | 3862 while(*s) { |
880 | 3863 if (*s=='\n') |
3864 printf("%cn",92); | |
3865 else if (*s<' ') | |
3866 printf("%c%03o",92,*s); | |
3867 else if (*s=='\\') | |
3868 printf("\\\\"); | |
3869 else if (*s==34) | |
3870 printf("%c%c",92,34); | |
3871 else | |
3872 printf("%c",*s); | |
3873 s++; | |
340 | 3874 } |
3875 printf("\\0%c\n\t.align 2\n",34); | |
3876 } | |
3877 | |
3878 extern int | |
3879 emit_string_label() { | |
3880 int lb; | |
3881 | |
3882 lb=fwdlabel(); | |
516 | 3883 cstring_mode(); |
662 | 3884 printf("%s%d:\n",lpfx,lb); |
340 | 3885 return lb; |
3886 } | |
3887 | |
518 | 3888 extern void |
3889 emit_string(char *s,int t) | |
3890 { | |
3891 t = type_value(t); | |
3892 if (car(t)==ARRAY && | |
3893 (type_value(cadr(t))==CHAR||type_value(cadr(t))==UCHAR)) { | |
3894 ascii(s); | |
3895 } else { | |
3896 int l = emit_string_label(); | |
3897 ascii(s); | |
3898 emit_label(l); | |
3899 } | |
3900 return; | |
3901 } | |
3902 | |
415 | 3903 void |
716 | 3904 code_align(int t) |
89 | 3905 { |
415 | 3906 int d; |
3907 switch(t) { | |
3908 case CHAR: case UCHAR: return; | |
3909 case SHORT: case USHORT: d = data_alignment & 1; break; | |
3910 default: d = data_alignment & 3; | |
3911 } | |
3912 if (d) { | |
3913 printf("\t.align 2\n"); | |
3914 data_alignment = 0; | |
89 | 3915 } |
3916 } | |
3917 | |
516 | 3918 void |
517 | 3919 emit_global(NMTBL *n,int a,int e) |
340 | 3920 { |
517 | 3921 int t = type_value(n->ty); |
3922 if (e>0 && car(e)==STRING && t>0 && car(t)==ARRAY && | |
880 | 3923 (type_value(cadr(t))==CHAR||type_value(cadr(t))==UCHAR)) { |
3924 cstring_mode(); | |
517 | 3925 } else |
880 | 3926 data_mode(n->nm); |
542 | 3927 if (n && n->sc!=STATIC) |
880 | 3928 printf("\t.globl\t%s%s\n",npfx,n->nm); |
662 | 3929 printf("%s%s:\n",npfx,n->nm); |
340 | 3930 } |
3931 | |
3932 extern void | |
3933 emit_space(int sp) | |
3934 { | |
3935 data_mode(0); | |
3936 printf("\t.space\t%d\n",sp); | |
3937 } | |
3938 | |
3939 extern void | |
3940 emit_char(int d) | |
89 | 3941 { |
340 | 3942 data_mode(0); |
3943 printf("\t.byte %d\n",d); | |
3944 } | |
3945 | |
3946 extern void | |
3947 emit_short(int d) | |
3948 { | |
3949 data_mode(0); | |
3950 printf("\t.short %d\n",d); | |
3951 } | |
3952 | |
3953 extern void | |
3954 emit_int(int d) | |
3955 { | |
3956 data_mode(0); | |
3957 printf("\t.long %d\n",d); | |
3958 } | |
3959 | |
3960 extern void | |
3961 emit_longlong(int e) | |
3962 { | |
206 | 3963 #if LONGLONG_CODE |
341 | 3964 long long d = lcadr(e); |
340 | 3965 data_mode(0); |
411 | 3966 #if ENDIAN_L==0 |
3967 printf("\t.long\t0x%x,0x%x\n",code_l1(d),code_l2(d)); | |
3968 #else | |
340 | 3969 printf("\t.long\t0x%x,0x%x\n",code_l2(d),code_l1(d)); |
195 | 3970 #endif |
411 | 3971 #endif |
340 | 3972 } |
3973 | |
3974 extern void | |
3975 emit_double(int e) | |
3976 { | |
195 | 3977 #if FLOAT_CODE |
341 | 3978 double d = dcadr(e); |
340 | 3979 data_mode(0); |
411 | 3980 #if ENDIAN_D==0 |
3981 printf("\t.long\t0x%x,0x%x\n",code_d1(d),code_d2(d)); | |
3982 #else | |
340 | 3983 printf("\t.long\t0x%x,0x%x\n",code_d2(d),code_d1(d)); |
339 | 3984 #endif |
411 | 3985 #endif |
340 | 3986 } |
3987 | |
3988 extern void | |
3989 emit_float(int e) | |
3990 { | |
3991 #if FLOAT_CODE | |
341 | 3992 float f = dcadr(e); |
340 | 3993 data_mode(0); |
3994 printf("\t.long\t0x%x\n",*(int *)&f); | |
3995 #endif | |
3996 } | |
3997 | |
3998 extern void | |
367 | 3999 emit_address(char *s,int offset) |
340 | 4000 { |
4001 data_mode(0); | |
367 | 4002 if (offset) |
880 | 4003 printf("\t.long %s%s+%d\n",npfx,s,offset); |
367 | 4004 else |
880 | 4005 printf("\t.long %s%s\n",npfx,s); |
340 | 4006 } |
4007 | |
4008 extern void | |
4009 emit_label(int labelno) | |
4010 { | |
4011 data_mode(0); | |
662 | 4012 printf("\t.long %s%d\n",lpfx,labelno); |
340 | 4013 } |
4014 | |
4015 extern void | |
89 | 4016 emit_data_closing(NMTBL *n) |
4017 { | |
126 | 4018 #ifdef DOT_SIZE |
89 | 4019 int lb; |
126 | 4020 #endif |
89 | 4021 if (mode==GDECL) { |
662 | 4022 #ifdef DOT_SIZE |
4023 #ifdef __APPLE__ | |
880 | 4024 data_mode(0); |
4025 lb=fwdlabel(); | |
4026 printf("%s%d:\n",lpfx,lb); | |
4027 printf("\t.size\t%s,%s%d-%%ss\n",n->nm,lb,lpfx,npfx,n->nm); | |
662 | 4028 #else |
880 | 4029 data_mode(0); |
4030 lb=fwdlabel(); | |
4031 printf(".LC%d:\n",lb); | |
4032 printf("\t.size\t%s,%s%d-%s%s\n",n->nm,lb,lpfx,npfx,n->nm); | |
662 | 4033 #endif |
126 | 4034 #endif |
89 | 4035 } |
4036 } | |
4037 | |
662 | 4038 #ifdef __APPLE__ |
89 | 4039 void |
4040 global_table(void) | |
4041 { | |
4042 NMTBL *n; | |
98 | 4043 int init; char *extrn; |
89 | 4044 init=0; |
803 | 4045 global_list = reversen(global_list); |
4046 text_mode(0); | |
350 | 4047 for(n = global_list;n!=&null_nptr;n = n->next) { |
880 | 4048 if ((n->sc == GVAR) && n->dsp != -1) { |
4049 /* n->dsp = -1 means initialized global */ | |
4050 if (init==0) { | |
4051 // data_mode(0); | |
4052 text_mode(0); | |
4053 printf("\t.align 3\n"); | |
4054 init=1; | |
4055 } | |
4056 int align; | |
4057 if ((align=attr_value(n,ALIGNED))) { | |
4058 int a = ilog(caddr(align)); | |
4059 printf(".comm %s%s,%d,%d\n",npfx,n->nm,size(n->ty),a); | |
4060 } else if (size(n->ty)>1) { | |
4061 printf(".comm %s%s,%d,2\n",npfx,n->nm,size(n->ty)); | |
4062 } else | |
4063 printf(".comm %s%s,%d\n",npfx,n->nm,size(n->ty)); | |
4064 } else if ((n->sc==STATIC) && n->dsp != -1) { | |
4065 /* n->dsp = -1 means initialized global */ | |
4066 if (is_code(n)||is_function(n)) continue; | |
4067 if (init==0) { | |
4068 text_mode(0); | |
4069 printf("\t.align 8\n"); | |
4070 // data_mode(0); | |
4071 init=1; | |
4072 } | |
4073 printf(".lcomm %s%s,%d\n",npfx,n->nm,size(n->ty)); | |
4074 } | |
97 | 4075 } |
350 | 4076 for(n = global_list;n!=&null_nptr;n = n->next) { |
880 | 4077 if (is_code(n)||is_function(n)) { |
4078 extrn = n->nm; | |
4079 if (n->sc==EXTRN1) { | |
4080 data_mode(0); | |
103 | 4081 printf(".picsymbol_stub\n"); |
97 | 4082 printf("L_%s$stub:\n",extrn); |
4083 printf("\t.indirect_symbol _%s\n",extrn); | |
4084 printf("\tmflr r0\n"); | |
4085 printf("\tbcl 20,31,L0$_%s\n",extrn); | |
4086 printf("L0$_%s:\n",extrn); | |
4087 printf("\tmflr r11\n"); | |
4088 printf("\taddis r11,r11,ha16(L_%s$lazy_ptr-L0$_%s)\n",extrn,extrn); | |
4089 printf("\tmtlr r0\n"); | |
4090 printf("\tlwz r12,lo16(L_%s$lazy_ptr-L0$_%s)(r11)\n",extrn,extrn); | |
4091 printf("\tmtctr r12\n"); | |
4092 printf("\taddi r11,r11,lo16(L_%s$lazy_ptr-L0$_%s)\n",extrn,extrn); | |
4093 printf("\tbctr\n"); | |
4094 printf(".data\n"); | |
4095 printf(".lazy_symbol_pointer\n"); | |
4096 printf("L_%s$lazy_ptr:\n",extrn); | |
4097 printf("\t.indirect_symbol _%s\n",extrn); | |
4098 printf("\t.long dyld_stub_binding_helper\n"); | |
880 | 4099 } else if (n->sc==STATIC) { |
4100 text_mode(0); | |
103 | 4101 printf("\t.set L_%s$stub,_%s\n",extrn,extrn); |
880 | 4102 data_mode(0); |
111 | 4103 printf("L_%s$non_lazy_ptr:\n\t.long\t_%s\n",extrn,extrn); |
880 | 4104 } |
4105 } | |
97 | 4106 } |
109 | 4107 init=0; |
350 | 4108 for(n = global_list;n!=&null_nptr;n = n->next) { |
880 | 4109 if (n->sc == GVAR) { |
4110 if (init==0) { | |
4111 printf(".data\n"); | |
4112 init=1; | |
4113 } | |
116 | 4114 printf("L_%s$non_lazy_ptr:\n\t.long\t_%s\n",n->nm,n->nm); |
880 | 4115 } |
109 | 4116 } |
97 | 4117 init = 0; |
350 | 4118 for(n = global_list;n!=&null_nptr;n = n->next) { |
880 | 4119 if ((is_code(n)||is_function(n))&& |
4120 !has_attr(n,FNAME)) // not used as value | |
4121 continue; | |
4122 if (n->sc==EXTRN1) { | |
4123 if(init==0) { | |
4124 printf(".data\n"); | |
97 | 4125 printf(".non_lazy_symbol_pointer\n"); |
880 | 4126 init=1; |
4127 } | |
97 | 4128 printf("L_%s$non_lazy_ptr:\n",n->nm); |
4129 printf("\t.indirect_symbol _%s\n",n->nm); | |
4130 printf("\t.long\t0\n"); | |
880 | 4131 } |
89 | 4132 } |
4133 } | |
662 | 4134 #else |
4135 | |
4136 static void | |
4137 comm(NMTBL *n) | |
4138 { | |
4139 int align = 1; | |
803 | 4140 if ((align=attr_value(n,ALIGNED))) { |
880 | 4141 align = ilog(caddr(align)); |
809 | 4142 } else { |
880 | 4143 if (size(n->ty)>4) |
4144 align = 2; | |
4145 else if (size(n->ty)>4) | |
4146 align = 0; | |
4147 switch(n->ty) { | |
4148 case DOUBLE: | |
4149 case LONGLONG: | |
4150 case ULONGLONG: | |
4151 align = 8; break; | |
4152 case INT: | |
4153 case UNSIGNED: | |
4154 case FLOAT: | |
4155 align = 4; break; | |
4156 case SHORT: | |
4157 case USHORT: | |
4158 align = 2; break; | |
4159 } | |
662 | 4160 } |
4161 printf("\t.comm %s,%d,%d\n",n->nm,size(n->ty),align); | |
4162 } | |
4163 | |
4164 void | |
4165 global_table(void) | |
4166 { | |
4167 NMTBL *n; | |
4168 int init; | |
4169 init=0; | |
809 | 4170 global_list = reversen(global_list); |
662 | 4171 for(n=global_list;n;n=n->next) { |
4172 if ((n->sc == GVAR) && n->dsp != -1) { | |
4173 /* n->dsp = -1 means initialized global */ | |
4174 if (init==0) { | |
4175 data_mode(0); | |
4176 init=1; | |
4177 } | |
4178 comm(n); | |
4179 } else if ((n->sc==STATIC) && n->dsp != -1) { | |
4180 /* n->dsp = -1 means initialized global */ | |
4181 if (is_code(n)||is_function(n)) continue; | |
4182 if (init==0) { | |
4183 data_mode(0); | |
4184 init=1; | |
4185 } | |
4186 // printf(".local %s\n",n->nm); | |
4187 comm(n); | |
4188 } | |
4189 } | |
4190 } | |
4191 #endif | |
4192 | |
4193 #ifdef __APPLE__ | |
89 | 4194 void |
4195 local_table(void) | |
4196 { | |
4197 NMTBL *n; | |
4198 int init; | |
4199 init=0; | |
4200 /* static local variables */ | |
350 | 4201 for(n = local_static_list;n!=&null_nptr;n = n->next) { |
880 | 4202 if (n->sc == STATIC) { |
4203 if (init==0) { | |
4204 data_mode(0); | |
4205 init=1; | |
4206 } | |
4207 if (n->dsp != -1) /* initialized static */ | |
4208 printf(".lcomm _%s,%d\n",n->nm,size(n->ty)); | |
4209 printf("L_%s$non_lazy_ptr:\n\t.long\t_%s\n",n->nm,n->nm); | |
4210 } | |
89 | 4211 } |
4212 } | |
662 | 4213 #else |
4214 void | |
4215 local_table(void) | |
4216 { | |
4217 NMTBL *n; | |
4218 int init; | |
4219 init=0; | |
4220 /* static local variables */ | |
4221 for(n = local_static_list;n!=&null_nptr;n = n->next) { | |
880 | 4222 if (n->sc == STATIC) { |
4223 if (init==0) { | |
4224 data_mode(0); | |
4225 init=1; | |
4226 } | |
4227 if (n->dsp != -1) /* initialized static */ | |
4228 printf(".lcomm %s,%d\n",n->nm,size(n->ty)); | |
4229 } | |
662 | 4230 } |
4231 } | |
4232 #endif | |
89 | 4233 |
4234 void | |
516 | 4235 cstring_mode(int align) |
4236 { | |
4237 if (output_mode!=RODATA_EMIT_MODE) { | |
662 | 4238 #ifdef __APPLE__ |
516 | 4239 printf(".cstring\n\t.align 2\n"); |
662 | 4240 #else |
4241 printf("\t.section\t.rodata\n\t.align 2\n"); | |
4242 #endif | |
516 | 4243 output_mode = RODATA_EMIT_MODE; |
4244 } | |
4245 } | |
4246 | |
4247 void | |
4248 text_mode(int align) | |
89 | 4249 { |
4250 if (output_mode!=TEXT_EMIT_MODE) { | |
880 | 4251 printf(".text\n"); |
4252 printf("\t.align 2\n"); | |
4253 output_mode = TEXT_EMIT_MODE; | |
89 | 4254 } |
4255 } | |
4256 | |
4257 void | |
4258 data_mode(char *name) | |
4259 { | |
4260 if (output_mode!=DATA_EMIT_MODE) { | |
880 | 4261 printf(".data\n"); |
4262 output_mode = DATA_EMIT_MODE; | |
89 | 4263 } |
108 | 4264 /* |
89 | 4265 if (name) |
880 | 4266 printf("\t.type\t%s,@object\n",name); |
108 | 4267 */ |
89 | 4268 } |
4269 | |
195 | 4270 #if FLOAT_CODE |
4271 | |
89 | 4272 /* floating point */ |
4273 | |
96 | 4274 static int float_one_lib_used=0; |
4275 static char *float_one_lib[] = { | |
4276 ".data", | |
108 | 4277 /* ".literal8", */ |
96 | 4278 " .align 3", |
4279 "__float_one:", | |
4280 " .long 1065353216", | |
4281 ".text", | |
109 | 4282 /* ".set L__float_one$non_lazy_ptr,__float_one", */ |
96 | 4283 0 |
4284 }; | |
97 | 4285 static int float_zero_lib_used=0; |
4286 static char *float_zero_lib[] = { | |
4287 ".data", | |
108 | 4288 /* ".literal8", */ |
97 | 4289 " .align 3", |
4290 "__float_zero:", | |
4291 " .long 0", | |
4292 ".text", | |
109 | 4293 /* ".set L__float_zero$non_lazy_ptr,__float_zero", */ |
97 | 4294 0 |
4295 }; | |
4296 | |
739
0c7a6ae119ba
i64 continue... compiler compiled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
726
diff
changeset
|
4297 char * fstore(int d) |
89 | 4298 { |
90 | 4299 return (d?"stfd":"stfs"); |
89 | 4300 } |
4301 | |
4302 char * | |
4303 fload(int d) | |
4304 { | |
90 | 4305 return d?"lfd":"lfs"; |
89 | 4306 } |
4307 | |
95 | 4308 void |
287 | 4309 code_cmp_dregister(int e2,int d,int label,int cond) |
95 | 4310 { |
99 | 4311 char *frn,*rrn,*grn; |
4312 int greg,r; | |
662 | 4313 grn = fregister_name(greg = get_dregister(d)); |
221 | 4314 use_float(d,e2); |
132 | 4315 frn = register_name(e2); |
99 | 4316 float_zero_lib_used=1; |
109 | 4317 r = get_ptr_cache(&float_zero); |
99 | 4318 rrn = register_name(r); |
108 | 4319 printf("\tlfs %s,0(%s)\n",grn,rrn); |
291 | 4320 inc_cmpflag(); |
662 | 4321 printf("\tfcmpu %s,%s,%s\n",crname(cmpflag),grn,frn); |
147 | 4322 free_register(greg); |
287 | 4323 jcond(label,cond); |
99 | 4324 return; |
95 | 4325 } |
4326 | |
4327 void | |
138 | 4328 code_dregister(int e2,int freg,int d) |
95 | 4329 { |
221 | 4330 use_float(d,freg); |
147 | 4331 if (freg!=e2) { |
880 | 4332 if (is_int_reg(e2)) error(-1); |
4333 printf("\tfmr %s,%s\n",fregister_name(freg),fregister_name(e2)); | |
147 | 4334 } |
95 | 4335 } |
4336 | |
211 | 4337 void |
4338 code_dassign_gvar(int e2,int freg,int d) | |
89 | 4339 { |
221 | 4340 use_float(d,freg); |
367 | 4341 code_ldf(fstore(d),fregister_name(freg),cadr(e2), |
880 | 4342 get_ptr_cache(ncaddr(e2))); |
89 | 4343 } |
4344 | |
211 | 4345 void |
4346 code_dassign_lvar(int e2,int freg,int d) | |
89 | 4347 { |
221 | 4348 use_float(d,freg); |
119 | 4349 lvar_intro(e2); |
4350 printf("\t%s %s,",fstore(d),fregister_name(freg)); | |
4351 lvar(e2); | |
89 | 4352 } |
4353 | |
211 | 4354 void |
4355 code_dassign(int e2,int freg,int d) | |
89 | 4356 { |
221 | 4357 use_float(d,freg); |
108 | 4358 printf("\t%s %s,0(%s)\n",fstore(d),fregister_name(freg),register_name(e2)); |
89 | 4359 } |
4360 | |
111 | 4361 void |
138 | 4362 code_dassign_dregister(int e2,int d,int freg) { |
221 | 4363 use_float(d,freg); |
147 | 4364 if (e2!=freg) { |
880 | 4365 printf("\tfmr %s,%s\n",fregister_name(e2),fregister_name(freg)); |
147 | 4366 } |
111 | 4367 } |
4368 | |
89 | 4369 static double d0 = 1.0; |
4370 | |
4371 int | |
4372 code_d1(double d) | |
4373 { | |
4374 int *i = (int *)&d0; int *j = (int *)&d; | |
99 | 4375 return (i[1] == 0x3ff00000)?j[0]:j[1]; |
89 | 4376 } |
4377 | |
4378 int | |
4379 code_d2(double d) | |
4380 { | |
4381 int *i = (int *)&d0; int *j = (int *)&d; | |
99 | 4382 return (i[1] == 0x3ff00000)?j[1]:j[0]; |
89 | 4383 } |
4384 | |
133 | 4385 int |
4386 code_f(double d) | |
4387 { | |
4388 float f = d; | |
4389 int *j = (int *)&f; | |
4390 return *j; | |
4391 } | |
4392 | |
779 | 4393 static void emit_dconst0(ValuePtr value, int lb, void *arg) |
4394 { | |
4395 long d = (long) arg; | |
4396 printf(" \t.data\n\t.align 3\n"); | |
4397 printf("%s%d:\n",lpfx,lb); | |
4398 if (d) { | |
4399 #if ENDIAN_D==0 | |
880 | 4400 printf("\t.long\t0x%x,0x%x\n",code_d1(value->d),code_d2(value->d)); |
779 | 4401 #else |
880 | 4402 printf("\t.long\t0x%x,0x%x\n",code_d2(value->d),code_d1(value->d)); |
779 | 4403 #endif |
4404 } else { | |
880 | 4405 printf("\t.long\t0x%x\n",code_f(value->f)); |
779 | 4406 } |
4407 if (output_mode==TEXT_EMIT_MODE) { | |
880 | 4408 printf(".text\n"); |
779 | 4409 } else { |
880 | 4410 text_mode(0); |
779 | 4411 } |
4412 } | |
4413 | |
4414 /* load double / float const | |
4415 we should keep what constant we have create | |
4416 */ | |
4417 | |
211 | 4418 void |
138 | 4419 code_dconst(int e2,int freg,int d) |
89 | 4420 { |
780
c5315f472912
ia32/powerpc regression test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
779
diff
changeset
|
4421 int sz; |
779 | 4422 Value value; |
4423 value.d = dcadr(e2); | |
90 | 4424 int r; |
97 | 4425 char *rrn,*frn; |
221 | 4426 use_float(d,freg); |
97 | 4427 frn = fregister_name(freg); |
779 | 4428 if (value.d==0.0) { |
880 | 4429 float_zero_lib_used=1; |
4430 r = get_ptr_cache(&float_zero); | |
4431 rrn = register_name(r); | |
4432 printf("\tlfs %s,0(%s)\n",frn,rrn); | |
4433 return; | |
89 | 4434 } |
779 | 4435 if (value.d==1.0) { |
880 | 4436 float_one_lib_used=1; |
4437 r = get_ptr_cache(&float_one); | |
4438 rrn = register_name(r); | |
4439 printf("\tlfs %s,0(%s)\n",frn,rrn); | |
4440 return; | |
89 | 4441 } |
779 | 4442 if (d) { |
4443 sz = sizeof(double); | |
4444 } else { | |
4445 sz = sizeof(float); | |
4446 value.f = (float) value.d; | |
4447 } | |
4448 | |
4449 long d_mode = d; | |
4450 int lb = get_data_label(&value,sz,emit_dconst0, (void*) d_mode); | |
4451 | |
97 | 4452 rrn = register_name((r=get_register())); |
780
c5315f472912
ia32/powerpc regression test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
779
diff
changeset
|
4453 // use_reg(r); // to clear ptr cache |
662 | 4454 code_label_value(lb,r); |
138 | 4455 if (d) { |
880 | 4456 printf("\tlfd %s,0(%s)\n",frn,rrn); |
133 | 4457 } else { |
880 | 4458 printf("\tlfs %s,0(%s)\n",frn,rrn); |
133 | 4459 } |
90 | 4460 free_register(r); |
89 | 4461 } |
4462 | |
616 | 4463 void |
4464 code_builtin_fabsf(int e) | |
4465 { | |
4466 char *frn; | |
4467 g_expr0(e); | |
4468 use_float(0,freg); | |
4469 frn = fregister_name(freg); | |
4470 printf("\tfabs %s,%s\n",frn,frn); | |
4471 } | |
4472 | |
4473 void | |
4474 code_builtin_fabs(int e) | |
4475 { | |
4476 char *frn; | |
4477 g_expr0(e); | |
4478 use_float(1,freg); | |
4479 frn = fregister_name(freg); | |
4480 printf("\tfabs %s,%s\n",frn,frn); | |
4481 } | |
4482 | |
4483 static void | |
4484 code_inf(int d) | |
4485 { | |
4486 int lb; | |
4487 int r; | |
4488 char *rrn,*frn; | |
4489 int freg = USE_CREG; | |
4490 | |
4491 use_float(d,freg); | |
4492 frn = fregister_name(freg); | |
4493 rrn = register_name((r=get_register())); | |
4494 use_reg(r); // to clear ptr cache | |
4495 printf(" \t.data\n\t.align 3\n"); | |
4496 lb=fwdlabel(); | |
4497 printf("L_%d:\n",lb); | |
4498 if (d) { | |
4499 #if ENDIAN_D==0 | |
880 | 4500 printf("\t.long\t0x%x,0x%x\n",0,0x7ff00000); |
616 | 4501 #else |
880 | 4502 printf("\t.long\t0x%x,0x%x\n",0x7ff00000,0); |
616 | 4503 #endif |
4504 } else { | |
880 | 4505 printf("\t.long\t0x%x\n",0x7f800000); |
616 | 4506 } |
4507 if (output_mode==TEXT_EMIT_MODE) { | |
880 | 4508 printf(".text\n"); |
616 | 4509 } else { |
880 | 4510 text_mode(0); |
616 | 4511 } |
662 | 4512 code_label_value(lb,r); |
616 | 4513 if (d) { |
880 | 4514 printf("\tlfd %s,0(%s)\n",frn,rrn); |
616 | 4515 } else { |
880 | 4516 printf("\tlfs %s,0(%s)\n",frn,rrn); |
616 | 4517 } |
4518 free_register(r); | |
4519 } | |
4520 | |
4521 void | |
4522 code_builtin_inff() | |
4523 { | |
4524 code_inf(0); | |
4525 } | |
4526 | |
4527 void | |
4528 code_builtin_inf() | |
4529 { | |
4530 code_inf(1); | |
4531 } | |
4532 | |
4533 | |
133 | 4534 |
211 | 4535 void |
4536 code_dneg(int freg,int d) | |
89 | 4537 { |
221 | 4538 char *frn; |
4539 use_float(d,freg); | |
4540 frn = fregister_name(freg); | |
95 | 4541 printf("\tfneg %s,%s\n",frn,frn); |
89 | 4542 } |
4543 | |
211 | 4544 void |
221 | 4545 code_d2i() |
89 | 4546 { |
147 | 4547 char *frn; |
4548 char *crn; | |
245 | 4549 int e2 = new_lvar(SIZE_OF_DOUBLE); |
147 | 4550 |
221 | 4551 use_double0(); |
4552 frn = fregister_name(freg); | |
4553 use_int0(); | |
147 | 4554 crn = register_name(creg); |
4555 | |
119 | 4556 free_lvar(e2); |
93 | 4557 printf("\tfctiwz %s,%s\n",frn,frn); |
119 | 4558 lvar_intro(e2); |
4559 printf("\tstfd %s,",frn); lvar(e2); | |
245 | 4560 lvar_intro(e2+SIZE_OF_DOUBLE-SIZE_OF_INT); |
4561 printf("\tlwz %s,",crn); lvar(e2+SIZE_OF_DOUBLE-SIZE_OF_INT); | |
89 | 4562 } |
4563 | |
91 | 4564 static int i2d_lib_used=0; |
662 | 4565 #ifdef __APPLE__ |
91 | 4566 static char *i2d_lib[] = { |
4567 ".data", | |
108 | 4568 /* ".literal8", */ |
91 | 4569 " .align 3", |
4570 "__i2dLC0:", | |
4571 " .long 1127219200", | |
4572 " .long -2147483648", | |
4573 ".text", | |
4574 " .align 2", | |
111 | 4575 "i2d_:", |
91 | 4576 " mflr r0", |
4577 " bcl 20,31,__i2dL1$pb", | |
4578 "__i2dL1$pb:", | |
4579 " mflr r10", | |
4580 " mtlr r0", | |
4581 " xoris r3,r3,0x8000", | |
375 | 4582 " stw r3,-28(r1)", |
91 | 4583 " lis r0,0x4330", |
375 | 4584 " stw r0,-32(r1)", |
4585 " lfd f0,-32(r1)", | |
91 | 4586 " addis r9,r10,ha16(__i2dLC0-__i2dL1$pb)", |
4587 " lfd f1,lo16(__i2dLC0-__i2dL1$pb)(r9)", | |
4588 " fsub f1,f0,f1", | |
4589 " blr", | |
4590 0 | |
4591 }; | |
662 | 4592 #else |
4593 static char *i2d_lib[] = { | |
4594 ".data", | |
4595 /* ".literal8", */ | |
4596 " .align 3", | |
663 | 4597 "__i2dLC0:", |
662 | 4598 " .long 1127219200", |
4599 " .long -2147483648", | |
4600 ".text", | |
4601 " .align 2", | |
4602 "i2d_:", | |
4603 " xoris 3,3,0x8000", | |
4604 " stw 3,-28(1)", | |
4605 " lis 0,0x4330", | |
4606 " stw 0,-32(1)", | |
4607 " lfd 0,-32(1)", | |
673 | 4608 " lis 9,__i2dLC0@ha", |
4609 " lfd 1,__i2dLC0@l(9)", | |
662 | 4610 " fsub 1,0,1", |
4611 " blr", | |
4612 0 | |
4613 }; | |
4614 #endif | |
91 | 4615 |
211 | 4616 void |
221 | 4617 code_i2d() |
89 | 4618 { |
95 | 4619 i2d_lib_used = 1; |
113 | 4620 clear_ptr_cache(); |
4621 code_save_stacks(); | |
207 | 4622 set_ireg(RET_REGISTER,1); |
91 | 4623 printf("\tbl i2d_\n"); |
104 | 4624 set_freg(RET_FREGISTER,0); |
89 | 4625 } |
4626 | |
91 | 4627 static int d2u_lib_used=0; |
662 | 4628 #ifdef __APPLE__ |
91 | 4629 static char *d2u_lib[] = { |
108 | 4630 /* ".literal8", */ |
91 | 4631 " .align 3", |
4632 "__d2uLC0:", | |
4633 " .long 1105199104", | |
4634 " .long 0", | |
4635 ".text", | |
4636 " .align 2", | |
111 | 4637 "d2u_:", |
91 | 4638 " mflr r0", |
4639 " bcl 20,31,__d2uL1$pb", | |
4640 "__d2uL1$pb:", | |
4641 " mflr r10", | |
4642 " mtlr r0", | |
4643 " addis r9,r10,ha16(__d2uLC0-__d2uL1$pb)", | |
4644 " lfd f0,lo16(__d2uLC0-__d2uL1$pb)(r9)", | |
4645 " fcmpu cr0,f1,f0", | |
4646 " cror 2,1,2", | |
4647 " beq- cr0,__d2uL2", | |
4648 " fctiwz f0,f1", | |
375 | 4649 " stfd f0,-32(r1)", |
4650 " lwz r3,-28(r1)", | |
91 | 4651 " blr", |
4652 "__d2uL2:", | |
4653 " addis r9,r10,ha16(__d2uLC0-__d2uL1$pb)", | |
4654 " lfd f0,lo16(__d2uLC0-__d2uL1$pb)(r9)", | |
4655 " fsub f0,f1,f0", | |
4656 " fctiwz f0,f0", | |
375 | 4657 " stfd f0,-24(r1)", |
4658 " lwz r3,-20(r1)", | |
91 | 4659 " xoris r3,r3,0x8000", |
4660 " blr", | |
4661 0 | |
4662 }; | |
662 | 4663 #else |
4664 static char *d2u_lib[] = { | |
4665 /* ".literal8", */ | |
4666 " .align 3", | |
4667 "__d2uLC0:", | |
4668 " .long 1105199104", | |
4669 " .long 0", | |
4670 ".text", | |
4671 " .align 2", | |
4672 "d2u_:", | |
673 | 4673 " lis 9,__d2uLC0@ha", |
4674 " lfd 0,__d2uLC0@l(9)", | |
663 | 4675 " fcmpu 0,1,0", |
662 | 4676 " cror 2,1,2", |
663 | 4677 " beq- 0,__d2uL2", |
4678 " fctiwz 0,1", | |
4679 " stfd 0,-32(1)", | |
4680 " lwz 3,-28(1)", | |
662 | 4681 " blr", |
4682 "__d2uL2:", | |
673 | 4683 " lis 9,__d2uLC0@ha", |
4684 " lfd 0,__d2uLC0@l(9)", | |
663 | 4685 " fsub 0,1,0", |
4686 " fctiwz 0,0", | |
4687 " stfd 0,-24(1)", | |
4688 " lwz 3,-20(1)", | |
4689 " xoris 3,3,0x8000", | |
662 | 4690 " blr", |
4691 0 | |
4692 }; | |
4693 #endif | |
91 | 4694 |
211 | 4695 void |
221 | 4696 code_d2u() |
89 | 4697 { |
113 | 4698 code_save_stacks(); |
4699 clear_ptr_cache(); | |
91 | 4700 d2u_lib_used=1; |
104 | 4701 set_freg(RET_FREGISTER,1); |
111 | 4702 printf("\tbl d2u_\n"); |
207 | 4703 set_ireg(RET_REGISTER,0); |
91 | 4704 } |
90 | 4705 |
91 | 4706 static int u2d_lib_used=0; |
662 | 4707 #ifdef __APPLE__ |
91 | 4708 static char *u2d_lib[] = { |
4709 ".data", | |
108 | 4710 /* ".literal8", */ |
91 | 4711 " .align 3", |
4712 "__u2dLC1:", | |
4713 " .long 1127219200", | |
4714 " .long 0", | |
4715 ".text", | |
4716 " .align 2", | |
111 | 4717 "u2d_:", |
91 | 4718 " mflr r0", |
4719 " bcl 20,31,__u2dL2$pb", | |
4720 "__u2dL2$pb:", | |
4721 " mflr r10", | |
4722 " mtlr r0", | |
375 | 4723 " stw r3,-28(r1)", |
91 | 4724 " lis r0,0x4330", |
375 | 4725 " stw r0,-32(r1)", |
4726 " lfd f0,-32(r1)", | |
91 | 4727 " addis r9,r10,ha16(__u2dLC1-__u2dL2$pb)", |
4728 " lfd f1,lo16(__u2dLC1-__u2dL2$pb)(r9)", | |
4729 " fsub f1,f0,f1", | |
4730 " blr", | |
4731 0 | |
4732 }; | |
662 | 4733 #else |
4734 static char *u2d_lib[] = { | |
4735 ".data", | |
4736 /* ".literal8", */ | |
4737 " .align 3", | |
4738 "__u2dLC1:", | |
4739 " .long 1127219200", | |
4740 " .long 0", | |
4741 ".text", | |
4742 " .align 2", | |
673 | 4743 ".u2d_:", |
4744 " stw 3,-28(1)", | |
4745 " lis 0,0x4330", | |
4746 " stw 0,-32(1)", | |
4747 " lfd 0,-32(1)", | |
4748 " lis 9,__u2dLC1@ha", | |
4749 " lfd 1,__u2dLC1@l(9)", | |
4750 " fsub 1,0,1", | |
662 | 4751 " blr", |
4752 0 | |
4753 }; | |
4754 #endif | |
89 | 4755 |
211 | 4756 void |
221 | 4757 code_u2d() |
89 | 4758 { |
113 | 4759 code_save_stacks(); |
4760 clear_ptr_cache(); | |
147 | 4761 u2d_lib_used = 1; |
207 | 4762 set_ireg(RET_REGISTER,1); |
673 | 4763 #ifdef __APPLE__ |
111 | 4764 printf("\tbl u2d_\n"); |
673 | 4765 #else |
4766 printf("\tbl .u2d_\n"); | |
4767 #endif | |
228 | 4768 set_freg(RET_FREGISTER,0); |
89 | 4769 } |
4770 | |
211 | 4771 void |
221 | 4772 code_d2f() { } |
211 | 4773 void |
221 | 4774 code_f2d() { } |
211 | 4775 void |
221 | 4776 code_f2i() { code_d2i(); } |
211 | 4777 void |
221 | 4778 code_f2u() { code_d2u(); } |
211 | 4779 void |
221 | 4780 code_i2f() { code_i2d(); } |
211 | 4781 void |
221 | 4782 code_u2f() { code_u2d(); } |
211 | 4783 |
4784 void | |
4785 code_drgvar(int e2,int d,int freg) | |
89 | 4786 { |
221 | 4787 use_float(d,freg); |
367 | 4788 code_ldf(fload(d),fregister_name(freg),cadr(e2), |
880 | 4789 get_ptr_cache(ncaddr(e2))); |
89 | 4790 } |
4791 | |
4792 | |
211 | 4793 void |
4794 code_drlvar(int e2,int d,int freg) | |
89 | 4795 { |
221 | 4796 use_float(d,freg); |
119 | 4797 lvar_intro(e2); |
4798 printf("\t%s %s,",fload(d),fregister_name(freg)); lvar(e2); | |
89 | 4799 } |
4800 | |
211 | 4801 void |
287 | 4802 code_cmp_drgvar(int e2,int reg,int d,int label,int cond) |
89 | 4803 { |
221 | 4804 char *frn; |
138 | 4805 int g=get_dregister(d); |
97 | 4806 char *grn=fregister_name(g); |
221 | 4807 |
4808 use_float(d,reg); | |
4809 frn=fregister_name(reg); | |
4810 | |
367 | 4811 code_ldf(fload(1),grn,cadr(e2), |
880 | 4812 get_ptr_cache(ncaddr(e2))); |
291 | 4813 inc_cmpflag(); |
662 | 4814 printf("\tfcmpu %s,%s,%s\n",crname(cmpflag),frn,grn); |
147 | 4815 free_register(g); |
287 | 4816 jcond(label,cond); |
89 | 4817 } |
4818 | |
211 | 4819 void |
287 | 4820 code_cmp_drlvar(int e2,int reg,int d,int label,int cond) |
89 | 4821 { |
221 | 4822 char *frn; |
138 | 4823 int g=get_dregister(d); |
97 | 4824 char *grn=fregister_name(g); |
108 | 4825 |
221 | 4826 use_float(d,reg); |
4827 frn=fregister_name(reg); | |
4828 | |
119 | 4829 lvar_intro(e2); |
4830 printf("\t%s %s,",fload(1),grn); lvar(e2); | |
291 | 4831 inc_cmpflag(); |
662 | 4832 printf("\tfcmpu %s,%s,%s\n",crname(cmpflag),frn,grn); |
147 | 4833 free_register(g); |
287 | 4834 jcond(label,cond); |
89 | 4835 } |
4836 | |
211 | 4837 void |
273 | 4838 dtosop(int op,int reg,int oreg) |
89 | 4839 { |
127 | 4840 char *opn=""; |
221 | 4841 char *frn; |
273 | 4842 char *grn; |
4843 int ox = -1; | |
221 | 4844 |
4845 use_float(1,reg); | |
273 | 4846 if(oreg==-1) { |
4847 error(-1); | |
4848 } else if (oreg<= -REG_LVAR_OFFSET) { | |
4849 ox = get_dregister(1); if (ox<0) error(-1); | |
4850 use_reg(ox); | |
4851 code_drlvar(oreg+REG_LVAR_OFFSET,1,ox); | |
4852 oreg = ox; | |
4853 } | |
4854 grn=fregister_name(oreg); | |
221 | 4855 frn=fregister_name(reg); |
89 | 4856 switch(op) { |
133 | 4857 case FADD: |
91 | 4858 case DADD: opn="fadd"; break; |
133 | 4859 case FSUB: |
101 | 4860 case DSUB: opn="fsub"; break; |
133 | 4861 case FDIV: |
101 | 4862 case DDIV: opn="fdiv"; break; |
133 | 4863 case FMUL: |
101 | 4864 case DMUL: opn="fmul"; break; |
133 | 4865 case FCMP: |
91 | 4866 case DCMP: |
880 | 4867 inc_cmpflag(); |
4868 printf("\tfcmpu %s,%s,%s\n",crname(cmpflag),frn,grn); | |
4869 if (ox!=-1) free_register(ox); | |
4870 return; | |
133 | 4871 case FCMPGE: |
91 | 4872 case DCMPGE: |
880 | 4873 inc_cmpflag(); |
4874 printf("\tfcmpu %s,%s,%s\n",crname(cmpflag),frn,grn); | |
4875 if (ox!=-1) free_register(ox); | |
4876 return; | |
133 | 4877 default: |
880 | 4878 error(-1); return; |
89 | 4879 } |
91 | 4880 printf("\t%s %s,%s,%s\n",opn,frn,frn,grn); |
273 | 4881 if (ox!=-1) free_register(ox); |
89 | 4882 } |
4883 | |
4884 void | |
221 | 4885 code_dassop(int op,int reg,int d) { |
91 | 4886 /* we have lvalue in creg, applied floating value is in freg */ |
221 | 4887 // (*creg) op = pop() |
138 | 4888 int xreg=emit_dpop(d); |
221 | 4889 char *crn; |
209 | 4890 char *frn; |
221 | 4891 |
4892 crn=register_name(ireg); | |
4893 use_float(d,reg); | |
4894 frn =fregister_name(reg); | |
209 | 4895 |
108 | 4896 printf("\t%s %s,0(%s)\n",fload(d),frn,crn); |
221 | 4897 dtosop(op,reg,xreg); |
108 | 4898 printf("\t%s %s,0(%s)\n",fstore(d),frn,crn); |
138 | 4899 emit_dpop_free(xreg,d); |
89 | 4900 } |
4901 | |
219 | 4902 void |
4903 code_register_dassop(int reg,int op,int d) { | |
221 | 4904 // reg op= dpop() |
219 | 4905 int xreg=emit_dpop(d); |
221 | 4906 dtosop(op,reg,xreg); |
4907 emit_dpop_free(xreg,d); | |
219 | 4908 } |
91 | 4909 |
273 | 4910 static int |
4911 code_dload_1(int d) | |
4912 { | |
4913 int r,g; | |
4914 char *drn,*grn; | |
4915 // load 1 | |
4916 float_one_lib_used=1; | |
4917 r = get_ptr_cache(&float_one); | |
4918 drn=register_name(r); | |
4919 grn=fregister_name(g=get_dregister(d)); | |
4920 printf("\tlfs %s,0(%s)\n",grn,drn); | |
4921 return g; | |
4922 } | |
4923 | |
89 | 4924 void |
107 | 4925 code_dpreinc(int e1,int e2,int d,int reg) { |
273 | 4926 char *frn,*crn,*grn; |
91 | 4927 int g; |
4928 | |
144 | 4929 if (car(e2)==DREGISTER||car(e2)==FREGISTER) { |
880 | 4930 crn=register_name(cadr(e2)); |
273 | 4931 grn = fregister_name(g = code_dload_1(d)); |
880 | 4932 if (reg==USE_CREG) { |
4933 reg=get_dregister(d); if (!reg) error(-1); | |
4934 set_freg(reg,0); | |
4935 } | |
4936 frn=fregister_name(reg); | |
4937 printf("\t%s %s,%s,%s\n",(caddr(e1)>0)?"fadd":"fsub",crn,crn,grn); | |
4938 if (use && reg!=cadr(e2)) | |
4939 printf("\tfmr %s,%s\n",frn,crn); | |
221 | 4940 } else { |
880 | 4941 g_expr(e2); |
4942 if (!is_int_reg(creg)) error(-1); | |
4943 crn=register_name(ireg); | |
4944 if (reg==USE_CREG) { | |
4945 reg=get_dregister(d); if (!reg) error(-1); | |
4946 set_freg(reg,0); | |
4947 } | |
4948 frn=fregister_name(reg); | |
273 | 4949 grn = fregister_name(g = code_dload_1(d)); |
880 | 4950 printf("\t%s %s,0(%s)\n",fload(d),frn,crn); |
4951 printf("\t%s %s,%s,%s\n",(caddr(e1)>0)?"fadd":"fsub",frn,frn,grn); | |
4952 printf("\t%s %s,0(%s)\n",fstore(d),frn,crn); | |
221 | 4953 } |
147 | 4954 free_register(g); |
89 | 4955 } |
4956 | |
4957 void | |
107 | 4958 code_dpostinc(int e1,int e2,int d,int reg) { |
273 | 4959 char *frn,*crn,*grn; |
91 | 4960 int g; |
4961 | |
144 | 4962 if (car(e2)==DREGISTER||car(e2)==FREGISTER) { |
880 | 4963 crn=register_name(cadr(e2)); |
273 | 4964 grn = fregister_name(g = code_dload_1(d)); |
880 | 4965 if (reg==USE_CREG) { |
4966 reg=get_dregister(d); if (!reg) error(-1); | |
4967 set_freg(reg,0); | |
4968 } | |
4969 frn=fregister_name(reg); | |
4970 if (use && reg!=cadr(e2)) | |
4971 printf("\tfmr %s,%s\n",frn,crn); | |
4972 printf("\t%s %s,%s,%s\n",(caddr(e1)>0)?"fadd":"fsub",crn,crn,grn); | |
221 | 4973 } else { |
880 | 4974 g_expr(e2); |
4975 if (!is_int_reg(creg)) error(-1); | |
4976 crn=register_name(ireg); | |
4977 if (reg==USE_CREG) { | |
4978 reg=get_dregister(d); if (!reg) error(-1); | |
4979 set_freg(reg,0); | |
4980 } | |
4981 frn=fregister_name(reg); | |
273 | 4982 grn = fregister_name(g = code_dload_1(d)); |
880 | 4983 printf("\t%s %s,0(%s)\n",fload(d),frn,crn); |
4984 printf("\t%s %s,%s,%s\n",(caddr(e1)>0)?"fadd":"fsub",grn,frn,grn); | |
4985 printf("\t%s %s,0(%s)\n",fstore(d),grn,crn); | |
221 | 4986 } |
147 | 4987 free_register(g); |
89 | 4988 } |
4989 | |
288 | 4990 static int |
4991 drexpr_bool(int e1,int reg) | |
4992 { | |
289 | 4993 int flag=-1,eq=-1,neg=-1,t; |
288 | 4994 char *rn; |
4995 switch(car(e1)) { | |
4996 case DOP+GT: case FOP+GT: flag = 2; break; | |
4997 case DOP+GE: case FOP+GE: flag = 2; eq=3; break; | |
4998 case DOP+LT: case FOP+LT: flag = 1; break; | |
4999 case DOP+LE: case FOP+LE: flag = 1; eq=3; break; | |
5000 case DOP+EQ: case FOP+EQ: flag = 3; break; | |
289 | 5001 case DOP+NEQ: case FOP+NEQ: flag = 3; neg=3; break; |
288 | 5002 default: return 0; |
5003 } | |
5004 g_expr(list3(DCMP,cadr(e1),caddr(e1))); | |
5005 use_int(reg); | |
5006 rn = register_name(reg); | |
289 | 5007 t = CRBITSIZ*cmpflag; |
288 | 5008 if (eq>0) { |
880 | 5009 printf("\tcror %d,%d,%d\n",t+flag-1,t+eq-1,t+flag-1); |
289 | 5010 } |
5011 if (neg>0) { | |
880 | 5012 neg = t+neg-1, |
5013 printf("\tcrnor %d,%d,%d\n",neg,neg,neg); | |
288 | 5014 } |
5015 printf("\tmfcr %s\n",rn); | |
289 | 5016 printf("\trlwinm %s,%s,%d,1\n",rn,rn,t+flag); |
288 | 5017 return 1; |
5018 } | |
5019 | |
438
626d705471d5
Unexecuted code in conditional. Lazy jmp code generation.
kono
parents:
436
diff
changeset
|
5020 int |
229 | 5021 drexpr(int e1, int e2,int l1, int op,int cond) |
5022 { | |
231 | 5023 if (!cond) { |
880 | 5024 switch(op) { |
5025 case FOP+GT: | |
5026 return drexpr(e2,e1,l1,FOP+GE,1); | |
5027 case FOP+GE: | |
5028 return drexpr(e2,e1,l1,FOP+GT,1); | |
5029 case FOP+EQ: | |
5030 op=FOP+NEQ; break; | |
5031 case FOP+NEQ: | |
5032 op=FOP+EQ; break; | |
5033 case DOP+GT: | |
5034 return drexpr(e2,e1,l1,DOP+GE,1); | |
5035 case DOP+GE: | |
5036 return drexpr(e2,e1,l1,DOP+GT,1); | |
5037 case DOP+EQ: | |
5038 op=DOP+NEQ; break; | |
5039 case DOP+NEQ: | |
5040 op=DOP+EQ; break; | |
5041 } | |
229 | 5042 } |
234 | 5043 g_expr(list3(DCMP, e1,e2)); |
89 | 5044 switch(op) { |
880 | 5045 case DOP+GT: case FOP+GT: |
5046 printf("\tbgt\t%s,%s%d\n",crname(cmpflag),lpfx,l1); | |
5047 break; | |
5048 case DOP+GE: case FOP+GE: | |
5049 printf("\tbge\t%s,%s%d\n",crname(cmpflag),lpfx,l1); | |
5050 break; | |
5051 case DOP+EQ: case FOP+EQ: | |
5052 printf("\tbeq\t%s,%s%d\n",crname(cmpflag),lpfx,l1); | |
5053 break; | |
5054 case DOP+NEQ: case FOP+NEQ: | |
5055 printf("\tbne\t%s,%s%d\n",crname(cmpflag),lpfx,l1); | |
5056 break; | |
89 | 5057 } |
438
626d705471d5
Unexecuted code in conditional. Lazy jmp code generation.
kono
parents:
436
diff
changeset
|
5058 return l1; |
89 | 5059 } |
5060 | |
138 | 5061 int emit_dpop(int d) |
89 | 5062 { |
114 | 5063 int xreg,reg; |
97 | 5064 xreg=pop_fregister(); |
5065 if (xreg<= -REG_LVAR_OFFSET) { | |
880 | 5066 reg = get_dregister(d); |
119 | 5067 code_drlvar(REG_LVAR_OFFSET+xreg,1,reg); |
880 | 5068 free_lvar(REG_LVAR_OFFSET+xreg); |
5069 xreg=reg; | |
96 | 5070 } |
5071 return xreg; | |
89 | 5072 } |
5073 | |
211 | 5074 void |
5075 emit_dpop_free(int e1,int d) | |
89 | 5076 { |
590 | 5077 if (e1>=0 && e1!=creg && regs[e1]!=REG_VAR) |
880 | 5078 free_register(e1); |
89 | 5079 } |
5080 | |
211 | 5081 void |
5082 emit_dpush(int d) | |
89 | 5083 { |
97 | 5084 int new_reg; |
221 | 5085 if (!is_float_reg(creg)) error(-1); |
102 | 5086 if (freg_sp>MAX_MAX) error(-1); |
724 | 5087 new_reg = get_dregister(1); /* 絶対に取れる */ |
5088 freg_stack[freg_sp++] = freg; /* push するかわりにレジスタを使う */ | |
147 | 5089 creg = freg = new_reg; |
89 | 5090 } |
5091 | |
195 | 5092 #endif |
5093 | |
5094 #if LONGLONG_CODE | |
5095 | |
5096 | |
5097 /* 64bit int part */ | |
219 | 5098 static void |
530 | 5099 lmove(int to,int from) // to <= from |
219 | 5100 { |
227 | 5101 int tmp; |
5102 if (regv_h(to)==regv_l(from)&&(regv_l(to)==regv_h(from))) { | |
880 | 5103 tmp = get_register(); |
5104 printf("\tmr %s,%s\n",register_name(tmp),lregister_name_low(from)); | |
5105 printf("\tmr %s,%s\n",lregister_name_high(to),lregister_name_high(from)); | |
5106 printf("\tmr %s,%s\n",lregister_name_low(to),register_name(tmp)); | |
5107 free_register(tmp); | |
227 | 5108 } else if (regv_h(to)==regv_l(from)) { |
880 | 5109 printf("\tmr %s,%s\n",lregister_name_low(to),lregister_name_low(from)); |
5110 printf("\tmr %s,%s\n",lregister_name_high(to),lregister_name_high(from)); | |
226 | 5111 } else { |
880 | 5112 printf("\tmr %s,%s\n",lregister_name_high(to),lregister_name_high(from)); |
5113 printf("\tmr %s,%s\n",lregister_name_low(to),lregister_name_low(from)); | |
226 | 5114 } |
219 | 5115 } |
195 | 5116 |
211 | 5117 static void |
280 | 5118 pcond(char *s,int cmpflag,int l1) |
5119 { | |
662 | 5120 printf("\tb%s %s,%s%d\n",s,crname(cmpflag),lpfx,l1); |
280 | 5121 } |
5122 | |
5123 static int | |
5124 lcmp(int op,int cond) | |
210 | 5125 { |
280 | 5126 if (op==LOP+UGT||op==LOP+UGE) { |
5127 return UCMP; | |
5128 } else if (op==LOP+LE||op==LOP+GE) { | |
5129 return CMP; | |
5130 } else { | |
5131 return CMP; | |
5132 } | |
210 | 5133 } |
5134 | |
438
626d705471d5
Unexecuted code in conditional. Lazy jmp code generation.
kono
parents:
436
diff
changeset
|
5135 int |
229 | 5136 lrexpr(int e1, int e2,int l1, int op,int cond) |
195 | 5137 { |
221 | 5138 int reg; |
210 | 5139 int e3; |
280 | 5140 int l2; |
5141 int op1,cr0,cr1; | |
5142 | |
210 | 5143 g_expr(e1); |
5144 emit_lpush(); | |
5145 g_expr(e2); | |
5146 e3 = emit_lpop(); | |
221 | 5147 if (!is_longlong_reg(creg)) error(-1); |
5148 reg = lreg; | |
280 | 5149 op1 = lcmp(op,cond); |
5150 tosop(op1,regv_h(e3),regv_h(reg)); | |
5151 cr0 = cmpflag; | |
291 | 5152 tosop(op1,regv_l(e3),regv_l(reg)); |
280 | 5153 cr1 = cmpflag; |
5154 | |
5155 l2 = fwdlabel(); | |
5156 // cond==0 jump on false condtion ( if(x) => rexpr(.. cond=0 ...) ) | |
433 | 5157 switch(op+(!cond)*BNOT) { |
210 | 5158 case LOP+GT: |
5159 case LOP+GE: | |
880 | 5160 pcond(code_gt(1),cr0,1?l1:l2); |
5161 pcond(code_eq(0),cr0,1?l2:l1); | |
5162 break; | |
280 | 5163 case LOP+UGT: |
5164 case LOP+UGE: | |
880 | 5165 pcond(code_ugt(1),cr0,1?l1:l2); |
5166 pcond(code_eq(0), cr0,1?l2:l1); | |
5167 break; | |
210 | 5168 case LOP+EQ: |
880 | 5169 pcond(code_eq(0),cr0,(1?l2:l1)); |
5170 pcond(code_eq(cond),cr1,l1); | |
5171 break; | |
210 | 5172 case LOP+NEQ: |
880 | 5173 pcond(code_eq(0),cr0,(1?l1:l2)); |
5174 pcond(code_eq(!1),cr1,l1); | |
5175 break; | |
433 | 5176 case LOP+GT+BNOT: |
5177 case LOP+GE+BNOT: | |
880 | 5178 pcond(code_gt(1),cr0,0?l1:l2); |
5179 pcond(code_eq(0),cr0,0?l2:l1); | |
5180 break; | |
433 | 5181 case LOP+UGT+BNOT: |
5182 case LOP+UGE+BNOT: | |
880 | 5183 pcond(code_ugt(1),cr0,0?l1:l2); |
5184 pcond(code_eq(0), cr0,0?l2:l1); | |
5185 break; | |
433 | 5186 case LOP+EQ+BNOT: |
880 | 5187 pcond(code_eq(0),cr0,(0?l2:l1)); |
5188 pcond(code_eq(0),cr1,l1); | |
5189 break; | |
433 | 5190 case LOP+NEQ+BNOT: |
880 | 5191 pcond(code_eq(0),cr0,(0?l1:l2)); |
5192 pcond(code_eq(!0),cr1,l1); | |
5193 break; | |
210 | 5194 default: |
880 | 5195 error(-1); |
210 | 5196 } |
433 | 5197 switch(op+BNOT*(!cond)) { |
5198 case LOP+GT: pcond(code_gt(1), cr1,l1); break; | |
5199 case LOP+GE: pcond(code_ge(1), cr1,l1); break; | |
5200 case LOP+UGT: pcond(code_ugt(1), cr1,l1); break; | |
5201 case LOP+UGE: pcond(code_uge(1), cr1,l1); break; | |
5202 case LOP+GT+BNOT: pcond(code_gt(0), cr1,l1); break; | |
5203 case LOP+GE+BNOT: pcond(code_ge(0), cr1,l1); break; | |
5204 case LOP+UGT+BNOT: pcond(code_ugt(0), cr1,l1); break; | |
5205 case LOP+UGE+BNOT: pcond(code_uge(0), cr1,l1); break; | |
280 | 5206 } |
5207 fwddef(l2); | |
5208 emit_lpop_free(e3); | |
438
626d705471d5
Unexecuted code in conditional. Lazy jmp code generation.
kono
parents:
436
diff
changeset
|
5209 return l1; |
280 | 5210 } |
195 | 5211 |
211 | 5212 int |
5213 emit_lpop() | |
195 | 5214 { |
210 | 5215 int xreg,reg; |
237 | 5216 xreg=lreg_stack[--lreg_sp]; |
210 | 5217 if (xreg<= -REG_LVAR_OFFSET) { |
5218 reg = get_lregister(); | |
5219 code_lrlvar(REG_LVAR_OFFSET+xreg,reg); | |
5220 free_lvar(REG_LVAR_OFFSET+xreg); | |
5221 xreg = reg; | |
5222 } | |
5223 return xreg; | |
195 | 5224 } |
5225 | |
211 | 5226 void |
5227 code_lregister(int e2,int reg) | |
195 | 5228 { |
221 | 5229 use_longlong(reg); |
5230 if (reg!=e2) { | |
880 | 5231 lmove(reg,e2); |
211 | 5232 } |
195 | 5233 } |
5234 | |
211 | 5235 void |
287 | 5236 code_cmp_lregister(int reg,int label,int cond) |
195 | 5237 { |
221 | 5238 use_longlong(reg); |
211 | 5239 printf("\tor %s,%s,%s\n", |
880 | 5240 lregister_name_low(reg), |
5241 lregister_name_low(reg), | |
5242 lregister_name_high(reg)); | |
291 | 5243 inc_cmpflag(); |
662 | 5244 printf("\tcmpwi %s,%s,0\n",crname(cmpflag),lregister_name_low(reg)); |
287 | 5245 jcond(label,cond); |
195 | 5246 } |
5247 | |
211 | 5248 void |
287 | 5249 code_cmp_lrgvar(int e1,int creg,int label,int cond) |
195 | 5250 { |
221 | 5251 use_longlong(creg); |
211 | 5252 code_lrgvar(e1,creg); |
287 | 5253 code_cmp_lregister(creg,label,cond); |
211 | 5254 } |
5255 | |
5256 void | |
287 | 5257 code_cmp_lrlvar(int e1,int creg,int label,int cond) |
211 | 5258 { |
221 | 5259 use_longlong(creg); |
211 | 5260 code_lrlvar(e1,creg); |
287 | 5261 code_cmp_lregister(creg,label,cond); |
195 | 5262 } |
5263 | |
211 | 5264 void |
5265 code_lassign(int e2,int creg) | |
195 | 5266 { |
211 | 5267 char *drn = register_name(e2); |
221 | 5268 char *crn_h; |
5269 char *crn_l; | |
5270 | |
5271 use_longlong(creg); | |
5272 crn_h = lregister_name_high(creg); | |
5273 crn_l = lregister_name_low(creg); | |
411 | 5274 #if ENDIAN_L==0 |
5275 printf("\tstw %s,0(%s)\n",crn_l,drn); | |
5276 printf("\tstw %s,%d(%s)\n",crn_h,SIZE_OF_INT,drn); | |
5277 #else | |
271 | 5278 printf("\tstw %s,0(%s)\n",crn_h,drn); |
5279 printf("\tstw %s,%d(%s)\n",crn_l,SIZE_OF_INT,drn); | |
411 | 5280 #endif |
195 | 5281 } |
5282 | |
211 | 5283 void |
5284 code_lassign_gvar(int e2,int creg) | |
195 | 5285 { |
211 | 5286 int r; |
367 | 5287 use_longlong(creg); |
711 | 5288 r = get_ptr_cache(ncaddr(e2)); |
411 | 5289 #if ENDIAN_L==0 |
5290 code_ldf(cstore(0),lregister_name_low(creg),cadr(e2),r); | |
5291 code_ldf(cstore(0),lregister_name_high(creg),cadr(e2)+SIZE_OF_INT,r); | |
5292 #else | |
367 | 5293 code_ldf(cstore(0),lregister_name_high(creg),cadr(e2),r); |
5294 code_ldf(cstore(0),lregister_name_low(creg),cadr(e2)+SIZE_OF_INT,r); | |
411 | 5295 #endif |
195 | 5296 } |
5297 | |
211 | 5298 void |
5299 code_lassign_lvar(int e2,int creg) | |
195 | 5300 { |
221 | 5301 char *crn_h; |
5302 char *crn_l; | |
5303 | |
5304 use_longlong(creg); | |
5305 crn_h = lregister_name_high(creg); | |
5306 crn_l = lregister_name_low(creg); | |
211 | 5307 lvar_intro(e2); |
411 | 5308 #if ENDIAN_L==0 |
5309 printf("\tstw %s,",crn_l);lvar(e2); | |
5310 printf("\tstw %s,",crn_h);lvar(e2+SIZE_OF_INT); | |
5311 #else | |
211 | 5312 printf("\tstw %s,",crn_h);lvar(e2); |
245 | 5313 printf("\tstw %s,",crn_l);lvar(e2+SIZE_OF_INT); |
411 | 5314 #endif |
195 | 5315 } |
5316 | |
211 | 5317 void |
5318 code_lassign_lregister(int e2,int reg) | |
195 | 5319 { |
221 | 5320 use_longlong(reg); |
219 | 5321 if (e2!=reg) { |
880 | 5322 lmove(e2,reg); |
211 | 5323 } |
195 | 5324 } |
5325 | |
207 | 5326 static long long ll0 = 1LL; |
206 | 5327 |
5328 static int | |
5329 code_l1(long long d) | |
5330 { | |
207 | 5331 int *i = (int *)&ll0; int *j = (int *)&d; |
206 | 5332 return (i[1] == 1)?j[1]:j[0]; |
5333 } | |
5334 | |
5335 static int | |
5336 code_l2(long long d) | |
5337 { | |
207 | 5338 int *i = (int *)&ll0; int *j = (int *)&d; |
206 | 5339 return (i[1] == 1)?j[0]:j[1]; |
5340 } | |
5341 | |
211 | 5342 void |
5343 code_lconst(int e1,int creg) | |
5344 { | |
221 | 5345 use_longlong(creg); |
411 | 5346 #if ENDIAN_L==0 |
5347 code_const(code_l1(lcadr(e1)),regv_h(creg)); | |
5348 code_const(code_l2(lcadr(e1)),regv_l(creg)); | |
5349 #else | |
211 | 5350 code_const(code_l1(lcadr(e1)),regv_l(creg)); |
5351 code_const(code_l2(lcadr(e1)),regv_h(creg)); | |
411 | 5352 #endif |
211 | 5353 } |
5354 | |
5355 void | |
5356 code_lneg(int creg) | |
195 | 5357 { |
221 | 5358 use_longlong(creg); |
211 | 5359 printf("\tsubfic %s,%s,0\n", |
880 | 5360 lregister_name_low(creg),lregister_name_low(creg)); |
221 | 5361 printf("\tsubfze %s,%s\n", |
880 | 5362 lregister_name_high(creg),lregister_name_high(creg)); |
195 | 5363 } |
5364 | |
211 | 5365 void |
221 | 5366 code_lrgvar(int e1,int creg) |
211 | 5367 { |
5368 int r; | |
221 | 5369 char *crn_h; |
5370 char *crn_l; | |
5371 use_longlong(creg); | |
5372 crn_h = lregister_name_high(creg); | |
5373 crn_l = lregister_name_low(creg); | |
711 | 5374 r = get_ptr_cache(ncaddr(e1)); |
411 | 5375 #if ENDIAN_L==0 |
5376 code_ldf(cload(0),crn_l,cadr(e1),r); | |
5377 code_ldf(cload(0),crn_h,cadr(e1)+SIZE_OF_INT,r); | |
5378 #else | |
367 | 5379 code_ldf(cload(0),crn_h,cadr(e1),r); |
5380 code_ldf(cload(0),crn_l,cadr(e1)+SIZE_OF_INT,r); | |
411 | 5381 #endif |
211 | 5382 } |
5383 | |
5384 void | |
5385 code_lrlvar(int e1,int creg) | |
195 | 5386 { |
221 | 5387 char *crn_h; |
5388 char *crn_l; | |
5389 use_longlong(creg); | |
5390 crn_h = lregister_name_high(creg); | |
5391 crn_l = lregister_name_low(creg); | |
211 | 5392 lvar_intro(e1); |
411 | 5393 #if ENDIAN_L==0 |
5394 printf("\tlwz %s,",crn_l); lvar(e1); | |
5395 printf("\tlwz %s,",crn_h); lvar(e1+SIZE_OF_INT); | |
5396 #else | |
211 | 5397 printf("\tlwz %s,",crn_h); lvar(e1); |
245 | 5398 printf("\tlwz %s,",crn_l); lvar(e1+SIZE_OF_INT); |
411 | 5399 #endif |
195 | 5400 } |
5401 | |
221 | 5402 #if 0 |
216 | 5403 static int lumod_lib_used=0; |
217 | 5404 static char *lumod_lib[] = { |
216 | 5405 }; |
5406 | |
5407 static int lmod_lib_used=0; | |
217 | 5408 static char *lmod_lib[] = { |
216 | 5409 }; |
5410 | |
5411 static int ludiv_lib_used=0; | |
217 | 5412 static char *ludiv_lib[] = { |
216 | 5413 }; |
5414 | |
5415 static int ldiv_lib_used=0; | |
217 | 5416 static char *ldiv_lib[] = { |
216 | 5417 }; |
221 | 5418 #endif |
216 | 5419 |
5420 static int lsrd_lib_used=0; | |
217 | 5421 static char *lsrd_lib[] = { |
662 | 5422 #ifdef __APPLE__ |
5423 ".text", | |
5424 " .align 2", | |
672 | 5425 ".lsrd__:", |
662 | 5426 " mr. r5,r5", |
5427 " beqlr", | |
5428 " subfic r2,r5,32", | |
5429 " stw r3,-32(r1)", | |
5430 " stw r4,-28(r1)", | |
5431 " cmpwi cr7,r2,0", | |
5432 " bgt+ cr7,L__lsrd1", | |
5433 " neg r0,r2", | |
5434 " lwz r2,-32(r1)", | |
5435 " li r9,0", | |
5436 " srw r2,r2,r0", | |
5437 " stw r9,-48(r1)", | |
5438 " b L__lsrd2", | |
5439 "L__lsrd1: lwz r0,-32(r1)", | |
5440 " slw r9,r0,r2", | |
5441 " lwz r2,-28(r1)", | |
5442 " srw r0,r0,r5", | |
5443 " srw r2,r2,r5", | |
5444 " stw r0,-48(r1)", | |
5445 " or r2,r2,r9", | |
5446 "L__lsrd2: stw r2,-44(r1)", | |
5447 " lwz r3,-48(r1)", | |
5448 " lwz r4,-44(r1)", | |
5449 " blr", | |
5450 #else | |
217 | 5451 ".text", |
5452 " .align 2", | |
672 | 5453 ".lsrd__:", |
5454 " mr. 5,5", | |
5455 " beqlr", | |
673 | 5456 " subfic 8,5,32", |
672 | 5457 " stw 3,-32(1)", |
5458 " stw 4,-28(1)", | |
673 | 5459 " cmpwi 7,8,0", |
672 | 5460 " bgt+ 7,.L__lsrd1", |
5461 " neg 0,2", | |
673 | 5462 " lwz 8,-32(1)", |
672 | 5463 " li 9,0", |
673 | 5464 " srw 8,8,0", |
672 | 5465 " stw 9,-48(1)", |
5466 " b .L__lsrd2", | |
5467 ".L__lsrd1: lwz 0,-32(1)", | |
673 | 5468 " slw 9,0,8", |
5469 " lwz 8,-28(1)", | |
672 | 5470 " srw 0,0,5", |
673 | 5471 " srw 8,8,5", |
672 | 5472 " stw 0,-48(1)", |
673 | 5473 " or 8,8,9", |
5474 ".L__lsrd2: stw 8,-44(1)", | |
672 | 5475 " lwz 3,-48(1)", |
5476 " lwz 4,-44(1)", | |
217 | 5477 " blr", |
662 | 5478 #endif |
219 | 5479 0 |
217 | 5480 }; |
5481 | |
5482 static int asld_lib_used=0; | |
5483 static char *asld_lib[] = { | |
662 | 5484 #ifdef __APPLE__ |
5485 ".text", | |
5486 " .align 2", | |
672 | 5487 ".asld__:", |
662 | 5488 " mr. r5,r5", |
5489 " beqlr", | |
5490 " subfic r2,r5,32", | |
5491 " stw r3,-32(r1)", | |
5492 " stw r4,-28(r1)", | |
5493 " cmpwi cr7,r2,0", | |
5494 " bgt+ cr7,L__asld1", | |
5495 " neg r0,r2", | |
5496 " lwz r2,-28(r1)", | |
5497 " li r9,0", | |
5498 " slw r2,r2,r0", | |
5499 " stw r9,-44(r1)", | |
5500 " b L__asld2", | |
5501 "L__asld1: lwz r0,-28(r1)", | |
5502 " srw r9,r0,r2", | |
5503 " lwz r2,-32(r1)", | |
5504 " slw r0,r0,r5", | |
5505 " slw r2,r2,r5", | |
5506 " stw r0,-44(r1)", | |
5507 " or r2,r2,r9", | |
5508 "L__asld2: stw r2,-48(r1)", | |
5509 " lwz r3,-48(r1)", | |
5510 " lwz r4,-44(r1)", | |
5511 " blr", | |
5512 #else | |
217 | 5513 ".text", |
5514 " .align 2", | |
672 | 5515 ".asld__:", |
5516 " mr. 5,5", | |
5517 " beqlr", | |
673 | 5518 " subfic 8,5,32", |
672 | 5519 " stw 3,-32(1)", |
5520 " stw 4,-28(1)", | |
673 | 5521 " cmpwi 7,8,0", |
672 | 5522 " bgt+ 7,.L__asld1", |
673 | 5523 " neg 0,8", |
5524 " lwz 8,-28(1)", | |
672 | 5525 " li 9,0", |
673 | 5526 " slw 8,8,0", |
672 | 5527 " stw 9,-44(1)", |
5528 " b .L__asld2", | |
5529 ".L__asld1: lwz 0,-28(1)", | |
673 | 5530 " srw 9,0,8", |
5531 " lwz 8,-32(1)", | |
672 | 5532 " slw 0,0,5", |
673 | 5533 " slw 8,8,5", |
672 | 5534 " stw 0,-44(1)", |
673 | 5535 " or 8,8,9", |
5536 ".L__asld2: stw 8,-48(1)", | |
672 | 5537 " lwz 3,-48(1)", |
5538 " lwz 4,-44(1)", | |
217 | 5539 " blr", |
662 | 5540 #endif |
219 | 5541 0 |
216 | 5542 }; |
5543 | |
5544 static int asrd_lib_used=0; | |
217 | 5545 static char *asrd_lib[] = { |
662 | 5546 #ifdef __APPLE__ |
217 | 5547 ".text", |
5548 " .align 2", | |
672 | 5549 ".asrd__:", |
217 | 5550 " mr. r5,r5", |
5551 " beqlr", | |
5552 " subfic r2,r5,32", | |
5553 " stw r3,-32(r1)", | |
5554 " stw r4,-28(r1)", | |
5555 " cmpwi cr7,r2,0", | |
5556 " bgt+ cr7,L__asrd1", | |
5557 " lwz r0,-32(r1)", | |
5558 " neg r2,r2", | |
5559 " sraw r2,r0,r2", | |
5560 " srawi r0,r0,31", | |
5561 " b L__asrd2", | |
5562 "L__asrd1: lwz r0,-32(r1)", | |
5563 " slw r9,r0,r2", | |
5564 " lwz r2,-28(r1)", | |
5565 " sraw r0,r0,r5", | |
5566 " srw r2,r2,r5", | |
5567 " or r2,r2,r9", | |
5568 "L__asrd2: stw r0,-48(r1)", | |
5569 " stw r2,-44(r1)", | |
5570 " lwz r3,-48(r1)", | |
5571 " lwz r4,-44(r1)", | |
5572 " blr", | |
662 | 5573 #else |
5574 ".text", | |
5575 " .align 2", | |
672 | 5576 ".asrd__:", |
5577 " mr. 5,5", | |
5578 " beqlr", | |
673 | 5579 " subfic 8,5,32", |
672 | 5580 " stw 3,-32(1)", |
5581 " stw 4,-28(1)", | |
673 | 5582 " cmpwi 7,8,0", |
672 | 5583 " bgt+ 7,.L__asrd1", |
5584 " lwz 0,-32(1)", | |
673 | 5585 " neg 8,8", |
5586 " sraw 8,0,8", | |
672 | 5587 " srawi 0,0,31", |
5588 " b .L__asrd2", | |
5589 ".L__asrd1: lwz 0,-32(1)", | |
673 | 5590 " slw 9,0,8", |
5591 " lwz 8,-28(1)", | |
672 | 5592 " sraw 0,0,5", |
673 | 5593 " srw 8,8,5", |
5594 " or 8,8,9", | |
672 | 5595 ".L__asrd2: stw 0,-48(1)", |
673 | 5596 " stw 8,-44(1)", |
672 | 5597 " lwz 3,-48(1)", |
5598 " lwz 4,-44(1)", | |
5599 " blr", | |
662 | 5600 #endif |
219 | 5601 0 |
216 | 5602 }; |
5603 | |
662 | 5604 #endif |
5605 | |
217 | 5606 static void |
5607 extern_conv(char *conv) | |
5608 { | |
5609 code_save_stacks(); | |
5610 clear_ptr_cache(); | |
5611 extern_define(conv,0,FUNCTION,1); | |
662 | 5612 #ifdef __APPLE__ |
217 | 5613 printf("\tbl L_%s$stub\n",conv); |
662 | 5614 #else |
5615 printf("\tbl %s\n",conv); | |
5616 #endif | |
217 | 5617 } |
5618 | |
216 | 5619 #if FLOAT_CODE |
218 | 5620 #if 0 |
217 | 5621 static int d2ll_lib_used=0; |
5622 static char *d2ll_lib[] = { | |
216 | 5623 }; |
5624 | |
5625 static int d2ull_lib_used=0; | |
217 | 5626 static char *d2ull_lib[] = { |
216 | 5627 }; |
5628 | |
5629 static int f2ll_lib_used=0; | |
217 | 5630 static char *f2ll_lib[] = { |
216 | 5631 }; |
5632 | |
5633 static int f2ull_lib_used=0; | |
217 | 5634 static char *f2ull_lib[] = { |
216 | 5635 }; |
5636 | |
5637 static int ll2d_lib_used=0; | |
217 | 5638 static char *ll2d_lib[] = { |
216 | 5639 }; |
5640 | |
5641 static int ll2f_lib_used=0; | |
217 | 5642 static char *ll2f_lib[] = { |
216 | 5643 }; |
218 | 5644 #endif |
216 | 5645 |
5646 #endif | |
5647 | |
5648 static void | |
255 | 5649 code_asld_lib(int reg,int oreg) |
211 | 5650 { |
5651 code_save_stacks(); | |
5652 clear_ptr_cache(); | |
5653 asld_lib_used = 1; | |
255 | 5654 set_lreg_operand(reg,1); |
5655 set_lreg(RET_LREGISTER,0); | |
228 | 5656 if (regv_l(oreg)!=5) { |
880 | 5657 printf("\tmr %s,%s\n", |
5658 register_name(5), | |
5659 lregister_name_low(oreg)); | |
228 | 5660 } |
672 | 5661 printf("\tbl .asld__\n"); |
195 | 5662 } |
5663 | |
216 | 5664 static void |
255 | 5665 code_asrd_lib(int reg,int oreg) // ___ashrdi3$stub |
216 | 5666 { |
5667 code_save_stacks(); | |
5668 clear_ptr_cache(); | |
5669 asrd_lib_used = 1; | |
255 | 5670 set_lreg_operand(reg,1); |
5671 set_lreg(RET_LREGISTER,0); | |
228 | 5672 if (regv_l(oreg)!=5) { |
880 | 5673 printf("\tmr %s,%s\n", |
5674 register_name(5), | |
5675 lregister_name_low(oreg)); | |
228 | 5676 } |
672 | 5677 printf("\tbl .asrd__\n"); |
216 | 5678 } |
5679 | |
5680 static void | |
255 | 5681 code_lsrd_lib(int reg,int oreg) // ___lshrdi3$stub |
216 | 5682 { |
5683 code_save_stacks(); | |
5684 clear_ptr_cache(); | |
5685 lsrd_lib_used = 1; | |
255 | 5686 set_lreg_operand(reg,1); |
5687 set_lreg(RET_LREGISTER,0); | |
231 | 5688 if (regv_l(oreg)!=5) { |
880 | 5689 printf("\tmr %s,%s\n", |
5690 register_name(5), | |
5691 lregister_name_low(oreg)); | |
231 | 5692 } |
672 | 5693 printf("\tbl .lsrd__\n"); |
216 | 5694 } |
5695 | |
5696 static void | |
255 | 5697 code_ldiv_lib(int reg,int oreg) // ___divdi3$stub |
216 | 5698 { |
223 | 5699 code_save_stacks(); |
5700 clear_ptr_cache(); | |
255 | 5701 set_lreg_operand(reg,1); |
5702 set_lreg(RET_LREGISTER,0); | |
5703 set_lreg_operand1(oreg,1); | |
217 | 5704 extern_conv("__divdi3"); |
216 | 5705 } |
5706 | |
5707 static void | |
255 | 5708 code_ludiv_lib(int reg,int oreg) // ___udivdi3$stub |
216 | 5709 { |
223 | 5710 code_save_stacks(); |
5711 clear_ptr_cache(); | |
255 | 5712 set_lreg_operand(reg,1); |
5713 set_lreg(RET_LREGISTER,0); | |
5714 set_lreg_operand1(oreg,1); | |
217 | 5715 extern_conv("__udivdi3"); |
216 | 5716 } |
5717 | |
5718 static void | |
255 | 5719 code_lmod_lib(int reg,int oreg) // ___moddi3$stub |
216 | 5720 { |
223 | 5721 code_save_stacks(); |
5722 clear_ptr_cache(); | |
255 | 5723 set_lreg_operand(reg,1); |
5724 set_lreg(RET_LREGISTER,0); | |
5725 set_lreg_operand1(oreg,1); | |
217 | 5726 extern_conv("__moddi3"); |
216 | 5727 } |
5728 | |
5729 static void | |
255 | 5730 code_lumod_lib(int reg,int oreg) // ___umoddi3$stub |
216 | 5731 { |
223 | 5732 code_save_stacks(); |
5733 clear_ptr_cache(); | |
255 | 5734 set_lreg(RET_LREGISTER,0); |
5735 set_lreg_operand(reg,1); | |
5736 set_lreg_operand1(oreg,1); | |
217 | 5737 extern_conv("__umoddi3"); |
216 | 5738 } |
5739 | |
530 | 5740 #define check_lreg(reg) if (reg!=lreg) { lmove(reg,lreg); /* reg<=lreg */ } |
5741 | |
5742 // reg = reg op oreg | |
221 | 5743 |
211 | 5744 void |
221 | 5745 ltosop(int op,int reg,int oreg) |
195 | 5746 { |
221 | 5747 int dx = -1; |
252 | 5748 int ox = -1; |
531 | 5749 int creg_mode = (reg==USE_CREG); |
211 | 5750 char *orn_h,*crn_h,*drn_h; |
5751 char *orn_l,*crn_l,*drn_l; | |
221 | 5752 // creg = creg op oreg |
5753 | |
5754 use_longlong(reg); | |
211 | 5755 if(oreg==-1) { |
880 | 5756 error(-1); |
211 | 5757 } else if (oreg<= -REG_LVAR_OFFSET) { |
880 | 5758 ox = get_lregister(); if (ox<0) error(-1); |
5759 use_reg(ox); | |
273 | 5760 code_lrlvar(oreg+REG_LVAR_OFFSET,ox); |
880 | 5761 oreg = ox; |
211 | 5762 } |
5763 | |
5764 switch(op) { | |
5765 case LLSHIFT: | |
5766 case LULSHIFT: | |
880 | 5767 code_asld_lib(reg,oreg); // ___ashldi3$stub |
5768 check_lreg(reg); | |
5769 if(ox!=-1) free_register(ox); | |
5770 return; | |
211 | 5771 case LRSHIFT: |
880 | 5772 code_asrd_lib(reg,oreg); // ___ashrdi3$stub |
5773 check_lreg(reg); | |
5774 if(ox!=-1) free_register(ox); | |
5775 return; | |
211 | 5776 case LURSHIFT: |
880 | 5777 code_lsrd_lib(reg,oreg); // ___lshrdi3$stub |
5778 check_lreg(reg); | |
5779 if(ox!=-1) free_register(ox); | |
5780 return; | |
211 | 5781 } |
5782 orn_h = lregister_name_high(oreg); | |
5783 orn_l = lregister_name_low(oreg); | |
221 | 5784 crn_h = lregister_name_high(reg); |
5785 crn_l = lregister_name_low(reg); | |
211 | 5786 switch(op) { |
219 | 5787 case LADD: |
880 | 5788 printf("\taddc %s,%s,%s\n",crn_l,crn_l,orn_l); |
5789 printf("\tadde %s,%s,%s\n",crn_h,crn_h,orn_h); | |
5790 break; | |
219 | 5791 case LSUB: |
880 | 5792 printf("\tsubfc %s,%s,%s\n",crn_l,orn_l,crn_l); |
5793 printf("\tsubfe %s,%s,%s\n",crn_h,orn_h,crn_h); | |
5794 break; | |
211 | 5795 case LCMP: |
880 | 5796 error(-1); |
5797 break; | |
219 | 5798 case LBAND: |
880 | 5799 printf("\tand %s,%s,%s\n",crn_l,crn_l,orn_l); |
5800 printf("\tand %s,%s,%s\n",crn_h,crn_h,orn_h); | |
5801 break; | |
219 | 5802 case LEOR: |
880 | 5803 printf("\txor %s,%s,%s\n",crn_l,crn_l,orn_l); |
5804 printf("\txor %s,%s,%s\n",crn_h,crn_h,orn_h); | |
5805 break; | |
219 | 5806 case LBOR: |
880 | 5807 printf("\tor %s,%s,%s\n",crn_l,crn_l,orn_l); |
5808 printf("\tor %s,%s,%s\n",crn_h,crn_h,orn_h); | |
5809 break; | |
219 | 5810 case LMUL: |
5811 case LUMUL: | |
880 | 5812 // code_save_stacks(); |
5813 // clear_ptr_cache(); | |
5814 dx=get_lregister(); if (dx<0) error(-1); | |
5815 use_reg(dx); | |
5816 drn_l = lregister_name_low(dx); | |
5817 drn_h = lregister_name_high(dx); | |
211 | 5818 /* |
5819 drn_l = l32( crn_l * orn_l); | |
5820 drn_h = h32( crn_l * orn_l); | |
593 | 5821 crn_h = l32( crn_h * orn_l); |
880 | 5822 drn_h = drn_h + crn_h; |
211 | 5823 crn_l = l32( crn_l * orn_h); |
880 | 5824 crn_h = drn_h + crn_l; |
5825 crn_l = drn_l; | |
211 | 5826 */ |
880 | 5827 printf("\tmulhwu %s,%s,%s\n",drn_h,crn_l,orn_l); |
5828 printf("\tmullw %s,%s,%s\n", drn_l,crn_l,orn_l); | |
5829 printf("\tmullw %s,%s,%s\n", crn_h,crn_h,orn_l); | |
5830 printf("\tadd %s,%s,%s\n", drn_h,drn_h,crn_h); | |
5831 printf("\tmullw %s,%s,%s\n", crn_l,orn_h,crn_l); | |
5832 printf("\tadd %s,%s,%s\n", crn_h,drn_h,crn_l); | |
5833 printf("\tmr %s,%s\n", crn_l,drn_l); | |
5834 break; | |
219 | 5835 case LDIV: |
880 | 5836 code_ldiv_lib(reg,oreg); // ___divdi3$stub |
5837 if (!creg_mode) check_lreg(reg); | |
5838 break; | |
219 | 5839 case LUDIV: |
880 | 5840 code_ludiv_lib(reg,oreg); // ___udivdi3$stub |
5841 if (!creg_mode) check_lreg(reg); | |
5842 break; | |
219 | 5843 case LMOD: |
880 | 5844 code_lmod_lib(reg,oreg); // ___moddi3$stub |
5845 if (!creg_mode) check_lreg(reg); | |
5846 break; | |
219 | 5847 case LUMOD: |
880 | 5848 code_lumod_lib(reg,oreg); // ___umoddi3$stub |
5849 if (!creg_mode) check_lreg(reg); | |
5850 break; | |
211 | 5851 default: |
880 | 5852 error(-1); |
211 | 5853 } |
530 | 5854 if(ox!=-1) free_register(ox); |
221 | 5855 if(dx!=-1) free_register(dx); |
195 | 5856 } |
5857 | |
216 | 5858 int |
5859 code_lconst_op_p(int op,int e) | |
214 | 5860 { |
215 | 5861 int v; |
5862 if (car(e)==LCONST) { | |
880 | 5863 if (!(-32766<lcadr(e)&&lcadr(e)<32767)) return 0; |
5864 v = lcadr(e); | |
215 | 5865 } else if (car(e)==CONST) { |
880 | 5866 if (!(-32766<cadr(e)&&cadr(e)<32767)) return 0; |
5867 v = cadr(e); | |
222 | 5868 } else return 0; |
215 | 5869 |
214 | 5870 switch(op) { |
436 | 5871 case LMUL: case LUMUL: case LUDIV: |
5872 // case LDIV: | |
5873 return ilog(v); | |
231 | 5874 case LLSHIFT: |
5875 case LULSHIFT: | |
5876 case LRSHIFT: | |
5877 case LURSHIFT: | |
880 | 5878 return (0<=v&&v<=64); |
219 | 5879 case LADD: |
5880 case LSUB: | |
880 | 5881 return 1; |
219 | 5882 case LBOR: |
880 | 5883 return (v>0); |
214 | 5884 default: |
880 | 5885 return 0; |
214 | 5886 } |
5887 } | |
5888 | |
216 | 5889 void |
221 | 5890 loprtc(int op,int creg,int e) |
213 | 5891 { |
221 | 5892 char *crn_h; |
5893 char *crn_l; | |
215 | 5894 char *grn; |
569 | 5895 int v=0; |
215 | 5896 int greg; |
5897 | |
221 | 5898 use_longlong(creg); |
5899 crn_h = lregister_name_high(creg); | |
5900 crn_l = lregister_name_low(creg); | |
5901 | |
222 | 5902 if (car(e)==LCONST) v = lcadr(e); |
5903 else if (car(e)==CONST) v = cadr(e); | |
213 | 5904 |
5905 switch(op) { | |
436 | 5906 case LMUL: case LUMUL: |
5907 v=ilog(v); | |
219 | 5908 case LLSHIFT: |
5909 case LULSHIFT: | |
880 | 5910 if (v==0) return; |
5911 if (v==32) { | |
5912 code_register(regv_l(creg),regv_h(creg)); | |
5913 code_const(0,regv_l(creg)); | |
5914 return; | |
5915 } else if (v>31) { | |
5916 printf("\tslwi %s,%s,%d\n",crn_h,crn_l,v-32); | |
5917 code_const(0,regv_l(creg)); | |
5918 return; | |
5919 } | |
5920 greg = get_register(); | |
5921 grn = register_name(greg); | |
5922 use_reg(greg); | |
5923 printf("\tsrwi %s,%s,%d\n",grn,crn_l,32-v); | |
5924 printf("\tslwi %s,%s,%d\n",crn_h,crn_h,v); | |
5925 printf("\tor %s,%s,%s\n",crn_h,grn,crn_h); | |
5926 printf("\tslwi %s,%s,%d\n",crn_l,crn_l,v); | |
5927 free_register(greg); | |
5928 return; | |
436 | 5929 case LDIV: |
5930 v=ilog(v); | |
219 | 5931 case LRSHIFT: |
880 | 5932 if (v==0) return; |
5933 if (v==32) { | |
5934 code_register(regv_h(creg),regv_l(creg)); | |
5935 printf("\tsrawi %s,%s,31\n",crn_h,crn_l); | |
5936 return; | |
5937 } else if (v>31) { | |
5938 printf("\tsrawi %s,%s,%d\n",crn_l,crn_h,v-32); | |
5939 printf("\tsrawi %s,%s,31\n",crn_h,crn_l); | |
5940 return; | |
5941 } | |
5942 greg = get_register(); | |
5943 use_reg(greg); | |
5944 grn = register_name(greg); | |
5945 printf("\tsrwi %s,%s,%d\n",grn,crn_l,v); | |
5946 printf("\tinsrwi %s,%s,%d,0\n",grn,crn_h,v); | |
5947 printf("\tsrawi %s,%s,%d\n",crn_h,crn_h,v); | |
5948 printf("\tmr %s,%s\n",crn_l,grn); | |
5949 free_register(greg); | |
5950 return; | |
436 | 5951 case LUDIV: |
5952 v=ilog(v); | |
219 | 5953 case LURSHIFT: |
880 | 5954 if (v==0) return; |
5955 if (v==32) { | |
5956 code_register(regv_h(creg),regv_l(creg)); | |
5957 code_const(0,regv_h(creg)); | |
5958 return; | |
5959 } else if (v>31) { | |
5960 printf("\tsrwi %s,%s,%d\n",crn_l,crn_h,v-32); | |
5961 code_const(0,regv_h(creg)); | |
5962 return; | |
5963 } | |
5964 greg = get_register(); | |
5965 use_reg(greg); | |
5966 grn = register_name(greg); | |
5967 printf("\tslwi %s,%s,%d\n",grn,crn_h,32-v); | |
5968 printf("\tsrwi %s,%s,%d\n",crn_l,crn_l,v); | |
5969 printf("\tor %s,%s,%s\n",crn_l,grn,crn_l); | |
5970 printf("\tsrwi %s,%s,%d\n",crn_h,crn_h,v); | |
5971 free_register(greg); | |
5972 return; | |
231 | 5973 case LSUB: |
880 | 5974 v = -v; |
219 | 5975 case LADD: |
880 | 5976 printf("\taddic %s,%s,%d\n",crn_l,crn_l,v); |
5977 if (v<0) | |
5978 printf("\taddme %s,%s\n",crn_h,crn_h); | |
5979 else | |
5980 printf("\taddze %s,%s\n",crn_h,crn_h); | |
5981 break; | |
219 | 5982 case LBOR: |
662 | 5983 #ifdef __APPLE__ |
880 | 5984 printf("\tori %s,%s,lo16(%d)\n",crn_l,crn_l,v); |
662 | 5985 #else |
880 | 5986 printf("\tori %s,%s,%d@l\n",crn_l,crn_l,v); |
5987 #endif | |
5988 break; | |
213 | 5989 default: |
880 | 5990 error(-1); |
213 | 5991 } |
5992 } | |
5993 | |
5994 | |
211 | 5995 void |
5996 emit_lpop_free(int xreg) | |
195 | 5997 { |
590 | 5998 if (xreg>=0 && xreg!=creg && regs[xreg]!=REG_VAR) |
211 | 5999 free_register(xreg); |
195 | 6000 } |
6001 | |
211 | 6002 void |
6003 emit_lpush() | |
6004 { | |
6005 int new_reg; | |
212 | 6006 if (!is_longlong_reg(creg)) error(-1); |
211 | 6007 if (lreg_sp>MAX_MAX) error(-1); |
724 | 6008 new_reg = get_lregister(); /* 絶対に取れる(?) */ |
6009 lreg_stack[lreg_sp++] = creg; /* push するかわりにレジスタを使う */ | |
211 | 6010 lreg = creg = new_reg; |
6011 } | |
6012 | |
6013 void | |
239 | 6014 code_i2ll(int reg) |
195 | 6015 { |
215 | 6016 char *crn,*crn_h,*crn_l; |
239 | 6017 int reg0; |
6018 crn = register_name(reg0 = ireg); | |
6019 use_longlong(reg); | |
221 | 6020 crn_h = lregister_name_high(lreg); |
6021 crn_l = lregister_name_low(lreg); | |
239 | 6022 if (reg0!=regv_l(lreg)) |
880 | 6023 printf("\tmr %s,%s\n",crn_l,crn); |
215 | 6024 printf("\tsrawi %s,%s,31\n",crn_h,crn_l); |
195 | 6025 } |
6026 | |
211 | 6027 void |
239 | 6028 code_i2ull(int reg) |
195 | 6029 { |
239 | 6030 code_i2ll(reg); |
195 | 6031 } |
6032 | |
211 | 6033 void |
239 | 6034 code_u2ll(int reg) |
195 | 6035 { |
215 | 6036 char *crn,*crn_h,*crn_l; |
239 | 6037 int reg0; |
6038 crn = register_name(reg0 = ireg); | |
6039 use_longlong(reg); | |
221 | 6040 crn_h = lregister_name_high(lreg); |
6041 crn_l = lregister_name_low(lreg); | |
239 | 6042 if (reg0!=regv_l(lreg)) |
880 | 6043 printf("\tmr %s,%s\n",crn_l,crn); |
215 | 6044 printf("\tli %s,0\n",crn_h); |
195 | 6045 } |
6046 | |
211 | 6047 void |
6048 code_u2ull(int creg) | |
195 | 6049 { |
215 | 6050 code_u2ll(creg); |
195 | 6051 } |
6052 | |
211 | 6053 void |
239 | 6054 code_ll2i(int reg) |
195 | 6055 { |
219 | 6056 char *crn_l; |
239 | 6057 int reg0; |
6058 crn_l = lregister_name_low(reg0=lreg); | |
6059 use_int(reg); | |
6060 if (ireg!=regv_l(reg0)) | |
880 | 6061 printf("\tmr %s,%s\n",register_name(ireg),crn_l); |
195 | 6062 } |
6063 | |
211 | 6064 void |
6065 code_ll2u(int creg) | |
195 | 6066 { |
215 | 6067 code_ll2i(creg); |
195 | 6068 } |
6069 | |
211 | 6070 void |
6071 code_ull2i(int creg) | |
195 | 6072 { |
215 | 6073 code_ll2i(creg); |
195 | 6074 } |
6075 | |
211 | 6076 void |
6077 code_ull2u(int creg) | |
195 | 6078 { |
215 | 6079 code_ll2i(creg); |
195 | 6080 } |
6081 | |
6082 #if FLOAT_CODE | |
216 | 6083 |
211 | 6084 void |
239 | 6085 code_d2ll(int reg) |
195 | 6086 { |
215 | 6087 // fixdfdi$stub |
218 | 6088 set_freg(RET_FREGISTER,1); |
221 | 6089 extern_conv("__fixdfdi"); |
216 | 6090 set_lreg(RET_LREGISTER,0); |
239 | 6091 if (reg!=USE_CREG&®!=RET_LREGISTER) |
880 | 6092 use_longlong(reg); |
195 | 6093 } |
6094 | |
211 | 6095 void |
239 | 6096 code_d2ull(int reg) |
195 | 6097 { |
218 | 6098 set_freg(RET_FREGISTER,1); |
221 | 6099 extern_conv("__fixunsdfdi"); |
216 | 6100 set_lreg(RET_LREGISTER,0); |
239 | 6101 if (reg!=USE_CREG&®!=RET_LREGISTER) |
880 | 6102 use_longlong(reg); |
195 | 6103 } |
6104 | |
211 | 6105 void |
239 | 6106 code_f2ll(int reg) |
195 | 6107 { |
218 | 6108 set_freg(RET_FREGISTER,1); |
221 | 6109 extern_conv("__fixdfdi"); |
216 | 6110 set_lreg(RET_LREGISTER,0); |
239 | 6111 if (reg!=USE_CREG&®!=RET_LREGISTER) |
880 | 6112 use_longlong(reg); |
195 | 6113 } |
6114 | |
211 | 6115 void |
239 | 6116 code_f2ull(int reg) |
195 | 6117 { |
218 | 6118 set_freg(RET_FREGISTER,1); |
221 | 6119 extern_conv("__fixsfdi"); |
216 | 6120 set_lreg(RET_LREGISTER,0); |
239 | 6121 if (reg!=USE_CREG&®!=RET_LREGISTER) |
880 | 6122 use_longlong(reg); |
195 | 6123 } |
6124 | |
211 | 6125 void |
239 | 6126 code_ll2d(int reg) |
195 | 6127 { |
216 | 6128 set_lreg(RET_LREGISTER,1); |
221 | 6129 extern_conv("__floatdidf"); |
218 | 6130 set_freg(RET_FREGISTER,0); |
239 | 6131 if (reg!=USE_CREG&®!=RET_FREGISTER) |
880 | 6132 use_float(1,reg); |
195 | 6133 } |
6134 | |
217 | 6135 |
211 | 6136 void |
239 | 6137 code_ll2f(int reg) |
195 | 6138 { |
216 | 6139 set_lreg(RET_LREGISTER,1); |
221 | 6140 extern_conv("__floatdisf"); |
218 | 6141 set_freg(RET_FREGISTER,0); |
239 | 6142 if (reg!=USE_CREG&®!=RET_FREGISTER) |
880 | 6143 use_float(0,reg); |
195 | 6144 } |
6145 | |
211 | 6146 void |
6147 code_ull2d(int creg) | |
195 | 6148 { |
215 | 6149 code_ll2d(creg); |
195 | 6150 } |
6151 | |
211 | 6152 void |
6153 code_ull2f(int creg) | |
195 | 6154 { |
215 | 6155 code_ll2f(creg); |
195 | 6156 } |
6157 | |
6158 | |
273 | 6159 static void |
6160 ladd(int creg,int reg,int dir) // creg=reg+dir | |
221 | 6161 { |
273 | 6162 printf("\taddic %s,%s,%d\n", |
880 | 6163 lregister_name_low(creg),lregister_name_low(reg), dir); |
273 | 6164 printf("\tadd%s %s,%s\n", dir>0?"ze":"me", |
880 | 6165 lregister_name_high(creg),lregister_name_high(reg)); |
221 | 6166 } |
195 | 6167 |
211 | 6168 void |
6169 code_lpreinc(int e1,int e2,int reg) | |
195 | 6170 { |
222 | 6171 int dreg,xreg; |
211 | 6172 int dir=caddr(e1); |
6173 if (car(e2)==LREGISTER) { | |
880 | 6174 use_longlong(reg); |
6175 ladd(cadr(e2),cadr(e2),dir); | |
273 | 6176 if (reg!=cadr(e2)) { |
880 | 6177 lmove(reg,cadr(e2)); |
6178 } | |
211 | 6179 return; |
6180 } | |
6181 g_expr(e2); | |
221 | 6182 if(!is_int_reg(creg)) error(-1); |
222 | 6183 emit_push(); |
221 | 6184 if (reg==USE_CREG) { |
880 | 6185 dreg=get_lregister(); if (!dreg) error(-1); |
6186 set_lreg(dreg,0); // free old lreg==creg | |
221 | 6187 } else { |
269 | 6188 dreg = reg; |
221 | 6189 } |
222 | 6190 xreg = emit_pop(0); |
269 | 6191 lload(xreg,dreg,0); |
273 | 6192 ladd(dreg,dreg,dir); |
269 | 6193 code_lassign(xreg,dreg); |
222 | 6194 emit_pop_free(xreg); |
195 | 6195 } |
6196 | |
211 | 6197 void |
6198 code_lpostinc(int e1,int e2,int reg) | |
195 | 6199 { |
222 | 6200 int dreg,nreg,xreg; |
211 | 6201 int dir=caddr(e1); |
6202 if (car(e2)==LREGISTER) { | |
880 | 6203 use_longlong(reg); |
6204 if (use && reg!=cadr(e2)) | |
6205 lmove(reg,cadr(e2)); | |
6206 ladd(cadr(e2),cadr(e2),dir); | |
211 | 6207 return; |
6208 } | |
6209 g_expr(e2); | |
221 | 6210 if(!is_int_reg(creg)) error(-1); |
222 | 6211 emit_push(); |
221 | 6212 nreg=get_lregister(); if (!nreg) error(-1); |
6213 if (reg==USE_CREG) { | |
880 | 6214 dreg=get_lregister(); if (!dreg) error(-1); |
6215 set_lreg(dreg,0); // free old lreg==creg | |
221 | 6216 } else { |
269 | 6217 dreg = reg; |
221 | 6218 } |
222 | 6219 xreg = emit_pop(0); |
269 | 6220 lload(xreg,dreg,0); |
273 | 6221 ladd(nreg,dreg,dir); |
269 | 6222 code_lassign(xreg,nreg); |
222 | 6223 emit_pop_free(xreg); |
211 | 6224 free_register(nreg); |
195 | 6225 } |
6226 | |
211 | 6227 void |
221 | 6228 code_lassop(int op,int reg) |
195 | 6229 { |
211 | 6230 int xreg; |
6231 int edx,edx0=-1; | |
221 | 6232 |
6233 // (*creg) op = pop() | |
211 | 6234 xreg = emit_lpop(0); /* pop e3 value */ |
6235 if (!is_int_reg(creg)) error(-1); | |
221 | 6236 edx = ireg; |
223 | 6237 emit_push(); |
221 | 6238 use_longlong(reg); |
6239 if (regv_l(lreg)==edx || regv_h(lreg)==edx) { | |
880 | 6240 // this can't happen |
6241 edx0 = get_register(); if(!edx0) error(-1); | |
6242 printf("## lassop\n\tmr %s,%s\n",register_name(edx0),register_name(edx)); | |
6243 edx = edx0; | |
211 | 6244 } |
269 | 6245 lload(edx0=edx,reg,0); |
221 | 6246 ltosop(op,reg,xreg); |
269 | 6247 use_reg(reg); |
223 | 6248 edx = emit_pop(0); |
269 | 6249 code_lassign(edx,reg); |
6250 if (edx0!=-1) | |
880 | 6251 free_register(edx0); |
269 | 6252 emit_pop_free(edx); |
211 | 6253 emit_lpop_free(xreg); |
195 | 6254 } |
6255 | |
219 | 6256 void |
6257 code_register_lassop(int reg,int op) { | |
221 | 6258 // reg op = pop() |
219 | 6259 int xreg=emit_lpop(); |
221 | 6260 ltosop(op,reg,xreg); |
6261 emit_lpop_free(xreg); | |
219 | 6262 } |
6263 | |
195 | 6264 |
6265 #endif | |
6266 | |
95 | 6267 void |
6268 code_save_stacks() | |
6269 { | |
103 | 6270 int i,reg; |
101 | 6271 for(i=0;i<reg_sp;i++) { |
103 | 6272 if ((reg=reg_stack[i])>=0) { |
101 | 6273 code_assign_lvar( |
245 | 6274 (reg_stack[i]=new_lvar(SIZE_OF_INT)),reg,0); |
101 | 6275 reg_stack[i]= reg_stack[i]-REG_LVAR_OFFSET; |
880 | 6276 free_register(reg); |
101 | 6277 } |
6278 } | |
195 | 6279 #if FLOAT_CODE |
101 | 6280 for(i=0;i<freg_sp;i++) { |
103 | 6281 if ((reg=freg_stack[i])>=0) { |
101 | 6282 code_dassign_lvar( |
245 | 6283 (freg_stack[i]=new_lvar(SIZE_OF_DOUBLE)),reg,1); |
101 | 6284 freg_stack[i]= freg_stack[i]-REG_LVAR_OFFSET; |
880 | 6285 free_register(reg); |
101 | 6286 } |
6287 } | |
195 | 6288 #endif |
212 | 6289 #if LONGLONG_CODE |
6290 for(i=0;i<lreg_sp;i++) { | |
6291 if ((reg=lreg_stack[i])>=0) { | |
223 | 6292 code_lassign_lvar( |
245 | 6293 (lreg_stack[i]=new_lvar(SIZE_OF_LONGLONG)),reg); |
212 | 6294 lreg_stack[i]= lreg_stack[i]-REG_LVAR_OFFSET; |
880 | 6295 free_register(reg); |
212 | 6296 } |
6297 } | |
6298 #endif | |
96 | 6299 } |
6300 | |
739
0c7a6ae119ba
i64 continue... compiler compiled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
726
diff
changeset
|
6301 static void |
96 | 6302 emit_lib(char *p[]) |
95 | 6303 { |
98 | 6304 while(*p) { |
880 | 6305 printf("%s\n",*p++); |
96 | 6306 } |
6307 } | |
6308 | |
6309 void | |
6310 code_closing() | |
6311 { | |
195 | 6312 #if FLOAT_CODE |
96 | 6313 if (d2u_lib_used) emit_lib(d2u_lib); |
6314 if (u2d_lib_used) emit_lib(u2d_lib); | |
6315 if (float_one_lib_used) emit_lib(float_one_lib); | |
98 | 6316 if (float_zero_lib_used) emit_lib(float_zero_lib); |
96 | 6317 if (i2d_lib_used) emit_lib(i2d_lib); |
739
0c7a6ae119ba
i64 continue... compiler compiled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
726
diff
changeset
|
6318 d2u_lib_used = u2d_lib_used= float_one_lib_used= float_zero_lib_used = i2d_lib_used = 0; |
195 | 6319 #endif |
213 | 6320 #if LONGLONG_CODE |
218 | 6321 if (asld_lib_used) emit_lib(asld_lib); |
221 | 6322 if (lsrd_lib_used) emit_lib(lsrd_lib); |
6323 if (asrd_lib_used) emit_lib(asrd_lib); | |
739
0c7a6ae119ba
i64 continue... compiler compiled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
726
diff
changeset
|
6324 asld_lib_used = lsrd_lib_used = asrd_lib_used = 0; |
221 | 6325 #if 0 |
216 | 6326 if (lumod_lib_used) emit_lib(lumod_lib); |
6327 if (lmod_lib_used) emit_lib(lmod_lib); | |
6328 if (ludiv_lib_used) emit_lib(ludiv_lib); | |
6329 if (ldiv_lib_used) emit_lib(ldiv_lib); | |
221 | 6330 #endif |
213 | 6331 #if FLOAT_CODE |
218 | 6332 #if 0 |
216 | 6333 if (dl2ll_lib_used) emit_lib(dl2ll_lib); |
6334 if (d2ull_lib_used) emit_lib(d2ull_lib); | |
6335 if (f2ll_lib_used) emit_lib(f2ll_lib); | |
6336 if (f2ull_lib_used) emit_lib(f2ull_lib); | |
6337 if (ll2d_lib_used) emit_lib(ll2d_lib); | |
6338 if (ll2f_lib_used) emit_lib(ll2f_lib); | |
213 | 6339 #endif |
6340 #endif | |
218 | 6341 #endif |
662 | 6342 #ifndef __APPLE__ |
6343 if (saveFP_used) emit_lib(saveFP_lib); | |
6344 #endif | |
97 | 6345 global_table(); |
108 | 6346 /* printf("\t.ident \"Micro-C compiled\"\n"); */ |
95 | 6347 } |
6348 | |
300 | 6349 #if CASE_CODE |
6350 | |
6351 int | |
382 | 6352 code_table_jump_p(int delta) { return 1; } |
300 | 6353 |
6354 void | |
302 | 6355 code_table_jump(int l,int csvalue,int delta,int max,int min,int dlabel) |
300 | 6356 { |
302 | 6357 int t,s,u=-1; |
6358 char *crn = register_name(csvalue); // can be t,s,u | |
300 | 6359 char *trn = register_name(t=get_register()); |
6360 char *srn = register_name(s=get_register()); | |
302 | 6361 char *urn; |
300 | 6362 |
6363 inc_cmpflag(); | |
6364 if (min>32767||min<-32765) { | |
880 | 6365 if (t==csvalue) { |
6366 code_const(min,s); | |
6367 printf("\tsub\t%s,%s,%s\n",trn,crn,srn); | |
6368 } else { | |
6369 code_const(min,t); | |
6370 printf("\tsub\t%s,%s,%s\n",trn,crn,trn); | |
6371 } | |
300 | 6372 } else { |
667 | 6373 #ifdef __APPLE__ |
880 | 6374 printf("\taddi\t%s,%s,lo16(%d)\n",trn,crn,-min); |
667 | 6375 #else |
880 | 6376 printf("\taddi\t%s,%s,%d@l\n",trn,crn,-min); |
667 | 6377 #endif |
300 | 6378 } |
662 | 6379 printf("\tcmplwi %s,%s,%d\n",crname(cmpflag),trn,max-min); |
6380 printf("\tbgt-\t%s,%s%d\n",crname(cmpflag),lpfx,dlabel); | |
300 | 6381 inc_cmpflag(); |
6382 switch(delta) { | |
6383 case 1: printf("\tslwi %s,%s,2\n",trn,trn); break; | |
302 | 6384 case 2: |
880 | 6385 printf("\tli %s,1\n",srn); |
6386 printf("\tand %s,%s,%s\n",srn,srn,trn); | |
6387 printf("\tcmplwi %s,%s,0\n",crname(cmpflag),srn); | |
6388 printf("\tbne\t%s,%s%d\n",crname(cmpflag),lpfx,dlabel); | |
6389 printf("\tslwi %s,%s,1\n",trn,trn); | |
6390 break; | |
302 | 6391 case 4: |
880 | 6392 printf("\tli %s,3\n",srn); |
6393 printf("\tand %s,%s,%s\n",srn,srn,trn); | |
6394 printf("\tcmplwi %s,%s,0\n",crname(cmpflag),srn); | |
6395 printf("\tbne\t%s,%s%d\n",crname(cmpflag),lpfx,dlabel); | |
6396 break; | |
300 | 6397 default: |
880 | 6398 urn = register_name(u=get_register()); |
6399 printf("\tli %s,%d\n",srn,delta); | |
6400 printf("\tdivwu %s,%s,%s\n",urn,trn,srn); | |
6401 printf("\tmullw %s,%s,%s\n",srn,urn,srn); | |
6402 printf("\tsubf %s,%s,%s\n",srn,trn,srn); | |
6403 printf("\tcmplwi %s,%s,0\n",crname(cmpflag),srn); | |
6404 printf("\tbne\t%s,%s%d\n",crname(cmpflag),lpfx,dlabel); | |
6405 printf("\tslwi %s,%s,2\n",trn,urn); | |
300 | 6406 } |
662 | 6407 #ifdef __APPLE__ |
300 | 6408 printf("\taddis %s,r31,ha16(L_%d-L_%d)\n", |
880 | 6409 srn,l,code_base); |
300 | 6410 printf("\tla %s,lo16(L_%d-L_%d)(%s)\n", |
880 | 6411 srn,l,code_base,srn); |
300 | 6412 printf("\tadd %s,%s,%s\n",trn,srn,trn); |
6413 printf("\tlwz r0,0(%s)\n",trn); | |
6414 printf("\tadd r0,r0,%s\n",srn); | |
6415 printf("\tmtctr r0\n"); | |
6416 printf("\tbctr\n"); | |
662 | 6417 #else |
672 | 6418 printf("\tlis %s,%s%d@ha\n",srn,lpfx,l); |
6419 printf("\tla %s,%s%d@l(%s)\n",srn,lpfx,l,srn); | |
662 | 6420 printf("\tadd %s,%s,%s\n",trn,srn,trn); |
6421 printf("\tlwz 0,0(%s)\n",trn); | |
6422 printf("\tadd 0,0,%s\n",srn); | |
6423 printf("\tmtctr 0\n"); | |
6424 printf("\tbctr\n"); | |
6425 #endif | |
300 | 6426 |
6427 free_register(s); | |
6428 free_register(t); | |
302 | 6429 if (u!=-1) free_register(u); |
300 | 6430 } |
6431 | |
6432 void | |
6433 code_table_open(int l) | |
6434 { | |
6435 printf("\t.p2align 2\n"); | |
6436 fwddef(l); | |
6437 } | |
6438 | |
6439 void | |
6440 code_table_value(int label,int table_top) | |
6441 { | |
662 | 6442 printf("\t.long %s%d-%s%d\n",lpfx,label,lpfx,table_top); |
300 | 6443 } |
6444 | |
6445 void | |
6446 code_table_close() | |
6447 { | |
6448 } | |
6449 | |
6450 #endif | |
6451 | |
316 | 6452 #if ASM_CODE |
6453 | |
318 | 6454 /* |
320 | 6455 print an operand |
318 | 6456 */ |
6457 | |
6458 static void | |
320 | 6459 emit_asm_operand(int rstr) |
318 | 6460 { |
6461 if (car(rstr)==REGISTER) { | |
880 | 6462 printf("%s",register_name(cadr(rstr))); |
318 | 6463 } else if (car(rstr)==CONST) { |
880 | 6464 printf("%d",cadr(rstr)); |
319 | 6465 } else if (car(rstr)==FNAME) { |
880 | 6466 printf("%s",ncaddr(rstr)->nm); |
711 | 6467 } else if (car(rstr)==LABEL) { |
880 | 6468 printf("%s%d:\n",lpfx,cadr(rstr)); |
318 | 6469 } else { |
880 | 6470 error(-1); |
318 | 6471 } |
6472 } | |
6473 | |
320 | 6474 /* |
6475 prepare asm operands | |
6476 | |
6477 char *constraints sgtring | |
326 | 6478 int oeprand expr |
320 | 6479 int mode (ASM_INPUT,ASM_OUTPUT) |
6480 int replacement list | |
6481 int output operands count | |
6482 int output operands replacement list | |
6483 | |
6484 retrun replacement list | |
6485 list3( operands, next, clobber ) | |
6486 0 can be shared in input/output | |
6487 1 can't be used in input | |
6488 */ | |
6489 | |
327 | 6490 extern int |
6491 code_asm_operand(char *p,int e1,int mode,int repl,int n,int repl0) | |
318 | 6492 { |
6493 int r; | |
6494 int c; | |
6495 int val; | |
6496 int clobber = 0; | |
6497 | |
527 | 6498 printf("## constraint %s\n",p); |
6499 retry: | |
6500 switch((c=*p)) { | |
6501 case '?': | |
6502 case '!': | |
6503 case '+': | |
6504 case '%': | |
6505 case '#': | |
6506 case '*': | |
6507 case '=': | |
880 | 6508 // output register |
6509 p++; | |
6510 goto retry; | |
527 | 6511 case '&': |
880 | 6512 // earlyclobber |
6513 p++; | |
6514 clobber = 1; | |
6515 goto retry; | |
527 | 6516 case 'b': // address base register (what?) |
6517 case 'r': | |
880 | 6518 if (mode==ASM_INPUT) { |
6519 for(;repl0;repl0 = cadr(repl0)) { | |
6520 if (car(car(repl0))==REGISTER && caddr(repl0)==0) { | |
6521 r = cadr(car(repl0)); | |
6522 caddr(repl0) = ASM_USED; | |
6523 break; | |
6524 } | |
318 | 6525 } |
880 | 6526 r = get_register(); |
6527 } else { | |
6528 r = get_register(); | |
6529 } | |
6530 repl = list3(list2(REGISTER,r),repl,clobber); | |
6531 break; | |
527 | 6532 case 'm': |
880 | 6533 repl = list3(list2(0,0),repl,clobber); |
6534 break; | |
527 | 6535 case 'i': |
880 | 6536 if (car(e1)==GVAR) { |
6537 e1=list3n(FNAME,0,ncaddr(e1)); | |
6538 } else if (car(e1)==FNAME) { | |
6539 e1=list3n(FNAME,0,ncaddr(e1)); | |
6540 } else if (car(e1)==STRING) { | |
6541 val = emit_string_label(); | |
6542 ascii(ncaddr(e1)->nm); | |
6543 e1=list2(LABEL,val); | |
6544 } else if (car(e1)==CONST) { | |
6545 } else error(-1); | |
6546 repl = list3(e1,repl,clobber); | |
6547 break; | |
527 | 6548 case '0': case '1': case '2': case '3': case '4': |
6549 case '5': case '6': case '7': case '8': case '9': | |
880 | 6550 val = 0; |
6551 do { val = val*10 + c-'0'; } while (digit(c=*p++)); | |
6552 if (val>MAX_ASM_REG) error(-1); // too large register | |
6553 if (n-val<0) error(-1); | |
6554 repl = list3(car(nth(n-val-1,repl0)),repl,clobber); | |
6555 break; | |
527 | 6556 default: |
880 | 6557 printf("### unknown asm constraint %c\n",c); |
527 | 6558 } |
318 | 6559 return repl; |
6560 } | |
6561 | |
320 | 6562 void |
327 | 6563 code_free_asm_operand(int repl) |
318 | 6564 { |
6565 for(;repl;repl=cadr(repl)) { | |
880 | 6566 if (car(car(repl))==REGISTER) |
6567 free_register(cadr(car(repl))); | |
318 | 6568 } |
6569 } | |
6570 | |
320 | 6571 |
6572 extern void | |
327 | 6573 code_asm(char *asm_str,int repl) |
316 | 6574 { |
320 | 6575 int c,i,rstr,val; |
318 | 6576 char *p; |
320 | 6577 int reg[MAX_ASM_REG]; |
6578 | |
516 | 6579 text_mode(0); |
320 | 6580 c = *asm_str; |
6581 if (c!='\t'&&c!=' ') printf("\t"); | |
6582 for(i=0;repl && i<MAX_ASM_REG;i++) { | |
880 | 6583 reg[i] = car(repl); |
6584 repl = cadr(repl); | |
320 | 6585 } |
6586 p = asm_str; | |
6587 while((c = *p++)) { | |
880 | 6588 if (c=='%') { |
6589 c = *p++; | |
6590 if (!c) { break; | |
6591 } else if (c=='%') { | |
6592 printf("%%"); continue; | |
6593 } else if (!digit(c)) { | |
6594 printf("%%%c",c); continue; | |
6595 } | |
6596 val = 0; | |
6597 do { val = val*10 + c-'0'; } while (digit(c=*p++)) ; | |
6598 p--; | |
6599 if (val>MAX_ASM_REG) error(-1); // too large register | |
6600 rstr = reg[val]; | |
6601 emit_asm_operand(rstr); | |
6602 } else { | |
6603 printf("%c",c); | |
6604 } | |
318 | 6605 } |
320 | 6606 printf("\n"); |
316 | 6607 } |
6608 | |
6609 #endif | |
6610 | |
6611 | |
329 | 6612 #if BIT_FIELD_CODE |
6613 | |
6614 /* bit field alignment calcuration */ | |
6615 | |
6616 static void | |
426 | 6617 set_bitsz(int type,int *pbitpos,int *pbitsize, |
880 | 6618 int *psign,int *pbitsz,int *palign,int *pl) |
329 | 6619 { |
569 | 6620 int sign=0,bitsz=0; |
6621 int align=4,l=0; | |
426 | 6622 *pbitpos = cadr(caddr(type)); |
6623 *pbitsize = caddr(caddr(type)); | |
420 | 6624 switch(cadr(type)) { /* value type */ |
880 | 6625 case INT: sign=1; bitsz=32; align=4;break; |
6626 case UNSIGNED: bitsz=32; align=4;break; | |
335 | 6627 case CHAR: sign=1; bitsz= 8; align=1;break; |
880 | 6628 case UCHAR: bitsz= 8; align=1;break; |
329 | 6629 case SHORT: sign=1; bitsz=16; align=2;break; |
6630 case USHORT: sign=1; bitsz=16; align=2;break; | |
676 | 6631 #ifdef __APPLE__ |
329 | 6632 case LONGLONG: sign=1; bitsz=64; align=4;l=1; break; |
880 | 6633 case ULONGLONG: bitsz=64; align=4;l=1; break; |
676 | 6634 #else |
6635 case LONGLONG: sign=1; bitsz=64; align=8;l=1; break; | |
880 | 6636 case ULONGLONG: bitsz=64; align=8;l=1; break; |
676 | 6637 #endif |
329 | 6638 default: error(-1); |
6639 } | |
6640 *psign = sign; | |
6641 *pbitsz = bitsz; | |
6642 *palign = align; | |
6643 *pl = l; | |
6644 } | |
6645 | |
6646 /* | |
6647 bit field alignment calcuration | |
6648 this is architecture depenedent | |
6649 */ | |
6650 | |
6651 extern int | |
6652 code_bit_field_disp(int type,int *poffset,int *bfd,int *sz) | |
6653 { | |
331 | 6654 int sign,bitsz,align; |
329 | 6655 int i; |
6656 int bitpos = *bfd; | |
426 | 6657 int bitpos0; |
6658 int bitsize; | |
329 | 6659 int offset = *poffset; |
6660 int l; | |
426 | 6661 set_bitsz(type,&bitpos0,&bitsize,&sign,&bitsz,&align,&l); |
329 | 6662 |
569 | 6663 if (bitsize>bitsz) { error(BTERR); bitsize = bitsz; } |
329 | 6664 |
6665 /* bfd means previous bit field bit offset */ | |
6666 if (bitpos) { | |
880 | 6667 /* previous field is bit field and spaces may remain */ |
6668 /* calc previsous offset */ | |
6669 | |
6670 i= offset-(bitpos+7)/8; | |
6671 | |
6672 for(l = bitpos;l>0;l -= 8,i++) { | |
6673 if ((i & (align-1))==0 && l+bitsize <= bitsz) { | |
6674 /* alignment is correct and space remains */ | |
6675 *poffset=offset=i; | |
6676 i = l+bitsize; | |
423 | 6677 *bfd = (i==bitsz)?0:i; |
880 | 6678 *sz = (i+7)/8; |
527 | 6679 // printf("## bitpos=%d bitsize=%d bitsz=%d offset=%d\n",l,bitsize,bitsz,*poffset); |
880 | 6680 return l; |
6681 } | |
6682 } | |
329 | 6683 } |
6684 | |
6685 /* first bit-field */ | |
6686 | |
6687 if ((i=(offset & (align-1)))) { | |
880 | 6688 *poffset = (offset += (align-i)); |
329 | 6689 } |
6690 bitpos = 0; | |
426 | 6691 *bfd = (bitsize==bitsz)?0:bitsize; |
329 | 6692 *sz = (bitsize+7)/8; |
6693 | |
527 | 6694 // printf("## bitpos=%d bitsize=%d bitsz=%d offset=%d\n",bitpos,bitsize,bitsz,*poffset); |
329 | 6695 return bitpos; |
6696 } | |
6697 | |
6698 /* bit field value */ | |
6699 | |
6700 extern void | |
426 | 6701 code_bit_field(int type,int adr, int reg) |
329 | 6702 { |
331 | 6703 int sign,bitsz,l,align; |
426 | 6704 int bitsize,bitpos; |
6705 int i,size; | |
6706 set_bitsz(type,&bitpos,&bitsize,&sign,&bitsz,&align,&l); | |
6707 size = bitsz/8; | |
527 | 6708 // printf("## %d: bitpos=%d bitsize=%d bitsz=%d\n",lineno,bitpos,bitsize,bitsz); |
329 | 6709 /* this implementation returns -1 for int i:1; */ |
6710 if (l==1) { | |
440 | 6711 #if LONGLONG_CODE |
880 | 6712 // use_int(adr); |
6713 use_longlong(reg); | |
6714 lload(adr,reg,0); | |
6715 /* shift left */ | |
6716 if (bitpos) | |
6717 loprtc(LLSHIFT,reg,list2(CONST,bitpos)); | |
6718 /* shift right */ | |
6719 if ((i=bitsz-bitsize)) | |
6720 loprtc(sign?LRSHIFT:LURSHIFT,reg,list2(CONST,i)); | |
440 | 6721 #endif |
329 | 6722 } else { |
880 | 6723 // use_int(adr); |
6724 use_int(reg); | |
662 | 6725 #ifdef __APPLE__ |
880 | 6726 printf("\t%s %s,lo16(%d)(%s)\n",cload(size), |
6727 register_name(reg),0,register_name(adr)); | |
662 | 6728 #else |
880 | 6729 printf("\t%s %s,%d@l(%s)\n",cload(size), |
6730 register_name(reg),0,register_name(adr)); | |
6731 #endif | |
6732 cext(sign,size,reg); | |
6733 /* shift left */ | |
6734 if ((i=bitpos+(32-bitsz))) | |
6735 oprtc(LSHIFT,reg,list2(CONST,i)); | |
6736 /* shift right */ | |
6737 if ((i=bitsz-bitsize+(32-bitsz))) | |
6738 oprtc(sign?RSHIFT:URSHIFT,reg,list2(CONST,i)); | |
329 | 6739 } |
6740 } | |
6741 | |
6742 /* bit field replacement */ | |
6743 | |
330 | 6744 static void |
331 | 6745 make_mask_and_or(int mask,int tmp,char *trn,char *crn,char *lrn) |
330 | 6746 { |
527 | 6747 // printf("## mask 0x%08x ~0x%08x\n",mask,~mask); |
880 | 6748 code_const(~mask,tmp); |
6749 printf("\tor %s,%s,%s\n",trn,crn,trn); | |
6750 /* do conjunction */ | |
6751 printf("\tand %s,%s,%s\n",lrn,trn,lrn); | |
6752 /* make or-mask */ | |
6753 code_const(mask,tmp); | |
6754 printf("\tand %s,%s,%s\n",trn,crn,trn); | |
6755 /* do disjunction */ | |
6756 printf("\tor %s,%s,%s\n",crn,trn,lrn); | |
330 | 6757 } |
6758 | |
329 | 6759 extern void |
431 | 6760 code_bit_replace(int adr,int value,int type) |
329 | 6761 { |
331 | 6762 int sign,bitsz,l,align; |
426 | 6763 int bitsize,bitpos; |
330 | 6764 int mask = 0; |
6765 int tmp = -1; | |
331 | 6766 int i; |
426 | 6767 int lvalue; |
330 | 6768 char *crn,*lrn,*trn; |
426 | 6769 int size; |
6770 set_bitsz(type,&bitpos,&bitsize,&sign,&bitsz,&align,&l); | |
6771 size = bitsz/8; | |
467 | 6772 // printf("## %d: bitpos=%d bitsize=%d bitsz=%d\n",lineno,bitpos,bitsize,bitsz); |
329 | 6773 if (l) { |
440 | 6774 #if LONGLONG_CODE |
880 | 6775 // use_int(adr); |
6776 lvalue = get_lregister(); | |
6777 lload(adr,lvalue,0); | |
6778 use_longlong(value); | |
6779 crn = lregister_name_low(value); | |
6780 lrn = lregister_name_low(lvalue); | |
6781 /* shift left */ | |
6782 if ((i=bitsz-bitsize-bitpos)) | |
6783 loprtc(LLSHIFT,value,list2(CONST,i)); | |
6784 trn = register_name(tmp = get_register()); | |
6785 if (bitpos+bitsize>=32) { | |
6786 /* make and-mask lower */ | |
6787 mask = make_mask(bitpos>=32?bitpos-32:0,bitpos+bitsize-32-1); | |
6788 make_mask_and_or(mask,tmp,trn,crn,lrn); | |
6789 } | |
6790 crn = lregister_name_high(value); | |
6791 lrn = lregister_name_high(lvalue); | |
6792 if (bitpos<32) { | |
6793 /* make and-mask upper */ | |
6794 mask = make_mask(bitpos,bitpos+bitsize>=32?31:bitpos+bitsize-1); | |
6795 make_mask_and_or(mask,tmp,trn,crn,lrn); | |
6796 } | |
6797 code_lassign(adr,value); | |
6798 free_register(lvalue); | |
6799 // free_register(adr); | |
440 | 6800 #endif |
329 | 6801 } else { |
880 | 6802 // use_int(adr); |
6803 use_int(value); | |
6804 lvalue = get_register(); | |
662 | 6805 #ifdef __APPLE__ |
880 | 6806 printf("\t%s %s,lo16(%d)(%s)\n",cload(size), |
6807 register_name(lvalue),0,register_name(adr)); | |
662 | 6808 #else |
880 | 6809 printf("\t%s %s,%d@l(%s)\n",cload(size), |
6810 register_name(lvalue),0,register_name(adr)); | |
6811 #endif | |
6812 cext(sign,size,lvalue); | |
6813 crn = register_name(value); | |
6814 lrn = register_name(lvalue); | |
6815 /* shift left */ | |
6816 if ((i=bitsz-bitsize-bitpos)) | |
6817 oprtc(LSHIFT,value,list2(CONST,i)); | |
6818 trn = register_name(tmp = get_register()); | |
6819 /* make and-mask */ | |
6820 mask = make_mask(bitpos+(32-bitsz),bitpos+bitsize-1+(32-bitsz)); | |
6821 make_mask_and_or(mask,tmp,trn,crn,lrn); | |
6822 free_register(lvalue); | |
6823 code_assign(adr,size,value); | |
329 | 6824 } |
330 | 6825 if (tmp!=-1) free_register(tmp); |
426 | 6826 if (use) { |
880 | 6827 code_bit_field(type,adr,USE_CREG); |
426 | 6828 } |
329 | 6829 } |
6830 | |
365 | 6831 static void |
6832 make_mask_and_or_const(int mask,char *crn,int c) | |
6833 { | |
6834 char *trn; | |
6835 int tmp = -1; | |
527 | 6836 // printf("## mask 0x%08x ~0x%08x\n",mask,~mask); |
365 | 6837 if ((~mask|c)!=-1) { |
880 | 6838 trn = register_name(tmp=get_register()); |
6839 code_const((~mask|c),tmp); | |
6840 /* do conjunction */ | |
6841 printf("\tand %s,%s,%s\n",crn,trn,crn); | |
365 | 6842 } |
6843 /* make or-mask */ | |
6844 c = mask&c; | |
6845 if (c!=0) { | |
880 | 6846 /* do disjunction */ |
6847 if (!((mask&c)&0xffff0000)) { | |
662 | 6848 #ifdef __APPLE__ |
880 | 6849 printf("\tori %s,%s,lo16(%d)\n",crn,crn,c); |
662 | 6850 #else |
880 | 6851 printf("\tori %s,%s,%d@l\n",crn,crn,c); |
6852 #endif | |
6853 } else { | |
6854 trn = register_name(tmp=get_register()); | |
6855 code_const(c,tmp); | |
6856 printf("\tor %s,%s,%s\n",crn,trn,crn); | |
6857 } | |
365 | 6858 } |
6859 if (tmp!=-1) free_register(tmp); | |
6860 } | |
6861 | |
6862 extern void | |
431 | 6863 code_bit_replace_const(int value,int adr,int type) |
365 | 6864 { |
6865 int sign,bitsz,l,align; | |
426 | 6866 int bitsize,bitpos,size; |
365 | 6867 int mask = 0; |
6868 int i; | |
6869 int c; | |
426 | 6870 int lvalue; |
365 | 6871 #if LONGLONG_CODE |
6872 long long lc; | |
6873 #endif | |
6874 char *crn; | |
426 | 6875 set_bitsz(type,&bitpos,&bitsize,&sign,&bitsz,&align,&l); |
6876 size = bitsz/8; | |
467 | 6877 // printf("## %d: bitpos=%d bitsize=%d bitsz=%d\n",lineno,bitpos,bitsize,bitsz); |
365 | 6878 if (l) { |
6879 #if LONGLONG_CODE | |
880 | 6880 use_int(adr); |
6881 lvalue = get_lregister(); | |
6882 lload(adr,lvalue,0); | |
6883 crn = lregister_name_low(lvalue); | |
6884 /* shift left */ | |
6885 lc = lcadr(value); | |
6886 if ((i=bitsz-bitsize-bitpos)) | |
6887 lc <<= i; | |
6888 if (bitpos+bitsize>=32) { | |
6889 /* make and-mask lower */ | |
6890 mask = make_mask(bitpos>=32?bitpos-32:0,bitpos+bitsize-32-1); | |
6891 make_mask_and_or_const(mask,crn,(int)lc); | |
6892 } | |
6893 crn = lregister_name_high(lvalue); | |
6894 if (bitpos<32) { | |
6895 /* make and-mask upper */ | |
6896 mask = make_mask(bitpos,bitpos+bitsize>=32?31:bitpos+bitsize-1); | |
6897 make_mask_and_or_const(mask,crn,(int)(lc>>32)); | |
6898 } | |
6899 code_lassign(adr,lvalue); | |
6900 free_register(lvalue); | |
365 | 6901 #endif |
6902 } else { | |
880 | 6903 use_int(adr); |
6904 lvalue = get_register(); | |
662 | 6905 #ifdef __APPLE__ |
880 | 6906 printf("\t%s %s,lo16(%d)(%s)\n",cload(size), |
6907 register_name(lvalue),0,register_name(adr)); | |
662 | 6908 #else |
880 | 6909 printf("\t%s %s,%d@l(%s)\n",cload(size), |
6910 register_name(lvalue),0,register_name(adr)); | |
6911 #endif | |
6912 cext(sign,size,lvalue); | |
6913 crn = register_name(lvalue); | |
6914 /* shift left */ | |
6915 c = cadr(value); | |
6916 if ((i=bitsz-bitsize-bitpos)) | |
6917 c <<= i; | |
6918 /* make and-mask */ | |
6919 mask = make_mask(bitpos+(32-bitsz),bitpos+bitsize-1+(32-bitsz)); | |
6920 make_mask_and_or_const(mask,crn,c); | |
6921 code_assign(adr,size,lvalue); | |
6922 free_register(lvalue); | |
426 | 6923 } |
6924 if (use) { | |
880 | 6925 code_bit_field(type,adr,USE_CREG); |
365 | 6926 } |
6927 } | |
6928 | |
329 | 6929 #endif |
6930 | |
715 | 6931 extern int |
782
003067098032
code argument offset in caller and callee
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
780
diff
changeset
|
6932 code_arg_alignment(int args,NMTBL *n, int type0,int sz, int is_code) |
003067098032
code argument offset in caller and callee
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
780
diff
changeset
|
6933 { |
003067098032
code argument offset in caller and callee
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
780
diff
changeset
|
6934 return code_arg_alignment0(args,n, type0,sz, is_code); |
715 | 6935 } |
6936 | |
6937 | |
6938 extern int | |
6939 code_lvar_alignment(int args,NMTBL *n, int type0,int sz) | |
6940 { | |
6941 return code_lvar_alignment0(args,n, type0,sz); | |
6942 } | |
6943 | |
6944 | |
89 | 6945 /* end */ |