]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/tree/modular-arithmetic/modular-arithmetic-tests.factor
Conflict resolution
[factor.git] / basis / compiler / tree / modular-arithmetic / modular-arithmetic-tests.factor
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
4 compiler.tree.builder
5 compiler.tree.optimizer
6 compiler.tree.debugger ;
7
8 : test-modular-arithmetic ( quot -- quot' )
9     build-tree optimize-tree nodes>quot ;
10
11 [ [ >R >fixnum R> >fixnum fixnum+fast ] ]
12 [ [ { integer integer } declare + >fixnum ] test-modular-arithmetic ] unit-test
13
14 [ [ +-integer-integer dup >fixnum ] ]
15 [ [ { integer integer } declare + dup >fixnum ] test-modular-arithmetic ] unit-test
16
17 [ [ >R >fixnum R> >fixnum fixnum+fast 4 fixnum*fast ] ]
18 [ [ { integer integer } declare + 4 * >fixnum ] test-modular-arithmetic ] unit-test
19
20 TUPLE: declared-fixnum { x fixnum } ;
21
22 [ t ] [
23     [ { declared-fixnum } declare [ 1 + ] change-x ]
24     { + fixnum+ >fixnum } inlined?
25 ] unit-test
26
27 [ t ] [
28     [ { declared-fixnum } declare x>> drop ]
29     { slot } inlined?
30 ] unit-test
31
32 [ f ] [
33     [ { integer } declare -63 shift 4095 bitand ]
34     \ shift inlined?
35 ] unit-test
36
37 [ t ] [
38     [ { integer } declare 127 bitand 3 + ]
39     { + +-integer-fixnum bitand } inlined?
40 ] unit-test
41
42 [ f ] [
43     [ { integer } declare 127 bitand 3 + ]
44     { >fixnum } inlined?
45 ] unit-test
46
47 [ t ] [
48     [
49         { integer } declare
50         dup 0 >= [
51             615949 * 797807 + 20 2^ mod dup 19 2^ -
52         ] [ dup ] if
53     ] { * + shift mod fixnum-mod fixnum* fixnum+ fixnum- } inlined?
54 ] unit-test
55
56 [ t ] [
57     [
58         { fixnum } declare
59         615949 * 797807 + 20 2^ mod dup 19 2^ -
60     ] { >fixnum } inlined?
61 ] unit-test
62
63 [ t ] [
64     [
65         { integer } declare 0 swap
66         [
67             drop 615949 * 797807 + 20 2^ rem dup 19 2^ -
68         ] map
69     ] { * + shift rem mod fixnum-mod fixnum* fixnum+ fixnum- } inlined?
70 ] unit-test
71
72 [ t ] [
73     [
74         { fixnum } declare 0 swap
75         [
76             drop 615949 * 797807 + 20 2^ rem dup 19 2^ -
77         ] map
78     ] { * + shift rem mod fixnum-mod fixnum* fixnum+ fixnum- >fixnum } inlined?
79 ] unit-test
80
81 [ t ] [
82     [ { string sbuf } declare ] \ push-all def>> append \ + inlined?
83 ] unit-test
84
85 [ t ] [
86     [ { string sbuf } declare ] \ push-all def>> append \ fixnum+ inlined?
87 ] unit-test
88
89 [ t ] [
90     [ { string sbuf } declare ] \ push-all def>> append \ >fixnum inlined?
91 ] unit-test
92
93
94
95 [ t ] [
96     [
97         { integer } declare [ 256 mod ] map
98     ] { mod fixnum-mod } inlined?
99 ] unit-test
100
101
102 [ f ] [
103     [
104         256 mod
105     ] { mod fixnum-mod } inlined?
106 ] unit-test
107
108 [ f ] [
109     [
110         dup 0 >= [ 256 mod ] when
111     ] { mod fixnum-mod } inlined?
112 ] unit-test
113
114 [ t ] [
115     [
116         { integer } declare dup 0 >= [ 256 mod ] when
117     ] { mod fixnum-mod } inlined?
118 ] unit-test
119
120 [ t ] [
121     [
122         { integer } declare 256 rem
123     ] { mod fixnum-mod } inlined?
124 ] unit-test
125
126 [ t ] [
127     [
128         { integer } declare [ 256 rem ] map
129     ] { mod fixnum-mod rem } inlined?
130 ] unit-test