[PATCH] Fix incorrect byte swap detection (PR tree-optimization/60454)

Jakub Jelinek jakub@redhat.com
Wed Mar 12 07:08:00 GMT 2014


On Wed, Mar 12, 2014 at 11:45:03AM +0800, Thomas Preud'homme wrote:
> > From: Jakub Jelinek [mailto:jakub@redhat.com]
> > 
> > In theory you could have __CHAR_BIT__ different from 8 and what you care
> > about is that uint32_t has exactly 32 bits, so the check would need to be
> >   if (sizeof (uint32_t) * __CHAR_BIT__ != 32)
> >     return 0;
> 
> I could go with:
> 
> In = (0x12 << (__CHAR_BIT__ * 3))
>         | (0x34 << (__CHAR_BIT__ * 2))
>         | (0x56 << __CHAR_BIT__)
>         | 0x78;
> 
> and compare with a similarly constructed out so that I could run the test whenever sizeof (uint32_t) * __CHAR_BIT__ >= 32, isn't it?

No need to bother, I think we don't have any __CHAR_BIT__ != 8 targets right
now, and after all, the bswap code doesn't bother with it either:
static unsigned int
execute_optimize_bswap (void)
{
  basic_block bb;
  bool bswap16_p, bswap32_p, bswap64_p;
  bool changed = false;
  tree bswap16_type = NULL_TREE, bswap32_type = NULL_TREE, bswap64_type =
  NULL_TREE;

  if (BITS_PER_UNIT != 8)
    return 0;

> Thanks for the review. See attachment and below to check the version you approved.

Thanks, this is ok.

	Jakub



More information about the Gcc-patches mailing list