This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, middle-end]: Implement lrint and llrint functions asbuilt-ins
- From: Uros Bizjak <uros at kss-loka dot si>
- To: Richard Henderson <rth at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org, Roger Sayle <roger at eyesopen dot com>
- Date: Wed, 23 Mar 2005 12:22:41 +0100
- Subject: Re: [PATCH, middle-end]: Implement lrint and llrint functions asbuilt-ins
- References: <423EAA81.6090908@kss-loka.si> <20050323053511.GA1784@redhat.com>
Richard Henderson wrote:
* optabs.h (enum optab_index): Add new OTI_lrint and OTI_llrint.
I don't like using separate optabs for lrint and llrint. The
target shouldn't equate to C types like this. You should be
doing something like rintsfsi2 and rintsfdi2.
There is indeed no need for two lrint optabs. Attached to this message,
please find a patch that removes superflous definitions.
Regarding "rint<FPmode><INTmode>2" definition: I was trying to implement
rint like fixtrunc is implemented, as a convert optab. Unfortunatelly,
there is no expand_builtin_* function, that could handle convert optabs
(with proper widening of its input argument), and I think that
substantial work would be needed to implement these expanders.
The way that "lrint" function is implemented is exactly the same as
ilogb is implemented. We provide pattern only for the widest FPmode
input argument, that target can handle, and let expanders expand this
argument via expand_unop() to this widest mode. Please note, that
builtins will be expanded to this pattern only for
!flag_unsafe_math_optimizations, so I think that no unwanted effects
will be introduced by this expansion (the only user for this builtin is
currently x87, where expansion to XFmode is free.). This way, lrint and
llrint builtins could use existing infrastructure (expand_builtin_mathfn
function) with minimum changes needed.
OTOH, by removing llrint optab, lrint pattern could be implemented with
integer mode macros:
(define_expand "lrint<mode>2"
[(use (match_operand:X87MODEI 0 "nonimmediate_operand" ""))
(use (match_operand:XF 1 "register_operand" ""))]
"TARGET_USE_FANCY_MATH_387
&& (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387)
&& flag_unsafe_math_optimizations"
{
if (memory_operand (operands[0], VOIDmode))
emit_insn (gen_fist<mode>2 (operands[0], operands[1]));
else
{
operands[2] = assign_386_stack_local (<MODE>mode, 0);
emit_insn (gen_fist<mode>2_with_temp (operands[0], operands[1],
operands[2]));
}
DONE;
})
The attached patch was bootstrapped with
http://gcc.gnu.org/ml/gcc-patches/2005-03/msg01973.html (the lrint
pattern was changed as above) on i686-pc-linux-gnu, regtested for c and
c++. OK for mainline?
2005-03-23 Uros Bizjak <uros@kss-loka.si>
* optabs.h (enum optab_index): Remove OTI_llrint.
(llrint_optab): Remove corresponding macro.
* optabs.c (init_optabs): Remove llrint_optab initialization.
* genopinit.c (optabs): Remove llrint_optab implementation.
* builtins.c (expand_builtin_mathfn): Handle BUILT_IN_LLRINT{,F,L}
using lrint_optab.
Uros.
Index: optabs.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/optabs.h,v
retrieving revision 1.51
diff -u -p -r1.51 optabs.h
--- optabs.h 21 Mar 2005 14:42:23 -0000 1.51
+++ optabs.h 23 Mar 2005 10:52:43 -0000
@@ -192,7 +192,6 @@ enum optab_index
OTI_nearbyint,
OTI_rint,
OTI_lrint,
- OTI_llrint,
/* Tangent */
OTI_tan,
/* Inverse tangent */
@@ -320,7 +319,6 @@ extern GTY(()) optab optab_table[OTI_MAX
#define nearbyint_optab (optab_table[OTI_nearbyint])
#define rint_optab (optab_table[OTI_rint])
#define lrint_optab (optab_table[OTI_lrint])
-#define llrint_optab (optab_table[OTI_llrint])
#define tan_optab (optab_table[OTI_tan])
#define atan_optab (optab_table[OTI_atan])
#define copysign_optab (optab_table[OTI_copysign])
Index: optabs.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/optabs.c,v
retrieving revision 1.267
diff -u -p -r1.267 optabs.c
--- optabs.c 23 Mar 2005 03:04:10 -0000 1.267
+++ optabs.c 23 Mar 2005 10:52:44 -0000
@@ -5039,7 +5039,6 @@ init_optabs (void)
nearbyint_optab = init_optab (UNKNOWN);
rint_optab = init_optab (UNKNOWN);
lrint_optab = init_optab (UNKNOWN);
- llrint_optab = init_optab (UNKNOWN);
sincos_optab = init_optab (UNKNOWN);
sin_optab = init_optab (UNKNOWN);
asin_optab = init_optab (UNKNOWN);
Index: genopinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/genopinit.c,v
retrieving revision 1.88
diff -u -p -r1.88 genopinit.c
--- genopinit.c 21 Mar 2005 14:42:25 -0000 1.88
+++ genopinit.c 23 Mar 2005 10:52:44 -0000
@@ -125,7 +125,6 @@ static const char * const optabs[] =
"nearbyint_optab->handlers[$A].insn_code = CODE_FOR_$(nearbyint$a2$)",
"rint_optab->handlers[$A].insn_code = CODE_FOR_$(rint$a2$)",
"lrint_optab->handlers[$A].insn_code = CODE_FOR_$(lrint$a2$)",
- "llrint_optab->handlers[$A].insn_code = CODE_FOR_$(llrint$a2$)",
"sincos_optab->handlers[$A].insn_code = CODE_FOR_$(sincos$a3$)",
"sin_optab->handlers[$A].insn_code = CODE_FOR_$(sin$a2$)",
"asin_optab->handlers[$A].insn_code = CODE_FOR_$(asin$a2$)",
Index: builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.446
diff -u -p -r1.446 builtins.c
--- builtins.c 21 Mar 2005 14:42:25 -0000 1.446
+++ builtins.c 23 Mar 2005 10:52:45 -0000
@@ -1761,11 +1761,10 @@ expand_builtin_mathfn (tree exp, rtx tar
case BUILT_IN_LRINT:
case BUILT_IN_LRINTF:
case BUILT_IN_LRINTL:
- builtin_optab = lrint_optab; break;
case BUILT_IN_LLRINT:
case BUILT_IN_LLRINTF:
case BUILT_IN_LLRINTL:
- builtin_optab = llrint_optab; break;
+ builtin_optab = lrint_optab; break;
default:
gcc_unreachable ();
}