116 lines · plain
1/*2 * memset - fill memory with a constant byte3 *4 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5 * See https://llvm.org/LICENSE.txt for license information.6 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7 */8 9/* Assumptions:10 *11 * ARMv8-a, AArch64, Advanced SIMD, unaligned accesses.12 *13 */14 15#include "../asmdefs.h"16 17#define dstin x018#define val x119#define valw w120#define count x221#define dst x322#define dstend x423#define zva_val x524 25ENTRY (__memset_aarch64)26 27 dup v0.16B, valw28 add dstend, dstin, count29 30 cmp count, 9631 b.hi L(set_long)32 cmp count, 1633 b.hs L(set_medium)34 mov val, v0.D[0]35 36 /* Set 0..15 bytes. */37 tbz count, 3, 1f38 str val, [dstin]39 str val, [dstend, -8]40 ret41 nop421: tbz count, 2, 2f43 str valw, [dstin]44 str valw, [dstend, -4]45 ret462: cbz count, 3f47 strb valw, [dstin]48 tbz count, 1, 3f49 strh valw, [dstend, -2]503: ret51 52 /* Set 17..96 bytes. */53L(set_medium):54 str q0, [dstin]55 tbnz count, 6, L(set96)56 str q0, [dstend, -16]57 tbz count, 5, 1f58 str q0, [dstin, 16]59 str q0, [dstend, -32]601: ret61 62 .p2align 463 /* Set 64..96 bytes. Write 64 bytes from the start and64 32 bytes from the end. */65L(set96):66 str q0, [dstin, 16]67 stp q0, q0, [dstin, 32]68 stp q0, q0, [dstend, -32]69 ret70 71 .p2align 472L(set_long):73 and valw, valw, 25574 bic dst, dstin, 1575 str q0, [dstin]76 cmp count, 16077 ccmp valw, 0, 0, hs78 b.ne L(no_zva)79 80#ifndef SKIP_ZVA_CHECK81 mrs zva_val, dczid_el082 and zva_val, zva_val, 3183 cmp zva_val, 4 /* ZVA size is 64 bytes. */84 b.ne L(no_zva)85#endif86 str q0, [dst, 16]87 stp q0, q0, [dst, 32]88 bic dst, dst, 6389 sub count, dstend, dst /* Count is now 64 too large. */90 sub count, count, 128 /* Adjust count and bias for loop. */91 92 .p2align 493L(zva_loop):94 add dst, dst, 6495 dc zva, dst96 subs count, count, 6497 b.hi L(zva_loop)98 stp q0, q0, [dstend, -64]99 stp q0, q0, [dstend, -32]100 ret101 102L(no_zva):103 sub count, dstend, dst /* Count is 16 too large. */104 sub dst, dst, 16 /* Dst is biased by -32. */105 sub count, count, 64 + 16 /* Adjust count and bias for loop. */106L(no_zva_loop):107 stp q0, q0, [dst, 32]108 stp q0, q0, [dst, 64]!109 subs count, count, 64110 b.hi L(no_zva_loop)111 stp q0, q0, [dstend, -64]112 stp q0, q0, [dstend, -32]113 ret114 115END (__memset_aarch64)116