This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] implement fmod() as built-in x87 intrinsic
- From: Uros Bizjak <uros at kss-loka dot si>
- To: Roger Sayle <roger at eyesopen dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 04 May 2004 17:22:08 +0200
- Subject: Re: [PATCH] implement fmod() as built-in x87 intrinsic
- References: <Pine.LNX.4.44.0405040537590.18609-100000@www.eyesopen.com>
Roger Sayle wrote:
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.
Hello Roger!
If I make a pattern as you described:
(define_insn "fpremxf_2"
[(set (match_operand:XF 0 "register_operand" "=f")
(unspec:XF [(match_operand:XF 1 "register_operand" "0")
(match_operand:XF 2 "register_operand" "u")]
UNSPEC_FPREM))
(set (reg:CC 18)
(unspec:CC [(const_int 0)] UNSPEC_NOP))]
"! TARGET_NO_FANCY_MATH_387 && TARGET_80387
&& flag_unsafe_math_optimizations"
"fprem"
[(set_attr "type" "fpspc")
(set_attr "mode" "XF")])
and use it as:
...
emit_label (label1);
tmp = gen_reg_rtx (HImode);
emit_insn (gen_fpremxf_2 (op1, op1, op2));
emit_insn (gen_x86_fnstsw_1 (tmp));
emit_insn (gen_x86_sahf_1 (tmp));
...
In this case fprem and fnstsw instructions mysteriously exchange places.
I have to declare
(set (reg:CC 18)... in fpremxf2 pattern, if I declare it as (set (reg
18)... I get:
builtins-40.c:18: internal compiler error: in cselib_invalidate_regno,
at cselib.c:977
Please submit a full bug report,
However, marking register 18 as (reg:CC 18) or (reg:CCFP 18) or
(reg:CCFPU 18), it gets marked as REG_UNUSED in flow2 pass, because
fnstsw pattern operates on (reg 18). I don't know, what to do with
fnstsw pattern - is it OK, or should I change (reg 18) to (reg:CC 18)?
Anyway, here is what I get with suggested approach:
test1:
pushl %ebp
movl %esp, %ebp
fldl 8(%ebp)
fldl 16(%ebp)
jmp .L2
.p2align 4,,7
.L7:
fxch %st(1)
.L2:
fxch %st(1)
fnstsw %ax
fprem
sahf
jp .L7
fstp %st(1)
popl %ebp
ret
I hope this helps.
Yes, thanks a lot for your help!
Uros.