[Zlib-devel] [PATCH] deflate.c: identify slide_Pos() for later optimization
John Reiser
jreiser at bitwagon.com
Tue Jul 24 20:30:37 EDT 2012
On 07/24/2012 03:23 PM, Jan Seiffert wrote:
> John Reiser schrieb:
>> On 07/24/2012 Jan Seiffert wrote:
[snip]
> If int is > 16bit, it can hold an unsigned short value just fine,
> only now the compiler is stuck with an signed type, which has
> undefined overflow semantic.
>
> He trapped himself...
The expression
(Pos)(m >= slide ? m-slide : NIL)
is exactly a definition of saturating subtract.
Overflow is impossible, and this is easy to infer.
Overflow using the un-widened quantities is impossible because
the subtraction is guarded by exactly the minimal condition
which guarantees no overflow.
If the compiler widens anything in this case, then the compiler
can notice and remember that all of the additional bits must be
'0' bits. The range does not change. Thus signed overflow
of subtraction of the widened quantities is impossible.
> [snip]
--
More information about the Zlib-devel
mailing list