A little warning in GMP.h

Torbjorn Granlund tege at swox.com
Sat Sep 25 02:52:24 CEST 2004

Brian Hurt <bhurt at spnz.org> writes:

  And in the past eliminating branchs wasn't that big of a problem.  It's
  only been recently that we've started getting CPUs where the branch
  mispredict cost was extreme.

If you by recently mean the last 10 years, then I agree.

  >   The advantage of the branched version is that it doesn't depend
  >   upon the system being twos complement.  And gcc (at least version 3.2.2)
  >   emits branchless code using the sete instruction with just -O2.
  > On which platforms?

  This was X86/Linux/Redhat 9.0.

One cannot make conclusions about GCC's general behaviour from

Micro-optimizing GMP is a difficult task.  It requires meticulous
testing of several platforms and compilers.

  > We're not going to go through the GMP code just to work around a
  > bogus Microsoft compiler warning.  Please use GCC for compiling
  > GMP if Microsoft's compiler's bogus warnings bother you.

  This isn't a microsoft-ism.

Really?  What other compilers have issues with twos complement of
unsigned types?

Curious remark: If you read the ISO C standard, you'll find out
that unary "-" is completely well-defined only for unsigned
types.  For signed types the standard allows negation to be
implementation defined when overflow occurs.  It may make demons
fly out from your nose without being in breach of the standard.

  This is a code quality question.

I don't understand.  Surely you don't mean that our decision not
to work around bogus compiler warnings mean our code quality
isn't good?


More information about the gmp-discuss mailing list