This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp_leavesub(): call FREETMPS and optimise
[perl5.git] / t / op / bop.t
1 #!./perl
2
3 #
4 # test the bit operators '&', '|', '^', '~', '<<', and '>>'
5 #
6
7 use warnings;
8 no warnings 'deprecated';
9
10 BEGIN {
11     chdir 't' if -d 't';
12     @INC = '../lib';
13     require "./test.pl"; require "./charset_tools.pl";
14     require Config;
15 }
16
17 # Tests don't have names yet.
18 # If you find tests are failing, please try adding names to tests to track
19 # down where the failure is, and supply your new names as a patch.
20 # (Just-in-time test naming)
21 plan tests => 192 + (10*13*2) + 5 + 29;
22
23 # numerics
24 ok ((0xdead & 0xbeef) == 0x9ead);
25 ok ((0xdead | 0xbeef) == 0xfeef);
26 ok ((0xdead ^ 0xbeef) == 0x6042);
27 ok ((~0xdead & 0xbeef) == 0x2042);
28
29 # shifts
30 ok ((257 << 7) == 32896);
31 ok ((33023 >> 7) == 257);
32
33 # signed vs. unsigned
34 ok ((~0 > 0 && do { use integer; ~0 } == -1));
35
36 my $bits = 0;
37 for (my $i = ~0; $i; $i >>= 1) { ++$bits; }
38 my $cusp = 1 << ($bits - 1);
39
40
41 ok (($cusp & -1) > 0 && do { use integer; $cusp & -1 } < 0);
42 ok (($cusp | 1) > 0 && do { use integer; $cusp | 1 } < 0);
43 ok (($cusp ^ 1) > 0 && do { use integer; $cusp ^ 1 } < 0);
44 ok ((1 << ($bits - 1)) == $cusp &&
45     do { use integer; 1 << ($bits - 1) } == -$cusp);
46 ok (($cusp >> 1) == ($cusp / 2) &&
47     do { use integer; abs($cusp >> 1) } == ($cusp / 2));
48
49 $Aaz = chr(ord("A") & ord("z"));
50 $Aoz = chr(ord("A") | ord("z"));
51 $Axz = chr(ord("A") ^ ord("z"));
52
53 # short strings
54 is (("AAAAA" & "zzzzz"), ($Aaz x 5));
55 is (("AAAAA" | "zzzzz"), ($Aoz x 5));
56 is (("AAAAA" ^ "zzzzz"), ($Axz x 5));
57
58 # long strings
59 $foo = "A" x 150;
60 $bar = "z" x 75;
61 $zap = "A" x 75;
62 # & truncates
63 is (($foo & $bar), ($Aaz x 75 ));
64 # | does not truncate
65 is (($foo | $bar), ($Aoz x 75 . $zap));
66 # ^ does not truncate
67 is (($foo ^ $bar), ($Axz x 75 . $zap));
68
69 # string constants.  These tests expect the bit patterns of these strings in
70 # ASCII, so convert to that.
71 sub _and($) { $_[0] & native_to_uni("+0") }
72 sub _oar($) { $_[0] | native_to_uni("+0") }
73 sub _xor($) { $_[0] ^ native_to_uni("+0") }
74 is _and native_to_uni("waf"), native_to_uni('# '),  'str var & const str'; # [perl #20661]
75 is _and native_to_uni("waf"), native_to_uni('# '),  'str var & const str again'; # [perl #20661]
76 is _oar native_to_uni("yit"), native_to_uni('{yt'), 'str var | const str';
77 is _oar native_to_uni("yit"), native_to_uni('{yt'), 'str var | const str again';
78 is _xor native_to_uni("yit"), native_to_uni('RYt'), 'str var ^ const str';
79 is _xor native_to_uni("yit"), native_to_uni('RYt'), 'str var ^ const str again';
80
81 SKIP: {
82     skip "Converting a numeric doesn't work with EBCDIC unlike the above tests",
83          3 if $::IS_EBCDIC;
84     is _and  0, '0',   'num var & const str';     # [perl #20661]
85     is _oar  0, '0',   'num var | const str';
86     is _xor  0, '0',   'num var ^ const str';
87 }
88
89 # But don’t mistake a COW for a constant when assigning to it
90 %h=(150=>1);
91 $i=(keys %h)[0];
92 $i |= 105;
93 is $i, 255, '[perl #108480] $cow |= number';
94 $i=(keys %h)[0];
95 $i &= 105;
96 is $i, 0, '[perl #108480] $cow &= number';
97 $i=(keys %h)[0];
98 $i ^= 105;
99 is $i, 255, '[perl #108480] $cow ^= number';
100
101 #
102 is ("ok \xFF\xFF\n" & "ok 19\n", "ok 19\n");
103 is ("ok 20\n" | "ok \0\0\n", "ok 20\n");
104 is ("o\000 \0001\000" ^ "\000k\0002\000\n", "ok 21\n");
105
106 #
107 is ("ok \x{FF}\x{FF}\n" & "ok 22\n", "ok 22\n");
108 is ("ok 23\n" | "ok \x{0}\x{0}\n", "ok 23\n");
109 is ("o\x{0} \x{0}4\x{0}" ^ "\x{0}k\x{0}2\x{0}\n", "ok 24\n");
110
111 #
112 is (sprintf("%vd", v4095 & v801), 801);
113 is (sprintf("%vd", v4095 | v801), 4095);
114 is (sprintf("%vd", v4095 ^ v801), 3294);
115
116 #
117 is (sprintf("%vd", v4095.801.4095 & v801.4095), '801.801');
118 is (sprintf("%vd", v4095.801.4095 | v801.4095), '4095.4095.4095');
119 is (sprintf("%vd", v801.4095 ^ v4095.801.4095), '3294.3294.4095');
120 #
121 is (sprintf("%vd", v120.300 & v200.400), '72.256');
122 is (sprintf("%vd", v120.300 | v200.400), '248.444');
123 is (sprintf("%vd", v120.300 ^ v200.400), '176.188');
124 #
125 {
126     my $a = v120.300;
127     my $b = v200.400;
128     $a ^= $b;
129     is (sprintf("%vd", $a), '176.188');
130 }
131 {
132     my $a = v120.300;
133     my $b = v200.400;
134     $a |= $b;
135     is (sprintf("%vd", $a), '248.444');
136 }
137
138 #
139 # UTF8 ~ behaviour
140 #
141
142 {
143     my @not36;
144
145     for (0x100...0xFFF) {
146     $a = ~(chr $_);
147         push @not36, sprintf("%#03X", $_)
148             if $a ne chr(~$_) or length($a) != 1 or ~$a ne chr($_);
149     }
150     is (join (', ', @not36), '');
151
152     my @not37;
153
154     for my $i (0xEEE...0xF00) {
155         for my $j (0x0..0x120) {
156             $a = ~(chr ($i) . chr $j);
157                 push @not37, sprintf("%#03X %#03X", $i, $j)
158                     if $a ne chr(~$i).chr(~$j) or
159                     length($a) != 2 or
160                     ~$a ne chr($i).chr($j);
161         }
162     }
163     is (join (', ', @not37), '');
164
165     is (~chr(~0), "\0");
166
167
168     my @not39;
169
170     for my $i (0x100..0x120) {
171         for my $j (0x100...0x120) {
172             push @not39, sprintf("%#03X %#03X", $i, $j)
173                 if ~(chr($i)|chr($j)) ne (~chr($i)&~chr($j));
174         }
175     }
176     is (join (', ', @not39), '');
177
178     my @not40;
179
180     for my $i (0x100..0x120) {
181         for my $j (0x100...0x120) {
182             push @not40, sprintf("%#03X %#03X", $i, $j)
183                 if ~(chr($i)&chr($j)) ne (~chr($i)|~chr($j));
184         }
185     }
186     is (join (', ', @not40), '');
187 }
188
189
190 # More variations on 19 and 22.
191 is ("ok \xFF\x{FF}\n" & "ok 41\n", "ok 41\n");
192 is ("ok \x{FF}\xFF\n" & "ok 42\n", "ok 42\n");
193
194 # Tests to see if you really can do casts negative floats to unsigned properly
195 $neg1 = -1.0;
196 ok (~ $neg1 == 0);
197 $neg7 = -7.0;
198 ok (~ $neg7 == 6);
199
200
201 # double magic tests
202
203 sub TIESCALAR { bless { value => $_[1], orig => $_[1] } }
204 sub STORE { $_[0]{store}++; $_[0]{value} = $_[1] }
205 sub FETCH { $_[0]{fetch}++; $_[0]{value} }
206 sub stores { tied($_[0])->{value} = tied($_[0])->{orig};
207              delete(tied($_[0])->{store}) || 0 }
208 sub fetches { delete(tied($_[0])->{fetch}) || 0 }
209
210 # numeric double magic tests
211
212 tie $x, "main", 1;
213 tie $y, "main", 3;
214
215 is(($x | $y), 3);
216 is(fetches($x), 1);
217 is(fetches($y), 1);
218 is(stores($x), 0);
219 is(stores($y), 0);
220
221 is(($x & $y), 1);
222 is(fetches($x), 1);
223 is(fetches($y), 1);
224 is(stores($x), 0);
225 is(stores($y), 0);
226
227 is(($x ^ $y), 2);
228 is(fetches($x), 1);
229 is(fetches($y), 1);
230 is(stores($x), 0);
231 is(stores($y), 0);
232
233 is(($x |= $y), 3);
234 is(fetches($x), 2);
235 is(fetches($y), 1);
236 is(stores($x), 1);
237 is(stores($y), 0);
238
239 is(($x &= $y), 1);
240 is(fetches($x), 2);
241 is(fetches($y), 1);
242 is(stores($x), 1);
243 is(stores($y), 0);
244
245 is(($x ^= $y), 2);
246 is(fetches($x), 2);
247 is(fetches($y), 1);
248 is(stores($x), 1);
249 is(stores($y), 0);
250
251 is(~~$y, 3);
252 is(fetches($y), 1);
253 is(stores($y), 0);
254
255 { use integer;
256
257 is(($x | $y), 3);
258 is(fetches($x), 1);
259 is(fetches($y), 1);
260 is(stores($x), 0);
261 is(stores($y), 0);
262
263 is(($x & $y), 1);
264 is(fetches($x), 1);
265 is(fetches($y), 1);
266 is(stores($x), 0);
267 is(stores($y), 0);
268
269 is(($x ^ $y), 2);
270 is(fetches($x), 1);
271 is(fetches($y), 1);
272 is(stores($x), 0);
273 is(stores($y), 0);
274
275 is(($x |= $y), 3);
276 is(fetches($x), 2);
277 is(fetches($y), 1);
278 is(stores($x), 1);
279 is(stores($y), 0);
280
281 is(($x &= $y), 1);
282 is(fetches($x), 2);
283 is(fetches($y), 1);
284 is(stores($x), 1);
285 is(stores($y), 0);
286
287 is(($x ^= $y), 2);
288 is(fetches($x), 2);
289 is(fetches($y), 1);
290 is(stores($x), 1);
291 is(stores($y), 0);
292
293 is(~$y, -4);
294 is(fetches($y), 1);
295 is(stores($y), 0);
296
297 } # end of use integer;
298
299 # stringwise double magic tests
300
301 tie $x, "main", "a";
302 tie $y, "main", "c";
303
304 is(($x | $y), ("a" | "c"));
305 is(fetches($x), 1);
306 is(fetches($y), 1);
307 is(stores($x), 0);
308 is(stores($y), 0);
309
310 is(($x & $y), ("a" & "c"));
311 is(fetches($x), 1);
312 is(fetches($y), 1);
313 is(stores($x), 0);
314 is(stores($y), 0);
315
316 is(($x ^ $y), ("a" ^ "c"));
317 is(fetches($x), 1);
318 is(fetches($y), 1);
319 is(stores($x), 0);
320 is(stores($y), 0);
321
322 is(($x |= $y), ("a" | "c"));
323 is(fetches($x), 2);
324 is(fetches($y), 1);
325 is(stores($x), 1);
326 is(stores($y), 0);
327
328 is(($x &= $y), ("a" & "c"));
329 is(fetches($x), 2);
330 is(fetches($y), 1);
331 is(stores($x), 1);
332 is(stores($y), 0);
333
334 is(($x ^= $y), ("a" ^ "c"));
335 is(fetches($x), 2);
336 is(fetches($y), 1);
337 is(stores($x), 1);
338 is(stores($y), 0);
339
340 is(~~$y, "c");
341 is(fetches($y), 1);
342 is(stores($y), 0);
343
344 $a = "\0\x{100}"; chop($a);
345 ok(utf8::is_utf8($a)); # make sure UTF8 flag is still there
346 $a = ~$a;
347 is($a, "\xFF", "~ works with utf-8");
348
349 # [rt.perl.org 33003]
350 # This would cause a segfault without malloc wrap
351 SKIP: {
352   skip "No malloc wrap checks" unless $Config::Config{usemallocwrap};
353   like( runperl(prog => 'eval q($#a>>=1); print 1'), qr/^1\n?/ );
354 }
355
356 # [perl #37616] Bug in &= (string) and/or m//
357 {
358     $a = "aa";
359     $a &= "a";
360     ok($a =~ /a+$/, 'ASCII "a" is NUL-terminated');
361
362     $b = "bb\x{100}";
363     $b &= "b";
364     ok($b =~ /b+$/, 'Unicode "b" is NUL-terminated');
365 }
366
367 {
368     $a = chr(0x101) x 0x101;
369     $b = chr(0x0FF) x 0x0FF;
370
371     $c = $a | $b;
372     is($c, chr(0x1FF) x 0xFF . chr(0x101) x 2);
373
374     $c = $b | $a;
375     is($c, chr(0x1FF) x 0xFF . chr(0x101) x 2);
376
377     $c = $a & $b;
378     is($c, chr(0x001) x 0x0FF);
379
380     $c = $b & $a;
381     is($c, chr(0x001) x 0x0FF);
382
383     $c = $a ^ $b;
384     is($c, chr(0x1FE) x 0x0FF . chr(0x101) x 2);
385
386     $c = $b ^ $a;
387     is($c, chr(0x1FE) x 0x0FF . chr(0x101) x 2);
388 }
389
390 {
391     $a = chr(0x101) x 0x101;
392     $b = chr(0x0FF) x 0x0FF;
393
394     $a |= $b;
395     is($a, chr(0x1FF) x 0xFF . chr(0x101) x 2);
396 }
397
398 {
399     $a = chr(0x101) x 0x101;
400     $b = chr(0x0FF) x 0x0FF;
401
402     $b |= $a;
403     is($b, chr(0x1FF) x 0xFF . chr(0x101) x 2);
404 }
405
406 {
407     $a = chr(0x101) x 0x101;
408     $b = chr(0x0FF) x 0x0FF;
409
410     $a &= $b;
411     is($a, chr(0x001) x 0x0FF);
412 }
413
414 {
415     $a = chr(0x101) x 0x101;
416     $b = chr(0x0FF) x 0x0FF;
417
418     $b &= $a;
419     is($b, chr(0x001) x 0x0FF);
420 }
421
422 {
423     $a = chr(0x101) x 0x101;
424     $b = chr(0x0FF) x 0x0FF;
425
426     $a ^= $b;
427     is($a, chr(0x1FE) x 0x0FF . chr(0x101) x 2);
428 }
429
430 {
431     $a = chr(0x101) x 0x101;
432     $b = chr(0x0FF) x 0x0FF;
433
434     $b ^= $a;
435     is($b, chr(0x1FE) x 0x0FF . chr(0x101) x 2);
436 }
437
438
439 # New string- and number-specific bitwise ops
440 {
441   use feature "bitwise";
442   no warnings "experimental::bitwise";
443   is "22" & "66", 2,    'numeric & with strings';
444   is "22" | "66", 86,   'numeric | with strings';
445   is "22" ^ "66", 84,   'numeric ^ with strings';
446   is ~"22" & 0xff, 233, 'numeric ~ with string';
447   is 22 &. 66, 22,     '&. with numbers';
448   is 22 |. 66, 66,     '|. with numbers';
449   is 22 ^. 66, "\4\4", '^. with numbers';
450   if ($::IS_EBCDIC) {
451     # ord('2') is 0xF2 on EBCDIC
452     is ~.22, "\x0d\x0d", '~. with number';
453   }
454   else {
455     # ord('2') is 0x32 on ASCII
456     is ~.22, "\xcd\xcd", '~. with number';
457   }
458   $_ = "22";
459   is $_ &= "66", 2,  'numeric &= with strings';
460   $_ = "22";
461   is $_ |= "66", 86, 'numeric |= with strings';
462   $_ = "22";
463   is $_ ^= "66", 84, 'numeric ^= with strings';
464   $_ = 22;
465   is $_ &.= 66, 22,     '&.= with numbers';
466   $_ = 22;
467   is $_ |.= 66, 66,     '|.= with numbers';
468   $_ = 22;
469   is $_ ^.= 66, "\4\4", '^.= with numbers';
470
471  # signed vs. unsigned
472  ok ((~0 > 0 && do { use integer; ~0 } == -1));
473
474  my $bits = 0;
475  for (my $i = ~0; $i; $i >>= 1) { ++$bits; }
476  my $cusp = 1 << ($bits - 1);
477
478  ok (($cusp & -1) > 0 && do { use integer; $cusp & -1 } < 0);
479  ok (($cusp | 1) > 0 && do { use integer; $cusp | 1 } < 0);
480  ok (($cusp ^ 1) > 0 && do { use integer; $cusp ^ 1 } < 0);
481  ok ((1 << ($bits - 1)) == $cusp &&
482      do { use integer; 1 << ($bits - 1) } == -$cusp);
483  ok (($cusp >> 1) == ($cusp / 2) &&
484     do { use integer; abs($cusp >> 1) } == ($cusp / 2));
485 }
486
487 # ref tests
488
489 my %res;
490
491 for my $str ("x", "\x{100}") {
492     for my $chr (qw/S A H G X ( * F/) {
493         for my $op (qw/| & ^/) {
494             my $co = ord $chr;
495             my $so = ord $str;
496             $res{"$chr$op$str"} = eval qq/chr($co $op $so)/;
497         }
498     }
499     $res{"undef|$str"} = $str;
500     $res{"undef&$str"} = "";
501     $res{"undef^$str"} = $str;
502 }
503
504 sub PVBM () { "X" }
505 1 if index "foo", PVBM;
506
507 my $warn = 0;
508 local $^W = 1;
509 local $SIG{__WARN__} = sub { $warn++ };
510
511 sub is_first {
512     my ($got, $orig, $op, $str, $name) = @_;
513     is(substr($got, 0, 1), $res{"$orig$op$str"}, $name);
514 }
515
516 for (
517     # [object to test, first char of stringification, name]
518     [undef,             "undef",    "undef"         ],
519     [\1,                "S",        "scalar ref"    ],
520     [[],                "A",        "array ref"     ],
521     [{},                "H",        "hash ref"      ],
522     [qr/x/,             "(",        "qr//"          ],
523     [*foo,              "*",        "glob"          ],
524     [\*foo,             "G",        "glob ref"      ],
525     [PVBM,              "X",        "PVBM"          ],
526     [\PVBM,             "S",        "PVBM ref"      ],
527     [bless([], "Foo"),  "F",        "object"        ],
528 ) {
529     my ($val, $orig, $type) = @$_;
530
531     for (["x", "string"], ["\x{100}", "utf8"]) {
532         my ($str, $desc) = @$_;
533
534         $warn = 0;
535
536         is_first($val | $str, $orig, "|", $str, "$type | $desc");
537         is_first($val & $str, $orig, "&", $str, "$type & $desc");
538         is_first($val ^ $str, $orig, "^", $str, "$type ^ $desc");
539
540         is_first($str | $val, $orig, "|", $str, "$desc | $type");
541         is_first($str & $val, $orig, "&", $str, "$desc & $type");
542         is_first($str ^ $val, $orig, "^", $str, "$desc ^ $type");
543
544         my $new;
545         ($new = $val) |= $str;
546         is_first($new, $orig, "|", $str, "$type |= $desc");
547         ($new = $val) &= $str;
548         is_first($new, $orig, "&", $str, "$type &= $desc");
549         ($new = $val) ^= $str;
550         is_first($new, $orig, "^", $str, "$type ^= $desc");
551
552         ($new = $str) |= $val;
553         is_first($new, $orig, "|", $str, "$desc |= $type");
554         ($new = $str) &= $val;
555         is_first($new, $orig, "&", $str, "$desc &= $type");
556         ($new = $str) ^= $val;
557         is_first($new, $orig, "^", $str, "$desc ^= $type");
558
559         if ($orig eq "undef") {
560             # undef |= and undef ^= don't warn
561             is($warn, 10, "no duplicate warnings");
562         }
563         else {
564             is($warn, 0, "no warnings");
565         }
566     }
567 }
568
569 my $strval;
570
571 {
572     package Bar;
573     use overload q/""/ => sub { $strval };
574
575     package Baz;
576     use overload q/|/ => sub { "y" };
577 }
578
579 ok(!eval { 1 if bless([], "Bar") | "x"; 1 },"string overload can't use |");
580 like($@, qr/no method found/,               "correct error");
581 is(eval { bless([], "Baz") | "x" }, "y",    "| overload works");
582
583 my $obj = bless [], "Bar";
584 $strval = "x";
585 eval { $obj |= "Q" };
586 $strval = "z";
587 is("$obj", "z", "|= doesn't break string overload");
588
589 # [perl #29070]
590 $^A .= new version ~$_ for eval sprintf('"\\x%02x"', 0xff - ord("1")),
591                            $::IS_EBCDIC ? v13 : v205, # 255 - ord('2')
592                            eval sprintf('"\\x%02x"', 0xff - ord("3"));
593 is $^A, "123", '~v0 clears vstring magic on retval';
594
595 {
596     my $w = $Config::Config{ivsize} * 8;
597
598     fail("unexpected w $w") unless $w == 32 || $w == 64;
599
600     is(1 << 1, 2, "UV 1 left shift 1");
601     is(1 >> 1, 0, "UV 1 right shift 1");
602
603     is(0x7b << -4, 0x007, "UV left negative shift == right shift");
604     is(0x7b >> -4, 0x7b0, "UV right negative shift == left shift");
605
606     is(0x7b <<  0, 0x07b, "UV left  zero shift == identity");
607     is(0x7b >>  0, 0x07b, "UV right zero shift == identity");
608
609     is(0x0 << -1, 0x0, "zero left  negative shift == zero");
610     is(0x0 >> -1, 0x0, "zero right negative shift == zero");
611
612     cmp_ok(1 << $w - 1, '==', 2 ** ($w - 1), # not is() because NV stringify.
613        "UV left $w - 1 shift == 2 ** ($w - 1)");
614     is(1 << $w,     0, "UV left shift $w     == zero");
615     is(1 << $w + 1, 0, "UV left shift $w + 1 == zero");
616
617     is(1 >> $w - 1, 0, "UV right shift $w - 1 == zero");
618     is(1 >> $w,     0, "UV right shift $w     == zero");
619     is(1 >> $w + 1, 0, "UV right shift $w + 1 == zero");
620
621     # Negative shiftees get promoted to UVs before shifting.  This is
622     # not necessarily the ideal behavior, but that is what is happening.
623     if ($w == 64) {
624         no warnings "portable";
625         no warnings "overflow"; # prevent compile-time warning for ivsize=4
626         is(-1 << 1, 0xFFFF_FFFF_FFFF_FFFE,
627            "neg UV (sic) left shift  = 0xFF..E");
628         is(-1 >> 1, 0x7FFF_FFFF_FFFF_FFFF,
629            "neg UV (sic) right right = 0x7F..F");
630     } elsif ($w == 32) {
631         no warnings "portable";
632         is(-1 << 1, 0xFFFF_FFFE, "neg left shift  == 0xFF..E");
633         is(-1 >> 1, 0x7FFF_FFFF, "neg right right == 0x7F..F");
634     }
635
636     {
637         # 'use integer' means use IVs instead of UVs.
638         use integer;
639
640         # No surprises here.
641         is(1 << 1, 2, "IV 1 left shift 1  == 2");
642         is(1 >> 1, 0, "IV 1 right shift 1 == 0");
643
644         # The left overshift should behave like without 'use integer',
645         # that is, return zero.
646         is(1 << $w,     0, "IV 1 left shift $w     == 0");
647         is(1 << $w + 1, 0, "IV 1 left shift $w + 1 == 0");
648         is(-1 << $w,     0, "IV -1 left shift $w     == 0");
649         is(-1 << $w + 1, 0, "IV -1 left shift $w + 1 == 0");
650
651         # Even for negative IVs, left shift is multiplication.
652         # But right shift should display the stuckiness to -1.
653         is(-1 <<      1, -2, "IV -1 left shift       1 == -2");
654         is(-1 >>      1, -1, "IV -1 right shift      1 == -1");
655
656         # As for UVs, negative shifting means the reverse shift.
657         is(-1 <<     -1, -1, "IV -1 left shift      -1 == -1");
658         is(-1 >>     -1, -2, "IV -1 right shift     -1 == -2");
659
660         # Test also at and around wordsize, expect stuckiness to -1.
661         is(-1 >> $w - 1, -1, "IV -1 right shift $w - 1 == -1");
662         is(-1 >> $w,     -1, "IV -1 right shift $w     == -1");
663         is(-1 >> $w + 1, -1, "IV -1 right shift $w + 1 == -1");
664     }
665 }