@@ -481,6 +481,7 @@ pub impl BigUint {
481481 }
482482}
483483
484+ #[ cfg( target_arch = "x86_64" ) ]
484485priv pure fn get_radix_base ( radix : uint ) -> ( uint , uint ) {
485486 assert 1 < radix && radix <= 16 ;
486487 match radix {
@@ -503,6 +504,30 @@ priv pure fn get_radix_base(radix: uint) -> (uint, uint) {
503504 }
504505}
505506
507+ #[ cfg( target_arch = "arm" ) ]
508+ #[ cfg( target_arch = "x86" ) ]
509+ priv pure fn get_radix_base ( radix : uint ) -> ( uint , uint ) {
510+ assert 1 < radix && radix <= 16 ;
511+ match radix {
512+ 2 => ( 65536 , 16 ) ,
513+ 3 => ( 59049 , 10 ) ,
514+ 4 => ( 65536 , 8 ) ,
515+ 5 => ( 15625 , 6 ) ,
516+ 6 => ( 46656 , 6 ) ,
517+ 7 => ( 16807 , 5 ) ,
518+ 8 => ( 32768 , 5 ) ,
519+ 9 => ( 59049 , 5 ) ,
520+ 10 => ( 10000 , 4 ) ,
521+ 11 => ( 14641 , 4 ) ,
522+ 12 => ( 20736 , 4 ) ,
523+ 13 => ( 28561 , 4 ) ,
524+ 14 => ( 38416 , 4 ) ,
525+ 15 => ( 50625 , 4 ) ,
526+ 16 => ( 65536 , 4 ) ,
527+ _ => fail
528+ }
529+ }
530+
506531/// A Sign is a BigInt's composing element.
507532pub enum Sign { Minus , Zero , Plus }
508533
@@ -853,8 +878,6 @@ mod biguint_tests {
853878 }
854879
855880 #[test]
856- #[ignore(cfg(target_arch = " x86") ) ]
857- #[ ignore ( cfg ( target_arch = "arm" ) ) ]
858881 fn test_shl() {
859882 fn check(v: ~[BigDigit], shift: uint, ans: ~[BigDigit]) {
860883 assert BigUint::new(v) << shift == BigUint::new(ans);
@@ -865,10 +888,34 @@ mod biguint_tests {
865888 check(~[1 << (BigDigit::bits - 2)], 2, ~[0, 1]);
866889 check(~[1 << (BigDigit::bits - 2)], 3, ~[0, 2]);
867890 check(~[1 << (BigDigit::bits - 2)], 3 + BigDigit::bits, ~[0, 0, 2]);
868- check ( ~[ 0x7654_3210 , 0xfedc_ba98 , 0x7654_3210 , 0xfedc_ba98 ] , 4 ,
869- ~[ 0x6543_2100 , 0xedcb_a987 , 0x6543_210f , 0xedcb_a987 , 0xf ] ) ;
870- check ( ~[ 0x2222_1111 , 0x4444_3333 , 0x6666_5555 , 0x8888_7777 ] , 16 ,
871- ~[ 0x1111_0000 , 0x3333_2222 , 0x5555_4444 , 0x7777_6666 , 0x8888 ] ) ;
891+
892+ test_shl_bits();
893+
894+ #[cfg(target_arch = " x86_64") ]
895+ fn test_shl_bits( ) {
896+ check ( ~[ 0x7654_3210 , 0xfedc_ba98 ,
897+ 0x7654_3210 , 0xfedc_ba98 ] , 4 ,
898+ ~[ 0x6543_2100 , 0xedcb_a987 ,
899+ 0x6543_210f , 0xedcb_a987 , 0xf ] ) ;
900+ check ( ~[ 0x2222_1111 , 0x4444_3333 ,
901+ 0x6666_5555 , 0x8888_7777 ] , 16 ,
902+ ~[ 0x1111_0000 , 0x3333_2222 ,
903+ 0x5555_4444 , 0x7777_6666 , 0x8888 ] ) ;
904+ }
905+
906+ #[ cfg( target_arch = "arm" ) ]
907+ #[ cfg( target_arch = "x86" ) ]
908+ fn test_shl_bits ( ) {
909+ check ( ~[ 0x3210 , 0x7654 , 0xba98 , 0xfedc ,
910+ 0x3210 , 0x7654 , 0xba98 , 0xfedc ] , 4 ,
911+ ~[ 0x2100 , 0x6543 , 0xa987 , 0xedcb ,
912+ 0x210f , 0x6543 , 0xa987 , 0xedcb , 0xf ] ) ;
913+ check ( ~[ 0x1111 , 0x2222 , 0x3333 , 0x4444 ,
914+ 0x5555 , 0x6666 , 0x7777 , 0x8888 ] , 16 ,
915+ ~[ 0x0000 , 0x1111 , 0x2222 , 0x3333 ,
916+ 0x4444 , 0x5555 , 0x6666 , 0x7777 , 0x8888 ] ) ;
917+ }
918+
872919 }
873920
874921 #[ test]
@@ -885,11 +932,32 @@ mod biguint_tests {
885932 check ( ~[ 1 << 2 ] , 2 , ~[ 1 ] ) ;
886933 check ( ~[ 1 , 2 ] , 3 , ~[ 1 << ( BigDigit :: bits - 2 ) ] ) ;
887934 check ( ~[ 1 , 1 , 2 ] , 3 + BigDigit :: bits, ~[ 1 << ( BigDigit :: bits - 2 ) ] ) ;
888- check ( ~[ 0x6543_2100 , 0xedcb_a987 , 0x6543_210f , 0xedcb_a987 , 0xf ] , 4 ,
889- ~[ 0x7654_3210 , 0xfedc_ba98 , 0x7654_3210 , 0xfedc_ba98 ] ) ;
890- check ( ~[ 0x1111_0000 , 0x3333_2222 , 0x5555_4444 , 0x7777_6666 , 0x8888 ] ,
891- 16 ,
892- ~[ 0x2222_1111 , 0x4444_3333 , 0x6666_5555 , 0x8888_7777 ] ) ;
935+ test_shr_bits ( ) ;
936+
937+ #[ cfg( target_arch = "x86_64" ) ]
938+ fn test_shr_bits ( ) {
939+ check ( ~[ 0x6543_2100 , 0xedcb_a987 ,
940+ 0x6543_210f , 0xedcb_a987 , 0xf ] , 4 ,
941+ ~[ 0x7654_3210 , 0xfedc_ba98 ,
942+ 0x7654_3210 , 0xfedc_ba98 ] ) ;
943+ check ( ~[ 0x1111_0000 , 0x3333_2222 ,
944+ 0x5555_4444 , 0x7777_6666 , 0x8888 ] , 16 ,
945+ ~[ 0x2222_1111 , 0x4444_3333 ,
946+ 0x6666_5555 , 0x8888_7777 ] ) ;
947+ }
948+
949+ #[ cfg( target_arch = "arm" ) ]
950+ #[ cfg( target_arch = "x86" ) ]
951+ fn test_shr_bits ( ) {
952+ check ( ~[ 0x2100 , 0x6543 , 0xa987 , 0xedcb ,
953+ 0x210f , 0x6543 , 0xa987 , 0xedcb , 0xf ] , 4 ,
954+ ~[ 0x3210 , 0x7654 , 0xba98 , 0xfedc ,
955+ 0x3210 , 0x7654 , 0xba98 , 0xfedc ] ) ;
956+ check ( ~[ 0x0000 , 0x1111 , 0x2222 , 0x3333 ,
957+ 0x4444 , 0x5555 , 0x6666 , 0x7777 , 0x8888 ] , 16 ,
958+ ~[ 0x1111 , 0x2222 , 0x3333 , 0x4444 ,
959+ 0x5555 , 0x6666 , 0x7777 , 0x8888 ] ) ;
960+ }
893961 }
894962
895963 #[ test]
@@ -1054,6 +1122,7 @@ mod biguint_tests {
10541122 }
10551123
10561124 fn to_str_pairs ( ) -> ~[ ( BigUint , ~[ ( uint , ~str ) ] ) ] {
1125+ let bits = BigDigit :: bits;
10571126 ~[ ( Zero :: zero ( ) , ~[
10581127 ( 2 , ~"0 ") , ( 3 , ~"0 ")
10591128 ] ) , ( BigUint :: from_slice ( [ 0xff ] ) , ~[
@@ -1077,24 +1146,39 @@ mod biguint_tests {
10771146 ( 4 , ~"333333 ") ,
10781147 ( 16 , ~"fff")
10791148 ] ) , ( BigUint :: from_slice ( [ 1 , 2 ] ) , ~[
1080- ( 2 , ~"10 " + str:: from_chars ( vec:: from_elem ( 31 , '0' ) ) + "1" ) ,
1081- ( 4 , ~"2 " + str:: from_chars ( vec:: from_elem ( 15 , '0' ) ) + "1" ) ,
1082- ( 10 , ~"8589934593 ") ,
1083- ( 16 , ~"2 " + str:: from_chars ( vec:: from_elem ( 7 , '0' ) ) + "1" )
1084- ] ) , ( BigUint :: from_slice ( [ 1 , 2 , 3 ] ) , ~[
1085- ( 2 , ~"11 " + str:: from_chars ( vec:: from_elem ( 30 , '0' ) ) + "10" +
1086- str:: from_chars ( vec:: from_elem ( 31 , '0' ) ) + "1" ) ,
1087- ( 4 , ~"3 " + str:: from_chars ( vec:: from_elem ( 15 , '0' ) ) + "2" +
1088- str:: from_chars ( vec:: from_elem ( 15 , '0' ) ) + "1" ) ,
1089- ( 10 , ~"55340232229718589441 ") ,
1090- ( 16 , ~"3 " + str:: from_chars ( vec:: from_elem ( 7 , '0' ) ) + "2" +
1091- str:: from_chars ( vec:: from_elem ( 7 , '0' ) ) + "1" )
1092- ] ) ]
1149+ ( 2 ,
1150+ ~"10 " +
1151+ str:: from_chars ( vec:: from_elem ( bits - 1 , '0' ) ) + "1" ) ,
1152+ ( 4 ,
1153+ ~"2 " +
1154+ str:: from_chars ( vec:: from_elem ( bits / 2 - 1 , '0' ) ) + "1" ) ,
1155+ ( 10 , match bits {
1156+ 32 => ~"8589934593 ", 16 => ~"131073 ", _ => fail
1157+ } ) ,
1158+ ( 16 ,
1159+ ~"2 " +
1160+ str:: from_chars ( vec:: from_elem ( bits / 4 - 1 , '0' ) ) + "1" )
1161+ ] ) , ( BigUint :: from_slice ( [ 1 , 2 , 3 ] ) , ~[
1162+ ( 2 ,
1163+ ~"11 " +
1164+ str:: from_chars ( vec:: from_elem ( bits - 2 , '0' ) ) + "10" +
1165+ str:: from_chars ( vec:: from_elem ( bits - 1 , '0' ) ) + "1" ) ,
1166+ ( 4 ,
1167+ ~"3 " +
1168+ str:: from_chars ( vec:: from_elem ( bits / 2 - 1 , '0' ) ) + "2" +
1169+ str:: from_chars ( vec:: from_elem ( bits / 2 - 1 , '0' ) ) + "1" ) ,
1170+ ( 10 , match bits {
1171+ 32 => ~"55340232229718589441 ",
1172+ 16 => ~"12885032961 ",
1173+ _ => fail
1174+ } ) ,
1175+ ( 16 , ~"3 " +
1176+ str:: from_chars ( vec:: from_elem ( bits / 4 - 1 , '0' ) ) + "2" +
1177+ str:: from_chars ( vec:: from_elem ( bits / 4 - 1 , '0' ) ) + "1" )
1178+ ] ) ]
10931179 }
10941180
10951181 #[ test]
1096- #[ ignore( cfg( target_arch = "x86" ) ) ]
1097- #[ ignore( cfg( target_arch = "arm" ) ) ]
10981182 fn test_to_str_radix( ) {
10991183 for to_str_pairs( ) . each |num_pair| {
11001184 let & ( n, rs) = num_pair;
@@ -1106,8 +1190,6 @@ mod biguint_tests {
11061190 }
11071191
11081192 #[ test]
1109- #[ ignore( cfg( target_arch = "x86" ) ) ]
1110- #[ ignore( cfg( target_arch = "arm" ) ) ]
11111193 fn test_from_str_radix( ) {
11121194 for to_str_pairs( ) . each |num_pair| {
11131195 let & ( n, rs) = num_pair;
0 commit comments