1 /* Optimized memcmp implementation for POWER10.
2 Copyright (C) 2021-2023 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 <https://www.gnu.org/licenses/>. */
21 /* TODO: Replace macros by the actual instructions when minimum binutils becomes
22 >= 2.35. This is used to keep compatibility with older versions. */
23 #define VEXTRACTBM(rt,vrb) \
30 #define LXVP(xtp,dq,ra) \
32 | ((((xtp)-32)>>1)<<(32-10)) \
37 /* Compare 32 bytes. */
38 #define COMPARE_32(vr1,vr2,offset,tail_1,tail_2)\
39 LXVP(32+vr1,offset,r3); \
40 LXVP(32+vr2,offset,r4); \
41 vcmpneb. v5,vr1+1,vr2+1; \
43 vcmpneb. v4,vr1,vr2; \
46 #define TAIL(v_res,s1,s2) \
53 /* int [r3] memcmp (const char *s1 [r3], const char *s2 [r4],
57 # define MEMCMP memcmp
60 ENTRY_TOCLESS (MEMCMP, 4)
66 /* Compare 64 bytes. This section is used for lengths <= 64 and for the last
67 bytes for larger lengths. */
76 /* Align up to 16 bytes. */
80 /* The sub. and vcmpneb. results are concatenated by the crnand in order
81 to do a single branch. It's doing a NOT(CR0.GT AND CR6.EQ) then
82 loading to CR0.LT. That means r9 is not bigger than 0 and v4 is not
86 crnand 4*cr0+lt,4*cr0+gt,4*cr6+eq
96 crnand 4*cr0+lt,4*cr0+gt,4*cr6+eq
106 crnand 4*cr0+lt,4*cr0+gt,4*cr6+eq
115 /* The contents are equal. */
120 /* Calculate how many loops to run. */
125 /* Main loop. Compares 128 bytes each loop. */
128 COMPARE_32(v0,v2,0,tail1,tail2)
129 COMPARE_32(v6,v8,32,tail3,tail4)
130 COMPARE_32(v10,v12,64,tail5,tail6)
131 COMPARE_32(v14,v16,96,tail7,tail8)
137 /* Account loop comparisons. */
141 /* Compares 64 bytes if length is still bigger than 64 bytes. */
146 COMPARE_32(v0,v2,0,tail1,tail2)
147 COMPARE_32(v6,v8,32,tail3,tail4)
178 libc_hidden_builtin_def (memcmp)
179 weak_alias (memcmp, bcmp)
180 strong_alias (memcmp, __memcmpeq)
181 libc_hidden_def (__memcmpeq)