2

我尝试修补 gcc,以便在 fdivd 之后将目标寄存器存储到堆栈中,即:

fdivd %f0, %f2, %f4; => 变成 fdivd %f0, %f2, %f4; 标准 %f4, [%fp+...]

我使用 define_expand 模式中的 (emit_insn,DONE) 序列为 divdf3 生成 rtl(见下文)。

在汇编器输出阶段,我使用 define_insn 并写出 "fdivd\t%%1, %%2, %%0; std %%0, %%3" 作为表达式字符串。

生成的代码似乎没问题。然而:

我的问题:

如何标记模式,使其不会被放入延迟槽?如何指定输出为 2 条指令并提示调度程序?define_insn divdf3_store(下)中的 (set_attr "length" "2") 属性是否已经足够?

——问候康拉德

-------------- changed sparc.md -------------------------
;;;;;;;;;;;;;;;;;; handle divdf3 ;;;;;;;;;;;;;;;;
(define_expand "divdf3"
  [(parallel [(set (match_operand:DF 0 "register_operand" "=e")
                      (div:DF (match_operand:DF 1 "register_operand" "e")
                (match_operand:DF 2 "register_operand" "e")))
          (clobber (match_scratch:SI 3 ""))])]
  "TARGET_FPU"
  "{
      output_divdf3_emit (operands[0], operands[1], operands[2], operands[3]);
      DONE;
    }")

(define_insn "divdf3_store"
  [(set (match_operand:DF 0 "register_operand" "=e")
                      (div:DF (match_operand:DF 1 "register_operand" "e")
                (match_operand:DF 2 "register_operand" "e")))
          (clobber (match_operand:DF 3 "memory_operand" ""  ))]
  "TARGET_FPU && TARGET_STORE_AFTER_DIVSQRT"
   {
       return output_divdf3 (operands[0], operands[1], operands[2], operands[3]);
   }
   [(set_attr "type" "fpdivd")
   (set_attr "fptype" "double")
   (set_attr "length" "2")])

(define_insn "divdf3_nostore"
  [(set (match_operand:DF 0 "register_operand" "=e")
    (div:DF (match_operand:DF 1 "register_operand" "e")
        (match_operand:DF 2 "register_operand" "e")))]
  "TARGET_FPU && (!TARGET_STORE_AFTER_DIVSQRT)"
  "fdivd\t%1, %2, %0"
  [(set_attr "type" "fpdivd")
   (set_attr "fptype" "double")])



-------------- changed sparc.c -------------------------

/**************************** handle fdivd ****************************/
char *
output_divdf3 (rtx op0, rtx op1, rtx dest, rtx scratch)
{
  static char string[128];
  if (debug_patch_divsqrt) {
    fprintf(stderr, "debug_patch_divsqrt:\n");
    debug_rtx(op0);
    debug_rtx(op1);
    debug_rtx(dest);
    fprintf(stderr, "scratch: 0x%x\n",(int)scratch);
  }
  sprintf(string,"fdivd\t%%1, %%2, %%0; std %%0, %%3 !!!");
  return string;
}

void
output_divdf3_emit (rtx dest, rtx op0, rtx op1, rtx scratch)
{
  rtx slot0, div, divsave;

  if (debug_patch_divsqrt) {
    fprintf(stderr, "output_divdf3_emit:\n");
    debug_rtx(op0);
    debug_rtx(op1);
    debug_rtx(dest);
    fprintf(stderr, "scratch: 0x%x\n",(int)scratch);
  }

  div = gen_rtx_SET (VOIDmode,
             dest,
             gen_rtx_DIV (DFmode,
                  op0,
                  op1));

  if (TARGET_STORE_AFTER_DIVSQRT) {
    slot0 = assign_stack_local (DFmode, 8, 8);
    divsave = gen_rtx_SET (VOIDmode, slot0, dest);
    emit_insn(divsave);
    emit_insn (gen_rtx_PARALLEL(VOIDmode,
                gen_rtvec (2,
                       div,
                       gen_rtx_CLOBBER (SImode,
                                slot0))));
  } else {
    emit_insn(div);
  }
} 
4

1 回答 1

1

我第二个 Laurynas。对于这样一个精确的问题,gcc@gcc.gnu.org 将非常有帮助。

于 2010-02-12T11:31:57.660 回答