"(1 << $firstbit)" seems to be a constant. Extract it from the loop and it should be faster.
You could remove the loop completely by (in the case of 32 bit) checking the high-bit, then shifting for $y, then or-ing with $FFFFFFFF shifted left 32-$y
In reply to Re: Implementing a signed/sign-propagating right bitwise shift
by jethro
in thread Implementing a signed/sign-propagating right bitwise shift
by LonelyPilgrim
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |