📄 sh.c
字号:
{ if (REGNO (src) == MACH_REG) return "sts mach,%S0\n\tsts macl,%R0"; /* When mov.d r1,r2 do r2->r3 then r1->r2; when mov.d r1,r0 do r1->r0 then r2->r1. */ if (REGNO (src) + 1 == REGNO (dst)) return "mov %T1,%T0\n\tmov %1,%0"; else return "mov %1,%0\n\tmov %T1,%T0"; } else if (GET_CODE (src) == CONST_INT) { if (INTVAL (src) < 0) output_asm_insn ("mov #-1,%S0", operands); else output_asm_insn ("mov #0,%S0", operands); return "mov %1,%R0"; } else if (GET_CODE (src) == MEM) { int ptrreg = -1; int dreg = REGNO (dst); rtx inside = XEXP (src, 0); if (GET_CODE (inside) == REG) ptrreg = REGNO (inside); else if (GET_CODE (inside) == SUBREG) ptrreg = REGNO (SUBREG_REG (inside)) + SUBREG_WORD (inside); else if (GET_CODE (inside) == PLUS) { ptrreg = REGNO (XEXP (inside, 0)); /* ??? A r0+REG address shouldn't be possible here, because it isn't an offsettable address. Unfortunately, offsettable addresses use QImode to check the offset, and a QImode offsettable address requires r0 for the other operand, which is not currently supported, so we can't use the 'o' constraint. Thus we must check for and handle r0+REG addresses here. We punt for now, since this is likely very rare. */ if (GET_CODE (XEXP (inside, 1)) == REG) abort (); } else if (GET_CODE (inside) == LABEL_REF) return "mov.l %1,%0\n\tmov.l %1+4,%T0"; else if (GET_CODE (inside) == POST_INC) return "mov.l %1,%0\n\tmov.l %1,%T0"; else abort (); /* Work out the safe way to copy. Copy into the second half first. */ if (dreg == ptrreg) return "mov.l %T1,%T0\n\tmov.l %1,%0"; } return "mov.l %1,%0\n\tmov.l %T1,%T0";}/* Print an instruction which would have gone into a delay slot after another instruction, but couldn't because the other instruction expanded into a sequence where putting the slot insn at the end wouldn't work. */static voidprint_slot (insn) rtx insn;{ final_scan_insn (XVECEXP (insn, 0, 1), asm_out_file, optimize, 0, 1); INSN_DELETED_P (XVECEXP (insn, 0, 1)) = 1;}char *output_far_jump (insn, op) rtx insn; rtx op;{ struct { rtx lab, reg, op; } this; char *jump; int far; this.lab = gen_label_rtx (); if (braf_branch_p (insn, 0)) { far = 0; jump = "mov.w %O0,%1;braf %1"; } else { far = 1; jump = "mov.l %O0,%1;jmp @%1"; } /* If we have a scratch register available, use it. */ if (GET_CODE (PREV_INSN (insn)) == INSN && INSN_CODE (PREV_INSN (insn)) == CODE_FOR_indirect_jump_scratch) { this.reg = SET_DEST (PATTERN (PREV_INSN (insn))); output_asm_insn (jump, &this.lab); if (dbr_sequence_length ()) print_slot (final_sequence); else output_asm_insn ("nop", 0); } else { /* Output the delay slot insn first if any. */ if (dbr_sequence_length ()) print_slot (final_sequence); this.reg = gen_rtx (REG, SImode, 13); output_asm_insn ("mov.l r13,@-r15", 0); output_asm_insn (jump, &this.lab); output_asm_insn ("mov.l @r15+,r13", 0); } if (far) output_asm_insn (".align 2", 0); ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (this.lab)); this.op = op; output_asm_insn (far ? ".long %O2" : ".word %O2-%O0", &this.lab); return "";}/* Local label counter, used for constants in the pool and inside pattern branches. */static int lf = 100;/* Output code for ordinary branches. */char *output_branch (logic, insn, operands) int logic; rtx insn; rtx *operands;{ int offset = (insn_addresses[INSN_UID (XEXP (XEXP (SET_SRC (PATTERN (insn)), 1), 0))] - insn_addresses[INSN_UID (insn)]); if (offset == 260 && final_sequence && ! INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))) { /* The filling of the delay slot has caused a forward branch to exceed its range. Just emit the insn from the delay slot in front of the branch. */ /* The call to print_slot will clobber the operands. */ rtx op0 = operands[0]; print_slot (final_sequence); operands[0] = op0; } else if (offset < -252 || offset > 258) { /* This can happen when other condbranches hoist delay slot insn from their destination, thus leading to code size increase. But the branch will still be in the range -4092..+4098 bytes. */ int label = lf++; /* The call to print_slot will clobber the operands. */ rtx op0 = operands[0]; /* If the instruction in the delay slot is annulled (true), then there is no delay slot where we can put it now. The only safe place for it is after the label. final will do that by default. */ if (final_sequence && ! INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))) { asm_fprintf (asm_out_file, "\tb%s%ss\t%LLF%d\n", logic ? "f" : "t", ASSEMBLER_DIALECT ? "/" : ".", label); print_slot (final_sequence); } else asm_fprintf (asm_out_file, "\tb%s\t%LLF%d\n", logic ? "f" : "t", label); output_asm_insn ("bra\t%l0", &op0); fprintf (asm_out_file, "\tnop\n"); ASM_OUTPUT_INTERNAL_LABEL(asm_out_file, "LF", label); return ""; } return logic ? "bt%.\t%l0" : "bf%.\t%l0";}int branch_offset ();char *output_branchy_insn (code, template, insn, operands) char *template; enum rtx_code code; rtx insn; rtx *operands;{ rtx next_insn = NEXT_INSN (insn); int label_nr; if (next_insn && GET_CODE (next_insn) == JUMP_INSN && condjump_p (next_insn)) { rtx src = SET_SRC (PATTERN (next_insn)); if (GET_CODE (src) == IF_THEN_ELSE && GET_CODE (XEXP (src, 0)) != code) { /* Following branch not taken */ operands[9] = gen_label_rtx (); emit_label_after (operands[9], next_insn); return template; } else { int offset = branch_offset (next_insn) + 4; if (offset >= -252 && offset <= 256) { if (GET_CODE (src) == IF_THEN_ELSE) /* branch_true */ src = XEXP (src, 1); operands[9] = src; return template; } } } operands[9] = gen_label_rtx (); emit_label_after (operands[9], insn); return template;}char *output_ieee_ccmpeq (insn, operands) rtx insn, operands;{ output_branchy_insn (NE, "bt\t%l9\\;fcmp/eq\t%1,%0", insn, operands);}/* Output to FILE the start of the assembler file. */voidoutput_file_start (file) FILE *file;{ register int pos; output_file_directive (file, main_input_filename); /* Switch to the data section so that the coffsem symbol and the gcc2_compiled. symbol aren't in the text section. */ data_section (); if (TARGET_LITTLE_ENDIAN) fprintf (file, "\t.little\n");}/* Actual number of instructions used to make a shift by N. */static char ashiftrt_insns[] = { 0,1,2,3,4,5,8,8,8,8,8,8,8,8,8,8,2,3,4,5,8,8,8,8,8,8,8,8,8,8,8,2};/* Left shift and logical right shift are the same. */static char shift_insns[] = { 0,1,1,2,2,3,3,4,1,2,2,3,3,4,3,3,1,2,2,3,3,4,3,3,2,3,3,4,4,4,3,3};/* Individual shift amounts needed to get the above length sequences. One bit right shifts clobber the T bit, so when possible, put one bit shifts in the middle of the sequence, so the ends are eligible for branch delay slots. */static short shift_amounts[32][5] = { {0}, {1}, {2}, {2, 1}, {2, 2}, {2, 1, 2}, {2, 2, 2}, {2, 2, 1, 2}, {8}, {8, 1}, {8, 2}, {8, 1, 2}, {8, 2, 2}, {8, 2, 1, 2}, {8, -2, 8}, {8, -1, 8}, {16}, {16, 1}, {16, 2}, {16, 1, 2}, {16, 2, 2}, {16, 2, 1, 2}, {16, -2, 8}, {16, -1, 8}, {16, 8}, {16, 1, 8}, {16, 8, 2}, {16, 8, 1, 2}, {16, 8, 2, 2}, {16, -1, -2, 16}, {16, -2, 16}, {16, -1, 16}};/* Likewise, but for shift amounts < 16, up to three highmost bits might be clobbered. This is typically used when combined with some kind of sign or zero extension. */ static char ext_shift_insns[] = { 0,1,1,2,2,3,2,2,1,2,2,3,3,3,2,2,1,2,2,3,3,4,3,3,2,3,3,4,4,4,3,3};static short ext_shift_amounts[32][4] = { {0}, {1}, {2}, {2, 1}, {2, 2}, {2, 1, 2}, {8, -2}, {8, -1}, {8}, {8, 1}, {8, 2}, {8, 1, 2}, {8, 2, 2}, {16, -2, -1}, {16, -2}, {16, -1}, {16}, {16, 1}, {16, 2}, {16, 1, 2}, {16, 2, 2}, {16, 2, 1, 2}, {16, -2, 8}, {16, -1, 8}, {16, 8}, {16, 1, 8}, {16, 8, 2}, {16, 8, 1, 2}, {16, 8, 2, 2}, {16, -1, -2, 16}, {16, -2, 16}, {16, -1, 16}};/* Assuming we have a value that has been sign-extended by at least one bit, can we use the ext_shift_amounts with the last shift turned to an arithmetic shift to shift it by N without data loss, and quicker than by other means? */#define EXT_SHIFT_SIGNED(n) (((n) | 8) == 15)/* This is used in length attributes in sh.md to help compute the length of arbitrary constant shift instructions. */intshift_insns_rtx (insn) rtx insn;{ rtx set_src = SET_SRC (XVECEXP (PATTERN (insn), 0, 0)); int shift_count = INTVAL (XEXP (set_src, 1)); enum rtx_code shift_code = GET_CODE (set_src); switch (shift_code) { case ASHIFTRT: return ashiftrt_insns[shift_count]; case LSHIFTRT: case ASHIFT: return shift_insns[shift_count]; default: abort(); }}/* Return the cost of a shift. */intshiftcosts (x) rtx x;{ int value = INTVAL (XEXP (x, 1)); /* If shift by a non constant, then this will be expensive. */ if (GET_CODE (XEXP (x, 1)) != CONST_INT) return SH_DYNAMIC_SHIFT_COST; /* Otherwise, return the true cost in instructions. */ if (GET_CODE (x) == ASHIFTRT) { int cost = ashiftrt_insns[value]; /* If SH3, then we put the constant in a reg and use shad. */ if (cost > 1 + SH_DYNAMIC_SHIFT_COST) cost = 1 + SH_DYNAMIC_SHIFT_COST; return cost; } else return shift_insns[value];}/* Return the cost of an AND operation. */intandcosts (x) rtx x;{ int i; /* Anding with a register is a single cycle and instruction. */ if (GET_CODE (XEXP (x, 1)) != CONST_INT) return 1; i = INTVAL (XEXP (x, 1)); /* These constants are single cycle extu.[bw] instructions. */ if (i == 0xff || i == 0xffff) return 1; /* Constants that can be used in an and immediate instruction is a single cycle, but this requires r0, so make it a little more expensive. */ if (CONST_OK_FOR_L (i)) return 2; /* Constants that can be loaded with a mov immediate and an and. This case is probably unnecessary. */ if (CONST_OK_FOR_I (i)) return 2; /* Any other constants requires a 2 cycle pc-relative load plus an and. This case is probably unnecessary. */ return 3;}/* Return the cost of a multiply. */intmultcosts (x) rtx x;{ if (TARGET_SH2) { /* We have a mul insn, so we can never take more than the mul and the read of the mac reg, but count more because of the latency and extra reg usage. */ if (TARGET_SMALLCODE) return 2; return 3; } /* If we're aiming at small code, then just count the number of insns in a multiply call sequence. */ if (TARGET_SMALLCODE) return 5; /* Otherwise count all the insns in the routine we'd be calling too. */ return 20;}/* Code to expand a shift. */voidgen_ashift (type, n, reg) int type; int n; rtx reg;{ /* Negative values here come from the shift_amounts array. */ if (n < 0) { if (type == ASHIFT) type = LSHIFTRT; else type = ASHIFT; n = -n; } switch (type) { case ASHIFTRT: emit_insn (gen_ashrsi3_k (reg, reg, GEN_INT (n))); break; case LSHIFTRT: if (n == 1) emit_insn (gen_lshrsi3_m (reg, reg, GEN_INT (n))); else emit_insn (gen_lshrsi3_k (reg, reg, GEN_INT (n))); break; case ASHIFT: emit_insn (gen_ashlsi3_k (reg, reg, GEN_INT (n))); break; }}/* Same for HImode */voidgen_ashift_hi (type, n, reg) int type; int n; rtx reg;{ /* Negative values here come from the shift_amounts array. */ if (n < 0) { if (type == ASHIFT) type = LSHIFTRT; else type = ASHIFT; n = -n; } switch (type) { case ASHIFTRT: emit_insn (gen_ashrhi3_k (reg, reg, GEN_INT (n))); break; case LSHIFTRT: if (n == 1) emit_insn (gen_lshrhi3_m (reg, reg, GEN_INT (n))); else emit_insn (gen_lshrhi3_k (reg, reg, GEN_INT (n))); break; case ASHIFT: emit_insn (gen_ashlhi3_k (reg, reg, GEN_INT (n))); break; }}/* Output RTL to split a constant shift into its component SH constant shift instructions. */ intgen_shifty_op (code, operands) int code; rtx *operands;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -