Blame string/wordcopy.c

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
  switch (len % 8)
Packit 6c4009
    {
Packit 6c4009
    case 2:
Packit 6c4009
      a0 = ((op_t *) srcp)[0];
Packit 6c4009
      srcp -= 6 * OPSIZ;
Packit 6c4009
      dstp -= 7 * OPSIZ;
Packit 6c4009
      len += 6;
Packit 6c4009
      goto do1;
Packit 6c4009
    case 3:
Packit 6c4009
      a1 = ((op_t *) srcp)[0];
Packit 6c4009
      srcp -= 5 * OPSIZ;
Packit 6c4009
      dstp -= 6 * OPSIZ;
Packit 6c4009
      len += 5;
Packit 6c4009
      goto do2;
Packit 6c4009
    case 4:
Packit 6c4009
      a0 = ((op_t *) srcp)[0];
Packit 6c4009
      srcp -= 4 * OPSIZ;
Packit 6c4009
      dstp -= 5 * OPSIZ;
Packit 6c4009
      len += 4;
Packit 6c4009
      goto do3;
Packit 6c4009
    case 5:
Packit 6c4009
      a1 = ((op_t *) srcp)[0];
Packit 6c4009
      srcp -= 3 * OPSIZ;
Packit 6c4009
      dstp -= 4 * OPSIZ;
Packit 6c4009
      len += 3;
Packit 6c4009
      goto do4;
Packit 6c4009
    case 6:
Packit 6c4009
      a0 = ((op_t *) srcp)[0];
Packit 6c4009
      srcp -= 2 * OPSIZ;
Packit 6c4009
      dstp -= 3 * OPSIZ;
Packit 6c4009
      len += 2;
Packit 6c4009
      goto do5;
Packit 6c4009
    case 7:
Packit 6c4009
      a1 = ((op_t *) srcp)[0];
Packit 6c4009
      srcp -= 1 * OPSIZ;
Packit 6c4009
      dstp -= 2 * OPSIZ;
Packit 6c4009
      len += 1;
Packit 6c4009
      goto do6;
Packit 6c4009
Packit 6c4009
    case 0:
Packit 6c4009
      if (OP_T_THRES <= 3 * OPSIZ && len == 0)
Packit 6c4009
	return;
Packit 6c4009
      a0 = ((op_t *) srcp)[0];
Packit 6c4009
      srcp -= 0 * OPSIZ;
Packit 6c4009
      dstp -= 1 * OPSIZ;
Packit 6c4009
      goto do7;
Packit 6c4009
    case 1:
Packit 6c4009
      a1 = ((op_t *) srcp)[0];
Packit 6c4009
      srcp -=-1 * OPSIZ;
Packit 6c4009
      dstp -= 0 * OPSIZ;
Packit 6c4009
      len -= 1;
Packit 6c4009
      if (OP_T_THRES <= 3 * OPSIZ && len == 0)
Packit 6c4009
	goto do0;
Packit 6c4009
      goto do8;			/* No-op.  */
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  do
Packit 6c4009
    {
Packit 6c4009
    do8:
Packit 6c4009
      a0 = ((op_t *) srcp)[0];
Packit 6c4009
      ((op_t *) dstp)[0] = a1;
Packit 6c4009
    do7:
Packit 6c4009
      a1 = ((op_t *) srcp)[1];
Packit 6c4009
      ((op_t *) dstp)[1] = a0;
Packit 6c4009
    do6:
Packit 6c4009
      a0 = ((op_t *) srcp)[2];
Packit 6c4009
      ((op_t *) dstp)[2] = a1;
Packit 6c4009
    do5:
Packit 6c4009
      a1 = ((op_t *) srcp)[3];
Packit 6c4009
      ((op_t *) dstp)[3] = a0;
Packit 6c4009
    do4:
Packit 6c4009
      a0 = ((op_t *) srcp)[4];
Packit 6c4009
      ((op_t *) dstp)[4] = a1;
Packit 6c4009
    do3:
Packit 6c4009
      a1 = ((op_t *) srcp)[5];
Packit 6c4009
      ((op_t *) dstp)[5] = a0;
Packit 6c4009
    do2:
Packit 6c4009
      a0 = ((op_t *) srcp)[6];
Packit 6c4009
      ((op_t *) dstp)[6] = a1;
Packit 6c4009
    do1:
Packit 6c4009
      a1 = ((op_t *) srcp)[7];
Packit 6c4009
      ((op_t *) dstp)[7] = a0;
Packit 6c4009
Packit 6c4009
      srcp += 8 * OPSIZ;
Packit 6c4009
      dstp += 8 * OPSIZ;
Packit 6c4009
      len -= 8;
Packit 6c4009
    }
Packit 6c4009
  while (len != 0);
Packit 6c4009
Packit 6c4009
  /* This is the right position for do0.  Please don't move
Packit 6c4009
     it into the loop.  */
Packit 6c4009
 do0:
Packit 6c4009
  ((op_t *) dstp)[0] = a1;
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, a3;
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
Packit 6c4009
  switch (len % 4)
Packit 6c4009
    {
Packit 6c4009
    case 2:
Packit 6c4009
      a1 = ((op_t *) srcp)[0];
Packit 6c4009
      a2 = ((op_t *) srcp)[1];
Packit 6c4009
      srcp -= 1 * OPSIZ;
Packit 6c4009
      dstp -= 3 * OPSIZ;
Packit 6c4009
      len += 2;
Packit 6c4009
      goto do1;
Packit 6c4009
    case 3:
Packit 6c4009
      a0 = ((op_t *) srcp)[0];
Packit 6c4009
      a1 = ((op_t *) srcp)[1];
Packit 6c4009
      srcp -= 0 * OPSIZ;
Packit 6c4009
      dstp -= 2 * OPSIZ;
Packit 6c4009
      len += 1;
Packit 6c4009
      goto do2;
Packit 6c4009
    case 0:
Packit 6c4009
      if (OP_T_THRES <= 3 * OPSIZ && len == 0)
Packit 6c4009
	return;
Packit 6c4009
      a3 = ((op_t *) srcp)[0];
Packit 6c4009
      a0 = ((op_t *) srcp)[1];
Packit 6c4009
      srcp -=-1 * OPSIZ;
Packit 6c4009
      dstp -= 1 * OPSIZ;
Packit 6c4009
      len += 0;
Packit 6c4009
      goto do3;
Packit 6c4009
    case 1:
Packit 6c4009
      a2 = ((op_t *) srcp)[0];
Packit 6c4009
      a3 = ((op_t *) srcp)[1];
Packit 6c4009
      srcp -=-2 * OPSIZ;
Packit 6c4009
      dstp -= 0 * OPSIZ;
Packit 6c4009
      len -= 1;
Packit 6c4009
      if (OP_T_THRES <= 3 * OPSIZ && len == 0)
Packit 6c4009
	goto do0;
Packit 6c4009
      goto do4;			/* No-op.  */
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  do
Packit 6c4009
    {
Packit 6c4009
    do4:
Packit 6c4009
      a0 = ((op_t *) srcp)[0];
Packit 6c4009
      ((op_t *) dstp)[0] = MERGE (a2, sh_1, a3, sh_2);
Packit 6c4009
    do3:
Packit 6c4009
      a1 = ((op_t *) srcp)[1];
Packit 6c4009
      ((op_t *) dstp)[1] = MERGE (a3, sh_1, a0, sh_2);
Packit 6c4009
    do2:
Packit 6c4009
      a2 = ((op_t *) srcp)[2];
Packit 6c4009
      ((op_t *) dstp)[2] = MERGE (a0, sh_1, a1, sh_2);
Packit 6c4009
    do1:
Packit 6c4009
      a3 = ((op_t *) srcp)[3];
Packit 6c4009
      ((op_t *) dstp)[3] = MERGE (a1, sh_1, a2, sh_2);
Packit 6c4009
Packit 6c4009
      srcp += 4 * OPSIZ;
Packit 6c4009
      dstp += 4 * OPSIZ;
Packit 6c4009
      len -= 4;
Packit 6c4009
    }
Packit 6c4009
  while (len != 0);
Packit 6c4009
Packit 6c4009
  /* This is the right position for do0.  Please don't move
Packit 6c4009
     it into the loop.  */
Packit 6c4009
 do0:
Packit 6c4009
  ((op_t *) dstp)[0] = MERGE (a2, sh_1, a3, sh_2);
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
  switch (len % 8)
Packit 6c4009
    {
Packit 6c4009
    case 2:
Packit 6c4009
      srcp -= 2 * OPSIZ;
Packit 6c4009
      dstp -= 1 * OPSIZ;
Packit 6c4009
      a0 = ((op_t *) srcp)[1];
Packit 6c4009
      len += 6;
Packit 6c4009
      goto do1;
Packit 6c4009
    case 3:
Packit 6c4009
      srcp -= 3 * OPSIZ;
Packit 6c4009
      dstp -= 2 * OPSIZ;
Packit 6c4009
      a1 = ((op_t *) srcp)[2];
Packit 6c4009
      len += 5;
Packit 6c4009
      goto do2;
Packit 6c4009
    case 4:
Packit 6c4009
      srcp -= 4 * OPSIZ;
Packit 6c4009
      dstp -= 3 * OPSIZ;
Packit 6c4009
      a0 = ((op_t *) srcp)[3];
Packit 6c4009
      len += 4;
Packit 6c4009
      goto do3;
Packit 6c4009
    case 5:
Packit 6c4009
      srcp -= 5 * OPSIZ;
Packit 6c4009
      dstp -= 4 * OPSIZ;
Packit 6c4009
      a1 = ((op_t *) srcp)[4];
Packit 6c4009
      len += 3;
Packit 6c4009
      goto do4;
Packit 6c4009
    case 6:
Packit 6c4009
      srcp -= 6 * OPSIZ;
Packit 6c4009
      dstp -= 5 * OPSIZ;
Packit 6c4009
      a0 = ((op_t *) srcp)[5];
Packit 6c4009
      len += 2;
Packit 6c4009
      goto do5;
Packit 6c4009
    case 7:
Packit 6c4009
      srcp -= 7 * OPSIZ;
Packit 6c4009
      dstp -= 6 * OPSIZ;
Packit 6c4009
      a1 = ((op_t *) srcp)[6];
Packit 6c4009
      len += 1;
Packit 6c4009
      goto do6;
Packit 6c4009
Packit 6c4009
    case 0:
Packit 6c4009
      if (OP_T_THRES <= 3 * OPSIZ && len == 0)
Packit 6c4009
	return;
Packit 6c4009
      srcp -= 8 * OPSIZ;
Packit 6c4009
      dstp -= 7 * OPSIZ;
Packit 6c4009
      a0 = ((op_t *) srcp)[7];
Packit 6c4009
      goto do7;
Packit 6c4009
    case 1:
Packit 6c4009
      srcp -= 9 * OPSIZ;
Packit 6c4009
      dstp -= 8 * OPSIZ;
Packit 6c4009
      a1 = ((op_t *) srcp)[8];
Packit 6c4009
      len -= 1;
Packit 6c4009
      if (OP_T_THRES <= 3 * OPSIZ && len == 0)
Packit 6c4009
	goto do0;
Packit 6c4009
      goto do8;			/* No-op.  */
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  do
Packit 6c4009
    {
Packit 6c4009
    do8:
Packit 6c4009
      a0 = ((op_t *) srcp)[7];
Packit 6c4009
      ((op_t *) dstp)[7] = a1;
Packit 6c4009
    do7:
Packit 6c4009
      a1 = ((op_t *) srcp)[6];
Packit 6c4009
      ((op_t *) dstp)[6] = a0;
Packit 6c4009
    do6:
Packit 6c4009
      a0 = ((op_t *) srcp)[5];
Packit 6c4009
      ((op_t *) dstp)[5] = a1;
Packit 6c4009
    do5:
Packit 6c4009
      a1 = ((op_t *) srcp)[4];
Packit 6c4009
      ((op_t *) dstp)[4] = a0;
Packit 6c4009
    do4:
Packit 6c4009
      a0 = ((op_t *) srcp)[3];
Packit 6c4009
      ((op_t *) dstp)[3] = a1;
Packit 6c4009
    do3:
Packit 6c4009
      a1 = ((op_t *) srcp)[2];
Packit 6c4009
      ((op_t *) dstp)[2] = a0;
Packit 6c4009
    do2:
Packit 6c4009
      a0 = ((op_t *) srcp)[1];
Packit 6c4009
      ((op_t *) dstp)[1] = a1;
Packit 6c4009
    do1:
Packit 6c4009
      a1 = ((op_t *) srcp)[0];
Packit 6c4009
      ((op_t *) dstp)[0] = a0;
Packit 6c4009
Packit 6c4009
      srcp -= 8 * OPSIZ;
Packit 6c4009
      dstp -= 8 * OPSIZ;
Packit 6c4009
      len -= 8;
Packit 6c4009
    }
Packit 6c4009
  while (len != 0);
Packit 6c4009
Packit 6c4009
  /* This is the right position for do0.  Please don't move
Packit 6c4009
     it into the loop.  */
Packit 6c4009
 do0:
Packit 6c4009
  ((op_t *) dstp)[7] = a1;
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, a3;
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
  srcp += OPSIZ;
Packit 6c4009
Packit 6c4009
  switch (len % 4)
Packit 6c4009
    {
Packit 6c4009
    case 2:
Packit 6c4009
      srcp -= 3 * OPSIZ;
Packit 6c4009
      dstp -= 1 * OPSIZ;
Packit 6c4009
      a2 = ((op_t *) srcp)[2];
Packit 6c4009
      a1 = ((op_t *) srcp)[1];
Packit 6c4009
      len += 2;
Packit 6c4009
      goto do1;
Packit 6c4009
    case 3:
Packit 6c4009
      srcp -= 4 * OPSIZ;
Packit 6c4009
      dstp -= 2 * OPSIZ;
Packit 6c4009
      a3 = ((op_t *) srcp)[3];
Packit 6c4009
      a2 = ((op_t *) srcp)[2];
Packit 6c4009
      len += 1;
Packit 6c4009
      goto do2;
Packit 6c4009
    case 0:
Packit 6c4009
      if (OP_T_THRES <= 3 * OPSIZ && len == 0)
Packit 6c4009
	return;
Packit 6c4009
      srcp -= 5 * OPSIZ;
Packit 6c4009
      dstp -= 3 * OPSIZ;
Packit 6c4009
      a0 = ((op_t *) srcp)[4];
Packit 6c4009
      a3 = ((op_t *) srcp)[3];
Packit 6c4009
      goto do3;
Packit 6c4009
    case 1:
Packit 6c4009
      srcp -= 6 * OPSIZ;
Packit 6c4009
      dstp -= 4 * OPSIZ;
Packit 6c4009
      a1 = ((op_t *) srcp)[5];
Packit 6c4009
      a0 = ((op_t *) srcp)[4];
Packit 6c4009
      len -= 1;
Packit 6c4009
      if (OP_T_THRES <= 3 * OPSIZ && len == 0)
Packit 6c4009
	goto do0;
Packit 6c4009
      goto do4;			/* No-op.  */
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  do
Packit 6c4009
    {
Packit 6c4009
    do4:
Packit 6c4009
      a3 = ((op_t *) srcp)[3];
Packit 6c4009
      ((op_t *) dstp)[3] = MERGE (a0, sh_1, a1, sh_2);
Packit 6c4009
    do3:
Packit 6c4009
      a2 = ((op_t *) srcp)[2];
Packit 6c4009
      ((op_t *) dstp)[2] = MERGE (a3, sh_1, a0, sh_2);
Packit 6c4009
    do2:
Packit 6c4009
      a1 = ((op_t *) srcp)[1];
Packit 6c4009
      ((op_t *) dstp)[1] = MERGE (a2, sh_1, a3, sh_2);
Packit 6c4009
    do1:
Packit 6c4009
      a0 = ((op_t *) srcp)[0];
Packit 6c4009
      ((op_t *) dstp)[0] = MERGE (a1, sh_1, a2, sh_2);
Packit 6c4009
Packit 6c4009
      srcp -= 4 * OPSIZ;
Packit 6c4009
      dstp -= 4 * OPSIZ;
Packit 6c4009
      len -= 4;
Packit 6c4009
    }
Packit 6c4009
  while (len != 0);
Packit 6c4009
Packit 6c4009
  /* This is the right position for do0.  Please don't move
Packit 6c4009
     it into the loop.  */
Packit 6c4009
 do0:
Packit 6c4009
  ((op_t *) dstp)[3] = MERGE (a0, sh_1, a1, sh_2);
Packit 6c4009
}