| 1 | #! /bin/false | ||
| 2 | |||
| 3 | # Copyright (C) 2021-2026 Guido Flohr <guido.flohr@cantanea.com>, | ||
| 4 | # all rights reserved. | ||
| 5 | |||
| 6 | # This program is free software. It comes without any warranty, to | ||
| 7 | # the extent permitted by applicable law. You can redistribute it | ||
| 8 | # and/or modify it under the terms of the Do What the Fuck You Want | ||
| 9 | # to Public License, Version 2, as published by Sam Hocevar. See | ||
| 10 | # http://www.wtfpl.net/ for more details. | ||
| 11 | |||
| 12 | # This is a macro that is not intended to run standalone. | ||
| 13 | |||
| 14 | ## no critic (TestingAndDebugging::RequireUseStrict) | ||
| 15 | |||
| 16 | (do { | ||
| 17 | my $B = $bb & -$bb; | ||
| 18 | my $A = $B - 1 - ((($B - 1) >> 1) & 0x5555_5555_5555_5555); | ||
| 19 | my $C = ($A & 0x3333_3333_3333_3333) + (($A >> 2) & 0x3333_3333_3333_3333); | ||
| 20 | my $n = $C + ($C >> 32); | ||
| 21 | $n = ($n & 0x0f0f0f0f) + (($n >> 4) & 0x0f0f0f0f); | ||
| 22 | $n = ($n & 0xffff) + ($n >> 16); | ||
| 23 | $n = ($n & 0xff) + ($n >> 8); | ||
| 24 | }) |