bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

testing for signed char / short / int addition overflow


From: Bruno Haible
Subject: testing for signed char / short / int addition overflow
Date: Mon, 15 Mar 2021 03:59:20 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-203-generic; KDE/5.18.0; x86_64; ; )

Hi Paul,

When one needs a fast test whether an addition of two 'signed char' or 'short'
overflows, the macros in intprops.h yield a valid answer, but it is not so
well optimized. The functions my_signed1_overflow, my_signed2_overflow
in the attached file produce better machine code than the corresponding
functions signed1_overflow, signed2_overflow that use intprops.h primitives.

Similarly, on 64-bit platforms, my_signed4_overflow produces slightly better
machine code (no conditional branch) than signed4_overflow. On 32-bit platforms
it depends: on SPARC my_signed4_overflow is good as well, but not on i386
(because 64-bit computations on 32-bit CPUs needs many registers, and i386
has few registers).

Would it be possible to include some of these tricks into intprops.h?

Bruno

Attachment: foo.c
Description: Text Data

Attachment: foo.s
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]