Contract integer of 64 bits into integer of 32 bits.
See On Spatial Orders and Location Codes, Stocco, LJ and Schrack, G, IEEE Transaction on Computers, vol 58, n 3, March 2009.
The resulting integer(int8/int16/int32) has only b' significant bits obtained by the following contraction:
ifbb/zx0/bb-1/zx0../b1/zx0/b0 => bb/bb-1/…/b1/b0; e.g. for(b=4,z=1):b3/0/b2/0/b1/0/b0 => b3/b2/b1/b0`.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=I8P), | intent(in) | :: | i | Input integer. |
||
| integer(kind=I2P), | intent(in) | :: | b | Number of significant bits of 'i' (2/4/8/16/32). |
||
| integer(kind=I1P), | intent(in) | :: | z | Number of zero 'i' (1/2). |
||
| integer(kind=I4P), | intent(out) | :: | c | Contracted integer. |
elemental subroutine contract(i, b, z, c)
!---------------------------------------------------------------------------------------------------------------------------------
!< Contract integer of 64 bits into integer of 32 bits.
!<
!< See *On Spatial Orders and Location Codes*, Stocco, LJ and Schrack, G, IEEE Transaction on Computers, vol 58, n 3, March 2009.
!< The resulting integer(int8/int16/int32) has only `b' significant bits obtained by the following contraction:
!< if `bb/zx0/bb-1/zx0../b1/zx0/b0 => bb/bb-1/.../b1/b0`; e.g. for `(b=4,z=1)`: `b3/0/b2/0/b1/0/b0 => b3/b2/b1/b0`.
!---------------------------------------------------------------------------------------------------------------------------------
integer(I8P), intent(in) :: i !< Input integer.
integer(I2P), intent(in) :: b !< Number of significant bits of 'i' (2/4/8/16/32).
integer(I1P), intent(in) :: z !< Number of zero 'i' (1/2).
integer(I4P), intent(out) :: c !< Contracted integer.
integer(I8P) :: d !< Temporary dilated integer.
integer(I1P) :: m !< Counter.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
d = iand(i, mask(1,z))
do m=1_I1P, int(log10(b*1._R4P)*log10_2_inv, I1P), 1_I1P !(1,5/4/3/2/1)
d = iand(ieor(d, ishft(d, -shft(m,z))), mask(m+1,z))
enddo
c = int(d, I4P)
!---------------------------------------------------------------------------------------------------------------------------------
endsubroutine contract