This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: divmod , signed division problem in rtl
- From: Jim Wilson <wilson at redhat dot com>
- To: Pierre Mallard <pierremallard at yahoo dot fr>
- Cc: gcc at gcc dot gnu dot org
- Date: 09 Oct 2002 12:58:48 -0400
- Subject: Re: divmod , signed division problem in rtl
- References: <20021009134151.67778.qmail@web20309.mail.yahoo.com>
I am assuming that your testcase is written in C. I am assuming that your
testcase divides one signed char variable by another signed char variable.
I am assuming that your target has 16-bit integers.
The C language says that all arithmetic operands undergo default promotions
before the operation is performed. That means your signed chars get promoted
to int, and we need to perform an integer divide and then truncate the result
to signed char. Since your integers are 16-bits, that means we will generate
the divmodhi4 pattern. The C front end has code to shorten operations when
possible. However, a 16-bit signed divide of two variables whose result is
truncated to 8-bits is not mathematically the same as an 8-bit signed divide,
thus we can not shorten this operation, which means we can not use the
divmodqi4 pattern.
There are a few ways around this. Try writing a testcase in a different
language. I am not expert with the other languages, but there is probably
one that doesn't have the default promotion rules of C. Try writing an
unsigned divide. These can be shortened, except that an unsigned divide won't
match a signed divide pattern, so this doesn't really help. Try writing a
divide of a signed char by a constant which is not -1. This can be shortened.
However, for many if not most targets, divide by constant will get emitted as
a series of shifts and adds, so this may not help either.
The simplest way to generate your divmodqi4 pattern is probably to add an
intrisic, i.e. a builtin function.
Jim