leadz

Date:

09-12-2012

NAME

_leadz, _leadz32, _leadz64, LEADZ - Count the number of leading 0 bits

SYNOPSIS

C Synopsis

#include <intrinsics.h>

long _leadz(unsigned long i);
long _leadz32(unsigned int i);
long _leadz64(unsigned long i);

Fortran Synopsis

INTEGER FUNCTION LEADZ ( [I=]I )
  INTEGER I

IMPLEMENTATION

Cray Linux Environment (CLE)

STANDARDS

C extension

Fortran extension

DESCRIPTION

These intrinsic functions count the number of leading 0 bits in i.

C

Use the leadz32 intrinsic on 32-bit integers and leadz and leadz64 on 64-bit integers.

The compiler generates inline code to produce the result.

Fortran

LEADZ accepts argument i, which is a boolean, integer, real, or Cray pointer value. Argument i cannot be declared as REAL(KIND=16).

LEADZ is an elemental function. The name of this function cannot be passed as an argument.

RETURN VALUES

C

_leadz and _leadz64 return a long.

_leadz32 returns an int.

Fortran

LEADZ returns a default integer.

EXAMPLES

The following lines of Fortran code shows the LEADZ function used with an argument of type integer. The bit pattern of the argument and the value of the result are also given. For simplicity, a 64-bit object is used:

INTEGER (KIND=8) I1, I2
I2 = LEADZ(I1)

-----------------------------------------------------------------
| 0 | 0 | 0 | 0 | 0 | 1 | 1 | . . . | 1 | 1 | 1 | 0 | 0 | 1 | 0 |
-----------------------------------------------------------------
                                I1

LEADZ returns 5 for integer variable I2.

SEE ALSO

For a complete list of C intrinsic functions, see the Cray C and C++ Reference Manual.