[Vm-dev] Re: Issue 92 in cog: 3 LargeInteger arithmetic primitive bugs with minimum signed 64 bit value

cog at googlecode.com cog at googlecode.com
Sun Sep 2 14:08:22 UTC 2012


Comment #6 on issue 92 by nicolas.... at gmail.com: 3 LargeInteger arithmetic  
primitive bugs with minimum signed 64 bit value
http://code.google.com/p/cog/issues/detail?id=92

As long as SmallInteger minVal negated (2^30) fits on 32 bits, there would  
be no such problem in SmallInteger primitives.

AFAICT, 0 - INT_MIN like problem was only in LargeInt primitives, and those  
are not jitted.

However, JIT is clever and for example in genPrimitiveAdd avoid shifting  
the SmallInteger tag (genShiftAwaySmallIntegerTagsInScratchReg:), and just  
remove it from one of operands (genRemoveSmallIntegerTagsInScratchReg:) so  
as to directly produce a tagged integer. Thus, testing if the result fits  
in 31 bit SmallInteger, become as simple as testing for 32 bit overflow...
Testing for overflow is much simpler than in C, see senders of  
#JumpOverflow:

Note that genPrimitiveDivide use another strategy for testing overflow case  
of (SmallInteger minVal/-1).



More information about the Vm-dev mailing list