xref: /xnu-8796.121.2/bsd/dev/arm64/cpu_memcmp_mask.s (revision c54f35ca767986246321eb901baf8f5ff7923f6a)
1*c54f35caSApple OSS Distributions/*
2*c54f35caSApple OSS Distributions * Copyright (c) 2020-2021 Apple Inc. All rights reserved.
3*c54f35caSApple OSS Distributions *
4*c54f35caSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*c54f35caSApple OSS Distributions *
6*c54f35caSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*c54f35caSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*c54f35caSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*c54f35caSApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*c54f35caSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*c54f35caSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*c54f35caSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*c54f35caSApple OSS Distributions * terms of an Apple operating system software license agreement.
14*c54f35caSApple OSS Distributions *
15*c54f35caSApple OSS Distributions * Please obtain a copy of the License at
16*c54f35caSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*c54f35caSApple OSS Distributions *
18*c54f35caSApple OSS Distributions * The Original Code and all software distributed under the License are
19*c54f35caSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*c54f35caSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*c54f35caSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*c54f35caSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*c54f35caSApple OSS Distributions * Please see the License for the specific language governing rights and
24*c54f35caSApple OSS Distributions * limitations under the License.
25*c54f35caSApple OSS Distributions *
26*c54f35caSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*c54f35caSApple OSS Distributions */
28*c54f35caSApple OSS Distributions
29*c54f35caSApple OSS Distributions/*
30*c54f35caSApple OSS Distributions * extern int os_memcmp_mask_{16,32,48,64,80}B(const uint8_t *src1,
31*c54f35caSApple OSS Distributions *     const uint8_t *src2, const uint8_t *mask);
32*c54f35caSApple OSS Distributions *
33*c54f35caSApple OSS Distributions * This module implements fixed-length memory compare with mask routines,
34*c54f35caSApple OSS Distributions * used mainly by the Skywalk networking subsystem.  Each routine is called
35*c54f35caSApple OSS Distributions * on every packet and therefore needs to be as efficient as possible.
36*c54f35caSApple OSS Distributions *
37*c54f35caSApple OSS Distributions * ARM64 kernel mode -- just like user mode -- no longer requires saving
38*c54f35caSApple OSS Distributions * the vector registers, since it's done by the exception handler code.
39*c54f35caSApple OSS Distributions */
40*c54f35caSApple OSS Distributions
41*c54f35caSApple OSS Distributions#ifndef KERNEL
42*c54f35caSApple OSS Distributions#ifndef LIBSYSCALL_INTERFACE
43*c54f35caSApple OSS Distributions#error "LIBSYSCALL_INTERFACE not defined"
44*c54f35caSApple OSS Distributions#endif /* !LIBSYSCALL_INTERFACE */
45*c54f35caSApple OSS Distributions#endif /* !KERNEL */
46*c54f35caSApple OSS Distributions
47*c54f35caSApple OSS Distributions#define	src1		x0	/* 1st arg */
48*c54f35caSApple OSS Distributions#define	src2		x1	/* 2nd arg */
49*c54f35caSApple OSS Distributions#define	mask		x2	/* 3rd arg */
50*c54f35caSApple OSS Distributions
51*c54f35caSApple OSS Distributions/*
52*c54f35caSApple OSS Distributions *  @abstract Compare 16-byte buffers src1 against src2, applying the byte
53*c54f35caSApple OSS Distributions *  masks to input data before comparison.
54*c54f35caSApple OSS Distributions *
55*c54f35caSApple OSS Distributions *  @discussion
56*c54f35caSApple OSS Distributions *  Returns zero if the two buffers are identical after applying the byte
57*c54f35caSApple OSS Distributions *  masks, otherwise non-zero.
58*c54f35caSApple OSS Distributions *
59*c54f35caSApple OSS Distributions *  @param src1 first 16-byte input buffer
60*c54f35caSApple OSS Distributions *  @param src2 second 16-byte input buffer
61*c54f35caSApple OSS Distributions *  @param byte_mask 16-byte byte mask applied before comparision
62*c54f35caSApple OSS Distributions */
63*c54f35caSApple OSS Distributions	.globl _os_memcmp_mask_16B
64*c54f35caSApple OSS Distributions	.text
65*c54f35caSApple OSS Distributions	.align	4
66*c54f35caSApple OSS Distributions_os_memcmp_mask_16B:
67*c54f35caSApple OSS Distributions
68*c54f35caSApple OSS Distributions	ld1.16b  {v0}, [src1]
69*c54f35caSApple OSS Distributions	ld1.16b  {v1}, [src2]
70*c54f35caSApple OSS Distributions	ld1.16b  {v2}, [mask]
71*c54f35caSApple OSS Distributions	eor.16b  v0, v0, v1
72*c54f35caSApple OSS Distributions	and.16b  v0, v0, v2
73*c54f35caSApple OSS Distributions	umaxv    b0, v0.16b
74*c54f35caSApple OSS Distributions	umov     w0, v0.s[0]
75*c54f35caSApple OSS Distributions
76*c54f35caSApple OSS Distributions	ret	lr
77*c54f35caSApple OSS Distributions
78*c54f35caSApple OSS Distributions/*
79*c54f35caSApple OSS Distributions *  @abstract Compare 32-byte buffers src1 against src2, applying the byte
80*c54f35caSApple OSS Distributions *  masks to input data before comparison.
81*c54f35caSApple OSS Distributions *
82*c54f35caSApple OSS Distributions *  @discussion
83*c54f35caSApple OSS Distributions *  Returns zero if the two buffers are identical after applying the byte
84*c54f35caSApple OSS Distributions *  masks, otherwise non-zero.
85*c54f35caSApple OSS Distributions *
86*c54f35caSApple OSS Distributions *  @param src1 first 32-byte input buffer
87*c54f35caSApple OSS Distributions *  @param src2 second 32-byte input buffer
88*c54f35caSApple OSS Distributions *  @param byte_mask 32-byte byte mask applied before comparision
89*c54f35caSApple OSS Distributions */
90*c54f35caSApple OSS Distributions	.globl _os_memcmp_mask_32B
91*c54f35caSApple OSS Distributions	.text
92*c54f35caSApple OSS Distributions	.align	4
93*c54f35caSApple OSS Distributions_os_memcmp_mask_32B:
94*c54f35caSApple OSS Distributions
95*c54f35caSApple OSS Distributions	ld1.16b  {v0, v1}, [src1]
96*c54f35caSApple OSS Distributions	ld1.16b  {v2, v3}, [src2]
97*c54f35caSApple OSS Distributions	ld1.16b  {v4, v5}, [mask]
98*c54f35caSApple OSS Distributions	eor.16b  v0, v0, v2
99*c54f35caSApple OSS Distributions	eor.16b  v1, v1, v3
100*c54f35caSApple OSS Distributions	and.16b  v0, v0, v4
101*c54f35caSApple OSS Distributions	and.16b  v1, v1, v5
102*c54f35caSApple OSS Distributions	orr.16b  v0, v0, v1
103*c54f35caSApple OSS Distributions	umaxv    b0, v0.16b
104*c54f35caSApple OSS Distributions	umov     w0, v0.s[0]
105*c54f35caSApple OSS Distributions
106*c54f35caSApple OSS Distributions	ret	lr
107*c54f35caSApple OSS Distributions
108*c54f35caSApple OSS Distributions/*
109*c54f35caSApple OSS Distributions *  @abstract Compare 48-byte buffers src1 against src2, applying the byte
110*c54f35caSApple OSS Distributions *  masks to input data before comparison.
111*c54f35caSApple OSS Distributions *
112*c54f35caSApple OSS Distributions *  @discussion
113*c54f35caSApple OSS Distributions *  Returns zero if the two buffers are identical after applying the byte
114*c54f35caSApple OSS Distributions *  masks, otherwise non-zero.
115*c54f35caSApple OSS Distributions *
116*c54f35caSApple OSS Distributions *  @param src1 first 48-byte input buffer
117*c54f35caSApple OSS Distributions *  @param src2 second 48-byte input buffer
118*c54f35caSApple OSS Distributions *  @param byte_mask 48-byte byte mask applied before comparision
119*c54f35caSApple OSS Distributions */
120*c54f35caSApple OSS Distributions	.globl _os_memcmp_mask_48B
121*c54f35caSApple OSS Distributions	.text
122*c54f35caSApple OSS Distributions	.align	4
123*c54f35caSApple OSS Distributions_os_memcmp_mask_48B:
124*c54f35caSApple OSS Distributions
125*c54f35caSApple OSS Distributions	ld1.16b  {v0, v1, v2}, [src1]
126*c54f35caSApple OSS Distributions	ld1.16b  {v3, v4, v5}, [src2]
127*c54f35caSApple OSS Distributions	ld1.16b  {v16, v17, v18}, [mask]
128*c54f35caSApple OSS Distributions	eor.16b  v0, v0, v3
129*c54f35caSApple OSS Distributions	eor.16b  v1, v1, v4
130*c54f35caSApple OSS Distributions	eor.16b  v2, v2, v5
131*c54f35caSApple OSS Distributions	and.16b  v0, v0, v16
132*c54f35caSApple OSS Distributions	and.16b  v1, v1, v17
133*c54f35caSApple OSS Distributions	and.16b  v2, v2, v18
134*c54f35caSApple OSS Distributions	orr.16b  v0, v0, v1
135*c54f35caSApple OSS Distributions	orr.16b  v0, v0, v2
136*c54f35caSApple OSS Distributions	umaxv    b0, v0.16b
137*c54f35caSApple OSS Distributions	umov     w0, v0.s[0]
138*c54f35caSApple OSS Distributions
139*c54f35caSApple OSS Distributions	ret	lr
140*c54f35caSApple OSS Distributions
141*c54f35caSApple OSS Distributions/*
142*c54f35caSApple OSS Distributions *  @abstract Compare 64-byte buffers src1 against src2, applying the byte
143*c54f35caSApple OSS Distributions *  masks to input data before comparison.
144*c54f35caSApple OSS Distributions *
145*c54f35caSApple OSS Distributions *  @discussion
146*c54f35caSApple OSS Distributions *  Returns zero if the two buffers are identical after applying the byte
147*c54f35caSApple OSS Distributions *  masks, otherwise non-zero.
148*c54f35caSApple OSS Distributions *
149*c54f35caSApple OSS Distributions *  @param src1 first 64-byte input buffer
150*c54f35caSApple OSS Distributions *  @param src2 second 64-byte input buffer
151*c54f35caSApple OSS Distributions *  @param byte_mask 64-byte byte mask applied before comparision
152*c54f35caSApple OSS Distributions */
153*c54f35caSApple OSS Distributions	.globl _os_memcmp_mask_64B
154*c54f35caSApple OSS Distributions	.text
155*c54f35caSApple OSS Distributions	.align	4
156*c54f35caSApple OSS Distributions_os_memcmp_mask_64B:
157*c54f35caSApple OSS Distributions
158*c54f35caSApple OSS Distributions	ld1.16b  {v0, v1, v2, v3}, [src1]
159*c54f35caSApple OSS Distributions	ld1.16b  {v4, v5, v6, v7}, [src2]
160*c54f35caSApple OSS Distributions	ld1.16b  {v16, v17, v18, v19}, [mask]
161*c54f35caSApple OSS Distributions	eor.16b  v0, v0, v4
162*c54f35caSApple OSS Distributions	eor.16b  v1, v1, v5
163*c54f35caSApple OSS Distributions	eor.16b  v2, v2, v6
164*c54f35caSApple OSS Distributions	eor.16b  v3, v3, v7
165*c54f35caSApple OSS Distributions	and.16b  v0, v0, v16
166*c54f35caSApple OSS Distributions	and.16b  v1, v1, v17
167*c54f35caSApple OSS Distributions	and.16b  v2, v2, v18
168*c54f35caSApple OSS Distributions	and.16b  v3, v3, v19
169*c54f35caSApple OSS Distributions	orr.16b  v0, v0, v1
170*c54f35caSApple OSS Distributions	orr.16b  v2, v2, v3
171*c54f35caSApple OSS Distributions	orr.16b  v0, v0, v2
172*c54f35caSApple OSS Distributions	umaxv    b0, v0.16b
173*c54f35caSApple OSS Distributions	umov     w0, v0.s[0]
174*c54f35caSApple OSS Distributions
175*c54f35caSApple OSS Distributions	ret	lr
176*c54f35caSApple OSS Distributions
177*c54f35caSApple OSS Distributions/*
178*c54f35caSApple OSS Distributions *  @abstract Compare 80-byte buffers src1 against src2, applying the byte
179*c54f35caSApple OSS Distributions *  masks to input data before comparison.
180*c54f35caSApple OSS Distributions *
181*c54f35caSApple OSS Distributions *  @discussion
182*c54f35caSApple OSS Distributions *  Returns zero if the two buffers are identical after applying the byte
183*c54f35caSApple OSS Distributions *  masks, otherwise non-zero.
184*c54f35caSApple OSS Distributions *
185*c54f35caSApple OSS Distributions *  @param src1 first 80-byte input buffer
186*c54f35caSApple OSS Distributions *  @param src2 second 80-byte input buffer
187*c54f35caSApple OSS Distributions *  @param byte_mask 80-byte byte mask applied before comparision
188*c54f35caSApple OSS Distributions */
189*c54f35caSApple OSS Distributions	.globl _os_memcmp_mask_80B
190*c54f35caSApple OSS Distributions	.text
191*c54f35caSApple OSS Distributions	.align	4
192*c54f35caSApple OSS Distributions_os_memcmp_mask_80B:
193*c54f35caSApple OSS Distributions
194*c54f35caSApple OSS Distributions	ld1.16b  {v0, v1, v2, v3}, [src1], #64
195*c54f35caSApple OSS Distributions	ld1.16b  {v4}, [src1]
196*c54f35caSApple OSS Distributions	ld1.16b  {v16, v17, v18, v19}, [src2], #64
197*c54f35caSApple OSS Distributions	ld1.16b  {v20}, [src2]
198*c54f35caSApple OSS Distributions	ld1.16b  {v21, v22, v23, v24}, [mask], #64
199*c54f35caSApple OSS Distributions	ld1.16b  {v25}, [mask]
200*c54f35caSApple OSS Distributions	eor.16b  v0, v0, v16
201*c54f35caSApple OSS Distributions	eor.16b  v1, v1, v17
202*c54f35caSApple OSS Distributions	eor.16b  v2, v2, v18
203*c54f35caSApple OSS Distributions	eor.16b  v3, v3, v19
204*c54f35caSApple OSS Distributions	eor.16b  v4, v4, v20
205*c54f35caSApple OSS Distributions	and.16b  v0, v0, v21
206*c54f35caSApple OSS Distributions	and.16b  v1, v1, v22
207*c54f35caSApple OSS Distributions	and.16b  v2, v2, v23
208*c54f35caSApple OSS Distributions	and.16b  v3, v3, v24
209*c54f35caSApple OSS Distributions	and.16b  v4, v4, v25
210*c54f35caSApple OSS Distributions	orr.16b  v0, v0, v1
211*c54f35caSApple OSS Distributions	orr.16b  v2, v2, v3
212*c54f35caSApple OSS Distributions	orr.16b  v0, v0, v2
213*c54f35caSApple OSS Distributions	orr.16b  v0, v0, v4
214*c54f35caSApple OSS Distributions	umaxv    b0, v0.16b
215*c54f35caSApple OSS Distributions	umov     w0, v0.s[0]
216*c54f35caSApple OSS Distributions
217*c54f35caSApple OSS Distributions	ret	lr
218