[Pixman] [PATCH] Resolve implementation-defined behaviour for division rounded to -infinity
Pekka Paalanen
ppaalanen at gmail.com
Thu Aug 27 02:28:52 PDT 2015
On Wed, 26 Aug 2015 14:21:07 +0100
"Ben Avison" <bavison at riscosopen.org> wrote:
> I hadn't really investigated that, but having had a bit of a play with
> ARM GCC, I see that it fails to use the runtime function that returns
> both the quotient and remainder (__aeabi_idivmod) with the operations in
> macro form. I get more luck writing them as functions:
>
> inline int
> DIV (int a, int b)
> {
> int q = a / b;
> int r = a - q * b;
> return q - (r < 0);
> }
>
> inline int
> MOD (int a, int b)
> {
> int r = a % b;
> if (r < 0)
> r += b;
> return r;
> }
>
> with the caveat that these are based on the macros from my 2015-08-18
> post, which rely on b being positive. (Set aside for the moment whether
> an inline function with an all-caps name is a good idea...)
FWIW, when I looked at the macros (old and proposed), my head started
spinning. Looking at these inline functions, I feel I could actually
understand them without rewriting them.
- my 2c on readability
Not to mention that unlike the macros, these do not evaluate the
arguments multiple times.
Btw. I personally agree with Siarhei's testing argument. If there is
any uncertainty whether existing code is good or not, writing a test to
explicitly check for it is a nice way. If users come back reporting
test failures, then we have a problem. Otherwise no need to pay
attention.
I just wish testing for performance was as reliable as for
correctness...
Thanks,
pq
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 811 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/pixman/attachments/20150827/84802d51/attachment-0001.sig>
More information about the Pixman
mailing list