1 ! Copyright (C) 2008, 2009 Slava Pestov, Daniel Ehrenberg.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel kernel.private tools.test math math.partial-dispatch
4 math.private accessors slots.private sequences sequences.private strings sbufs
6 compiler.tree.normalization
8 alien.accessors layouts combinators byte-arrays ;
9 IN: compiler.tree.modular-arithmetic.tests
11 : test-modular-arithmetic ( quot -- quot' )
12 cleaned-up-tree nodes>quot ;
14 [ [ >R >fixnum R> >fixnum fixnum+fast ] ]
15 [ [ { integer integer } declare + >fixnum ] test-modular-arithmetic ] unit-test
17 [ [ +-integer-integer dup >fixnum ] ]
18 [ [ { integer integer } declare + dup >fixnum ] test-modular-arithmetic ] unit-test
20 [ [ >R >fixnum R> >fixnum fixnum+fast 4 fixnum*fast ] ]
21 [ [ { integer integer } declare + 4 * >fixnum ] test-modular-arithmetic ] unit-test
23 TUPLE: declared-fixnum { x fixnum } ;
26 [ { declared-fixnum } declare [ 1 + ] change-x ]
27 { + fixnum+ >fixnum } inlined?
31 [ { declared-fixnum } declare x>> drop ]
36 [ { integer } declare -63 shift 4095 bitand ]
41 [ { integer } declare 127 bitand 3 + ]
42 { + +-integer-fixnum bitand } inlined?
46 [ { integer } declare 127 bitand 3 + ]
54 615949 * 797807 + 20 2^ mod dup 19 2^ -
56 ] { * + shift mod fixnum-mod fixnum* fixnum+ fixnum- } inlined?
62 615949 * 797807 + 20 2^ mod dup 19 2^ -
63 ] { >fixnum } inlined?
68 { integer } declare 0 swap
70 drop 615949 * 797807 + 20 2^ rem dup 19 2^ -
72 ] { * + shift rem mod fixnum-mod fixnum* fixnum+ fixnum- } inlined?
77 { fixnum } declare 0 swap
79 drop 615949 * 797807 + 20 2^ rem dup 19 2^ -
81 ] { * + shift rem mod fixnum-mod fixnum* fixnum+ fixnum- >fixnum } inlined?
85 [ { string sbuf } declare ] \ push-all def>> append \ + inlined?
89 [ { string sbuf } declare ] \ push-all def>> append \ fixnum+ inlined?
93 [ { string sbuf } declare ] \ push-all def>> append \ >fixnum inlined?
100 { integer } declare [ 256 mod ] map
101 ] { mod fixnum-mod } inlined?
107 ] { mod fixnum-mod } inlined?
113 ] { mod fixnum-mod } inlined?
118 dup 0 >= [ 256 mod ] when
119 ] { mod fixnum-mod } inlined?
124 { integer } declare dup 0 >= [ 256 mod ] when
125 ] { mod fixnum-mod } inlined?
130 { integer } declare 256 rem
131 ] { mod fixnum-mod } inlined?
136 { integer } declare [ 256 rem ] map
137 ] { mod fixnum-mod rem } inlined?
140 [ [ >fixnum 255 fixnum-bitand ] ]
141 [ [ >integer 256 rem ] test-modular-arithmetic ] unit-test
143 [ [ "COMPLEX SHUFFLE" fixnum+fast "COMPLEX SHUFFLE" set-alien-unsigned-1 ] ]
144 [ [ [ { fixnum fixnum } declare + ] 2dip set-alien-unsigned-1 ] test-modular-arithmetic ] unit-test
146 [ [ "COMPLEX SHUFFLE" fixnum+fast "COMPLEX SHUFFLE" set-alien-unsigned-2 ] ]
147 [ [ [ { fixnum fixnum } declare + ] 2dip set-alien-unsigned-2 ] test-modular-arithmetic ] unit-test
150 { 4 [ [ [ "COMPLEX SHUFFLE" fixnum+ "COMPLEX SHUFFLE" set-alien-unsigned-4 ] ] ] }
151 { 8 [ [ [ "COMPLEX SHUFFLE" fixnum+fast "COMPLEX SHUFFLE" set-alien-unsigned-4 ] ] ] }
153 [ [ [ { fixnum fixnum } declare + ] 2dip set-alien-unsigned-4 ] test-modular-arithmetic ] unit-test
155 [ [ "COMPLEX SHUFFLE" fixnum+ "COMPLEX SHUFFLE" set-alien-unsigned-8 ] ]
156 [ [ [ { fixnum fixnum } declare + ] 2dip set-alien-unsigned-8 ] test-modular-arithmetic ] unit-test
158 [ [ "COMPLEX SHUFFLE" fixnum+fast "COMPLEX SHUFFLE" set-alien-signed-1 ] ]
159 [ [ [ { fixnum fixnum } declare + ] 2dip set-alien-signed-1 ] test-modular-arithmetic ] unit-test
161 [ [ "COMPLEX SHUFFLE" fixnum+fast "COMPLEX SHUFFLE" set-alien-signed-2 ] ]
162 [ [ [ { fixnum fixnum } declare + ] 2dip set-alien-signed-2 ] test-modular-arithmetic ] unit-test
165 { 4 [ [ [ "COMPLEX SHUFFLE" fixnum+ "COMPLEX SHUFFLE" set-alien-signed-4 ] ] ] }
166 { 8 [ [ [ "COMPLEX SHUFFLE" fixnum+fast "COMPLEX SHUFFLE" set-alien-signed-4 ] ] ] }
168 [ [ [ { fixnum fixnum } declare + ] 2dip set-alien-signed-4 ] test-modular-arithmetic ] unit-test
170 [ [ "COMPLEX SHUFFLE" fixnum+ "COMPLEX SHUFFLE" set-alien-signed-8 ] ]
171 [ [ [ { fixnum fixnum } declare + ] 2dip set-alien-signed-8 ] test-modular-arithmetic ] unit-test
173 [ t ] [ [ { fixnum byte-array } declare [ + ] with map ] { + fixnum+ >fixnum } inlined? ] unit-test
176 [ 0 10 <byte-array> 10 [ 1 pick 0 + >fixnum pick set-nth-unsafe [ 1 + >fixnum ] dip ] times ]