A little warning in GMP.h

Brian Hurt bhurt at spnz.org
Sat Sep 25 03:28:00 CEST 2004


On 25 Sep 2004, Torbjorn Granlund wrote:

> 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.

More like last five.  There's some handwaving around what precisely 
"extreme" means.  The P3 had a 12-stage pipeline IIRC- a branch 
mispredict was about half the cost on the P3 as on the P4 in term of 
clock cycles.

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

I agree.  And if shaving every single clock cycle off the operation is 
needed, it probably needs to be done in assembly- for precisely the 
reasons being stated- the difficulty of handling different compilers all 
efficiently.

> 
>   > 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.
> :-)

Taking a look at the C standard that I happen to have within arm's reach, 
I find section 6.2.6.2, which does define not one, but at least three 
different effects negation can have on unsigned numbers.  Note that this 
is the C99 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?

No.  The fact that you're applying micro-optimizations to your C code 
makes it harder to maintain.  You can stop attacking that straw man now.

-- 
"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
                                - Gene Spafford 
Brian



More information about the gmp-discuss mailing list