memset and host char requirement

Paulo J. Matos paulo@matos-sorge.com
Thu Jul 26 12:11:00 GMT 2012


Hi,

My target has 16bit chars.
What I am seeing is that in a memset call, the call is not inlined by 
GCC whenever fill value is bigger than host char.

This seems to be due to the code (GCC 4.6.5) in target_char_cast 
(builtins.c), called from expand_builtin_memset_args:

static int
target_char_cast (tree cst, char *p)
{
   unsigned HOST_WIDE_INT val, hostval;

   if (TREE_CODE (cst) != INTEGER_CST
       || CHAR_TYPE_SIZE > HOST_BITS_PER_WIDE_INT)
     return 1;

   val = TREE_INT_CST_LOW (cst);
   if (CHAR_TYPE_SIZE < HOST_BITS_PER_WIDE_INT)
     val &= (((unsigned HOST_WIDE_INT) 1) << CHAR_TYPE_SIZE) - 1;

   hostval = val;
   if (HOST_BITS_PER_CHAR < HOST_BITS_PER_WIDE_INT)
     hostval &= (((unsigned HOST_WIDE_INT) 1) << HOST_BITS_PER_CHAR) - 1;

   if (val != hostval)
     return 1;

   *p = hostval;
   return 0;
}


This requires the tree cst variable to fit in target char (which makes 
sense) and in host char (which doesn't make sense).

Why would the fill value in a memset call be required to fit in a host 
char?

Cheers,

-- 
PMatos




More information about the Gcc mailing list