@@ -945,6 +945,39 @@ mem_ref (rtx x)
return NULL_RTX;
}
+/* True if any of the floating-point instruction's source
+ registers is the same as the provided register. */
+
+static int
+fpop_reg_depend_p (rtx_insn *insn, unsigned int reg)
+{
+ extract_insn (insn);
+ return (REGNO (recog_data.operand[1]) == reg
+ || (recog_data.n_operands == 3
+ && REGNO (recog_data.operand[2]) == reg));
+}
+
+/* True if the instruction is floating-point division or
+ floating-point square-root. */
+
+static int
+div_sqrt_insn_p (rtx_insn *insn)
+{
+ if ( GET_CODE (PATTERN (insn)) != SET)
+ return false;
+
+ switch (get_attr_type (insn))
+ {
+ case TYPE_FPDIVS:
+ case TYPE_FPSQRTS:
+ case TYPE_FPDIVD:
+ case TYPE_FPSQRTD:
+ return true;
+ default:
+ return false;
+ }
+}
+
/* True if floating-point instruction. */
static int
@@ -1064,6 +1097,80 @@ sparc_do_work_around_errata (void)
insert_nop = true;
}
+ /* Look for sequences that could trigger the TN-0013 errata. */
+ if (sparc_fix_tn0013
+ && NONJUMP_INSN_P (insn)
+ && div_sqrt_insn_p (insn))
+ {
+ int i;
+ int fp_found = 0;
+ unsigned int dest_reg;
+ rtx_insn *after;
+
+ dest_reg = REGNO (SET_DEST (single_set (insn)));
+
+ next = next_active_insn (insn);
+ if (!next)
+ break;
+
+ for (after = next, i = 0; i < 4; i++)
+ {
+ /* Count floating-point operations. */
+ if (i != 3
+ && fpop_insn_p (after))
+ {
+ /* If the insn uses the destination register of
+ the div/sqrt, then it cannot be problematic. */
+ if (fpop_reg_depend_p (after, dest_reg))
+ break;
+ fp_found++;
+ }
+
+ /* Count floating-point loads. */
+ if (i != 3
+ && (set = single_set (after)) != NULL_RTX
+ && REG_P (SET_DEST (set))
+ && REGNO (SET_DEST (set)) > 31)
+ {
+ /* If the insn uses the destination register of
+ the div/sqrt, then it cannot be problematic. */
+ if (REGNO (SET_DEST (set)) == dest_reg)
+ break;
+ fp_found++;
+ }
+
+ /* Check if this is a problematic sequence. */
+ if (i > 1
+ && fp_found >= 2
+ && div_sqrt_insn_p (after))
+ {
+ /* Add extra NOP to prevent second version of
+ problematic sequence. */
+ if (i == 2)
+ emit_insn_before (gen_nop (), next);
+ insert_nop = true;
+ break;
+ }
+
+ /* No need to scan past a second div/sqrt. */
+ if (div_sqrt_insn_p (after))
+ break;
+
+ /* Insert NOP before branch. */
+ if (i < 3
+ && (!NONJUMP_INSN_P (after)
+ || GET_CODE (PATTERN (after)) == SEQUENCE))
+ {
+ insert_nop = true;
+ break;
+ }
+
+ after = next_active_insn (after);
+ if (!after)
+ break;
+ }
+ }
+
/* Look for either of these two sequences:
Sequence A:
@@ -1392,7 +1499,7 @@ public:
virtual bool gate (function *)
{
return sparc_fix_at697f || sparc_fix_ut699 || sparc_fix_b2bst
- || sparc_fix_gr712rc;
+ || sparc_fix_gr712rc || sparc_fix_tn0013;
}
virtual unsigned int execute (function *)
@@ -1762,9 +1869,12 @@ sparc_option_override (void)
if (!(target_flags_explicit & MASK_LRA))
target_flags |= MASK_LRA;
- /* Enable the back-to-back store errata workaround for LEON3FT. */
+ /* Enable applicable errata workarounds for LEON3FT. */
if (sparc_fix_ut699 || sparc_fix_ut700 || sparc_fix_gr712rc)
+ {
sparc_fix_b2bst = 1;
+ sparc_fix_tn0013 = 1;
+ }
/* Disable FsMULd for the UT699 since it doesn't work correctly. */
if (sparc_fix_ut699)
@@ -430,6 +430,10 @@
(symbol_ref "(sparc_fix_b2bst != 0
? FIX_B2BST_TRUE : FIX_B2BST_FALSE)"))
+(define_attr "fix_tn0013" "false,true"
+ (symbol_ref "(sparc_fix_tn0013 != 0
+ ? FIX_TN0013_TRUE : FIX_TN0013_FALSE)"))
+
(define_attr "fix_gr712rc" "false,true"
(symbol_ref "(sparc_fix_gr712rc != 0
? FIX_GR712RC_TRUE : FIX_GR712RC_FALSE)"))
@@ -581,6 +585,9 @@
(define_attr "in_branch_delay" "false,true"
(cond [(eq_attr "type" "uncond_branch,branch,cbcond,uncond_cbcond,call,sibcall,call_no_delay_slot,multi")
(const_string "false")
+ (and (eq_attr "fix_tn0013" "true")
+ (eq_attr "type" "fpdivs,fpsqrts,fpdivd,fpsqrtd"))
+ (const_string "false")
(and (eq_attr "fix_b2bst" "true") (eq_attr "type" "store,fpstore"))
(const_string "false")
(and (eq_attr "fix_ut699" "true") (eq_attr "type" "load,sload"))
@@ -253,6 +253,10 @@ Enable workarounds for the errata of the GR712RC processor.
TargetVariable
unsigned int sparc_fix_b2bst
+;; Enable workaround for TN-0013 errata
+TargetVariable
+unsigned int sparc_fix_tn0013
+
Mask(LONG_DOUBLE_128)
;; Use 128-bit long double