(root)/
glibc-2.38/
sysdeps/
alpha/
string-fzi.h
       1  /* string-fzi.h -- zero byte detection; indices.  Alpha version.
       2     Copyright (C) 2023 Free Software Foundation, Inc.
       3     This file is part of the GNU C Library.
       4  
       5     The GNU C Library is free software; you can redistribute it and/or
       6     modify it under the terms of the GNU Lesser General Public
       7     License as published by the Free Software Foundation; either
       8     version 2.1 of the License, or (at your option) any later version.
       9  
      10     The GNU C Library is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13     Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public
      16     License along with the GNU C Library; if not, see
      17     <http://www.gnu.org/licenses/>.  */
      18  
      19  #ifndef _STRING_FZI_H
      20  #define _STRING_FZI_H
      21  
      22  #include <stdint.h>
      23  #include <string-optype.h>
      24  #include <string-fza.h>
      25  
      26  /* Note that since CMPBGE creates a bit mask rather than a byte mask,
      27     we cannot simply provide a target-specific string-fza.h.  */
      28  
      29  /* A subroutine for the index_zero functions.  Given a bitmask C,
      30     return the index of the first bit set in memory order.  */
      31  static __always_inline unsigned int
      32  index_first (find_t c)
      33  {
      34  #ifdef __alpha_cix__
      35    return __builtin_ctzl (c);
      36  #else
      37    c = c & -c;
      38    return (c & 0xf0 ? 4 : 0) + (c & 0xcc ? 2 : 0) + (c & 0xaa ? 1 : 0);
      39  #endif
      40  }
      41  
      42  /* Similarly, but return the (memory order) index of the last bit
      43     that is non-zero.  Note that only the least 8 bits may be nonzero.  */
      44  
      45  static __always_inline unsigned int
      46  index_last (find_t x)
      47  {
      48  #ifdef __alpha_cix__
      49    return __builtin_clzl (x) ^ 63;
      50  #else
      51    unsigned r = 0;
      52    if (x & 0xf0)
      53      r += 4;
      54    if (x & (0xc << r))
      55      r += 2;
      56    if (x & (0x2 << r))
      57      r += 1;
      58    return r;
      59  #endif
      60  }
      61  
      62  #endif /* _STRING_FZI_H */