math.intervals: workaround possible compiler bug by widening interval-bitor.

IN: scratchpad [
                   { byte-array } declare
                   [ 0 alien-unsigned-4 32 shift ]
                   [ 4 alien-unsigned-4 ] bi bitor
                   64 >signed
               ] optimized.

! working
[
    dup >R 0 alien-unsigned-4 32 fixnum-shift
    R> 4 alien-unsigned-4 over tag 0 eq?
    [ fixnum-bitor ] [ fixnum>bignum bignum-bitor ] if
    18446744073709551615 >R >bignum R> bignum-bitand
    dup 63 bignum-bit? [ 18446744073709551616 bignum- ] [ ] if
]

! broken
[
    dup >R 0 alien-unsigned-4 32 fixnum-shift
    R> 4 alien-unsigned-4 over tag 0 eq?
    [ fixnum-bitor ] [ fixnum>bignum bignum-bitor ] if
    dup 63 bignum-bit? [ 18446744073709551616 bignum- ] [ ] if
]

The second case correctly eliminates the bitand but incorrectly assumes
that the item on the stack (which is an integer -- either a fixnum or a
bignum), was converted to a bignum.
clean-macosx-x86-64
John Benediktsson 2019-10-31 10:45:54 -07:00
parent f68df75b84
commit e256a4ba18
2 changed files with 4 additions and 3 deletions

View File

@ -413,8 +413,8 @@ ${ 0 0xff [a,b] } [ -0xff -1 [a,b] 0 0xff [a,b] interval-bitand ] unit-test
[ 0 15 [a,b] interval-contains? ] all?
] unit-test
${ 0 255 [a,b] } [ 0 255 [a,b] dup interval-bitor ] unit-test
${ 0 511 [a,b] } [ 0 256 [a,b] dup interval-bitor ] unit-test
${ 0 256 [a,b] } [ 0 255 [a,b] dup interval-bitor ] unit-test
${ 0 512 [a,b] } [ 0 256 [a,b] dup interval-bitor ] unit-test
${ -128 127 [a,b] } [ -128 127 [a,b] dup interval-bitor ] unit-test
${ -256 255 [a,b] } [ -128 128 [a,b] dup interval-bitor ] unit-test

View File

@ -447,7 +447,8 @@ PRIVATE>
: interval-bitor ( i1 i2 -- i3 )
[
{ { [ 2dup [ interval-nonnegative? ] both? ]
[ [ max-lower-bound ] [ max-upper-bound ] 2bi bit-weight 1 - [a,b] ] }
! FIXME: this should maybe be bitweight 1 -
[ [ max-lower-bound ] [ max-upper-bound ] 2bi bit-weight [a,b] ] }
{ [ 2dup [ interval-negative? ] both? ]
[ max-lower-bound -1 [a,b] ] }
[ interval-union interval-bit-weight [ neg ] [ 1 - ] bi [a,b] ]