CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC c CVS Info c $Date: 2005/01/10 21:55:52 $ c $Revision: 1.2 $ c $RCSfile: util_cray.f,v $ c $Name: rel_5 $ C C Following are software versions of the leading zero and popcount C functions needed for those architectures without these features. C It also contains versions of the timing routines. The timing C routines most likely will need to be modified for each C architecture. C C Contents: C INITPC - Popcount table initialization C POPCNT - Popcount function C INITLZ - Leading zero table initialization C LEADZ - Leading zero function C WALL - Wall Clock timer function C CPUTIME - CPU timer function C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC C C SUBROUTINE INITPC Cc Uncomment this routine for machines without popcnt hardware. Cc This routine initializes a 2^16 array to contain the popcount Cc of each index. Then the popcount of a 64 bit number can be Cc performed with four table look-ups. C C IMPLICIT INTEGER (A-Z) C COMMON /POPS/POPS(0:65535) C INTEGER POPS2(0:255) C INTEGER POPS3(0:15) C Cc POPS3 contains the popcount of 4 bit indices C DATA POPS3/0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4/ C Cc Generate array POPS2 to contain the popcount of 8 bit indices C DO 10 I = 0,15 C DO 10 J = 0,15 C POPS2(I*16+J) = POPS3(I) + POPS3(J) C 10 CONTINUE C Cc Finally, generate array POPS to contain the popcount of 16 bit indices C DO 20 I = 0,255 C DO 20 J = 0,255 C POPS(I*256+J) = POPS2(I) + POPS2(J) C 20 CONTINUE C RETURN C END C C C FUNCTION POPCNT(IVAL) Cc Uncomment this routine for machines without popcnt hardware. Cc This routine uses the array initialized in INITPC to find the Cc popcount of a 64-bit number. C C IMPLICIT INTEGER (A-Z) Cc Version for 64-bit words C COMMON /POPS/POPS(0:65535) C C POPCNT = POPS(IAND(65535,IVAL)) + C & POPS(IAND(65535,ISHFT(IVAL,16))) + C & POPS(IAND(65535,ISHFT(IVAL,32))) + C & POPS(IAND(65535,ISHFT(IVAL,48))) C C RETURN C END C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC C C SUBROUTINE INITLZ Cc Uncomment this routine for machines without leadz hardware. Cc This routine initializes a 2^16 array to contain the position of Cc the leading zero of each index. This is used in the LEADZ Cc subroutine which follows. C C IMPLICIT INTEGER (A-Z) C COMMON /LZCNT/LZCNT(0:65535) C C LZCNT(0) = 16 C LZCNT(1) = 15 C DO 20 I = 2,16 C DO 10 J = 2**(i-1),2**I-1 C LZCNT(J) = 16-I C 10 CONTINUE C 20 CONTINUE C RETURN C END C C C FUNCTION LEADZ(IVAL) Cc Uncomment this routine for machines without leadz hardware. Cc This routine uses the array initialized in INITLZ to find the Cc leading zero in the first non-zero double byte. C C IMPLICIT INTEGER (A-Z) Cc Version for 64-bit words C COMMON /LZCNT/LZCNT(0:65535) C IF (IVAL .GE. ISHFT(1,49)) THEN C LEADZ = LZCNT(ISHFT(IVAL,-48)) C ELSE IF (IVAL .GE. ISHFT(1,33)) THEN C LEADZ = 16 + LZCNT(IAND(65535,ISHFT(IVAL,-32))) C ELSE IF (IVAL .GT. 65535) THEN C LEADZ = 32 + LZCNT(IAND(65535,ISHFT(IVAL,-16))) C ELSE C LEADZ = 48 + LZCNT(IAND(65535,IVAL)) C END IF C RETURN C END FUNCTION WALL() cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc c c Computes the amount of wall clock time that has elapsed. c c Make suitable changes to provide access to wall clock time c on architecture being used. c ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc C--CVS variable declaration TYPE CVS sequence character( 160 ) string integer stringend END TYPE CVS C--CVS initilaize variables TYPE( CVS ),save :: CVS_INFO = $ CVS("BMARKGRP $Date: 2005/01/10 21:55:52 $ $Revision: 1.2 $" // $ "$RCSfile: util_cray.f,v $ $Name: rel_5 $", 0) WALL = SECONDR() RETURN END FUNCTION CPUTIME() cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc c c Computes the amount of cpu time that has elapsed. c c Make suitable changes to provide access to cpu time on c architecture being used. c cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc CPUTIME = SECOND() RETURN END