386 optimized bitblit code

Brian Hurt bhurt at spnz.org
Sat Jan 31 19:39:00 CET 2004


On 31 Jan 2004, Niels Möller wrote:

> Note that for signed numbers, limit % 4 is not necessarily equivalent
> to limit & 3. 

Point taken.  But limit & 3 may have it's own problems.  Consider the
difference between sign-magnitude, one's complement, and two's complement.  
The binary represention (in sixteen bits) of -1 in those three are
0x8001, 0xFFFE, and 0xFFFF, respectively.  So -1 & 3 could yield 1, 2, or 
3 respectively.

My solution here is that since I don't need signed variables, I just use 
unsigned everywhere.

> So be careful that you don't use signed values by mistake. size_t is
> usually unsigned, but I'm not sure that it *always* is.

My copy of the C standard is in transit at the moment.  I do, however,
have a copy of Plauger handy, who quotes the C89 standard.  Plauger quotes
that size_t is "the unsigned integral type of the result of the sizeof
operator" (section 7.1.6).  C89 required size_t to be unsigned, and I
don't recall C99 screwing *that* up.

There should be no signed integers anywhere in the code.

-- 
"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-devel mailing list