1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00
Files
amiga-clib2/library/string_memmove.c
Olaf Barthel 7f0f7929ba - Updated copyright text and contact information
- Replaced ISO Latin 1 code #160 with a plain blank space (ASCII code #32) where necessary


git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15305 87f5fb63-7c3d-0410-a384-fd976d0f7a62
2015-06-10 13:13:40 +00:00

618 lines
13 KiB
C

/*
* $Id: string_memmove.c,v 1.7 2006-09-22 09:02:51 obarthel Exp $
*
* :ts=4
*
* Portable ISO 'C' (1994) runtime library for the Amiga computer
* Copyright (c) 2002-2015 by Olaf Barthel <obarthel (at) gmx.net>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Neither the name of Olaf Barthel nor the names of contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _STDLIB_NULL_POINTER_CHECK_H
#include "stdlib_null_pointer_check.h"
#endif /* _STDLIB_NULL_POINTER_CHECK_H */
/****************************************************************************/
#ifndef _STRING_HEADERS_H
#include "string_headers.h"
#endif /* _STRING_HEADERS_H */
/****************************************************************************/
#if (defined(__GNUC__) && defined(__mc68020__) && defined(NDEBUG) && defined(undefined))
/****************************************************************************/
asm("
.text
.even
.globl ___ovbcopy
___ovbcopy:
moveml sp@(4),a0-a1
movel sp@(12),d0
movel a2,sp@-
cmpal a0,a1
bcs forwards
| If A0 is less than A1 then we _may_ have to do the memory move
| backwards. However, since doing the memory move backwards is less
| efficient if we have to do any byte moves, I'll first check to see
| whether there is actually any overlap.
lea a0@(0,d0:l),a2
cmpal a2,a1 | If A2 is greater than A1 then there is overlap,
bcs backwards | and we'd better do the move backwards.
forwards:
movew a0,d1 | Make sure that A0 is long word aligned.
notw d1 | This may de-align A1, but that's life.
andiw #3,d1
align_loop1:
moveb a0@+,a1@+ | Move from one to four bytes to long
subql #1,d0 | word align A0.
dbeq d1,align_loop1
beq done
movew d0,d1
andiw #511,d1
movew d1,sp@-
moveq #9,d1
lsrl d1,d0
beq no_big_chunks_to_move1
moveml d2-d7/a3-a6,sp@-
swap d0
movew d0,sp@-
swap d0
bras move_big_chunk_end1
move_big_chunk1:
moveml a0@+,d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@
moveml a0@+,d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@(48)
moveml a0@+,d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@(96)
moveml a0@+,d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@(144)
moveml a0@+,d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@(192)
moveml a0@+,d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@(240)
moveml a0@+,d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@(288)
moveml a0@+,d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@(336)
moveml a0@+,d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@(384)
moveml a0@+,d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@(432)
moveml a0@+,d1-d7/a2
moveml d1-d7/a2,a1@(480)
addaw #512,a1
move_big_chunk_end1:
dbf d0,move_big_chunk1
subqw #1,sp@
bge move_big_chunk1
addqw #2,sp
moveml sp@+,d2-d7/a3-a6
no_big_chunks_to_move1:
movew sp@+,d0
movew d0,d1
lsrw #5,d1 | D1 now holds numbytes / 32 and
andiw #31,d0 | D0 holds numbytes % 32.
bras move_eight_longs_end1
move_eight_longs1:
movel a0@+,a1@+
movel a0@+,a1@+
movel a0@+,a1@+
movel a0@+,a1@+
movel a0@+,a1@+
movel a0@+,a1@+
movel a0@+,a1@+
movel a0@+,a1@+
move_eight_longs_end1:
dbf d1,move_eight_longs1
movew d0,d1
lsrw #2,d1 | D1 now holds numbytes / 4
bras move_long_end1
move_long1:
movel a0@+,a1@+
move_long_end1:
dbf d1,move_long1
andiw #3,d0 | D0 now holds numbytes % 4.
bra move_byte_end1
move_byte1:
moveb a0@+,a1@+
move_byte_end1:
dbf d0,move_byte1
done:
movel sp@+,a2
rts
backwards:
addal d0,a0
addal d0,a1
movew a0,d1 | Make sure that A0 is long word aligned.
subqw #1,d1 | This may de-align A1, but that's life.
andiw #3,d1
align_loop2:
moveb a0@-,a1@-
subql #1,d0
dbeq d1,align_loop2
beq done
movew d0,d1
andiw #511,d1
movew d1,sp@-
moveq #9,d1
lsrl d1,d0
beq no_big_chunks_to_move2
moveml d2-d7/a3-a6,sp@-
swap d0
movew d0,sp@-
swap d0
subaw #48,a0
bras move_big_chunk_end2
move_big_chunk2:
moveml a0@,d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@-
moveml a0@(-48),d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@-
moveml a0@(-96),d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@-
moveml a0@(-144),d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@-
moveml a0@(-192),d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@-
moveml a0@(-240),d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@-
moveml a0@(-288),d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@-
moveml a0@(-336),d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@-
moveml a0@(-384),d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@-
moveml a0@(-432),d1-d7/a2-a6
moveml d1-d7/a2-a6,a1@-
moveml a0@(-464),d1-d7/a2
moveml d1-d7/a2,a1@-
subaw #512,a0
move_big_chunk_end2:
dbf d0,move_big_chunk2
subqw #1,sp@
bge move_big_chunk2
addaw #48,a0
addqw #2,sp
moveml sp@+,d2-d7/a3-a6
no_big_chunks_to_move2:
movew sp@+,d0
movew d0,d1
lsrw #5,d1 | D1 now holds numbytes / 32 and
andiw #31,d0 | D0 holds numbytes % 32.
bras move_eight_longs_end2
move_eight_longs2:
movel a0@-,a1@-
movel a0@-,a1@-
movel a0@-,a1@-
movel a0@-,a1@-
movel a0@-,a1@-
movel a0@-,a1@-
movel a0@-,a1@-
movel a0@-,a1@-
move_eight_longs_end2:
dbf d1,move_eight_longs2
movew d0,d1
lsrw #2,d1 | D1 now holds numbytes / 4
bra move_long_end2
move_long2:
movel a0@-,a1@-
move_long_end2:
dbf d1,move_long2
andiw #3,d0 | D0 now holds numbytes % 4.
bra move_byte_end2