build-many-glibcs.py: Add openrisc hard float glibc variant
[glibc.git] / sysdeps / riscv / string-fza.h
blobee5c31317f5e726066eed43e7a0283852bbd5431
1 /* Zero byte detection; basics. RISCV version.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
19 #ifndef _RISCV_STRING_FZA_H
20 #define _RISCV_STRING_FZA_H 1
22 #if defined __riscv_zbb || defined __riscv_xtheadbb
23 /* With bitmap extension we can use orc.b to find all zero bytes. */
24 # include <string-misc.h>
25 # include <string-optype.h>
27 /* The functions return a byte mask. */
28 typedef op_t find_t;
30 /* This function returns 0xff for each byte that is zero in X. */
31 static __always_inline find_t
32 find_zero_all (op_t x)
34 find_t r;
35 #ifdef __riscv_xtheadbb
36 asm ("th.tstnbz %0, %1" : "=r" (r) : "r" (x));
37 return r;
38 #else
39 asm ("orc.b %0, %1" : "=r" (r) : "r" (x));
40 return ~r;
41 #endif
44 /* This function returns 0xff for each byte that is equal between X1 and
45 X2. */
46 static __always_inline find_t
47 find_eq_all (op_t x1, op_t x2)
49 return find_zero_all (x1 ^ x2);
52 /* Identify zero bytes in X1 or equality between X1 and X2. */
53 static __always_inline find_t
54 find_zero_eq_all (op_t x1, op_t x2)
56 return find_zero_all (x1) | find_eq_all (x1, x2);
59 /* Identify zero bytes in X1 or inequality between X1 and X2. */
60 static __always_inline find_t
61 find_zero_ne_all (op_t x1, op_t x2)
63 return find_zero_all (x1) | ~find_eq_all (x1, x2);
66 /* Define the "inexact" versions in terms of the exact versions. */
67 # define find_zero_low find_zero_all
68 # define find_eq_low find_eq_all
69 # define find_zero_eq_low find_zero_eq_all
70 #else
71 #include <sysdeps/generic/string-fza.h>
72 #endif
74 #endif /* _RISCV_STRING_FZA_H */