Kapace/test bitops #108

Merged
3 commits merged into from Jan 9, 2011
@@ -396,7 +396,7 @@ inline op lsr(invar PMC, invar PMC, invar PMC) :base_core {
const UINTVAL a = (UINTVAL)VTABLE_get_integer(interp, $2);
const UINTVAL b = (UINTVAL)VTABLE_get_integer(interp, $3);
const UINTVAL c = a >> b;
- VTABLE_set_integer_native(interp, $3, (INTVAL)c);
+ VTABLE_set_integer_native(interp, $1, (INTVAL)c);
}
=item B<rot>(out INT, in INT, in INT, inconst INT)
View
@@ -21,7 +21,7 @@ number types.
.sub main :main
.include 'test_more.pir'
- plan(125)
+ plan(139)
bnot_p_p_creates_destination()
band_1()
@@ -41,6 +41,7 @@ number types.
shl_3()
shr_1()
shr_2()
+ lsr_1()
bxor_1()
bxors_null_string()
bxors_2()
@@ -49,6 +50,8 @@ number types.
bnots_null_string()
bnots_2()
bnots_cow()
+ bnot_1()
+ rot_1()
# END_OF_TESTS
.end
@@ -397,6 +400,34 @@ number types.
is( $P1, 1, 'shr_p_p_p' )
.end
+.sub lsr_1
+ $P0 = new ["Integer"]
+ $P1 = new ["Integer"]
+ $I0 = 1
+ $P0 = 4
+ $P1 = 8
+
+ lsr_p_i $P0, $I0
+ is($P0, 2, "lsr_p_i")
+
+ lsr_p_ic $P0, 1
+ is($P0, 1, "lsr_p_ic")
+
+ lsr_p_p $P1, $P0
+ is($P1, 4, "lsr_p_p")
+
+ $I0 = 1
+ lsr_p_p_i $P1, $P1, $I0
+ is($P1, 2, "lsr_p_p_i")
+
+ lsr_p_p_ic $P1, $P1, 1
+ is($P1, 1, "lsr_p_p_ic")
+
+ $P1 = 4
+ lsr_p_p_p $P1, $P1, $P0
+ is($P1, 2, "lsr_p_p_p")
+.end
+
.sub bxor_1
$P0 = box 3
$I0 = 3
@@ -534,6 +565,20 @@ number types.
is( $S2, "foo", 'bxors COW' )
.end
+.sub bnot_1
+ $I0 = 10
+ bnot $I0
+ is($I0, -11, "bnot_i")
+
+ $I0 = bnot 11
+ is($I0, -12, "bnot_i_ic")
+
+ $P0 = new ["Integer"]
+ $P0 = 12
+ bnot $P0
+ is($P0, -13, "bnot_p")
+.end
+
.sub bnots_null_string
null $S1
null $S2
@@ -575,6 +620,32 @@ number types.
is( $S2, "foo", 'bnots COW' )
.end
+.sub rot_1
+ # Test basic rotation, really just a shift
+ $I0 = 0
+ $I1 = 10 # 10 rot 1 should be 20 (just a shift)
+ $I2 = 1
+ rot_i_i_i_ic $I0, $I1, $I2, 32
+ is ($I0, 20, "rot_i_i_i_ic")
+
+ # Reverse the rotation, shift the other way
+ $I2 = -1
+ rot_i_i_i_ic $I0, $I0, $I2, 32
+ is ($I0, 10, "rot_i_i_i_ic reverse")
+
+ $I0 = 0
+ $I1 = -1
+ rot_i_ic_i_ic $I0, 20, $I1, 32
+ is ($I0, 10, "rot_i_ic_i_ic")
+
+ $I0 = 0
+ rot_i_ic_ic_ic $I0, 20, 1, 32
+ is ($I0, 40, "rot_i_ic_ic_ic")
+
+ rot_i_ic_ic_ic $I0, 27, -3, 32
+ is($I0, 1610612739, "rot_i_ic_ic_ic")
+.end
+
# Local Variables:
# mode: pir
# fill-column: 100