[PATCH, middle-end]: Implement lrint and llrint functions as built-ins

Uros Bizjak uros@kss-loka.si
Wed Mar 23 11:24:00 GMT 2005

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" ""))]
   && flag_unsafe_math_optimizations"
  if (memory_operand (operands[0], VOIDmode))
    emit_insn (gen_fist<mode>2 (operands[0], operands[1]));
      operands[2] = assign_386_stack_local (<MODE>mode, 0);
      emit_insn (gen_fist<mode>2_with_temp (operands[0], operands[1],

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.


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: lrint2.diff
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20050323/3947881f/attachment.ksh>

More information about the Gcc-patches mailing list