Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Kapace/test bitops #108

Merged
3 commits merged into from

1 participant

@kapace

bit ops dynoplib tests, including lsr_, rot_ and in place bnot.
Increases bit ops code coverage to 90%.

Also included is a small fix for lsr_p_p_p to output to the first argument.

GCI Task Link: http://www.google-melange.com/gci/task/show/google/gci2010/parrot_perl_foundations/t129452083990

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 73 additions and 2 deletions.
  1. +1 −1  src/dynoplibs/bit.ops
  2. +72 −1 t/dynoplibs/bit.t
View
2  src/dynoplibs/bit.ops
@@ -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
73 t/dynoplibs/bit.t
@@ -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
Something went wrong with that request. Please try again.