1 IN: compiler.tree.modular-arithmetic.tests
2 USING: kernel kernel.private tools.test math math.partial-dispatch
3 math.private accessors slots.private sequences strings sbufs
5 compiler.tree.optimizer
6 compiler.tree.debugger ;
8 : test-modular-arithmetic ( quot -- quot' )
9 build-tree optimize-tree nodes>quot ;
11 [ [ >r >fixnum r> >fixnum fixnum+fast ] ]
12 [ [ { integer integer } declare + >fixnum ] test-modular-arithmetic ] unit-test
14 [ [ +-integer-integer dup >fixnum ] ]
15 [ [ { integer integer } declare + dup >fixnum ] test-modular-arithmetic ] unit-test
17 [ [ >r >fixnum r> >fixnum fixnum+fast 4 fixnum*fast ] ]
18 [ [ { integer integer } declare + 4 * >fixnum ] test-modular-arithmetic ] unit-test
20 TUPLE: declared-fixnum { x fixnum } ;
23 [ { declared-fixnum } declare [ 1 + ] change-x ]
24 { + fixnum+ >fixnum } inlined?
28 [ { declared-fixnum } declare x>> drop ]
33 [ { integer } declare -63 shift 4095 bitand ]
38 [ { integer } declare 127 bitand 3 + ]
39 { + +-integer-fixnum bitand } inlined?
43 [ { integer } declare 127 bitand 3 + ]
51 615949 * 797807 + 20 2^ mod dup 19 2^ -
53 ] { * + shift mod fixnum-mod fixnum* fixnum+ fixnum- } inlined?
59 615949 * 797807 + 20 2^ mod dup 19 2^ -
60 ] { >fixnum } inlined?
65 { integer } declare 0 swap
67 drop 615949 * 797807 + 20 2^ rem dup 19 2^ -
69 ] { * + shift rem mod fixnum-mod fixnum* fixnum+ fixnum- } inlined?
74 { fixnum } declare 0 swap
76 drop 615949 * 797807 + 20 2^ rem dup 19 2^ -
78 ] { * + shift rem mod fixnum-mod fixnum* fixnum+ fixnum- >fixnum } inlined?
82 [ { string sbuf } declare ] \ push-all def>> append \ + inlined?
86 [ { string sbuf } declare ] \ push-all def>> append \ fixnum+ inlined?
90 [ { string sbuf } declare ] \ push-all def>> append \ >fixnum inlined?
97 { integer } declare [ 256 mod ] map
98 ] { mod fixnum-mod } inlined?
105 ] { mod fixnum-mod } inlined?
110 dup 0 >= [ 256 mod ] when
111 ] { mod fixnum-mod } inlined?
116 { integer } declare dup 0 >= [ 256 mod ] when
117 ] { mod fixnum-mod } inlined?
122 { integer } declare 256 rem
123 ] { mod fixnum-mod } inlined?
128 { integer } declare [ 256 rem ] map
129 ] { mod fixnum-mod rem } inlined?