1 DDI_FFS(9F)              Kernel Functions for Drivers              DDI_FFS(9F)
   2 
   3 NAME
   4      ddi_ffs, ddi_ffsll, ddi_fls, ddi_flsll - find first (last) bit set in a
   5      long (long) integer
   6 
   7 SYNOPSIS
   8      #include <sys/conf.h>
   9      #include <sys/ddi.h>
  10      #include <sys/sunddi.h>
  11 
  12      int
  13      ddi_ffs(long mask);
  14 
  15      int
  16      ddi_fls(long mask);
  17 
  18      int
  19      ddi_ffs(long long mask);
  20 
  21      int
  22      ddi_fls(long long mask);
  23 
  24 INTERFACE LEVEL
  25      Solaris DDI specific (Solaris DDI).
  26 
  27 PARAMETERS
  28      mask          A 32-bit or 64-bit argument value to search through.
  29 
  30 DESCRIPTION
  31      The functions ddi_ffs() and ddi_ffsll() take their argument and return
  32      the shift count that the first (least significant) bit set in the
  33      argument corresponds to.  The functions ddi_fls() and ddi_flsll() do the
  34      same, only they returns the shift count for the last (most significant)
  35      bit set in the argument.  ddi_ffs() and ddi_fls() operate on 32-bit
  36      values, while ddi_ffsll() and ddi_flsll() operate on 64-bit values.
  37 
  38 CONTEXT
  39      These functions can be called from user, interrupt, or kernel context.
  40 
  41 RETURN VALUES
  42      0             No bits are set in mask.
  43 
  44      N             Bit N is the least significant (ddi_ffs(), ddi_ffsll()) or
  45                    most significant (ddi_fls(), ddi_flsll()) bit set in mask.
  46                    Bits are numbered from 1 to 32 or 64, with bit 1 being the
  47                    least significant bit position and bit 32 or 64 the most
  48                    significant position, depending on the variant of the
  49                    functions used.
  50 
  51 SEE ALSO
  52      Writing Device Drivers
  53 
  54 illumos                          July 14, 2017                         illumos