|
Packit |
6c4009 |
/* _memcopy.c -- subroutines for memory copy functions.
|
|
Packit |
6c4009 |
Copyright (C) 1991-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
Contributed by Torbjorn Granlund (tege@sics.se).
|
|
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 |
/* BE VERY CAREFUL IF YOU CHANGE THIS CODE...! */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <stddef.h>
|
|
Packit |
6c4009 |
#include <memcopy.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* _wordcopy_fwd_aligned -- Copy block beginning at SRCP to
|
|
Packit |
6c4009 |
block beginning at DSTP with LEN `op_t' words (not LEN bytes!).
|
|
Packit |
6c4009 |
Both SRCP and DSTP should be aligned for memory operations on `op_t's. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifndef WORDCOPY_FWD_ALIGNED
|
|
Packit |
6c4009 |
# define WORDCOPY_FWD_ALIGNED _wordcopy_fwd_aligned
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
void
|
|
Packit |
6c4009 |
WORDCOPY_FWD_ALIGNED (long int dstp, long int srcp, size_t len)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
op_t a0, a1;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (len & 1)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
((op_t *) dstp)[0] = ((op_t *) srcp)[0];
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (len == 1)
|
|
Packit |
6c4009 |
return;
|
|
Packit |
6c4009 |
srcp += OPSIZ;
|
|
Packit |
6c4009 |
dstp += OPSIZ;
|
|
Packit |
6c4009 |
len -= 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
do
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
a0 = ((op_t *) srcp)[0];
|
|
Packit |
6c4009 |
a1 = ((op_t *) srcp)[1];
|
|
Packit |
6c4009 |
((op_t *) dstp)[0] = a0;
|
|
Packit |
6c4009 |
((op_t *) dstp)[1] = a1;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
srcp += 2 * OPSIZ;
|
|
Packit |
6c4009 |
dstp += 2 * OPSIZ;
|
|
Packit |
6c4009 |
len -= 2;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
while (len != 0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* _wordcopy_fwd_dest_aligned -- Copy block beginning at SRCP to
|
|
Packit |
6c4009 |
block beginning at DSTP with LEN `op_t' words (not LEN bytes!).
|
|
Packit |
6c4009 |
DSTP should be aligned for memory operations on `op_t's, but SRCP must
|
|
Packit |
6c4009 |
*not* be aligned. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifndef WORDCOPY_FWD_DEST_ALIGNED
|
|
Packit |
6c4009 |
# define WORDCOPY_FWD_DEST_ALIGNED _wordcopy_fwd_dest_aligned
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
void
|
|
Packit |
6c4009 |
WORDCOPY_FWD_DEST_ALIGNED (long int dstp, long int srcp, size_t len)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
op_t a0, a1, a2;
|
|
Packit |
6c4009 |
int sh_1, sh_2;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Calculate how to shift a word read at the memory operation
|
|
Packit |
6c4009 |
aligned srcp to make it aligned for copy. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
sh_1 = 8 * (srcp % OPSIZ);
|
|
Packit |
6c4009 |
sh_2 = 8 * OPSIZ - sh_1;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Make SRCP aligned by rounding it down to the beginning of the `op_t'
|
|
Packit |
6c4009 |
it points in the middle of. */
|
|
Packit |
6c4009 |
srcp &= -OPSIZ;
|
|
Packit |
6c4009 |
a0 = ((op_t *) srcp)[0];
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (len & 1)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
a1 = ((op_t *) srcp)[1];
|
|
Packit |
6c4009 |
((op_t *) dstp)[0] = MERGE (a0, sh_1, a1, sh_2);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (len == 1)
|
|
Packit |
6c4009 |
return;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
a0 = a1;
|
|
Packit |
6c4009 |
srcp += OPSIZ;
|
|
Packit |
6c4009 |
dstp += OPSIZ;
|
|
Packit |
6c4009 |
len -= 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
do
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
a1 = ((op_t *) srcp)[1];
|
|
Packit |
6c4009 |
a2 = ((op_t *) srcp)[2];
|
|
Packit |
6c4009 |
((op_t *) dstp)[0] = MERGE (a0, sh_1, a1, sh_2);
|
|
Packit |
6c4009 |
((op_t *) dstp)[1] = MERGE (a1, sh_1, a2, sh_2);
|
|
Packit |
6c4009 |
a0 = a2;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
srcp += 2 * OPSIZ;
|
|
Packit |
6c4009 |
dstp += 2 * OPSIZ;
|
|
Packit |
6c4009 |
len -= 2;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
while (len != 0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* _wordcopy_bwd_aligned -- Copy block finishing right before
|
|
Packit |
6c4009 |
SRCP to block finishing right before DSTP with LEN `op_t' words
|
|
Packit |
6c4009 |
(not LEN bytes!). Both SRCP and DSTP should be aligned for memory
|
|
Packit |
6c4009 |
operations on `op_t's. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifndef WORDCOPY_BWD_ALIGNED
|
|
Packit |
6c4009 |
# define WORDCOPY_BWD_ALIGNED _wordcopy_bwd_aligned
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
void
|
|
Packit |
6c4009 |
WORDCOPY_BWD_ALIGNED (long int dstp, long int srcp, size_t len)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
op_t a0, a1;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (len & 1)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
srcp -= OPSIZ;
|
|
Packit |
6c4009 |
dstp -= OPSIZ;
|
|
Packit |
6c4009 |
((op_t *) dstp)[0] = ((op_t *) srcp)[0];
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (len == 1)
|
|
Packit |
6c4009 |
return;
|
|
Packit |
6c4009 |
len -= 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
do
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
srcp -= 2 * OPSIZ;
|
|
Packit |
6c4009 |
dstp -= 2 * OPSIZ;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
a1 = ((op_t *) srcp)[1];
|
|
Packit |
6c4009 |
a0 = ((op_t *) srcp)[0];
|
|
Packit |
6c4009 |
((op_t *) dstp)[1] = a1;
|
|
Packit |
6c4009 |
((op_t *) dstp)[0] = a0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
len -= 2;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
while (len != 0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* _wordcopy_bwd_dest_aligned -- Copy block finishing right
|
|
Packit |
6c4009 |
before SRCP to block finishing right before DSTP with LEN `op_t'
|
|
Packit |
6c4009 |
words (not LEN bytes!). DSTP should be aligned for memory
|
|
Packit |
6c4009 |
operations on `op_t', but SRCP must *not* be aligned. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifndef WORDCOPY_BWD_DEST_ALIGNED
|
|
Packit |
6c4009 |
# define WORDCOPY_BWD_DEST_ALIGNED _wordcopy_bwd_dest_aligned
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
void
|
|
Packit |
6c4009 |
WORDCOPY_BWD_DEST_ALIGNED (long int dstp, long int srcp, size_t len)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
op_t a0, a1, a2;
|
|
Packit |
6c4009 |
int sh_1, sh_2;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Calculate how to shift a word read at the memory operation
|
|
Packit |
6c4009 |
aligned srcp to make it aligned for copy. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
sh_1 = 8 * (srcp % OPSIZ);
|
|
Packit |
6c4009 |
sh_2 = 8 * OPSIZ - sh_1;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Make srcp aligned by rounding it down to the beginning of the op_t
|
|
Packit |
6c4009 |
it points in the middle of. */
|
|
Packit |
6c4009 |
srcp &= -OPSIZ;
|
|
Packit |
6c4009 |
a2 = ((op_t *) srcp)[0];
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (len & 1)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
srcp -= OPSIZ;
|
|
Packit |
6c4009 |
dstp -= OPSIZ;
|
|
Packit |
6c4009 |
a1 = ((op_t *) srcp)[0];
|
|
Packit |
6c4009 |
((op_t *) dstp)[0] = MERGE (a1, sh_1, a2, sh_2);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (len == 1)
|
|
Packit |
6c4009 |
return;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
a2 = a1;
|
|
Packit |
6c4009 |
len -= 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
do
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
srcp -= 2 * OPSIZ;
|
|
Packit |
6c4009 |
dstp -= 2 * OPSIZ;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
a1 = ((op_t *) srcp)[1];
|
|
Packit |
6c4009 |
a0 = ((op_t *) srcp)[0];
|
|
Packit |
6c4009 |
((op_t *) dstp)[1] = MERGE (a1, sh_1, a2, sh_2);
|
|
Packit |
6c4009 |
((op_t *) dstp)[0] = MERGE (a0, sh_1, a1, sh_2);
|
|
Packit |
6c4009 |
a2 = a0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
len -= 2;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
while (len != 0);
|
|
Packit |
6c4009 |
}
|