This is the mail archive of the
mailing list for the GCC project.
Re: changing "configure" to default to "gcc -g -O2 -fwrapv ..."
- From: kenner at vlsi1 dot ultra dot nyu dot edu (Richard Kenner)
- To: vincent+gcc at vinc17 dot org
- Cc: autoconf-patches at gnu dot org, bug-gnulib at gnu dot org, dewar at adacore dot com, eggert at cs dot ucla dot edu, gcc at gcc dot gnu dot org
- Date: Sun, 31 Dec 2006 20:54:50 EST
- Subject: Re: changing "configure" to default to "gcc -g -O2 -fwrapv ..."
- References: <10612302258.AA24598@vlsi1.ultra.nyu.edu> <firstname.lastname@example.org> <10612310029.AA28910@vlsi1.ultra.nyu.edu> <email@example.com> <20061231112419.GR32297@ay.vinc17.org> <10612311403.AA19198@vlsi1.ultra.nyu.edu> <20061231143915.GV32297@ay.vinc17.org> <10612311508.AA23381@vlsi1.ultra.nyu.edu> <20061231155917.GZ32297@ay.vinc17.org> <10612311637.AA27185@vlsi1.ultra.nyu.edu> <20070101010431.GH32297@ay.vinc17.org>
> This isn't just about old code. If you're saying that old code with
> overflow checking can't be fixed (in a portable manner...), then new
> code will probably use the same tricks.
I said there's no "good" way, meaning as compact as the current tests. But
it's certainly easy to test for overflow in a correct and portable manner
that's not TOO inefficient. I haven't tested it, but this ought to do it and
is only 9 instructions on x86-64:
/* Return 1 IFF a + b will overflow as signed numbers. Assumes two's
overflow (int a, int b)
unsigned int pos_a, pos_b;
/* If they have different signs, their sum can't overflow. */
if ((a ^ b) < 0)
/* Otherwise, sum the non-sign bits as unsigned (this is close to abs,
but avoids overflow for INT_MIN) and see if that, interpreted as a
signed number, would be negative. If so, the sum will overflow. */
pos_a = (a & ((1u << (sizeof (int) * HOST_BITS_PER_CHAR - 1)) - 1));
pos_b = (b & ((1u << (sizeof (int) * HOST_BITS_PER_CHAR - 1)) - 1));
return (pos_a + pos_b) >> (sizeof (int) * HOST_BITS_PER_CHAR - 1);