syslinux/com32/lib/memmove.S
<<
>>
Prefs
   1/* ----------------------------------------------------------------------- *
   2 *
   3 *   Copyright 2008 H. Peter Anvin - All Rights Reserved
   4 *   Copyright 2010 Intel Corporation; author: H. Peter Anvin
   5 *
   6 *   Permission is hereby granted, free of charge, to any person
   7 *   obtaining a copy of this software and associated documentation
   8 *   files (the "Software"), to deal in the Software without
   9 *   restriction, including without limitation the rights to use,
  10 *   copy, modify, merge, publish, distribute, sublicense, and/or
  11 *   sell copies of the Software, and to permit persons to whom
  12 *   the Software is furnished to do so, subject to the following
  13 *   conditions:
  14 *
  15 *   The above copyright notice and this permission notice shall
  16 *   be included in all copies or substantial portions of the Software.
  17 *
  18 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  20 *   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21 *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  22 *   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  23 *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  24 *   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  25 *   OTHER DEALINGS IN THE SOFTWARE.
  26 *
  27 * ----------------------------------------------------------------------- */
  28
  29/*
  30 * memmove.S
  31 *
  32 * Reasonably efficient memmove, using aligned transfers at least
  33 * for the destination operand.
  34 */
  35
  36        .globl  memmove
  37        .type   memmove,@function
  38        .text
  39memmove:
  40        jecxz   4f
  41
  42        pushl   %esi
  43        pushl   %edi
  44        pushl   %eax            /* Return value */
  45
  46        movl    %eax,%edi
  47        movl    %edx,%esi
  48
  49        cmpl    %edi,%esi
  50        jb      2f
  51
  52        /* source >= dest, forwards move */
  53
  54        /* Initial alignment */
  551:
  56        movl    %edi,%edx
  57        shrl    $1,%edx
  58        jnc     11f
  59        movsb
  60        decl    %ecx
  6111:
  62        movb    %cl,%al
  63        cmpl    $2,%ecx
  64        jb      13f
  65
  66        shrl    $1,%edx
  67        jnc     12f
  68        movsw
  69        subl    $2,%ecx
  7012:
  71        /* Bulk transfer */
  72        movb    %cl,%al
  73        shrl    $2,%ecx
  74        rep; movsl
  75
  76        /* Final alignment */
  77        testb   $2,%al
  78        jz      14f
  79        movsw
  8013:
  8114:
  82        testb   $1,%al
  83        jz      15f
  84        movsb
  8515:
  86        /* Common exit stub */
  873:
  88        popl    %eax            /* Return value */
  89        popl    %edi
  90        popl    %esi
  914:
  92        ret
  93
  94
  952:
  96        /* source < dest, backwards move if overlap */
  97        leal    -1(%ecx,%esi),%eax
  98        cmpl    %eax,%edi
  99        ja      1b                      /* No overlap, after all... */
 100
 101        std
 102        leal    -1(%ecx,%edi),%edi
 103        movl    %eax,%esi
 104
 105        /* Initial alignment */
 106        movl    %edi,%edx
 107        shrl    $1,%edx
 108        jc      21f
 109        movsb
 110        decl    %ecx
 11121:
 112        decl    %esi
 113        decl    %edi
 114        movb    %cl,%al
 115        cmpl    $2,%ecx
 116        jb      23f
 117        shrl    $1,%edx
 118        jc      22f
 119        movsw
 120        subl    $2,%ecx
 12122:
 122        /* Bulk transfer */
 123        subl    $2,%esi
 124        subl    $2,%edi
 125        movb    %cl,%al
 126        shrl    $2,%ecx
 127        rep; movsl
 128
 129        /* Final alignment */
 130        addl    $2,%esi
 131        addl    $2,%edi
 132        testb   $2,%al
 133        jz      24f
 134        movsw
 13523:
 13624:
 137        incl    %esi
 138        incl    %edi
 139        testb   $1,%al
 140        jz      25f
 141        movsb
 14225:
 143        cld
 144        jmp     3b
 145
 146        .size   memmove, .-memmove
 147
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.