diff options
author | Alistair Delva <adelva@google.com> | 2021-02-16 21:01:22 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-02-16 21:01:22 +0000 |
commit | efb2826bb8160e2d8e0fcec85133a7468484f9fd (patch) | |
tree | 37a21c69306801ee7cdda5167a30896c8740155b /lib/libc/memset.c | |
parent | b00a71fc312c9781fa6f404dccfb55b062b2ccac (diff) | |
parent | faa476c0caaa598afa5a6109d17102db5fe35ec6 (diff) | |
download | platform_external_arm-trusted-firmware-master.tar.gz platform_external_arm-trusted-firmware-master.tar.bz2 platform_external_arm-trusted-firmware-master.zip |
Merge branch 'aosp/upstream-master' into HEAD am: faa476c0caHEADandroid-s-beta-5android-s-beta-4android-s-beta-3android-s-beta-2android-s-beta-1mastermain-cg-testing-releaseandroid-s-beta-5android-s-beta-4
Original change: https://android-review.googlesource.com/c/platform/external/arm-trusted-firmware/+/1589611
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: I3a25534ceed4f8e188510641080d8b8ed49b8f62
Diffstat (limited to 'lib/libc/memset.c')
-rw-r--r-- | lib/libc/memset.c | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/lib/libc/memset.c b/lib/libc/memset.c index d8007d8e9..f9dd4c5db 100644 --- a/lib/libc/memset.c +++ b/lib/libc/memset.c @@ -1,18 +1,48 @@ /* - * Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ #include <stddef.h> #include <string.h> +#include <stdint.h> void *memset(void *dst, int val, size_t count) { char *ptr = dst; + uint64_t *ptr64; + uint64_t fill = (unsigned char)val; - while (count--) + /* Simplify code below by making sure we write at least one byte. */ + if (count == 0) { + return dst; + } + + /* Handle the first part, until the pointer becomes 64-bit aligned. */ + while (((uintptr_t)ptr & 7)) { + *ptr++ = val; + if (--count == 0) { + return dst; + } + } + + /* Duplicate the fill byte to the rest of the 64-bit word. */ + fill |= fill << 8; + fill |= fill << 16; + fill |= fill << 32; + + /* Use 64-bit writes for as long as possible. */ + ptr64 = (void *)ptr; + for (; count >= 8; count -= 8) { + *ptr64++ = fill; + } + + /* Handle the remaining part byte-per-byte. */ + ptr = (void *)ptr64; + while (count--) { *ptr++ = val; + } return dst; } |