6 use Bit::Vector::Overload;
8 # ======================================================================
9 # $carry_out = $vector->rotate_left();
10 # $carry_out = $vector->rotate_right();
11 # $carry_out = $vector->shift_left($carry_in);
12 # $carry_out = $vector->shift_right($carry_in);
13 # $vector->Move_Left($bits);
14 # $vector->Move_Right($bits);
15 # ======================================================================
16 # $vec1 = $vec2->Shadow();
17 # $vec1 = $vec2->Clone();
18 # ======================================================================
24 foreach $limit (15,16,31,32,63,64,127,128,255,256,511,512,1023,1024)
26 $ref = Bit::Vector->new($limit);
31 for ( $j = 4; $j < $limit; $j += 2 ) { $ref->Bit_Off($j); }
32 for ( $i = 3; ($j = $i * $i) < $limit; $i += 2 )
34 for ( ; $j < $limit; $j += $i ) { $ref->Bit_Off($j); }
42 $crl = $rol->Shadow();
43 $crr = $ror->Shadow();
44 $csl = $shl->Shadow();
45 $csr = $shr->Shadow();
47 &test_rotat_reg_same(0);
48 &test_shift_reg_same(0);
49 &test_rotat_carry_same(1);
50 &test_shift_carry_same(1);
52 for ( $i = 0; $i < $limit; $i++ )
54 $crl->shift_left ( $rol->rotate_left () );
55 $crr->shift_right( $ror->rotate_right() );
56 $csl->shift_left ( $shl->shift_left ( $shl->bit_test($limit-1) ) );
57 $csr->shift_right( $shr->shift_right ( $shr->bit_test(0) ) );
59 if (($i == 0) || ($i == ($limit-2)))
61 &test_rotat_reg_same(1);
62 &test_shift_reg_same(1);
63 &test_rotat_carry_same(1);
64 &test_shift_carry_same(1);
66 &test_rotat_carry_diff if ($i);
68 &test_shift_carry_diff if ($i);
72 &test_rotat_reg_same(0);
73 &test_shift_reg_same(0);
74 &test_rotat_carry_same(0);
75 &test_shift_carry_same(0);
78 $ref = Bit::Vector->new(1);
79 $Minimum = $ref->Min();
80 $Maximum = $ref->Max();
82 if ($Minimum >= 32767)
83 {print "ok $n\n";} else {print "not ok $n\n";}
86 if ($Maximum <= -32767)
87 {print "ok $n\n";} else {print "not ok $n\n";}
90 foreach $limit (15,16,31,32,63,64,127,128,1023,1024)
92 $ref = Bit::Vector->new($limit);
94 for ( $bits = -2; $bits <= $limit + 1; $bits++ )
97 $vec = ($ref << $bits);
98 $ref->Move_Left($bits);
99 $norm_ = $limit - $bits;
102 if (($norm_ <= 0) || ($bits < 0))
110 if ($vec->equal($ref))
111 {print "ok $n\n";} else {print "not ok $n\n";}
115 if ($vec->equal($ref))
116 {print "ok $n\n";} else {print "not ok $n\n";}
120 $vec = ($ref >> $bits);
121 $ref->Move_Right($bits);
122 $norm_ = $limit - $bits;
124 $max_ = $limit - $bits - 1;
125 if (($norm_ <= 0) || ($bits < 0))
133 if ($vec->equal($ref))
134 {print "ok $n\n";} else {print "not ok $n\n";}
138 if ($vec->equal($ref))
139 {print "ok $n\n";} else {print "not ok $n\n";}
146 sub test_rotat_reg_same
150 if (($ref->equal($rol)) ^ $flag)
151 {print "ok $n\n";} else {print "not ok $n\n";}
154 if (($ref->equal($ror)) ^ $flag)
155 {print "ok $n\n";} else {print "not ok $n\n";}
159 sub test_shift_reg_same
163 if (($ref->equal($shl)) ^ $flag)
164 {print "ok $n\n";} else {print "not ok $n\n";}
167 if (($ref->equal($shr)) ^ $flag)
168 {print "ok $n\n";} else {print "not ok $n\n";}
172 sub test_rotat_carry_same
176 if (($ref->equal($crl)) ^ $flag)
177 {print "ok $n\n";} else {print "not ok $n\n";}
180 if (($ref->equal($crr)) ^ $flag)
181 {print "ok $n\n";} else {print "not ok $n\n";}
185 sub test_shift_carry_same
189 if (($ref->equal($csl)) ^ $flag)
190 {print "ok $n\n";} else {print "not ok $n\n";}
193 if (($ref->equal($csr)) ^ $flag)
194 {print "ok $n\n";} else {print "not ok $n\n";}
198 sub test_rotat_reg_diff
200 unless ($rol->equal($ror))
201 {print "ok $n\n";} else {print "not ok $n\n";}
205 sub test_rotat_carry_diff
207 unless ($crl->equal($crr))
208 {print "ok $n\n";} else {print "not ok $n\n";}
212 sub test_shift_reg_diff
214 unless ($shl->equal($shr))
215 {print "ok $n\n";} else {print "not ok $n\n";}
219 sub test_shift_carry_diff
221 unless ($csl->equal($csr))
222 {print "ok $n\n";} else {print "not ok $n\n";}
228 $norm = $ref->Norm();
230 {print "ok $n\n";} else {print "not ok $n\n";}
232 unless (($min,$max) = $ref->Interval_Scan_inc(0))
238 {print "ok $n\n";} else {print "not ok $n\n";}
241 {print "ok $n\n";} else {print "not ok $n\n";}
243 unless (($min,$max) = $ref->Interval_Scan_dec($limit-1))
249 {print "ok $n\n";} else {print "not ok $n\n";}
252 {print "ok $n\n";} else {print "not ok $n\n";}