(root)/
glibc-2.38/
sysdeps/
riscv/
string-fzi.h
       1  /* Zero byte detection; indexes.  RISCV 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_RISCV_FZI_H
      20  #define _STRING_RISCV_FZI_H 1
      21  
      22  #ifdef __riscv_zbb
      23  # include <sysdeps/generic/string-fzi.h>
      24  #else
      25  /* Without bitmap clz/ctz extensions, it is faster to direct test the bits
      26     instead of calling compiler auxiliary functions.  */
      27  # include <string-optype.h>
      28  
      29  static __always_inline unsigned int
      30  index_first (find_t c)
      31  {
      32    if (c & 0x80U)
      33      return 0;
      34    if (c & 0x8000U)
      35      return 1;
      36    if (c & 0x800000U)
      37      return 2;
      38  
      39    if (sizeof (op_t) == 4)
      40      return 3;
      41  
      42    if (c & 0x80000000U)
      43      return 3;
      44    if (c & 0x8000000000UL)
      45      return 4;
      46    if (c & 0x800000000000UL)
      47      return 5;
      48    if (c & 0x80000000000000UL)
      49      return 6;
      50    return 7;
      51  }
      52  
      53  static __always_inline unsigned int
      54  index_last (find_t c)
      55  {
      56    if (sizeof (op_t) == 8)
      57      {
      58        if (c & 0x8000000000000000UL)
      59  	return 7;
      60        if (c & 0x80000000000000UL)
      61  	return 6;
      62        if (c & 0x800000000000UL)
      63  	return 5;
      64        if (c & 0x8000000000UL)
      65  	return 4;
      66      }
      67    if (c & 0x80000000U)
      68      return 3;
      69    if (c & 0x800000U)
      70      return 2;
      71    if (c & 0x8000U)
      72      return 1;
      73    return 0;
      74  }
      75  #endif
      76  
      77  #endif /* STRING_FZI_H */