[PATCH v2] builtins: rs6000: Add builtins for fegetround, feclearexcept and feraiseexcept [PR94193]

Hans-Peter Nilsson hp@bitrange.com
Mon Oct 5 01:56:01 GMT 2020


Please excuse a comment from the gallery:

On Mon, 28 Sep 2020, will schmidt via Gcc-patches wrote:
> On Fri, 2020-09-04 at 12:52 -0300, Raoni Fassina Firmino via Gcc-patches wrote:

> > 2020-08-13  Raoni Fassina Firmino  <raoni@linux.ibm.com>
> >
> > gcc/ChangeLog:

> > 	* config/rs6000/rs6000.md (fegetroundsi): New pattern.
> > 	(feclearexceptsi): New Pattern.
> > 	(feraiseexceptsi): New Pattern.

> > +(define_expand "feraiseexceptsi"
> > +  [(use (match_operand:SI 1 "const_int_operand" "n"))
> > +   (set (match_operand:SI 0 "gpc_reg_operand")
> > +	(const_int 0))]
> > +  "TARGET_HARD_FLOAT"
> > +{
> > +  switch (INTVAL (operands[1]))
> > +    {
> > +    case 0x2000000:  /* FE_INEXACT */
> > +    case 0x4000000:  /* FE_DIVBYZERO */
> > +    case 0x8000000:  /* FE_UNDERFLOW */
> > +    case 0x10000000: /* FE_OVERFLOW */
> > +      break;
> > +    default:
> > +      FAIL;
> > +    }
> > +
> > +  rtx tmp = gen_rtx_CONST_INT (SImode, __builtin_clz (INTVAL (operands[1])));

This doesn't appear to be very portable, to any-cxx11-compiler
that doesn't pretend to be gcc-intrinsics-compatible.

If the valid values had been more complicated, there'd be
bitmap.c:bitmap_last_set_bit to follow for a suitable portable
pattern.  It conditionalizes like:
#if GCC_VERSION >= 3004
  gcc_assert (sizeof (long) == sizeof (word));
  bit_no += BITMAP_WORD_BITS - __builtin_clzl (word) - 1;
#else
...
#endif

Better, there's "ffs".

brgds, H-P
PS. No less than four targets fail like that.  Meh.


More information about the Gcc-patches mailing list