string-fza.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Basic zero byte detection. Generic C version.
  2. Copyright (C) 2023-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _STRING_FZA_H
  16. #define _STRING_FZA_H 1
  17. #include <string-misc.h>
  18. #include <string-optype.h>
  19. /* The CMPBGE instruction creates a bit mask rather than a byte mask.
  20. However, if we narrow find_t to either 'int' or 'uint8_t', we get
  21. unnecessary truncation instructions from the 'unsigned long' type
  22. returned by __builtin_alpha_cmpbge. */
  23. typedef op_t find_t;
  24. static __always_inline find_t
  25. find_zero_all (op_t x)
  26. {
  27. return __builtin_alpha_cmpbge (0, x);
  28. }
  29. static __always_inline find_t
  30. find_eq_all (op_t x1, op_t x2)
  31. {
  32. return find_zero_all (x1 ^ x2);
  33. }
  34. static __always_inline find_t
  35. find_zero_eq_all (op_t x1, op_t x2)
  36. {
  37. return find_zero_all (x1) | find_zero_all (x1 ^ x2);
  38. }
  39. static __always_inline find_t
  40. find_zero_ne_all (op_t x1, op_t x2)
  41. {
  42. return find_zero_all (x1) | (find_zero_all (x1 ^ x2) ^ 0xff);
  43. }
  44. /* Define the "inexact" versions in terms of the exact versions. */
  45. #define find_zero_low find_zero_all
  46. #define find_eq_low find_eq_all
  47. #define find_zero_eq_low find_zero_eq_all
  48. #endif /* _STRING_FZA_H */