blob: 92dd5a15739f17bb2f55a83e5c4c1e1a706e41a2 [file] [log] [blame]
Summer Qinf24dbb52020-07-23 14:53:54 +08001/*
2 * Copyright (c) 2020, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include "crt_impl_private.h"
9
10void *memset(void *s, int c, size_t n)
11{
12 union tfm_mem_addr_t p_mem;
13 uint32_t quad_pattern;
14
15 p_mem.p_byte = (uint8_t *)s;
16 quad_pattern = (((uint8_t)c) << 24) | (((uint8_t)c) << 16) |
17 (((uint8_t)c) << 8) | ((uint8_t)c);
18
19 while (n && (p_mem.uint_addr & (sizeof(uint32_t) - 1))) {
20 *p_mem.p_byte++ = (uint8_t)c;
21 n--;
22 }
23
24 while (n >= sizeof(uint32_t)) {
25 *p_mem.p_qbyte++ = quad_pattern;
26 n -= sizeof(uint32_t);
27 }
28
29 while (n--) {
30 *p_mem.p_byte++ = (uint8_t)c;
31 }
32
33 return s;
34}