1  /* Zero byte detection, boolean.  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_FZB_H
      20  #define _STRING_FZB_H 1
      21  
      22  #include <sys/cdefs.h>
      23  #include <string-optype.h>
      24  
      25  _Static_assert (sizeof (op_t) == 4, "64-bit not supported");
      26  
      27  /* Determine if any byte within X is zero.  This is a pure boolean test.  */
      28  static __always_inline _Bool
      29  has_zero (op_t x)
      30  {
      31    /* It's more useful to expose a control transfer to the compiler
      32       than to expose a proper boolean result.  */
      33    asm goto ("uxor,sbz %%r0,%0,%%r0\n\t"
      34  	    "b,n %l1" : : "r"(x) : : nbz);
      35    return 1;
      36   nbz:
      37    return 0;
      38  }
      39  
      40  /* Likewise, but for byte equality between X1 and X2.  */
      41  static __always_inline _Bool
      42  has_eq (op_t x1, op_t x2)
      43  {
      44    asm goto ("uxor,sbz %0,%1,%%r0\n\t"
      45  	    "b,n %l2" : : "r"(x1), "r"(x2) : : nbz);
      46    return 1;
      47   nbz:
      48    return 0;
      49  }
      50  
      51  /* Likewise, but for zeros in X1 and equal bytes between X1 and X2.  */
      52  static __always_inline _Bool
      53  has_zero_eq (op_t x1, op_t x2)
      54  {
      55    asm goto ("uxor,sbz %%r0,%0,%%r0\n\t"
      56  	    "uxor,nbz %0,%1,%%r0\n\t"
      57  	    "b,n %l2" : : "r"(x1), "r"(x2) : : sbz);
      58    return 0;
      59   sbz:
      60    return 1;
      61  }
      62  
      63  #endif /* _STRING_FZB_H */