]> gitweb.factorcode.org Git - factor.git/commitdiff
math.intervals: workaround possible compiler bug by widening interval-bitor.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 31 Oct 2019 17:45:54 +0000 (10:45 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 31 Oct 2019 17:45:54 +0000 (10:45 -0700)
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.

basis/math/intervals/intervals-tests.factor
basis/math/intervals/intervals.factor

index 73706da34052576ea91438621a3f831ac60c3cb2..87028ea93f4b34a5730587c4fed3d4bde4b779d4 100644 (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
index 63fa4582fd3df8b331fccd46efc107daa307327f..f36b659b3b0fe5ae47bae9e11e30f15369b5444d 100644 (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] ]