]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - string/aarch64/__mtag_tag_zero_region.S
Import Arm Optimized Routines v21.02
[FreeBSD/FreeBSD.git] / string / aarch64 / __mtag_tag_zero_region.S
1 /*
2  * __mtag_tag_zero_region - tag memory and fill it with zero bytes
3  *
4  * Copyright (c) 2021, Arm Limited.
5  * SPDX-License-Identifier: MIT
6  */
7
8 /* Assumptions:
9  *
10  * ARMv8-a, AArch64, MTE, LP64 ABI.
11  *
12  * Interface contract:
13  * Address is 16 byte aligned and size is multiple of 16.
14  * Returns the passed pointer.
15  * The memory region may remain untagged if tagging is not enabled.
16  */
17
18 #include "../asmdefs.h"
19
20 #if __ARM_FEATURE_MEMORY_TAGGING
21
22 #define dstin   x0
23 #define count   x1
24 #define dst     x2
25 #define dstend  x3
26 #define tmp     x4
27 #define zva_val x4
28
29 ENTRY (__mtag_tag_zero_region)
30         PTR_ARG (0)
31         SIZE_ARG (1)
32
33         add     dstend, dstin, count
34
35         cmp     count, 96
36         b.hi    L(set_long)
37
38         tbnz    count, 6, L(set96)
39
40         /* Set 0, 16, 32, or 48 bytes.  */
41         lsr     tmp, count, 5
42         add     tmp, dstin, tmp, lsl 4
43         cbz     count, L(end)
44         stzg    dstin, [dstin]
45         stzg    dstin, [tmp]
46         stzg    dstin, [dstend, -16]
47 L(end):
48         ret
49
50         .p2align 4
51         /* Set 64..96 bytes.  Write 64 bytes from the start and
52            32 bytes from the end.  */
53 L(set96):
54         stz2g   dstin, [dstin]
55         stz2g   dstin, [dstin, 32]
56         stz2g   dstin, [dstend, -32]
57         ret
58
59         .p2align 4
60         /* Size is > 96 bytes.  */
61 L(set_long):
62         cmp     count, 160
63         b.lo    L(no_zva)
64
65 #ifndef SKIP_ZVA_CHECK
66         mrs     zva_val, dczid_el0
67         and     zva_val, zva_val, 31
68         cmp     zva_val, 4              /* ZVA size is 64 bytes.  */
69         b.ne    L(no_zva)
70 #endif
71         stz2g   dstin, [dstin]
72         stz2g   dstin, [dstin, 32]
73         bic     dst, dstin, 63
74         sub     count, dstend, dst      /* Count is now 64 too large.  */
75         sub     count, count, 128       /* Adjust count and bias for loop.  */
76
77         .p2align 4
78 L(zva_loop):
79         add     dst, dst, 64
80         dc      gzva, dst
81         subs    count, count, 64
82         b.hi    L(zva_loop)
83         stz2g   dstin, [dstend, -64]
84         stz2g   dstin, [dstend, -32]
85         ret
86
87 L(no_zva):
88         sub     dst, dstin, 32          /* Dst is biased by -32.  */
89         sub     count, count, 64        /* Adjust count for loop.  */
90 L(no_zva_loop):
91         stz2g   dstin, [dst, 32]
92         stz2g   dstin, [dst, 64]!
93         subs    count, count, 64
94         b.hi    L(no_zva_loop)
95         stz2g   dstin, [dstend, -64]
96         stz2g   dstin, [dstend, -32]
97         ret
98
99 END (__mtag_tag_zero_region)
100 #endif