xref: /aosp_15_r20/external/cronet/third_party/boringssl/src/gen/bcm/bn-armv8-apple.S (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1// This file is generated from a similarly-named Perl script in the BoringSSL
2// source tree. Do not edit by hand.
3
4#include <openssl/asm_base.h>
5
6#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_AARCH64) && defined(__APPLE__)
7#include <openssl/arm_arch.h>
8
9.text
10
11// BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
12//                       size_t num);
13
14.globl	_bn_add_words
15.private_extern	_bn_add_words
16.align	4
17_bn_add_words:
18	AARCH64_VALID_CALL_TARGET
19	# Clear the carry flag.
20	cmn	xzr, xzr
21
22	# aarch64 can load two registers at a time, so we do two loop iterations at
23	# at a time. Split x3 = 2 * x8 + x3. This allows loop
24	# operations to use CBNZ without clobbering the carry flag.
25	lsr	x8, x3, #1
26	and	x3, x3, #1
27
28	cbz	x8, Ladd_tail
29Ladd_loop:
30	ldp	x4, x5, [x1], #16
31	ldp	x6, x7, [x2], #16
32	sub	x8, x8, #1
33	adcs	x4, x4, x6
34	adcs	x5, x5, x7
35	stp	x4, x5, [x0], #16
36	cbnz	x8, Ladd_loop
37
38Ladd_tail:
39	cbz	x3, Ladd_exit
40	ldr	x4, [x1], #8
41	ldr	x6, [x2], #8
42	adcs	x4, x4, x6
43	str	x4, [x0], #8
44
45Ladd_exit:
46	cset	x0, cs
47	ret
48
49
50// BN_ULONG bn_sub_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
51//                       size_t num);
52
53.globl	_bn_sub_words
54.private_extern	_bn_sub_words
55.align	4
56_bn_sub_words:
57	AARCH64_VALID_CALL_TARGET
58	# Set the carry flag. Arm's borrow bit is flipped from the carry flag,
59	# so we want C = 1 here.
60	cmp	xzr, xzr
61
62	# aarch64 can load two registers at a time, so we do two loop iterations at
63	# at a time. Split x3 = 2 * x8 + x3. This allows loop
64	# operations to use CBNZ without clobbering the carry flag.
65	lsr	x8, x3, #1
66	and	x3, x3, #1
67
68	cbz	x8, Lsub_tail
69Lsub_loop:
70	ldp	x4, x5, [x1], #16
71	ldp	x6, x7, [x2], #16
72	sub	x8, x8, #1
73	sbcs	x4, x4, x6
74	sbcs	x5, x5, x7
75	stp	x4, x5, [x0], #16
76	cbnz	x8, Lsub_loop
77
78Lsub_tail:
79	cbz	x3, Lsub_exit
80	ldr	x4, [x1], #8
81	ldr	x6, [x2], #8
82	sbcs	x4, x4, x6
83	str	x4, [x0], #8
84
85Lsub_exit:
86	cset	x0, cc
87	ret
88
89#endif  // !OPENSSL_NO_ASM && defined(OPENSSL_AARCH64) && defined(__APPLE__)
90