|
Packit |
6c4009 |
/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <string.h>
|
|
Packit |
6c4009 |
#include <memcopy.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#undef memset
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
void *
|
|
Packit |
6c4009 |
inhibit_loop_to_libcall
|
|
Packit |
6c4009 |
memset (void *dstpp, int c, size_t len)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
long int dstp = (long int) dstpp;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (len >= 8)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
size_t xlen;
|
|
Packit |
6c4009 |
op_t cccc;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
cccc = (unsigned char) c;
|
|
Packit |
6c4009 |
cccc |= cccc << 8;
|
|
Packit |
6c4009 |
cccc |= cccc << 16;
|
|
Packit |
6c4009 |
if (OPSIZ > 4)
|
|
Packit |
6c4009 |
/* Do the shift in two steps to avoid warning if long has 32 bits. */
|
|
Packit |
6c4009 |
cccc |= (cccc << 16) << 16;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* There are at least some bytes to set.
|
|
Packit |
6c4009 |
No need to test for LEN == 0 in this alignment loop. */
|
|
Packit |
6c4009 |
while (dstp % OPSIZ != 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
((byte *) dstp)[0] = c;
|
|
Packit |
6c4009 |
dstp += 1;
|
|
Packit |
6c4009 |
len -= 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Write 8 `op_t' per iteration until less than 8 `op_t' remain. */
|
|
Packit |
6c4009 |
xlen = len / (OPSIZ * 8);
|
|
Packit |
6c4009 |
while (xlen > 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
((op_t *) dstp)[0] = cccc;
|
|
Packit |
6c4009 |
((op_t *) dstp)[1] = cccc;
|
|
Packit |
6c4009 |
((op_t *) dstp)[2] = cccc;
|
|
Packit |
6c4009 |
((op_t *) dstp)[3] = cccc;
|
|
Packit |
6c4009 |
((op_t *) dstp)[4] = cccc;
|
|
Packit |
6c4009 |
((op_t *) dstp)[5] = cccc;
|
|
Packit |
6c4009 |
((op_t *) dstp)[6] = cccc;
|
|
Packit |
6c4009 |
((op_t *) dstp)[7] = cccc;
|
|
Packit |
6c4009 |
dstp += 8 * OPSIZ;
|
|
Packit |
6c4009 |
xlen -= 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
len %= OPSIZ * 8;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Write 1 `op_t' per iteration until less than OPSIZ bytes remain. */
|
|
Packit |
6c4009 |
xlen = len / OPSIZ;
|
|
Packit |
6c4009 |
while (xlen > 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
((op_t *) dstp)[0] = cccc;
|
|
Packit |
6c4009 |
dstp += OPSIZ;
|
|
Packit |
6c4009 |
xlen -= 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
len %= OPSIZ;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Write the last few bytes. */
|
|
Packit |
6c4009 |
while (len > 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
((byte *) dstp)[0] = c;
|
|
Packit |
6c4009 |
dstp += 1;
|
|
Packit |
6c4009 |
len -= 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return dstpp;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
libc_hidden_builtin_def (memset)
|