Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use popcnt intrinsic for bitcount #1011

Merged
merged 2 commits into from
Oct 1, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/framework/MOM_checksums.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1849,20 +1849,12 @@ end subroutine chksum_error
!> Does a bitcount of a number by first casting to an integer and then using BTEST
!! to check bit by bit
integer function bitcount(x)
real :: x !< Number to be bitcount
real, intent(in) :: x !< Number to be bitcount

! Local variables
integer(kind(x)) :: y !< Store the integer representation of the memory used by x
integer :: bit

bitcount = 0
y = transfer(x,y)

! Fortran standard says that bit indexing start at 0
do bit = 0, bit_size(y)-1
if (BTEST(y,bit)) bitcount = bitcount+1
enddo
integer, parameter :: xk = kind(x) !< Kind type of x

! NOTE: Assumes that reals and integers of kind=xk are the same size
bitcount = popcnt(transfer(x, 1_xk))
end function bitcount

end module MOM_checksums