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