Merged trunk at revision 161680 into branch.
[official-gcc.git] / gcc / config / lm32 / lm32.h
blob0bf37455627b46d6cf1a8c433e5af7ed87d3dc23
1 /* Definitions of target machine for GNU compiler, Lattice Mico32 architecture.
2 Contributed by Jon Beniston <jon@beniston.com>
4 Copyright (C) 2009, 2010 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published
10 by the Free Software Foundation; either version 3, or (at your
11 option) any later version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /*-------------------------------*/
23 /* Run-time Target Specification */
24 /*-------------------------------*/
26 /* Print subsidiary information on the compiler version in use. */
27 #ifndef TARGET_VERSION
28 #define TARGET_VERSION fprintf (stderr, " (LatticeMico32)")
29 #endif
31 /* Target CPU builtins. */
32 #define TARGET_CPU_CPP_BUILTINS() \
33 do \
34 { \
35 builtin_define ("__lm32__"); \
36 builtin_assert ("cpu=lm32"); \
37 builtin_assert ("machine=lm32"); \
38 if (TARGET_MULTIPLY_ENABLED) \
39 builtin_define ("__multiply_enabled__"); \
40 if (TARGET_DIVIDE_ENABLED) \
41 builtin_define ("__divide_enabled__"); \
42 if (TARGET_BARREL_SHIFT_ENABLED) \
43 builtin_define ("__barrel_shift_enabled__"); \
44 if (TARGET_SIGN_EXTEND_ENABLED) \
45 builtin_define ("__sign_extend_enabled__"); \
46 if (TARGET_USER_ENABLED) \
47 builtin_define ("__user_enabled__"); \
48 } \
49 while (0)
51 #undef ASM_SPEC
52 #define ASM_SPEC "\
53 %{mmultiply-enabled} \
54 %{mdivide-enabled} \
55 %{mbarrel-shift-enabled} \
56 %{msign-extend-enabled} \
57 %{muser-extend-enabled} \
58 %{v} \
61 /* Let link script define all link options.
62 Default to using simulator link script. */
64 #undef STARTFILE_SPEC
65 #define STARTFILE_SPEC ""
66 #undef ENDFILE_SPEC
67 #define ENDFILE_SPEC ""
68 #undef LIB_SPEC
69 #define LIB_SPEC "%{!T*:-T sim.ld}"
71 #define OVERRIDE_OPTIONS lm32_override_options()
73 extern int target_flags;
75 /* Add -G xx support. */
77 #undef SWITCH_TAKES_ARG
78 #define SWITCH_TAKES_ARG(CHAR) \
79 (DEFAULT_SWITCH_TAKES_ARG (CHAR) || (CHAR) == 'G')
81 #undef CC1_SPEC
82 #define CC1_SPEC "%{G*}"
84 /*---------------------------------*/
85 /* Target machine storage layout. */
86 /*---------------------------------*/
88 #define BITS_BIG_ENDIAN 0
89 #define BYTES_BIG_ENDIAN 1
90 #define WORDS_BIG_ENDIAN 1
91 #define LIBGCC2_WORDS_BIG_ENDIAN 1
93 #define BITS_PER_UNIT 8
94 #define BITS_PER_WORD 32
95 #define UNITS_PER_WORD 4
97 #define POINTER_SIZE 32
99 #define PROMOTE_MODE(MODE,UNSIGNEDP,TYPE) \
100 do { \
101 if (GET_MODE_CLASS (MODE) == MODE_INT \
102 && GET_MODE_SIZE (MODE) < UNITS_PER_WORD) \
103 (MODE) = word_mode; \
104 } while (0)
106 #define PARM_BOUNDARY 32
108 #define STACK_BOUNDARY 32
110 #define BIGGEST_ALIGNMENT 64
112 #define FUNCTION_BOUNDARY 32
114 #define EMPTY_FIELD_BOUNDARY 32
116 #define STRICT_ALIGNMENT 1
118 #define TARGET_FLOAT_FORMAT IEEE_FLOAT_FORMAT
120 /* Make strings word-aligned so strcpy from constants will be faster. */
121 #define CONSTANT_ALIGNMENT(EXP, ALIGN) \
122 (TREE_CODE (EXP) == STRING_CST \
123 && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN))
125 /* Make arrays and structures word-aligned to allow faster copying etc. */
126 #define DATA_ALIGNMENT(TYPE, ALIGN) \
127 ((((ALIGN) < BITS_PER_WORD) \
128 && (TREE_CODE (TYPE) == ARRAY_TYPE \
129 || TREE_CODE (TYPE) == UNION_TYPE \
130 || TREE_CODE (TYPE) == RECORD_TYPE)) ? BITS_PER_WORD : (ALIGN))
132 /* We need this for the same reason as DATA_ALIGNMENT, namely to cause
133 character arrays to be word-aligned so that `strcpy' calls that copy
134 constants to character arrays can be done inline, and 'strcmp' can be
135 optimised to use word loads. */
136 #define LOCAL_ALIGNMENT(TYPE, ALIGN) \
137 DATA_ALIGNMENT (TYPE, ALIGN)
139 /*----------------------------------------*/
140 /* Layout of source language data types. */
141 /*----------------------------------------*/
143 #define INT_TYPE_SIZE 32
144 #define SHORT_TYPE_SIZE 16
145 #define LONG_TYPE_SIZE 32
146 #define LONG_LONG_TYPE_SIZE 64
148 #define FLOAT_TYPE_SIZE 32
149 #define DOUBLE_TYPE_SIZE 64
150 #define LONG_DOUBLE_TYPE_SIZE 64
152 #define DEFAULT_SIGNED_CHAR 0
154 #define SIZE_TYPE "unsigned int"
156 #define PTRDIFF_TYPE "int"
158 /*---------------------------*/
159 /* Standard register usage. */
160 /*---------------------------*/
162 #define FIRST_PSEUDO_REGISTER 32
164 #define RV_REGNUM 1
165 #define GP_REGNUM 26
166 #define FP_REGNUM 27
167 #define SP_REGNUM 28
168 #define RA_REGNUM 29
170 #define G_REG_P(X) ((X)<32)
172 #define FIXED_REGISTERS \
173 { 1, 0, 0, 0, 0, 0, 0, 0, \
174 0, 0, 0, 0, 0, 0, 0, 0, \
175 0, 0, 0, 0, 0, 0, 0, 0, \
176 0, 0, 1, 0, 1, 0, 1, 1}
178 #define CALL_USED_REGISTERS \
179 { 1, 1, 1, 1, 1, 1, 1, 1, \
180 1, 1, 1, 0, 0, 0, 0, 0, \
181 0, 0, 0, 0, 0, 0, 0, 0, \
182 0, 0, 1, 0, 1, 0, 1, 1}
184 #define HARD_REGNO_NREGS(REGNO, MODE) \
185 ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
187 #define HARD_REGNO_MODE_OK(REGNO, MODE) G_REG_P(REGNO)
189 #define MODES_TIEABLE_P(MODE1, MODE2) \
190 ( GET_MODE_CLASS (MODE1) == MODE_INT \
191 && GET_MODE_CLASS (MODE2) == MODE_INT \
192 && GET_MODE_SIZE (MODE1) <= UNITS_PER_WORD \
193 && GET_MODE_SIZE (MODE2) <= UNITS_PER_WORD)
195 #define AVOID_CCMODE_COPIES
197 /*----------------------------------*/
198 /* Register classes and constants. */
199 /*----------------------------------*/
201 enum reg_class
203 NO_REGS,
204 GENERAL_REGS,
205 ALL_REGS,
206 LIM_REG_CLASSES
209 #define N_REG_CLASSES (int) LIM_REG_CLASSES
211 #define REG_CLASS_NAMES { "NO_REGS", "GENERAL_REGS", "ALL_REGS" }
213 #define REG_CLASS_CONTENTS \
214 { {0x00000000}, \
215 {0xffffffff}, \
216 {0xffffffff} \
219 #define REGNO_REG_CLASS(REGNO) \
220 (G_REG_P(REGNO) ? GENERAL_REGS : NO_REGS)
222 #define CLASS_MAX_NREGS(CLASS, MODE) \
223 ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
225 #define INDEX_REG_CLASS NO_REGS
227 #define BASE_REG_CLASS GENERAL_REGS
229 #define REGNO_OK_FOR_BASE_P(REGNO) \
230 (G_REG_P (REGNO) || G_REG_P ((unsigned) reg_renumber[REGNO]))
232 #define REGNO_OK_FOR_INDEX_P(REGNO) 0
234 #define PREFERRED_RELOAD_CLASS(X,CLASS) (CLASS)
236 /*----------------------------------------*/
237 /* Stack Layout and Calling Conventions. */
238 /*----------------------------------------*/
240 #define STACK_GROWS_DOWNWARD 1
242 #define FRAME_GROWS_DOWNWARD 1
244 #define STACK_POINTER_OFFSET (UNITS_PER_WORD)
246 #define STARTING_FRAME_OFFSET (UNITS_PER_WORD)
248 #define FIRST_PARM_OFFSET(FNDECL) (UNITS_PER_WORD)
250 #define STACK_POINTER_REGNUM SP_REGNUM
252 #define FRAME_POINTER_REGNUM FP_REGNUM
254 #define ARG_POINTER_REGNUM FRAME_POINTER_REGNUM
256 #define RETURN_ADDR_RTX(count, frame) \
257 lm32_return_addr_rtx (count, frame)
259 /* FIXME - This is not yet supported. */
260 #define STATIC_CHAIN_REGNUM 9
262 #define ELIMINABLE_REGS \
263 {{ FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM }, \
264 { ARG_POINTER_REGNUM, STACK_POINTER_REGNUM }, \
267 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
268 (OFFSET) = lm32_compute_initial_elimination_offset (FROM, TO)
270 /*-----------------------------*/
271 /* Function argument passing. */
272 /*-----------------------------*/
274 #define ACCUMULATE_OUTGOING_ARGS 1
276 /*--------------------------------*/
277 /* Passing Arguments in Registers */
278 /*--------------------------------*/
280 /* The first argument register. */
281 #define LM32_FIRST_ARG_REG 1
283 /* The number of (integer) argument register available. */
284 #define LM32_NUM_ARG_REGS 8
286 #define FUNCTION_ARG(CUM, MODE, TYPE, NAMED) \
287 lm32_function_arg ((CUM), (MODE), (TYPE), (NAMED))
289 #define CUMULATIVE_ARGS int
291 #define INIT_CUMULATIVE_ARGS(CUM,FNTYPE,LIBNAME,INDIRECT,N_NAMED_ARGS) \
292 (CUM) = 0
294 #define FUNCTION_ARG_ADVANCE(CUM, MODE, TYPE, NAMED) \
295 (CUM) += LM32_NUM_REGS2 (MODE, TYPE)
297 #define FUNCTION_ARG_REGNO_P(r) \
298 (((r) >= LM32_FIRST_ARG_REG) && ((r) <= LM32_NUM_ARG_REGS))
300 /*--------------------*/
301 /* Function results. */
302 /*--------------------*/
304 #define FUNCTION_VALUE(VALTYPE, FUNC) \
305 gen_rtx_REG ((INTEGRAL_TYPE_P (VALTYPE) \
306 && TYPE_PRECISION (VALTYPE) < BITS_PER_WORD) \
307 ? word_mode \
308 : TYPE_MODE (VALTYPE), \
309 RV_REGNUM)
311 #define LIBCALL_VALUE(MODE) gen_rtx_REG (MODE, RV_REGNUM)
313 #define FUNCTION_VALUE_REGNO_P(N) ((N) == RV_REGNUM)
315 #define RETURN_IN_MEMORY(TYPE) lm32_return_in_memory (TYPE)
317 #define DEFAULT_PCC_STRUCT_RETURN 0
319 /* Convert from bytes to ints. */
320 #define LM32_NUM_INTS(X) (((X) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
322 /* The number of (integer) registers required to hold a quantity of
323 type MODE. */
324 #define LM32_NUM_REGS(MODE) LM32_NUM_INTS (GET_MODE_SIZE (MODE))
326 /* The number of (integer) registers required to hold a quantity of
327 TYPE MODE. */
328 #define LM32_NUM_REGS2(MODE, TYPE) \
329 LM32_NUM_INTS ((MODE) == BLKmode ? \
330 int_size_in_bytes (TYPE) : GET_MODE_SIZE (MODE))
332 #define STRUCT_VALUE 0
334 /*---------------------------*/
335 /* Function entry and exit. */
336 /*---------------------------*/
338 /*-------------*/
339 /* Profiling. */
340 /*-------------*/
342 #define FUNCTION_PROFILER(FILE, LABELNO)
344 /*---------------*/
345 /* Trampolines. */
346 /*---------------*/
348 #define TRAMPOLINE_SIZE 0
350 /*---------------------*/
351 /* Addressing Modes. */
352 /*---------------------*/
354 #define CONSTANT_ADDRESS_P(X) \
355 ((GET_CODE (X) == LABEL_REF || GET_CODE (X) == SYMBOL_REF \
356 || GET_CODE (X) == CONST_INT || GET_CODE (X) == HIGH \
357 || (GET_CODE (X) == CONST)))
359 #define MAX_REGS_PER_ADDRESS 1
361 #define STRICT_REG_OK_FOR_BASE_P(X) \
362 (REGNO_OK_FOR_BASE_P (REGNO (X)))
363 #define NONSTRICT_REG_OK_FOR_BASE_P(X) \
364 (G_REG_P (REGNO (X)) || !HARD_REGISTER_NUM_P (REGNO (X)))
366 #ifdef REG_OK_STRICT
367 #define REG_OK_FOR_BASE_P(X) STRICT_REG_OK_FOR_BASE_P(X)
368 #else
369 #define REG_OK_FOR_BASE_P(X) NONSTRICT_REG_OK_FOR_BASE_P(X)
370 #endif
372 #define LEGITIMATE_CONSTANT_P(X) lm32_legitimate_constant_p
374 /*-------------------------*/
375 /* Condition Code Status. */
376 /*-------------------------*/
378 #define REVERSIBLE_CC_MODE(MODE) 1
380 /*---------*/
381 /* Costs. */
382 /*---------*/
384 #define SLOW_BYTE_ACCESS 1
386 #define NO_FUNCTION_CSE
388 #define BRANCH_COST(speed_p, predictable_p) 4
390 #define MOVE_RATIO(speed) (speed ? 24 : 3)
392 /*------------*/
393 /* Sections. */
394 /*------------*/
396 #define TEXT_SECTION_ASM_OP "\t.section\t.text"
397 #define DATA_SECTION_ASM_OP "\t.section\t.data"
398 #define SDATA_SECTION_ASM_OP "\t.section\t.sdata,\"aw\""
399 #define BSS_SECTION_ASM_OP "\t.section\t.bss"
400 #define SBSS_SECTION_ASM_OP "\t.section\t.sbss,\"aw\""
402 /*-------*/
403 /* PIC. */
404 /*-------*/
406 #define PIC_OFFSET_TABLE_REGNUM (flag_pic ? GP_REGNUM : INVALID_REGNUM)
408 #define JUMP_TABLES_IN_TEXT_SECTION (flag_pic)
410 #define LEGITIMATE_PIC_OPERAND_P(X) \
411 (!(nonpic_symbol_mentioned_p (X)))
413 /*-------------*/
414 /* Assembler. */
415 /*-------------*/
417 #define ASM_COMMENT_START "#"
419 #define ASM_APP_ON "#APP\n"
421 #define ASM_APP_OFF "#NO_APP\n"
423 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
424 do { \
425 fputc ( '\t', FILE); \
426 assemble_name (FILE, LABEL1); \
427 fputs ( " = ", FILE); \
428 assemble_name (FILE, LABEL2); \
429 fputc ( '\n', FILE); \
430 } while (0)
432 /* Override default implementation in elfos.h to support -G. */
433 #undef ASM_OUTPUT_ALIGNED_LOCAL
434 #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \
435 do { \
436 if ((SIZE) <= g_switch_value) \
437 switch_to_section (sbss_section); \
438 else \
439 switch_to_section (bss_section); \
440 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \
441 if (!flag_inhibit_size_directive) \
442 ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, SIZE); \
443 ASM_OUTPUT_ALIGN ((FILE), exact_log2((ALIGN) / BITS_PER_UNIT)); \
444 ASM_OUTPUT_LABEL(FILE, NAME); \
445 ASM_OUTPUT_SKIP((FILE), (SIZE) ? (SIZE) : 1); \
446 } while (0)
448 /* Override default implementation in elfos.h to support -G. */
449 #undef ASM_OUTPUT_ALIGNED_COMMON
450 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \
451 do \
453 if ((SIZE) <= g_switch_value) \
455 switch_to_section (sbss_section); \
456 (*targetm.asm_out.globalize_label) (FILE, NAME); \
457 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \
458 if (!flag_inhibit_size_directive) \
459 ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, SIZE); \
460 ASM_OUTPUT_ALIGN ((FILE), exact_log2((ALIGN) / BITS_PER_UNIT)); \
461 ASM_OUTPUT_LABEL(FILE, NAME); \
462 ASM_OUTPUT_SKIP((FILE), (SIZE) ? (SIZE) : 1); \
464 else \
466 switch_to_section (bss_section); \
467 fprintf ((FILE), "%s", COMMON_ASM_OP); \
468 assemble_name ((FILE), (NAME)); \
469 fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n", \
470 (SIZE), (ALIGN) / BITS_PER_UNIT); \
473 while (0)
475 #define ASM_OUTPUT_LABEL(FILE, NAME) \
476 do { assemble_name (FILE, NAME); fputs (":\n", FILE); } while (0)
478 #define ASM_OUTPUT_LABELREF(FILE,NAME) \
479 do { \
480 const char *xname = (NAME); \
481 if (xname[0] == '@') \
482 xname += 1; \
483 if (xname[0] == '*') \
484 xname += 1; \
485 fputs (xname, FILE); \
486 } while (0)
488 #define ASM_OUTPUT_SYMBOL_REF(STREAM, SYMBOL) \
489 do { \
490 assemble_name (STREAM, XSTR (SYMBOL, 0)); \
491 } while (0)
493 #define GLOBAL_ASM_OP "\t.global\t"
495 #define REGISTER_NAMES \
497 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
498 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", \
499 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", \
500 "r24", "r25", "gp", "fp", "sp", "ra", "ea", "ba"}
502 #define PRINT_OPERAND_PUNCT_VALID_P(CHAR) \
503 (((CHAR) == '&') || ((CHAR) == '@') || ((CHAR) == '*'))
505 #define PRINT_OPERAND(FILE, X, CODE) \
506 lm32_print_operand (FILE, X, CODE)
508 #define PRINT_OPERAND_ADDRESS(FILE, ADDR) \
509 lm32_print_operand_address (FILE, ADDR)
511 #ifndef LOCAL_LABEL_PREFIX
512 #define LOCAL_LABEL_PREFIX "."
513 #endif
515 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
516 do { if ((LOG) != 0) fprintf (FILE, "\t.align %d\n", (1 << (LOG))); } while (0)
518 #define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \
519 do { \
520 char label[64]; \
521 ASM_GENERATE_INTERNAL_LABEL (label, "L", VALUE); \
522 fprintf (FILE, "\n\t.word\t"); \
523 assemble_name (FILE, label); \
524 fprintf (FILE, "\n"); \
525 } while (0)
527 #define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL) \
528 do { \
529 char label[64]; \
530 fprintf (FILE, "\t.word\t("); \
531 ASM_GENERATE_INTERNAL_LABEL (label, "L", VALUE); \
532 assemble_name (FILE, label); \
533 fprintf (FILE, "-"); \
534 ASM_GENERATE_INTERNAL_LABEL (label, "L", REL); \
535 assemble_name (FILE, label); \
536 fprintf (FILE, ")\n"); \
537 } while (0)
539 /*-------------*/
540 /* Debugging. */
541 /*-------------*/
543 #define DBX_REGISTER_NUMBER(REGNO) (REGNO)
545 #define CAN_DEBUG_WITHOUT_FP
547 #define DEFAULT_GDB_EXTENSIONS 1
549 /*--------*/
550 /* Misc. */
551 /*--------*/
553 #define CASE_VECTOR_MODE Pmode
555 #define WORD_REGISTER_OPERATIONS
557 #define LOAD_EXTEND_OP(MODE) ZERO_EXTEND
559 #define SHORT_IMMEDIATES_SIGN_EXTEND
561 #define MOVE_MAX UNITS_PER_WORD
562 #define MAX_MOVE_MAX 4
564 #define SHIFT_COUNT_TRUNCATED 1
566 #define TRULY_NOOP_TRUNCATION(OUTPREC, INPREC) 1
568 #define Pmode SImode
570 #define FUNCTION_MODE SImode
572 #ifndef NO_IMPLICIT_EXTERN_C
573 #define NO_IMPLICIT_EXTERN_C
574 #endif
576 #define STORE_FLAG_VALUE 1