2014-07-12 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / gcc / config / lm32 / lm32.h
blobe4db519478a73e8494c9169d645c6953872fb16d
1 /* Definitions of target machine for GNU compiler, Lattice Mico32 architecture.
2 Contributed by Jon Beniston <jon@beniston.com>
4 Copyright (C) 2009-2014 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 /* Target CPU builtins. */
27 #define TARGET_CPU_CPP_BUILTINS() \
28 do \
29 { \
30 builtin_define ("__lm32__"); \
31 builtin_assert ("cpu=lm32"); \
32 builtin_assert ("machine=lm32"); \
33 if (TARGET_MULTIPLY_ENABLED) \
34 builtin_define ("__multiply_enabled__"); \
35 if (TARGET_DIVIDE_ENABLED) \
36 builtin_define ("__divide_enabled__"); \
37 if (TARGET_BARREL_SHIFT_ENABLED) \
38 builtin_define ("__barrel_shift_enabled__"); \
39 if (TARGET_SIGN_EXTEND_ENABLED) \
40 builtin_define ("__sign_extend_enabled__"); \
41 if (TARGET_USER_ENABLED) \
42 builtin_define ("__user_enabled__"); \
43 } \
44 while (0)
46 #undef ASM_SPEC
47 #define ASM_SPEC "\
48 %{mmultiply-enabled} \
49 %{mdivide-enabled} \
50 %{mbarrel-shift-enabled} \
51 %{msign-extend-enabled} \
52 %{muser-enabled} \
55 /* Let link script define all link options.
56 Default to using simulator link script. */
58 #undef STARTFILE_SPEC
59 #define STARTFILE_SPEC ""
60 #undef ENDFILE_SPEC
61 #define ENDFILE_SPEC ""
62 #undef LIB_SPEC
63 #define LIB_SPEC "%{!T*:-T sim.ld}"
65 #undef CC1_SPEC
66 #define CC1_SPEC "%{G*}"
68 /*---------------------------------*/
69 /* Target machine storage layout. */
70 /*---------------------------------*/
72 #define BITS_BIG_ENDIAN 0
73 #define BYTES_BIG_ENDIAN 1
74 #define WORDS_BIG_ENDIAN 1
76 #define BITS_PER_WORD 32
77 #define UNITS_PER_WORD 4
79 #define POINTER_SIZE 32
81 #define PROMOTE_MODE(MODE,UNSIGNEDP,TYPE) \
82 do { \
83 if (GET_MODE_CLASS (MODE) == MODE_INT \
84 && GET_MODE_SIZE (MODE) < UNITS_PER_WORD) \
85 (MODE) = word_mode; \
86 } while (0)
88 #define PARM_BOUNDARY 32
90 #define STACK_BOUNDARY 32
92 #define BIGGEST_ALIGNMENT 64
94 #define FUNCTION_BOUNDARY 32
96 #define EMPTY_FIELD_BOUNDARY 32
98 #define STRICT_ALIGNMENT 1
100 #define TARGET_FLOAT_FORMAT IEEE_FLOAT_FORMAT
102 /* Make strings word-aligned so strcpy from constants will be faster. */
103 #define CONSTANT_ALIGNMENT(EXP, ALIGN) \
104 (TREE_CODE (EXP) == STRING_CST \
105 && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN))
107 /* Make arrays and structures word-aligned to allow faster copying etc. */
108 #define DATA_ALIGNMENT(TYPE, ALIGN) \
109 ((((ALIGN) < BITS_PER_WORD) \
110 && (TREE_CODE (TYPE) == ARRAY_TYPE \
111 || TREE_CODE (TYPE) == UNION_TYPE \
112 || TREE_CODE (TYPE) == RECORD_TYPE)) ? BITS_PER_WORD : (ALIGN))
114 /* We need this for the same reason as DATA_ALIGNMENT, namely to cause
115 character arrays to be word-aligned so that `strcpy' calls that copy
116 constants to character arrays can be done inline, and 'strcmp' can be
117 optimised to use word loads. */
118 #define LOCAL_ALIGNMENT(TYPE, ALIGN) \
119 DATA_ALIGNMENT (TYPE, ALIGN)
121 /*----------------------------------------*/
122 /* Layout of source language data types. */
123 /*----------------------------------------*/
125 #define INT_TYPE_SIZE 32
126 #define SHORT_TYPE_SIZE 16
127 #define LONG_TYPE_SIZE 32
128 #define LONG_LONG_TYPE_SIZE 64
130 #define FLOAT_TYPE_SIZE 32
131 #define DOUBLE_TYPE_SIZE 64
132 #define LONG_DOUBLE_TYPE_SIZE 64
134 #define DEFAULT_SIGNED_CHAR 0
136 #define SIZE_TYPE "unsigned int"
138 #define PTRDIFF_TYPE "int"
140 /*---------------------------*/
141 /* Standard register usage. */
142 /*---------------------------*/
144 #define FIRST_PSEUDO_REGISTER 32
146 #define RV_REGNUM 1
147 #define GP_REGNUM 26
148 #define FP_REGNUM 27
149 #define SP_REGNUM 28
150 #define RA_REGNUM 29
152 #define G_REG_P(X) ((X)<32)
154 #define FIXED_REGISTERS \
155 { 1, 0, 0, 0, 0, 0, 0, 0, \
156 0, 0, 0, 0, 0, 0, 0, 0, \
157 0, 0, 0, 0, 0, 0, 0, 0, \
158 0, 0, 1, 0, 1, 0, 1, 1}
160 #define CALL_USED_REGISTERS \
161 { 1, 1, 1, 1, 1, 1, 1, 1, \
162 1, 1, 1, 0, 0, 0, 0, 0, \
163 0, 0, 0, 0, 0, 0, 0, 0, \
164 0, 0, 1, 0, 1, 0, 1, 1}
166 #define HARD_REGNO_NREGS(REGNO, MODE) \
167 ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
169 #define HARD_REGNO_MODE_OK(REGNO, MODE) G_REG_P(REGNO)
171 #define MODES_TIEABLE_P(MODE1, MODE2) \
172 ( GET_MODE_CLASS (MODE1) == MODE_INT \
173 && GET_MODE_CLASS (MODE2) == MODE_INT \
174 && GET_MODE_SIZE (MODE1) <= UNITS_PER_WORD \
175 && GET_MODE_SIZE (MODE2) <= UNITS_PER_WORD)
177 #define AVOID_CCMODE_COPIES
179 /*----------------------------------*/
180 /* Register classes and constants. */
181 /*----------------------------------*/
183 enum reg_class
185 NO_REGS,
186 GENERAL_REGS,
187 ALL_REGS,
188 LIM_REG_CLASSES
191 #define N_REG_CLASSES (int) LIM_REG_CLASSES
193 #define REG_CLASS_NAMES { "NO_REGS", "GENERAL_REGS", "ALL_REGS" }
195 #define REG_CLASS_CONTENTS \
196 { {0x00000000}, \
197 {0xffffffff}, \
198 {0xffffffff} \
201 #define REGNO_REG_CLASS(REGNO) \
202 (G_REG_P(REGNO) ? GENERAL_REGS : NO_REGS)
204 #define INDEX_REG_CLASS NO_REGS
206 #define BASE_REG_CLASS GENERAL_REGS
208 #define REGNO_OK_FOR_BASE_P(REGNO) \
209 (G_REG_P (REGNO) || G_REG_P ((unsigned) reg_renumber[REGNO]))
211 #define REGNO_OK_FOR_INDEX_P(REGNO) 0
213 /*----------------------------------------*/
214 /* Stack Layout and Calling Conventions. */
215 /*----------------------------------------*/
217 #define STACK_GROWS_DOWNWARD 1
219 #define FRAME_GROWS_DOWNWARD 1
221 #define STACK_POINTER_OFFSET (UNITS_PER_WORD)
223 #define STARTING_FRAME_OFFSET (UNITS_PER_WORD)
225 #define FIRST_PARM_OFFSET(FNDECL) (UNITS_PER_WORD)
227 #define STACK_POINTER_REGNUM SP_REGNUM
229 #define FRAME_POINTER_REGNUM FP_REGNUM
231 #define ARG_POINTER_REGNUM FRAME_POINTER_REGNUM
233 #define INCOMING_RETURN_ADDR_RTX gen_rtx_REG (SImode, RA_REGNUM)
235 #define RETURN_ADDR_RTX(count, frame) \
236 lm32_return_addr_rtx (count, frame)
238 /* FIXME - This is not yet supported. */
239 #define STATIC_CHAIN_REGNUM 9
241 #define ELIMINABLE_REGS \
242 {{ FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM }, \
243 { ARG_POINTER_REGNUM, STACK_POINTER_REGNUM }, \
246 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
247 (OFFSET) = lm32_compute_initial_elimination_offset (FROM, TO)
249 /*-----------------------------*/
250 /* Function argument passing. */
251 /*-----------------------------*/
253 #define ACCUMULATE_OUTGOING_ARGS 1
255 /*--------------------------------*/
256 /* Passing Arguments in Registers */
257 /*--------------------------------*/
259 /* The first argument register. */
260 #define LM32_FIRST_ARG_REG 1
262 /* The number of (integer) argument register available. */
263 #define LM32_NUM_ARG_REGS 8
265 #define CUMULATIVE_ARGS int
267 #define INIT_CUMULATIVE_ARGS(CUM,FNTYPE,LIBNAME,INDIRECT,N_NAMED_ARGS) \
268 (CUM) = 0
270 #define FUNCTION_ARG_REGNO_P(r) \
271 (((r) >= LM32_FIRST_ARG_REG) && ((r) <= LM32_NUM_ARG_REGS))
273 /*--------------------*/
274 /* Function results. */
275 /*--------------------*/
277 #define FUNCTION_VALUE(VALTYPE, FUNC) \
278 gen_rtx_REG ((INTEGRAL_TYPE_P (VALTYPE) \
279 && TYPE_PRECISION (VALTYPE) < BITS_PER_WORD) \
280 ? word_mode \
281 : TYPE_MODE (VALTYPE), \
282 RV_REGNUM)
284 #define LIBCALL_VALUE(MODE) gen_rtx_REG (MODE, RV_REGNUM)
286 #define FUNCTION_VALUE_REGNO_P(N) ((N) == RV_REGNUM)
288 #define RETURN_IN_MEMORY(TYPE) lm32_return_in_memory (TYPE)
290 #define DEFAULT_PCC_STRUCT_RETURN 0
292 /* Convert from bytes to ints. */
293 #define LM32_NUM_INTS(X) (((X) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
295 /* The number of (integer) registers required to hold a quantity of
296 type MODE. */
297 #define LM32_NUM_REGS(MODE) LM32_NUM_INTS (GET_MODE_SIZE (MODE))
299 /* The number of (integer) registers required to hold a quantity of
300 TYPE MODE. */
301 #define LM32_NUM_REGS2(MODE, TYPE) \
302 LM32_NUM_INTS ((MODE) == BLKmode ? \
303 int_size_in_bytes (TYPE) : GET_MODE_SIZE (MODE))
305 #define STRUCT_VALUE 0
307 /*---------------------------*/
308 /* Function entry and exit. */
309 /*---------------------------*/
311 /*-------------*/
312 /* Profiling. */
313 /*-------------*/
315 #define FUNCTION_PROFILER(FILE, LABELNO)
317 /*---------------*/
318 /* Trampolines. */
319 /*---------------*/
321 #define TRAMPOLINE_SIZE 0
323 /*---------------------*/
324 /* Addressing Modes. */
325 /*---------------------*/
327 #define CONSTANT_ADDRESS_P(X) \
328 ((GET_CODE (X) == LABEL_REF || GET_CODE (X) == SYMBOL_REF \
329 || GET_CODE (X) == CONST_INT || GET_CODE (X) == HIGH \
330 || (GET_CODE (X) == CONST)))
332 #define MAX_REGS_PER_ADDRESS 1
334 #define STRICT_REG_OK_FOR_BASE_P(X) \
335 (REGNO_OK_FOR_BASE_P (REGNO (X)))
336 #define NONSTRICT_REG_OK_FOR_BASE_P(X) \
337 (G_REG_P (REGNO (X)) || !HARD_REGISTER_NUM_P (REGNO (X)))
339 #ifdef REG_OK_STRICT
340 #define REG_OK_FOR_BASE_P(X) STRICT_REG_OK_FOR_BASE_P(X)
341 #else
342 #define REG_OK_FOR_BASE_P(X) NONSTRICT_REG_OK_FOR_BASE_P(X)
343 #endif
345 /*-------------------------*/
346 /* Condition Code Status. */
347 /*-------------------------*/
349 #define REVERSIBLE_CC_MODE(MODE) 1
351 /*---------*/
352 /* Costs. */
353 /*---------*/
355 #define SLOW_BYTE_ACCESS 1
357 #define NO_FUNCTION_CSE
359 #define BRANCH_COST(speed_p, predictable_p) 4
361 #define MOVE_RATIO(speed) (speed ? 24 : 3)
363 /*------------*/
364 /* Sections. */
365 /*------------*/
367 #define TEXT_SECTION_ASM_OP "\t.section\t.text"
368 #define DATA_SECTION_ASM_OP "\t.section\t.data"
369 #define SDATA_SECTION_ASM_OP "\t.section\t.sdata,\"aw\""
370 #define BSS_SECTION_ASM_OP "\t.section\t.bss"
371 #define SBSS_SECTION_ASM_OP "\t.section\t.sbss,\"aw\""
373 /*-------*/
374 /* PIC. */
375 /*-------*/
377 #define PIC_OFFSET_TABLE_REGNUM (flag_pic ? GP_REGNUM : INVALID_REGNUM)
379 #define JUMP_TABLES_IN_TEXT_SECTION (flag_pic)
381 #define LEGITIMATE_PIC_OPERAND_P(X) \
382 (!(nonpic_symbol_mentioned_p (X)))
384 /*-------------*/
385 /* Assembler. */
386 /*-------------*/
388 #define ASM_COMMENT_START "#"
390 #define ASM_APP_ON "#APP\n"
392 #define ASM_APP_OFF "#NO_APP\n"
394 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
395 do { \
396 fputc ( '\t', FILE); \
397 assemble_name (FILE, LABEL1); \
398 fputs ( " = ", FILE); \
399 assemble_name (FILE, LABEL2); \
400 fputc ( '\n', FILE); \
401 } while (0)
403 /* Override default implementation in elfos.h to support -G. */
404 #undef ASM_OUTPUT_ALIGNED_LOCAL
405 #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \
406 do { \
407 if ((SIZE) <= (unsigned HOST_WIDE_INT) g_switch_value) \
408 switch_to_section (sbss_section); \
409 else \
410 switch_to_section (bss_section); \
411 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \
412 if (!flag_inhibit_size_directive) \
413 ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, SIZE); \
414 ASM_OUTPUT_ALIGN ((FILE), exact_log2((ALIGN) / BITS_PER_UNIT)); \
415 ASM_OUTPUT_LABEL(FILE, NAME); \
416 ASM_OUTPUT_SKIP((FILE), (SIZE) ? (SIZE) : 1); \
417 } while (0)
419 /* Override default implementation in elfos.h to support -G. */
420 #undef ASM_OUTPUT_ALIGNED_COMMON
421 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \
422 do \
424 if ((SIZE) <= (unsigned HOST_WIDE_INT) g_switch_value) \
426 switch_to_section (sbss_section); \
427 (*targetm.asm_out.globalize_label) (FILE, NAME); \
428 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \
429 if (!flag_inhibit_size_directive) \
430 ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, SIZE); \
431 ASM_OUTPUT_ALIGN ((FILE), exact_log2((ALIGN) / BITS_PER_UNIT)); \
432 ASM_OUTPUT_LABEL(FILE, NAME); \
433 ASM_OUTPUT_SKIP((FILE), (SIZE) ? (SIZE) : 1); \
435 else \
437 switch_to_section (bss_section); \
438 fprintf ((FILE), "%s", COMMON_ASM_OP); \
439 assemble_name ((FILE), (NAME)); \
440 fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n", \
441 (SIZE), (ALIGN) / BITS_PER_UNIT); \
444 while (0)
446 #define ASM_OUTPUT_LABEL(FILE, NAME) \
447 do { assemble_name (FILE, NAME); fputs (":\n", FILE); } while (0)
449 #define ASM_OUTPUT_LABELREF(FILE,NAME) \
450 do { \
451 const char *xname = (NAME); \
452 if (xname[0] == '@') \
453 xname += 1; \
454 if (xname[0] == '*') \
455 xname += 1; \
456 fputs (xname, FILE); \
457 } while (0)
459 #define ASM_OUTPUT_SYMBOL_REF(STREAM, SYMBOL) \
460 do { \
461 assemble_name (STREAM, XSTR (SYMBOL, 0)); \
462 } while (0)
464 #define GLOBAL_ASM_OP "\t.global\t"
466 #define REGISTER_NAMES \
468 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
469 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", \
470 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", \
471 "r24", "r25", "gp", "fp", "sp", "ra", "ea", "ba"}
473 #define PRINT_OPERAND_PUNCT_VALID_P(CHAR) \
474 (((CHAR) == '&') || ((CHAR) == '@') || ((CHAR) == '*'))
476 #define PRINT_OPERAND(FILE, X, CODE) \
477 lm32_print_operand (FILE, X, CODE)
479 #define PRINT_OPERAND_ADDRESS(FILE, ADDR) \
480 lm32_print_operand_address (FILE, ADDR)
482 #ifndef LOCAL_LABEL_PREFIX
483 #define LOCAL_LABEL_PREFIX "."
484 #endif
486 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
487 do { if ((LOG) != 0) fprintf (FILE, "\t.align %d\n", (1 << (LOG))); } while (0)
489 #define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \
490 do { \
491 char label[64]; \
492 ASM_GENERATE_INTERNAL_LABEL (label, "L", VALUE); \
493 fprintf (FILE, "\n\t.word\t"); \
494 assemble_name (FILE, label); \
495 fprintf (FILE, "\n"); \
496 } while (0)
498 #define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL) \
499 do { \
500 char label[64]; \
501 fprintf (FILE, "\t.word\t("); \
502 ASM_GENERATE_INTERNAL_LABEL (label, "L", VALUE); \
503 assemble_name (FILE, label); \
504 fprintf (FILE, "-"); \
505 ASM_GENERATE_INTERNAL_LABEL (label, "L", REL); \
506 assemble_name (FILE, label); \
507 fprintf (FILE, ")\n"); \
508 } while (0)
510 /*-------------*/
511 /* Debugging. */
512 /*-------------*/
514 #define DBX_REGISTER_NUMBER(REGNO) (REGNO)
516 #define DEFAULT_GDB_EXTENSIONS 1
518 /*--------*/
519 /* Misc. */
520 /*--------*/
522 #define CASE_VECTOR_MODE Pmode
524 #define WORD_REGISTER_OPERATIONS
526 #define LOAD_EXTEND_OP(MODE) ZERO_EXTEND
528 #define SHORT_IMMEDIATES_SIGN_EXTEND
530 #define MOVE_MAX UNITS_PER_WORD
531 #define MAX_MOVE_MAX 4
533 #define SHIFT_COUNT_TRUNCATED 1
535 #define TRULY_NOOP_TRUNCATION(OUTPREC, INPREC) 1
537 #define Pmode SImode
539 #define FUNCTION_MODE SImode
541 #ifndef NO_IMPLICIT_EXTERN_C
542 #define NO_IMPLICIT_EXTERN_C
543 #endif
545 #define STORE_FLAG_VALUE 1