* Ulf Magnusson:

> Are you thinking of something like this?
>
> bool overflow_bit2(unsigned int a, unsigned int b) {
>     const unsigned int ashift = a << 24;
>     const unsigned int bshift = b << 24;
>     const unsigned int sum = a + b;
>     return (int)(~(a ^ b) & (a ^ sum)) < 0;
> }

Yes, but rather like :

  bool overflow_bit2(unsigned char a, unsigned char b) {
    const unsigned char sum = a + b;
    return ((signed char)(~(a ^ b) & (a ^ sum))) < 0;
  }

It still results in abysmal code, given that this should result in two
or three instructions on most architectures.

Are machine code insertions an option?

Reply via email to