📄 alpha.c
字号:
rtx x; int in_struct_p, volatile_p, unchanging_p;{ int i; switch (GET_CODE (x)) { case SEQUENCE: case PARALLEL: for (i = XVECLEN (x, 0) - 1; i >= 0; i--) alpha_set_memflags_1 (XVECEXP (x, 0, i), in_struct_p, volatile_p, unchanging_p); break; case INSN: alpha_set_memflags_1 (PATTERN (x), in_struct_p, volatile_p, unchanging_p); break; case SET: alpha_set_memflags_1 (SET_DEST (x), in_struct_p, volatile_p, unchanging_p); alpha_set_memflags_1 (SET_SRC (x), in_struct_p, volatile_p, unchanging_p); break; case MEM: MEM_IN_STRUCT_P (x) = in_struct_p; MEM_VOLATILE_P (x) = volatile_p; RTX_UNCHANGING_P (x) = unchanging_p; break; }}/* Given INSN, which is either an INSN or a SEQUENCE generated to perform a memory operation, look for any MEMs in either a SET_DEST or a SET_SRC and copy the in-struct, unchanging, and volatile flags from REF into each of the MEMs found. If REF is not a MEM, don't do anything. */voidalpha_set_memflags (insn, ref) rtx insn; rtx ref;{ /* Note that it is always safe to get these flags, though they won't be what we think if REF is not a MEM. */ int in_struct_p = MEM_IN_STRUCT_P (ref); int volatile_p = MEM_VOLATILE_P (ref); int unchanging_p = RTX_UNCHANGING_P (ref); if (GET_CODE (ref) != MEM || (! in_struct_p && ! volatile_p && ! unchanging_p)) return; alpha_set_memflags_1 (insn, in_struct_p, volatile_p, unchanging_p);}/* Try to output insns to set TARGET equal to the constant C if it can be done in less than N insns. Returns 1 if it can be done and the insns have been emitted. If it would take more than N insns, zero is returned and no insns and emitted. */intalpha_emit_set_const (target, c, n) rtx target; HOST_WIDE_INT c; int n;{ HOST_WIDE_INT new = c; int i, bits;#if HOST_BITS_PER_WIDE_INT == 64 /* We are only called for SImode and DImode. If this is SImode, ensure that we are sign extended to a full word. This does not make any sense when cross-compiling on a narrow machine. */ if (GET_MODE (target) == SImode) c = (c & 0xffffffff) - 2 * (c & 0x80000000);#endif /* If this is a sign-extended 32-bit constant, we can do this in at most three insns, so do it if we have enough insns left. We always have a sign-extended 32-bit constant when compiling on a narrow machine. */ if (HOST_BITS_PER_WIDE_INT != 64 || c >> 31 == -1 || c >> 31 == 0) { HOST_WIDE_INT low = (c & 0xffff) - 2 * (c & 0x8000); HOST_WIDE_INT tmp1 = c - low; HOST_WIDE_INT high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000); HOST_WIDE_INT tmp2 = c - (high << 16) - low; HOST_WIDE_INT extra = 0; if (tmp2) { extra = 0x4000; tmp1 -= 0x40000000; high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000); } if (c == low || (low == 0 && extra == 0)) { emit_move_insn (target, GEN_INT (c)); return 1; } else if (n >= 2 + (extra != 0)) { emit_move_insn (target, GEN_INT (low)); if (extra != 0) emit_insn (gen_add2_insn (target, GEN_INT (extra << 16))); emit_insn (gen_add2_insn (target, GEN_INT (high << 16))); return 1; } } /* If we couldn't do it that way, try some other methods (that depend on being able to compute in the target's word size). But if we have no instructions left, don't bother. Also, don't even try if this is SImode (in which case we should have already done something, but do a sanity check here). */ if (n == 1 || HOST_BITS_PER_WIDE_INT < 64 || GET_MODE (target) != DImode) return 0; /* First, see if can load a value into the target that is the same as the constant except that all bytes that are 0 are changed to be 0xff. If we can, then we can do a ZAPNOT to obtain the desired constant. */ for (i = 0; i < 64; i += 8) if ((new & ((HOST_WIDE_INT) 0xff << i)) == 0) new |= (HOST_WIDE_INT) 0xff << i; if (alpha_emit_set_const (target, new, n - 1)) { emit_insn (gen_anddi3 (target, target, GEN_INT (c | ~ new))); return 1; } /* Find, see if we can load a related constant and then shift and possibly negate it to get the constant we want. Try this once each increasing numbers of insns. */ for (i = 1; i < n; i++) { /* First try complementing. */ if (alpha_emit_set_const (target, ~ c, i)) { emit_insn (gen_one_cmpldi2 (target, target)); return 1; } /* First try to form a constant and do a left shift. We can do this if some low-order bits are zero; the exact_log2 call below tells us that information. The bits we are shifting out could be any value, but here we'll just try the 0- and sign-extended forms of the constant. To try to increase the chance of having the same constant in more than one insn, start at the highest number of bits to shift, but try all possibilities in case a ZAPNOT will be useful. */ if ((bits = exact_log2 (c & - c)) > 0) for (; bits > 0; bits--) if (alpha_emit_set_const (target, c >> bits, i) || alpha_emit_set_const (target, ((unsigned HOST_WIDE_INT) c) >> bits, i)) { emit_insn (gen_ashldi3 (target, target, GEN_INT (bits))); return 1; } /* Now try high-order zero bits. Here we try the shifted-in bits as all zero and all ones. */ if ((bits = HOST_BITS_PER_WIDE_INT - floor_log2 (c) - 1) > 0) for (; bits > 0; bits--) if (alpha_emit_set_const (target, c << bits, i) || alpha_emit_set_const (target, ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)), i)) { emit_insn (gen_lshrdi3 (target, target, GEN_INT (bits))); return 1; } /* Now try high-order 1 bits. We get that with a sign-extension. But one bit isn't enough here. */ if ((bits = HOST_BITS_PER_WIDE_INT - floor_log2 (~ c) - 2) > 0) for (; bits > 0; bits--) if (alpha_emit_set_const (target, c << bits, i) || alpha_emit_set_const (target, ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)), i)) { emit_insn (gen_ashrdi3 (target, target, GEN_INT (bits))); return 1; } } return 0;}/* Adjust the cost of a scheduling dependency. Return the new cost of a dependency LINK or INSN on DEP_INSN. COST is the current cost. */intalpha_adjust_cost (insn, link, dep_insn, cost) rtx insn; rtx link; rtx dep_insn; int cost;{ rtx set; /* If the dependence is an anti-dependence, there is no cost. For an output dependence, there is sometimes a cost, but it doesn't seem worth handling those few cases. */ if (REG_NOTE_KIND (link) != 0) return 0; /* If INSN is a store insn and DEP_INSN is setting the data being stored, we can sometimes lower the cost. */ if (recog_memoized (insn) >= 0 && get_attr_type (insn) == TYPE_ST && (set = single_set (dep_insn)) != 0 && GET_CODE (PATTERN (insn)) == SET && rtx_equal_p (SET_DEST (set), SET_SRC (PATTERN (insn)))) switch (get_attr_type (dep_insn)) { case TYPE_LD: /* No savings here. */ return cost; case TYPE_IMULL: case TYPE_IMULQ: /* In these cases, we save one cycle. */ return cost - 2; default: /* In all other cases, we save two cycles. */ return MAX (0, cost - 4); } /* Another case that needs adjustment is an arithmetic or logical operation. It's cost is usually one cycle, but we default it to two in the MD file. The only case that it is actually two is for the address in loads and stores. */ if (recog_memoized (dep_insn) >= 0 && get_attr_type (dep_insn) == TYPE_IADDLOG) switch (get_attr_type (insn)) { case TYPE_LD: case TYPE_ST: return cost; default: return 2; } /* The final case is when a compare feeds into an integer branch. The cost is only one cycle in that case. */ if (recog_memoized (dep_insn) >= 0 && get_attr_type (dep_insn) == TYPE_ICMP && recog_memoized (insn) >= 0 && get_attr_type (insn) == TYPE_IBR) return 2; /* Otherwise, return the default cost. */ return cost;}/* Print an operand. Recognize special options, documented below. */voidprint_operand (file, x, code) FILE *file; rtx x; char code;{ int i; switch (code) { case 'r': /* If this operand is the constant zero, write it as "$31". */ if (GET_CODE (x) == REG) fprintf (file, "%s", reg_names[REGNO (x)]); else if (x == CONST0_RTX (GET_MODE (x))) fprintf (file, "$31"); else output_operand_lossage ("invalid %%r value"); break; case 'R': /* Similar, but for floating-point. */ if (GET_CODE (x) == REG) fprintf (file, "%s", reg_names[REGNO (x)]); else if (x == CONST0_RTX (GET_MODE (x))) fprintf (file, "$f31"); else output_operand_lossage ("invalid %%R value"); break; case 'N': /* Write the 1's complement of a constant. */ if (GET_CODE (x) != CONST_INT) output_operand_lossage ("invalid %%N value"); fprintf (file, "%ld", ~ INTVAL (x)); break; case 'P': /* Write 1 << C, for a constant C. */ if (GET_CODE (x) != CONST_INT) output_operand_lossage ("invalid %%P value"); fprintf (file, "%ld", (HOST_WIDE_INT) 1 << INTVAL (x)); break; case 'h': /* Write the high-order 16 bits of a constant, sign-extended. */ if (GET_CODE (x) != CONST_INT) output_operand_lossage ("invalid %%h value"); fprintf (file, "%ld", INTVAL (x) >> 16); break; case 'L': /* Write the low-order 16 bits of a constant, sign-extended. */ if (GET_CODE (x) != CONST_INT) output_operand_lossage ("invalid %%L value"); fprintf (file, "%ld", (INTVAL (x) & 0xffff) - 2 * (INTVAL (x) & 0x8000)); break; case 'm': /* Write mask for ZAP insn. */ if (GET_CODE (x) == CONST_DOUBLE) { HOST_WIDE_INT mask = 0; HOST_WIDE_INT value; value = CONST_DOUBLE_LOW (x); for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++, value >>= 8) if (value & 0xff) mask |= (1 << i); value = CONST_DOUBLE_HIGH (x); for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++, value >>= 8) if (value & 0xff) mask |= (1 << (i + sizeof (int))); fprintf (file, "%ld", mask & 0xff); } else if (GET_CODE (x) == CONST_INT) { HOST_WIDE_INT mask = 0, value = INTVAL (x); for (i = 0; i < 8; i++, value >>= 8) if (value & 0xff) mask |= (1 << i); fprintf (file, "%ld", mask); } else output_operand_lossage ("invalid %%m value"); break; case 'M': /* 'b', 'w', or 'l' as the value of the constant. */ if (GET_CODE (x) != CONST_INT || (INTVAL (x) != 8 && INTVAL (x) != 16 && INTVAL (x) != 32)) output_operand_lossage ("invalid %%M value"); fprintf (file, "%s", INTVAL (x) == 8 ? "b" : INTVAL (x) == 16 ? "w" : "l"); break; case 'U': /* Similar, except do it from the mask. */ if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0xff) fprintf (file, "b"); else if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0xffff) fprintf (file, "w");#if HOST_BITS_PER_WIDE_INT == 32 else if (GET_CODE (x) == CONST_DOUBLE && CONST_DOUBLE_HIGH (x) == 0 && CONST_DOUBLE_LOW (x) == -1) fprintf (file, "l");#else else if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0xffffffff) fprintf (file, "l");#endif else output_operand_lossage ("invalid %%U value"); break; case 's': /* Write the constant value divided by 8. */ if (GET_CODE (x) != CONST_INT && (unsigned HOST_WIDE_INT) INTVAL (x) >= 64 && (INTVAL (x) & 7) != 8) output_operand_lossage ("invalid %%s value"); fprintf (file, "%ld", INTVAL (x) / 8); break; case 'S': /* Same, except compute (64 - c) / 8 */ if (GET_CODE (x) != CONST_INT && (unsigned HOST_WIDE_INT) INTVAL (x) >= 64 && (INTVAL (x) & 7) != 8) output_operand_lossage ("invalid %%s value"); fprintf (file, "%ld", (64 - INTVAL (x)) / 8); break; case 'C': /* Write out comparison name. */ if (GET_RTX_CLASS (GET_CODE (x)) != '<') output_operand_lossage ("invalid %%C value"); if (GET_CODE (x) == LEU) fprintf (file, "ule"); else if (GET_CODE (x) == LTU) fprintf (file, "ult"); else fprintf (file, "%s", GET_RTX_NAME (GET_CODE (x))); break; case 'D': /* Similar, but write reversed code. We can't get an unsigned code here. */ if (GET_RTX_CLASS (GET_CODE (x)) != '<') output_operand_lossage ("invalid %%D value"); fprintf (file, "%s", GET_RTX_NAME (reverse_condition (GET_CODE (x)))); break; case 'E': /* Write the divide or modulus operator. */ switch (GET_CODE (x)) { case DIV: fprintf (file, "div%s", GET_MODE (x) == SImode ? "l" : "q"); break; case UDIV: fprintf (file, "div%su", GET_MODE (x) == SImode ? "l" : "q"); break; case MOD: fprintf (file, "rem%s", GET_MODE (x) == SImode ? "l" : "q"); break; case UMOD: fprintf (file, "rem%su", GET_MODE (x) == SImode ? "l" : "q"); break; default: output_operand_lossage ("invalid %%E value"); break; } break; case 'F': /* Write the symbol; if the current function uses GP, write a modified version. */ if (GET_CODE (x) != SYMBOL_REF) output_operand_lossage ("invalid %%F value"); output_addr_const (file, x); if (alpha_function_needs_gp) fprintf (file, "..ng"); break; case 'A': /* Write "_u" for unaligned access. */ if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == AND) fprintf (file, "_u"); break; case 0: if (GET_CODE (x) == REG) fprintf (file, "%s", reg_names[REGNO (x)]); else if (GET_CODE (x) == MEM) output_address (XEXP (x, 0)); else output_addr_const (file, x); break; default: output_operand_lossage ("invalid %%xn code"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -