Logical (zero-filling) right shift of a 64-bit word by n bits,
0 <= n <= 63. Written with ibits rather than ishft(x, -n) or the
Fortran 2008 shiftr for the portability reasons given in the module
documentation.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int64), | intent(in) | :: | x | |||
| integer(kind=default_int), | intent(in) | :: | n |
pure function u64_shr(x, n) result(r) !! Logical (zero-filling) right shift of a 64-bit word by `n` bits, !! `0 <= n <= 63`. Written with `ibits` rather than `ishft(x, -n)` or the !! Fortran 2008 `shiftr` for the portability reasons given in the module !! documentation. integer(int64), intent(in) :: x integer(default_int), intent(in) :: n integer(int64) :: r ! A shift of zero is handled separately rather than falling through to ! `ibits(x, 0, 64)`. That call is conforming -- F2018 16.9.105 requires ! only POS + LEN <= BIT_SIZE(I) -- but LFortran 0.65.0 returns 0 from it ! for every input, while `ibits(x, 1, 63)` is correct. ! ! test_pic_uint64's "shr by 0 is identity" is the regression test for ! this guard, not a reproducer of the defect: with the guard in place ! the offending call is never reached. To see the bug itself, call ! `ibits(x, 0, 64)` directly under LFortran. if (n <= 0_default_int) then r = x else r = ibits(x, n, 64 - n) end if end function u64_shr