1  /* string-fzi.h -- zero byte indexes.  HPPA 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 1
      21  
      22  #include <string-optype.h>
      23  #include <string-fza.h>
      24  
      25  _Static_assert (sizeof (op_t) == 4, "64-bit not supported");
      26  
      27  static __always_inline unsigned int
      28  index_first (find_t c)
      29  {
      30    unsigned int ret;
      31  
      32    /* Since we have no clz insn, direct tests of the bytes is faster
      33       than loading up the constants to do the masking.  */
      34    asm ("extrw,u,= %1,23,8,%%r0\n\t"
      35         "ldi 2,%0\n\t"
      36         "extrw,u,= %1,15,8,%%r0\n\t"
      37         "ldi 1,%0\n\t"
      38         "extrw,u,= %1,7,8,%%r0\n\t"
      39         "ldi 0,%0"
      40         : "=r"(ret) : "r"(c), "0"(3));
      41  
      42    return ret;
      43  }
      44  
      45  static __always_inline unsigned int
      46  index_last (find_t c)
      47  {
      48    unsigned int ret;
      49  
      50    /* Since we have no ctz insn, direct tests of the bytes is faster
      51       than loading up the constants to do the masking.  */
      52    asm ("extrw,u,= %1,15,8,%%r0\n\t"
      53         "ldi 1,%0\n\t"
      54         "extrw,u,= %1,23,8,%%r0\n\t"
      55         "ldi 2,%0\n\t"
      56         "extrw,u,= %1,31,8,%%r0\n\t"
      57         "ldi 3,%0"
      58         : "=r"(ret) : "r"(c), "0"(0));
      59  
      60    return ret;
      61  }
      62  
      63  #endif /* _STRING_FZI_H */