| /* |
| * Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved. |
| * |
| * SPDX-License-Identifier: MIT |
| */ |
| |
| #include "aml_memset.h" |
| |
| void *memset(void *dest, int c, size_t len) |
| { |
| char *d = (char *)dest; |
| uint32_t cccc; |
| uint32_t *dw; |
| char *head; |
| char *const tail = (char *)dest + len; |
| /* Set 'body' to the last word boundary */ |
| uint32_t *const body = (uint32_t *)((uintptr_t)tail & ~3); |
| |
| c &= 0xff; /* Clear upper bits before ORing below */ |
| cccc = c | (c << 8) | (c << 16) | (c << 24); |
| |
| if ((uintptr_t)tail < (((uintptr_t)d + 3) & ~3)) |
| /* len is shorter than the first word boundary */ |
| head = tail; |
| else |
| /* Set 'head' to the first word boundary */ |
| head = (char *)(((uintptr_t)d + 3) & ~3); |
| |
| /* Copy head */ |
| while (d < head) |
| *(d++) = c; |
| |
| /* Copy body */ |
| dw = (uint32_t *)d; |
| while (dw < body) |
| *(dw++) = cccc; |
| |
| /* Copy tail */ |
| d = (char *)dw; |
| while (d < tail) |
| *(d++) = c; |
| |
| return dest; |
| } |