dbcsr_unpack_i8_2i4 Subroutine

public subroutine dbcsr_unpack_i8_2i4(merged, array_upper, array_lower)

Splits an array of int8 values into two int4 arrays.

Arguments

Type IntentOptional Attributes Name
integer(kind=int_8), intent(in), DIMENSION(:) :: merged

array of merged values

integer(kind=int_4), intent(out), DIMENSION(:) :: array_upper

array to fill with the upper bytes of the merged values array to fill with the lower bytes of the merged values

integer(kind=int_4), intent(out), DIMENSION(:) :: array_lower

array to fill with the upper bytes of the merged values array to fill with the lower bytes of the merged values


Source Code

   SUBROUTINE dbcsr_unpack_i8_2i4(merged, array_upper, array_lower)
      !! Splits an array of int8 values into two int4 arrays.

      INTEGER(KIND=int_8), DIMENSION(:), INTENT(IN)      :: merged
         !! array of merged values
      INTEGER(KIND=int_4), DIMENSION(:), INTENT(OUT)     :: array_upper, array_lower
         !! array to fill with the upper bytes of the merged values
         !! array to fill with the lower bytes of the merged values

      INTEGER(KIND=int_8), PARAMETER                     :: lmask8 = 4294967295_int_8

      INTEGER                                            :: i

!
!   ---------------------------------------------------------------------------
! Lmask is used to filter in the lower 4 bytes and so its lower 32 bits are
! set to 1: lmask8 = 2^32-1.
! Umask is used to filter in the higher 4 bytes and so its higher 32 bits
! are set to 1: umask8 = 2^32-1 << 32
!lmask8 = 4294967295 ! 2^32-1
!umask8 = 18446744069414584320 ! (2^32-1) * 2^32 = (2^64-1)-(2^32-1)

      DO i = 1, SIZE(merged)
         array_upper(i) = INT(ISHFT(merged(i), -32), KIND=int_4)
         array_lower(i) = INT(IAND(merged(i), lmask8), KIND=int_4)
      END DO
   END SUBROUTINE dbcsr_unpack_i8_2i4