Snap for 6183524 from 1072d97f750b3d5836f18a2cf57537944724d856 to r-keystone-qcom-release

Change-Id: Ic4366ea22c3c979b7387ca8c807f7e2e4330cd29
diff --git a/Android.bp b/Android.bp
index 5628f64..dd88ec4 100755
--- a/Android.bp
+++ b/Android.bp
@@ -5,21 +5,29 @@
         "-Werror",
         "-Wno-unused-parameter",
         "-O2",
+        "-ffp-contract=fast",
+        "-fno-math-errno",
+
+        // bionic configuration.
+
         // We're actually implementing bionic here, so we don't want <math.h>
         // to try to be helpful by renaming long double routines.
         "-D__BIONIC_LP32_USE_LONG_DOUBLE",
-        "-DWANT_ROUNDING=0",
-        "-DWANT_ERRNO=0",
-        "-DWANT_VMATH=0",
         "-DFLT_EVAL_METHOD=0",
-        "-ffp-contract=fast",
-        "-fno-math-errno",
+
+        // arm-optimized-routines configuration.
+
+        // BSD libm doesn't set errno, and bionic was based on the BSDs.
+        // https://github.com/ARM-software/optimized-routines/issues/16#issuecomment-572009659
+        "-DWANT_ERRNO=0",
+        // TODO: we may want the vector code in future, but it's not ready yet.
+        "-DWANT_VMATH=0",
     ],
     local_include_dirs: ["math/include"],
 }
 
 cc_library {
-    name: "libarm-optimized-routines",
+    name: "libarm-optimized-routines-math",
     defaults: ["arm-optimized-routines-defaults"],
     recovery_available: true,
     native_bridge_supported: true,
diff --git a/METADATA b/METADATA
index 287d51d..73c448b 100644
--- a/METADATA
+++ b/METADATA
@@ -9,11 +9,11 @@
     type: GIT
     value: "https://github.com/ARM-software/optimized-routines.git"
   }
-  version: "1fd2aaae0fcb13f3a53be8de50b68d269145a0a4"
+  version: "3377796fe24ff1d5396609205426402678208eb1"
   license_type: NOTICE
   last_upgrade_date {
     year: 2019
-    month: 11
-    day: 25
+    month: 12
+    day: 26
   }
 }
diff --git a/Makefile b/Makefile
index c661b33..dee6134 100644
--- a/Makefile
+++ b/Makefile
@@ -30,8 +30,7 @@
 
 -include config.mk
 
-include $(srcdir)/math/Dir.mk
-include $(srcdir)/string/Dir.mk
+$(foreach sub,$(SUBS),$(eval include $(srcdir)/$(sub)/Dir.mk))
 
 # Required targets of subproject foo:
 #   all-foo
diff --git a/README b/README
index 32747ec..76fe018 100644
--- a/README
+++ b/README
@@ -1,11 +1,13 @@
 Arm Optimized Routines
 ----------------------
 
-This repository contains implementations of math library functions
+This repository contains implementations of library functions
 provided by Arm under MIT License (See LICENSE). Contributions
 to this project are accepted, but the terms will need negotiation (so
 relicensing and copyright assignment to the FSF is possible later).
 
+Regular quarterly releases are tagged as vYY.MM (e.g. v19.11).
+
 Source code layout:
 
 build/          - build directory (created by make).
diff --git a/string/aarch64/memcpy.S b/string/aarch64/memcpy.S
index 8ae0e76..1aad88e 100644
--- a/string/aarch64/memcpy.S
+++ b/string/aarch64/memcpy.S
@@ -11,6 +11,8 @@
  *
  */
 
+#include "../asmdefs.h"
+
 #define dstin	x0
 #define src	x1
 #define count	x2
@@ -38,68 +40,53 @@
 #define H_h	srcend
 #define tmp1	x14
 
-#define L(l) .L ## l
+/* This implementation of memcpy correctly handles overlaps, therefore
+   __memmove_aarch64 aliases to __memcpy_aarch64. By moving the src and
+   dst buffer overlap check from the start of memmove code to the
+   beginning of large copy code, the overhead of combining memcpy
+   and memmove implementations is negligible.
 
-	.macro def_fn f p2align=0
-	.text
-	.p2align \p2align
-	.global \f
-	.type \f, %function
-\f:
-	.endm
+   Copies are split into 3 main cases: small copies of up to 16 bytes,
+   medium copies of 17..128 bytes which are fully unrolled, and large
+   copies (moves).
 
-/* Copies are split into 3 main cases: small copies of up to 32 bytes,
-   medium copies of 33..128 bytes which are fully unrolled. Large copies
-   of more than 128 bytes align the destination and use an unrolled loop
+   Large forward moves align the destination and use an unrolled loop
    processing 64 bytes per iteration.
-   In order to share code with memmove, small and medium copies read all
-   data before writing, allowing any kind of overlap. So small, medium
-   and large backwards memmoves are handled by falling through into memcpy.
-   Overlapping large forward memmoves use a loop that copies backwards.
+
+   Large backward moves align dstend and use an unrolled loop processing
+   64 bytes per iteration.
 */
 
-def_fn __memcpy_aarch64 p2align=6
-	prfm	PLDL1KEEP, [src]
+ENTRY (__memcpy_aarch64)
+ENTRY_ALIAS (__memmove_aarch64)
 	add	srcend, src, count
 	add	dstend, dstin, count
-	cmp	count, 32
-	b.ls	L(copy32)
+	cmp	count, 16
+	b.ls	L(copy16)
 	cmp	count, 128
-	b.hi	L(copy_long)
+	b.hi	L(move_long)
 
-	/* Medium copies: 33..128 bytes.  */
+	/* Medium copies: 17..128 bytes.  */
 	ldp	A_l, A_h, [src]
-	ldp	B_l, B_h, [src, 16]
-	ldp	C_l, C_h, [srcend, -32]
 	ldp	D_l, D_h, [srcend, -16]
-	cmp	count, 64
-	b.hi	L(copy128)
+	cmp	count, 32
+	b.hi	L(copy33_128)
 	stp	A_l, A_h, [dstin]
-	stp	B_l, B_h, [dstin, 16]
-	stp	C_l, C_h, [dstend, -32]
 	stp	D_l, D_h, [dstend, -16]
 	ret
 
 	.p2align 4
-	/* Small copies: 0..32 bytes.  */
-L(copy32):
-	/* 16-32 bytes.  */
-	cmp	count, 16
-	b.lo	1f
-	ldp	A_l, A_h, [src]
-	ldp	B_l, B_h, [srcend, -16]
-	stp	A_l, A_h, [dstin]
-	stp	B_l, B_h, [dstend, -16]
-	ret
-	.p2align 4
-1:
+	/* Small copies: 0..16 bytes.  */
+L(copy16):
 	/* 8-15 bytes.  */
-	tbz	count, 3, 1f
+	cmp	count, 8
+	b.lo	1f
 	ldr	A_l, [src]
 	ldr	A_h, [srcend, -8]
 	str	A_l, [dstin]
 	str	A_h, [dstend, -8]
 	ret
+
 	.p2align 4
 1:
 	/* 4-7 bytes.  */
@@ -110,6 +97,7 @@
 	str	A_hw, [dstend, -4]
 	ret
 
+	.p2align 4
 	/* Copy 0..3 bytes.  Use a branchless sequence that copies the same
 	   byte 3 times if count==1, or the 2nd byte twice if count==2.  */
 1:
@@ -124,33 +112,51 @@
 2:	ret
 
 	.p2align 4
-	/* Copy 65..128 bytes.  Copy 64 bytes from the start and
-	   64 bytes from the end.  */
-L(copy128):
+	/* Copy 33..128 bytes.  */
+L(copy33_128):
+	ldp	B_l, B_h, [src, 16]
+	ldp	C_l, C_h, [srcend, -32]
+	cmp	count, 64
+	b.hi	L(copy65_128)
+	stp	A_l, A_h, [dstin]
+	stp	D_l, D_h, [dstend, -16]
+	stp	B_l, B_h, [dstin, 16]
+	stp	C_l, C_h, [dstend, -32]
+	ret
+
+	.p2align 4
+	/* Copy 65..128 bytes.  */
+L(copy65_128):
 	ldp	E_l, E_h, [src, 32]
 	ldp	F_l, F_h, [src, 48]
 	ldp	G_l, G_h, [srcend, -64]
 	ldp	H_l, H_h, [srcend, -48]
 	stp	A_l, A_h, [dstin]
+	stp	D_l, D_h, [dstend, -16]
 	stp	B_l, B_h, [dstin, 16]
+	stp	C_l, C_h, [dstend, -32]
 	stp	E_l, E_h, [dstin, 32]
 	stp	F_l, F_h, [dstin, 48]
 	stp	G_l, G_h, [dstend, -64]
 	stp	H_l, H_h, [dstend, -48]
-	stp	C_l, C_h, [dstend, -32]
-	stp	D_l, D_h, [dstend, -16]
 	ret
 
-	/* Align DST to 16 byte alignment so that we don't cross cache line
+	.p2align 4
+	/* Move more than 128 bytes.  */
+L(move_long):
+	sub	tmp1, dstin, src	/* Overlap check.  */
+	cbz	tmp1, L(copy0)
+	cmp	tmp1, count
+	b.lo	L(move_long_backwards)
+
+	/* Align dst to 16 byte alignment so that we don't cross cache line
 	   boundaries on both loads and stores.  There are at least 128 bytes
 	   to copy, so copy 16 bytes unaligned and then align.  The loop
 	   copies 64 bytes per iteration and prefetches one iteration ahead.  */
 
-	.p2align 4
-L(copy_long):
+	ldp	D_l, D_h, [src]
 	and	tmp1, dstin, 15
 	bic	dst, dstin, 15
-	ldp	D_l, D_h, [src]
 	sub	src, src, tmp1
 	add	count, count, tmp1	/* Count is now 16 too large.  */
 	ldp	A_l, A_h, [src, 16]
@@ -159,7 +165,8 @@
 	ldp	C_l, C_h, [src, 48]
 	ldp	D_l, D_h, [src, 64]!
 	subs	count, count, 128 + 16	/* Test and readjust count.  */
-	b.ls	L(last64)
+	b.ls	L(copy64_from_end)
+
 L(loop64):
 	stp	A_l, A_h, [dst, 16]
 	ldp	A_l, A_h, [src, 16]
@@ -175,7 +182,7 @@
 	/* Write the last full set of 64 bytes.  The remainder is at most 64
 	   bytes, so it is safe to always copy 64 bytes from the end even if
 	   there is just 1 byte left.  */
-L(last64):
+L(copy64_from_end):
 	ldp	E_l, E_h, [srcend, -64]
 	stp	A_l, A_h, [dst, 16]
 	ldp	A_l, A_h, [srcend, -48]
@@ -188,6 +195,61 @@
 	stp	A_l, A_h, [dstend, -48]
 	stp	B_l, B_h, [dstend, -32]
 	stp	C_l, C_h, [dstend, -16]
+
+L(copy0):
 	ret
 
-	.size	__memcpy_aarch64, . - __memcpy_aarch64
+	.p2align 4
+
+	/* Move more than 128 bytes where src and dst buffers overlap
+	   and dst > src.
+
+     Align dstend to 16 byte alignment so that we don't cross cache line
+	   boundaries on both loads and stores.  There are at least 128 bytes
+	   to copy, so copy 16 bytes unaligned and then align.  The loop
+	   copies 64 bytes per iteration and prefetches one iteration ahead.  */
+L(move_long_backwards):
+	ldp	D_l, D_h, [srcend, -16]
+	and	tmp1, dstend, 15
+	sub	srcend, srcend, tmp1
+	sub	count, count, tmp1
+	ldp	A_l, A_h, [srcend, -16]
+	stp	D_l, D_h, [dstend, -16]
+	ldp	B_l, B_h, [srcend, -32]
+	ldp	C_l, C_h, [srcend, -48]
+	ldp	D_l, D_h, [srcend, -64]!
+	sub	dstend, dstend, tmp1
+	subs	count, count, 128
+	b.ls	L(copy64_from_start)
+
+L(loop64_backwards):
+	stp	A_l, A_h, [dstend, -16]
+	ldp	A_l, A_h, [srcend, -16]
+	stp	B_l, B_h, [dstend, -32]
+	ldp	B_l, B_h, [srcend, -32]
+	stp	C_l, C_h, [dstend, -48]
+	ldp	C_l, C_h, [srcend, -48]
+	stp	D_l, D_h, [dstend, -64]!
+	ldp	D_l, D_h, [srcend, -64]!
+	subs	count, count, 64
+	b.hi	L(loop64_backwards)
+
+	/* Write the last full set of 64 bytes.  The remainder is at most 64
+	   bytes, so it is safe to always copy 64 bytes from the start even if
+	   there is just 1 byte left.  */
+L(copy64_from_start):
+	ldp	G_l, G_h, [src, 48]
+	stp	A_l, A_h, [dstend, -16]
+	ldp	A_l, A_h, [src, 32]
+	stp	B_l, B_h, [dstend, -32]
+	ldp	B_l, B_h, [src, 16]
+	stp	C_l, C_h, [dstend, -48]
+	ldp	C_l, C_h, [src]
+	stp	D_l, D_h, [dstend, -64]
+	stp	G_l, G_h, [dstin, 48]
+	stp	A_l, A_h, [dstin, 32]
+	stp	B_l, B_h, [dstin, 16]
+	stp	C_l, C_h, [dstin]
+	ret
+
+END (__memcpy_aarch64)
diff --git a/string/aarch64/memcpy_simd.S b/string/aarch64/memcpy_simd.S
new file mode 100644
index 0000000..fa2442f
--- /dev/null
+++ b/string/aarch64/memcpy_simd.S
@@ -0,0 +1,265 @@
+/*
+ * memcpy/memmove using SIMD registers
+ *
+ * Copyright (c) 2019, Arm Limited.
+ * SPDX-License-Identifier: MIT
+ */
+
+/* Assumptions:
+ *
+ * ARMv8-a, AArch64, unaligned accesses.
+ *
+ */
+
+#include "../asmdefs.h"
+
+#define dstin	x0
+#define src	x1
+#define count	x2
+#define dst	x3
+#define srcend	x4
+#define dstend	x5
+#define A_l	x6
+#define A_lw	w6
+#define A_h	x7
+#define A_hw	w7
+#define B_l	x8
+#define B_lw	w8
+#define B_h	x9
+#define C_l	x10
+#define C_h	x11
+#define D_l	x12
+#define D_h	x13
+#define E_l	x14
+#define E_h	x15
+#define F_l	x16
+#define F_h	x17
+#define G_l	count
+#define G_h	dst
+#define H_l	src
+#define H_h	srcend
+#define tmp1	x14
+
+#define A_q	q0
+#define B_q	q1
+#define C_q	q2
+#define D_q	q3
+#define E_q	q4
+#define F_q	q5
+#define G_q	q6
+#define H_q	q7
+
+/* This implementation of memcpy correctly handles overlaps, therefore
+   __memmove_aarch64_simd aliases to __memcpy_aarch64_simd. By moving the
+   src and dst buffer overlap check from the start of memmove code to the
+   beginning of large copy code, the overhead of combining memcpy
+   and memmove implementations is negligible.
+
+   Copies are split into 3 main cases: small copies of up to 16 bytes,
+   medium copies of 17..128 bytes which are fully unrolled, and large
+   copies (moves).
+
+   Large forward moves align the source and use an unrolled loop
+   processing 64 bytes per iteration.
+
+   Large backward moves align srcend and use an unrolled loop processing
+   64 bytes per iteration.
+*/
+
+ENTRY (__memcpy_aarch64_simd)
+ENTRY_ALIAS (__memmove_aarch64_simd)
+	add	srcend, src, count
+	add	dstend, dstin, count
+	cmp	count, 16
+	b.ls	L(copy16_simd)
+	cmp	count, 128
+	b.hi	L(move_long_simd)
+
+	/* Medium copies: 17..128 bytes.  */
+	ldr	A_q, [src]
+	ldr	D_q, [srcend, -16]
+	cmp	count, 32
+	b.hi	L(copy33_128_simd)
+	str	A_q, [dstin]
+	str	D_q, [dstend, -16]
+	ret
+
+	.p2align 4
+	/* Small copies: 0..16 bytes.  */
+L(copy16_simd):
+	/* 8-15 bytes.  */
+	cmp	count, 8
+	b.lo	1f
+	ldr	A_l, [src]
+	ldr	A_h, [srcend, -8]
+	str	A_l, [dstin]
+	str	A_h, [dstend, -8]
+	ret
+
+	.p2align 4
+1:
+	/* 4-7 bytes.  */
+	tbz	count, 2, 1f
+	ldr	A_lw, [src]
+	ldr	A_hw, [srcend, -4]
+	str	A_lw, [dstin]
+	str	A_hw, [dstend, -4]
+	ret
+
+	.p2align 4
+	/* Copy 0..3 bytes.  Use a branchless sequence that copies the same
+	   byte 3 times if count==1, or the 2nd byte twice if count==2.  */
+1:
+	cbz	count, 2f
+	lsr	tmp1, count, 1
+	ldrb	A_lw, [src]
+	ldrb	A_hw, [srcend, -1]
+	ldrb	B_lw, [src, tmp1]
+	strb	A_lw, [dstin]
+	strb	B_lw, [dstin, tmp1]
+	strb	A_hw, [dstend, -1]
+2:	ret
+
+	.p2align 4
+	/* Copy 33..128 bytes.  */
+L(copy33_128_simd):
+	ldr	B_q, [src, 16]
+	ldr	C_q, [srcend, -32]
+	cmp	count, 64
+	b.hi	L(copy65_128_simd)
+	str	A_q, [dstin]
+	str	D_q, [dstend, -16]
+	str	B_q, [dstin, 16]
+	str	C_q, [dstend, -32]
+	ret
+
+	.p2align 4
+	/* Copy 65..128 bytes.  */
+L(copy65_128_simd):
+	ldr	E_q, [src, 32]
+	ldr	F_q, [src, 48]
+	ldr	G_q, [srcend, -64]
+	ldr	H_q, [srcend, -48]
+	str	A_q, [dstin]
+	str	D_q, [dstend, -16]
+	str	B_q, [dstin, 16]
+	str	C_q, [dstend, -32]
+	str	E_q, [dstin, 32]
+	str	F_q, [dstin, 48]
+	str	G_q, [dstend, -64]
+	str	H_q, [dstend, -48]
+	ret
+
+	.p2align 4
+	/* Move more than 128 bytes.  */
+L(move_long_simd):
+	sub	tmp1, dstin, src	/* Overlap check.  */
+	cbz	tmp1, L(copy0_simd)
+	cmp	tmp1, count
+	b.lo	L(move_long_backwards_simd)
+
+	/* Align src to 16 byte alignment so that we don't cross cache line
+	   boundaries on both loads and stores.  There are at least 128 bytes
+	   to copy, so copy 16 bytes unaligned and then align.  The loop
+	   copies 64 bytes per iteration and prefetches one iteration ahead.  */
+
+	ldr	D_q, [src]
+	and	tmp1, src, 15
+	bic	src, src, 15
+	sub	dst, dstin, tmp1
+	add	count, count, tmp1	/* Count is now 16 too large.  */
+	ldr	A_q, [src, 16]
+	str	D_q, [dstin]
+	ldr	B_q, [src, 32]
+	ldr	C_q, [src, 48]
+	ldr	D_q, [src, 64]!
+	subs	count, count, 128 + 16	/* Test and readjust count.  */
+	b.ls	L(copy64_from_end_simd)
+
+L(loop64_simd):
+	str	A_q, [dst, 16]
+	ldr	A_q, [src, 16]
+	str	B_q, [dst, 32]
+	ldr	B_q, [src, 32]
+	str	C_q, [dst, 48]
+	ldr	C_q, [src, 48]
+	str	D_q, [dst, 64]!
+	ldr	D_q, [src, 64]!
+	subs	count, count, 64
+	b.hi	L(loop64_simd)
+
+	/* Write the last full set of 64 bytes.  The remainder is at most 64
+	   bytes, so it is safe to always copy 64 bytes from the end even if
+	   there is just 1 byte left.  */
+L(copy64_from_end_simd):
+	ldr	E_q, [srcend, -64]
+	str	A_q, [dst, 16]
+	ldr	A_q, [srcend, -48]
+	str	B_q, [dst, 32]
+	ldr	B_q, [srcend, -32]
+	str	C_q, [dst, 48]
+	ldr	C_q, [srcend, -16]
+	str	D_q, [dst, 64]
+	str	E_q, [dstend, -64]
+	str	A_q, [dstend, -48]
+	str	B_q, [dstend, -32]
+	str	C_q, [dstend, -16]
+
+L(copy0_simd):
+	ret
+
+	.p2align 4
+
+	/* Move more than 128 bytes where src and dst buffers overlap
+	   and dst > src.
+
+     Align srcend to 16 byte alignment so that we don't cross cache line
+	   boundaries on both loads and stores.  There are at least 128 bytes
+	   to copy, so copy 16 bytes unaligned and then align.  The loop
+	   copies 64 bytes per iteration and prefetches one iteration ahead.  */
+
+L(move_long_backwards_simd):
+	ldr	D_q, [srcend, -16]
+	and	tmp1, srcend, 15
+	sub	srcend, srcend, tmp1
+	sub	count, count, tmp1
+	ldr	A_q, [srcend, -16]
+	str	D_q, [dstend, -16]
+	ldr	B_q, [srcend, -32]
+	ldr	C_q, [srcend, -48]
+	ldr	D_q, [srcend, -64]!
+	sub	dstend, dstend, tmp1
+	subs	count, count, 128
+	b.ls	L(copy64_from_start_simd)
+
+L(loop64_backwards_simd):
+	str	A_q, [dstend, -16]
+	ldr	A_q, [srcend, -16]
+	str	B_q, [dstend, -32]
+	ldr	B_q, [srcend, -32]
+	str	C_q, [dstend, -48]
+	ldr	C_q, [srcend, -48]
+	str	D_q, [dstend, -64]!
+	ldr	D_q, [srcend, -64]!
+	subs	count, count, 64
+	b.hi	L(loop64_backwards_simd)
+
+	/* Write the last full set of 64 bytes.  The remainder is at most 64
+	   bytes, so it is safe to always copy 64 bytes from the start even if
+	   there is just 1 byte left.  */
+L(copy64_from_start_simd):
+	ldr	G_q, [src, 48]
+	str	A_q, [dstend, -16]
+	ldr	A_q, [src, 32]
+	str	B_q, [dstend, -32]
+	ldr	B_q, [src, 16]
+	str	C_q, [dstend, -48]
+	ldr	C_q, [src]
+	str	D_q, [dstend, -64]
+	str	G_q, [dstin, 48]
+	str	A_q, [dstin, 32]
+	str	B_q, [dstin, 16]
+	str	C_q, [dstin]
+	ret
+
+END (__memcpy_aarch64_simd)
diff --git a/string/aarch64/memmove.S b/string/aarch64/memmove.S
deleted file mode 100644
index 5e70f21..0000000
--- a/string/aarch64/memmove.S
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * memmove - copy memory area
- *
- * Copyright (c) 2013, Arm Limited.
- * SPDX-License-Identifier: MIT
- */
-
-/* Assumptions:
- *
- * ARMv8-a, AArch64, unaligned accesses
- */
-
-	.macro def_fn f p2align=0
-	.text
-	.p2align \p2align
-	.global \f
-	.type \f, %function
-\f:
-	.endm
-
-/* Parameters and result.  */
-#define dstin	x0
-#define src	x1
-#define count	x2
-#define srcend	x3
-#define dstend	x4
-#define tmp1	x5
-#define A_l	x6
-#define A_h	x7
-#define B_l	x8
-#define B_h	x9
-#define C_l	x10
-#define C_h	x11
-#define D_l	x12
-#define D_h	x13
-#define E_l	count
-#define E_h	tmp1
-
-/* All memmoves up to 96 bytes are done by memcpy as it supports overlaps.
-   Larger backwards copies are also handled by memcpy. The only remaining
-   case is forward large copies.  The destination is aligned, and an
-   unrolled loop processes 64 bytes per iteration.
-*/
-
-def_fn __memmove_aarch64, 6
-	sub	tmp1, dstin, src
-	cmp	count, 96
-	ccmp	tmp1, count, 2, hi
-	b.hs	__memcpy_aarch64
-
-	cbz	tmp1, 3f
-	add	dstend, dstin, count
-	add	srcend, src, count
-
-	/* Align dstend to 16 byte alignment so that we don't cross cache line
-	   boundaries on both loads and stores.	 There are at least 96 bytes
-	   to copy, so copy 16 bytes unaligned and then align.	The loop
-	   copies 64 bytes per iteration and prefetches one iteration ahead.  */
-
-	and	tmp1, dstend, 15
-	ldp	D_l, D_h, [srcend, -16]
-	sub	srcend, srcend, tmp1
-	sub	count, count, tmp1
-	ldp	A_l, A_h, [srcend, -16]
-	stp	D_l, D_h, [dstend, -16]
-	ldp	B_l, B_h, [srcend, -32]
-	ldp	C_l, C_h, [srcend, -48]
-	ldp	D_l, D_h, [srcend, -64]!
-	sub	dstend, dstend, tmp1
-	subs	count, count, 128
-	b.ls	2f
-	nop
-1:
-	stp	A_l, A_h, [dstend, -16]
-	ldp	A_l, A_h, [srcend, -16]
-	stp	B_l, B_h, [dstend, -32]
-	ldp	B_l, B_h, [srcend, -32]
-	stp	C_l, C_h, [dstend, -48]
-	ldp	C_l, C_h, [srcend, -48]
-	stp	D_l, D_h, [dstend, -64]!
-	ldp	D_l, D_h, [srcend, -64]!
-	subs	count, count, 64
-	b.hi	1b
-
-	/* Write the last full set of 64 bytes.	 The remainder is at most 64
-	   bytes, so it is safe to always copy 64 bytes from the start even if
-	   there is just 1 byte left.  */
-2:
-	ldp	E_l, E_h, [src, 48]
-	stp	A_l, A_h, [dstend, -16]
-	ldp	A_l, A_h, [src, 32]
-	stp	B_l, B_h, [dstend, -32]
-	ldp	B_l, B_h, [src, 16]
-	stp	C_l, C_h, [dstend, -48]
-	ldp	C_l, C_h, [src]
-	stp	D_l, D_h, [dstend, -64]
-	stp	E_l, E_h, [dstin, 48]
-	stp	A_l, A_h, [dstin, 32]
-	stp	B_l, B_h, [dstin, 16]
-	stp	C_l, C_h, [dstin]
-3:	ret
-
-	.size	__memmove_aarch64, . - __memmove_aarch64
diff --git a/string/asmdefs.h b/string/asmdefs.h
index 7a5bf6b..7d143a9 100644
--- a/string/asmdefs.h
+++ b/string/asmdefs.h
@@ -5,13 +5,27 @@
  * SPDX-License-Identifier: MIT
  */
 
-#define ENTRY(name)	\
+#ifndef _ASMDEFS_H
+#define _ASMDEFS_H
+
+#define ENTRY_ALIGN(name, alignment)	\
   .global name;		\
   .type name,%function;	\
-  .align 4;		\
+  .align alignment;		\
   name:			\
   .cfi_startproc;
 
+#define ENTRY(name)	ENTRY_ALIGN(name, 6)
+
+#define ENTRY_ALIAS(name)	\
+  .global name;		\
+  .type name,%function;	\
+  name:
+
 #define END(name)	\
   .cfi_endproc;		\
   .size name, .-name;
+
+#define L(l) .L ## l
+
+#endif
diff --git a/string/include/stringlib.h b/string/include/stringlib.h
index 96647cf..3f60220 100644
--- a/string/include/stringlib.h
+++ b/string/include/stringlib.h
@@ -15,7 +15,7 @@
 #if __aarch64__
 void *__memcpy_bytewise (void *__restrict, const void *__restrict, size_t);
 void *__memcpy_aarch64 (void *__restrict, const void *__restrict, size_t);
-void *__memmove_aarch64 (void *__restrict, const void *__restrict, size_t);
+void *__memmove_aarch64 (void *, const void *, size_t);
 void *__memset_aarch64 (void *, int, size_t);
 void *__memchr_aarch64 (const void *, int, size_t);
 int __memcmp_aarch64 (const void *, const void *, size_t);
@@ -26,6 +26,10 @@
 size_t __strlen_aarch64 (const char *);
 size_t __strnlen_aarch64 (const char *, size_t);
 int __strncmp_aarch64 (const char *, const char *, size_t);
+#if __ARM_NEON
+void *__memcpy_aarch64_simd (void *__restrict, const void *__restrict, size_t);
+void *__memmove_aarch64_simd (void *, const void *, size_t);
+#endif
 # if __ARM_FEATURE_SVE
 void *__memchr_aarch64_sve (const void *, int, size_t);
 int __memcmp_aarch64_sve (const void *, const void *, size_t);
diff --git a/string/memcpy.S b/string/memcpy.S
index c0f23e3..b52b603 100644
--- a/string/memcpy.S
+++ b/string/memcpy.S
@@ -7,6 +7,9 @@
 
 #if __aarch64__
 #include "aarch64/memcpy.S"
+# if __ARM_NEON
+#include "aarch64/memcpy_simd.S"
+# endif
 #elif __arm__
 #include "arm/memcpy.S"
 #endif
diff --git a/string/memmove.S b/string/memmove.S
deleted file mode 100644
index be3c7a1..0000000
--- a/string/memmove.S
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * Selected possible memmmove implementations.
- *
- * Copyright (c) 2019, Arm Limited.
- * SPDX-License-Identifier: MIT
- */
-
-#if __aarch64__
-#include "aarch64/memmove.S"
-#endif
diff --git a/string/test/memcpy.c b/string/test/memcpy.c
index a6c0e48..e31f359 100644
--- a/string/test/memcpy.c
+++ b/string/test/memcpy.c
@@ -21,6 +21,9 @@
 #if __aarch64__
 F(__memcpy_bytewise)
 F(__memcpy_aarch64)
+# if __ARM_NEON
+F(__memcpy_aarch64_simd)
+# endif
 #elif __arm__
 F(__memcpy_arm)
 #endif
diff --git a/string/test/memmove.c b/string/test/memmove.c
index c2197c6..7891b14 100644
--- a/string/test/memmove.c
+++ b/string/test/memmove.c
@@ -20,6 +20,9 @@
 F(memmove)
 #if __aarch64__
 F(__memmove_aarch64)
+# if __ARM_NEON
+F(__memmove_aarch64_simd)
+# endif
 #endif
 #undef F
 	{0, 0}