This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] implement fmod() as built-in x87 intrinsic


On Tue, 4 May 2004, Uros Bizjak wrote:
> Attached to this message, please find a patch, that implements fmod() as
> built-in x87 intrinsic.

Hi Uros,

These patterns are beginning to contain a significant amount of
duplication.  May I recommend that you create a helper function in
i386.c, providing a prototype in i386-protos.h, something like:

void x86_emit_fp_unordered_jump (rtx lab)
{
  rtx tmp = gen_reg_rtx (HImode);
  emit_insn (gen_x86_fnstsw_1 (tmp));
  emit_insn (gen_x86_sahf_1 (tmp));
  ...
  tmp = gen_rtx_UNORDERED (...)
  ..
  tmp = gen_rtx_SET (VOIDmode, pc_rtx, tmp);
  emit_jump_insn (tmp);
}


You should remove the asterisk from the x86_fnstsw_1 pattern in
i386.md, then you can reuse it rather than bundle a "fnstsw" with
the fpremxf_1 a pattern.  This way the fpremxf_1 and fprem1xf_1
patterns describe a single instruction.

The new x86_emit_fp_unordered_jump can create its own HImode, temporary
and construct the conditional jump to lab, then call emit_jump_insn.

In your current patch you create a forward conditional "ordered" jump
over a backward unconditional jump.  A better approach is just generate a
single backward conditional "unordered" jump.  gen_rtx_UNORDERED and
and gen_rtx_LABEL_REF (VOIDmode, label1).  This should reduce the amount
of initial RTL.

The final fmoddf3 expanders should look like:

  rtx lab = gen_label_rtx ();
  rtx op1 = gen_reg_rtx (XFmode);
  rtx op2 = gen_reg_rtx (XFmode);
  emit_insn (gen_extenddfxf2 (op1, operands[1]));
  emit_insn (gen_extenddfxf2 (op2, operands[2]));
  emit_label (lab);
  emit_insn (gen_fpremxf_1 (op1, op1, op2));
  x86_emit_fp_unordered_jump (lab);
  emit_insn (gen_trunxxfdf2_noop (operands[0], op1));

[You missed some whitespace between emit_insn and "(" in your posting].
The above pattern body factors as much code as possible into a subroutine,
which makes the SFmode, DFmode, XFmode and the future dremdf3 expanders
much simpler to write and maintain.


I hope this helps.

Roger
--


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]