1  /* Zero byte detection; basics.  ARM 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_FZA_H
      20  #define _STRING_FZA_H 1
      21  
      22  #include <string-misc.h>
      23  #include <string-optype.h>
      24  
      25  /* The functions return a byte mask.  */
      26  typedef op_t find_t;
      27  
      28  /* This function returns at least one bit set within every byte
      29     of X that is zero.  */
      30  static __always_inline find_t
      31  find_zero_all (op_t x)
      32  {
      33    /* Use unsigned saturated subtraction from 1 in each byte.
      34       That leaves 1 for every byte that was zero.  */
      35    op_t ones = repeat_bytes (0x01);
      36    op_t ret;
      37    asm ("uqsub8 %0,%1,%2" : "=r"(ret) : "r"(ones), "r"(x));
      38    return ret;
      39  }
      40  
      41  /* Identify bytes that are equal between X1 and X2.  */
      42  static __always_inline find_t
      43  find_eq_all (op_t x1, op_t x2)
      44  {
      45    return find_zero_all (x1 ^ x2);
      46  }
      47  
      48  /* Identify zero bytes in X1 or equality between X1 and X2.  */
      49  static __always_inline find_t
      50  find_zero_eq_all (op_t x1, op_t x2)
      51  {
      52    return find_zero_all (x1) | find_zero_all (x1 ^ x2);
      53  }
      54  
      55  /* Identify zero bytes in X1 or inequality between X1 and X2.  */
      56  static __always_inline find_t
      57  find_zero_ne_all (op_t x1, op_t x2)
      58  {
      59    /* Make use of the fact that we'll already have ONES in a register.  */
      60    op_t ones = repeat_bytes (0x01);
      61    return find_zero_all (x1) | (find_zero_all (x1 ^ x2) ^ ones);
      62  }
      63  
      64  /* Define the "inexact" versions in terms of the exact versions.  */
      65  #define find_zero_low		find_zero_all
      66  #define find_eq_low		find_eq_all
      67  #define find_zero_eq_low	find_zero_eq_all
      68  
      69  #endif /* _STRING_FZA_H */