OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libc/] [machine/] [z8k/] [memmove.S] - Diff between revs 207 and 345

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
/*
/*
 * memmove routine for Z8000
 * memmove routine for Z8000
 * Copyright (C) 2004 Christian Groessler 
 * Copyright (C) 2004 Christian Groessler 
 *
 *
 * Permission to use, copy, modify, and distribute this file
 * Permission to use, copy, modify, and distribute this file
 * for any purpose is hereby granted without fee, provided that
 * for any purpose is hereby granted without fee, provided that
 * the above copyright notice and this notice appears in all
 * the above copyright notice and this notice appears in all
 * copies.
 * copies.
 *
 *
 * This file is distributed WITHOUT ANY WARRANTY; without even the implied
 * This file is distributed WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */
 */
/* void *memmove(void *dest, const void *src, size_t length);
/* void *memmove(void *dest, const void *src, size_t length);
 */
 */
        name    "memmove.S"
        name    "memmove.S"
        .text
        .text
        even
        even
global  _memmove
global  _memmove
_memmove:
_memmove:
#ifdef __Z8001__
#ifdef __Z8001__
        segm
        segm
#ifdef __STD_CALL__
#ifdef __STD_CALL__
        ldl     rr6,rr14(#4)
        ldl     rr6,rr14(#4)
        ldl     rr4,rr14(#8)
        ldl     rr4,rr14(#8)
        ldl     rr2,rr14(#12)
        ldl     rr2,rr14(#12)
#else
#else
        pushl   @rr14,rr6
        pushl   @rr14,rr6
#endif
#endif
/* rr2  - length        (high word ignored)
/* rr2  - length        (high word ignored)
 * rr4  - src
 * rr4  - src
 * rr6  - dest
 * rr6  - dest
 */
 */
        testl   rr2
        testl   rr2
        jr      z,finish
        jr      z,finish
/*  check for destructive overlap (src < dest && dest < src + length) */
/*  check for destructive overlap (src < dest && dest < src + length) */
        cpl     rr6,rr4
        cpl     rr6,rr4
        jp      ule,memmove_entry       /* non-destructive, let memcpy do the work */
        jp      ule,memmove_entry       /* non-destructive, let memcpy do the work */
        ldl     rr0,rr2
        ldl     rr0,rr2
        addl    rr0,rr4                 /* rr0 = src + length */
        addl    rr0,rr4                 /* rr0 = src + length */
        cpl     rr0,rr6
        cpl     rr0,rr6
        jp      ult,memmove_entry       /* non-destructive, let memcpy do the work */
        jp      ult,memmove_entry       /* non-destructive, let memcpy do the work */
/* set-up pointers to copy backwards, add (length - 1) */
/* set-up pointers to copy backwards, add (length - 1) */
        addl    rr4,rr2                 /* src + length */
        addl    rr4,rr2                 /* src + length */
        addl    rr6,rr2                 /* dest + length */
        addl    rr6,rr2                 /* dest + length */
        subl    rr4,#1
        subl    rr4,#1
        subl    rr6,#1
        subl    rr6,#1
/* check alignment */
/* check alignment */
        bitb    rl7,#0          /* odd destination address? */
        bitb    rl7,#0          /* odd destination address? */
        jr      z,testsrc
        jr      z,testsrc
        bitb    rl5,#0          /* odd source address? */
        bitb    rl5,#0          /* odd source address? */
        jr      z,odd_copy
        jr      z,odd_copy
        jr      even_copy
        jr      even_copy
testsrc:
testsrc:
        bitb    rl5,#0
        bitb    rl5,#0
        jr      nz,odd_copy     /* src even, dest odd */
        jr      nz,odd_copy     /* src even, dest odd */
        lddb    @rr6,@rr4,r3
        lddb    @rr6,@rr4,r3
        jr      ov,finish       /* jump if r5 is zero now */
        jr      ov,finish       /* jump if r5 is zero now */
/* copy words */
/* copy words */
even_copy:
even_copy:
        ld      r2,r3                   /* remember length */
        ld      r2,r3                   /* remember length */
        srl     r3,#1
        srl     r3,#1
/*      jr      z,no_words         it cannot be zero here */
/*      jr      z,no_words         it cannot be zero here */
        dec     r5,#1
        dec     r5,#1
        dec     r7,#1
        dec     r7,#1
        lddr    @rr6,@rr4,r3
        lddr    @rr6,@rr4,r3
no_words:
no_words:
        bitb    rl2,#0          /* odd length? */
        bitb    rl2,#0          /* odd length? */
        jr      z,finish
        jr      z,finish
        inc     r5,#1
        inc     r5,#1
        inc     r7,#1
        inc     r7,#1
        lddb    @rr6,@rr4,r2    /* yes, copy last byte */
        lddb    @rr6,@rr4,r2    /* yes, copy last byte */
        jr      finish
        jr      finish
/* copy bytes */
/* copy bytes */
odd_copy:
odd_copy:
        lddrb   @rr6,@rr4,r3
        lddrb   @rr6,@rr4,r3
finish:
finish:
#ifdef __STD_CALL__
#ifdef __STD_CALL__
        ldl     rr6,rr14(#4)
        ldl     rr6,rr14(#4)
#else
#else
        popl    rr2,@rr14
        popl    rr2,@rr14
#endif
#endif
#else           /* above Z8001, below Z8002 */
#else           /* above Z8001, below Z8002 */
        unsegm
        unsegm
#ifdef __STD_CALL__
#ifdef __STD_CALL__
        ld      r7,r15(#2)
        ld      r7,r15(#2)
        ld      r6,r15(#4)
        ld      r6,r15(#4)
        ld      r5,r15(#6)
        ld      r5,r15(#6)
#else
#else
        ld      r2,r7           /* buffer pointer return value */
        ld      r2,r7           /* buffer pointer return value */
#endif
#endif
/* r5  - length
/* r5  - length
 * r6  - src
 * r6  - src
 * r7  - dest
 * r7  - dest
 */
 */
        test    r5
        test    r5
        jr      z,finish
        jr      z,finish
/*  check for destructive overlap (src < dest && dest < src + length) */
/*  check for destructive overlap (src < dest && dest < src + length) */
        cp      r7,r6
        cp      r7,r6
        jp      ule,memmove_entry       /* non-destructive, let memcpy do the work */
        jp      ule,memmove_entry       /* non-destructive, let memcpy do the work */
        ld      r0,r5
        ld      r0,r5
        add     r0,r6                   /* r0 = src + length */
        add     r0,r6                   /* r0 = src + length */
        cp      r0,r7
        cp      r0,r7
        jp      ult,memmove_entry       /* non-destructive, let memcpy do the work */
        jp      ult,memmove_entry       /* non-destructive, let memcpy do the work */
/* set-up pointers to copy backwards, add (length - 1) */
/* set-up pointers to copy backwards, add (length - 1) */
        add     r6,r5                   /* src + length */
        add     r6,r5                   /* src + length */
        add     r7,r5                   /* dest + length */
        add     r7,r5                   /* dest + length */
        dec     r6,#1
        dec     r6,#1
        dec     r7,#1
        dec     r7,#1
/* check alignment */
/* check alignment */
        bitb    rl7,#0          /* odd destination address? */
        bitb    rl7,#0          /* odd destination address? */
        jr      z,testsrc
        jr      z,testsrc
        bitb    rl6,#0          /* odd source address? */
        bitb    rl6,#0          /* odd source address? */
        jr      z,odd_copy
        jr      z,odd_copy
        jr      even_copy
        jr      even_copy
testsrc:
testsrc:
        bitb    rl6,#0
        bitb    rl6,#0
        jr      nz,odd_copy     /* src even, dest odd */
        jr      nz,odd_copy     /* src even, dest odd */
        lddb    @r7,@r6,r5
        lddb    @r7,@r6,r5
        jr      ov,finish       /* jump if r5 is zero now */
        jr      ov,finish       /* jump if r5 is zero now */
/* copy words */
/* copy words */
even_copy:
even_copy:
        ld      r4,r5           /* remember length */
        ld      r4,r5           /* remember length */
        srl     r5,#1
        srl     r5,#1
/*      jr      z,no_words         it cannot be zero here */
/*      jr      z,no_words         it cannot be zero here */
        dec     r6,#1
        dec     r6,#1
        dec     r7,#1
        dec     r7,#1
        lddr    @r7,@r6,r5
        lddr    @r7,@r6,r5
no_words:
no_words:
        bitb    rl4,#0          /* odd length? */
        bitb    rl4,#0          /* odd length? */
        jr      z,finish
        jr      z,finish
        inc     r6,#1
        inc     r6,#1
        inc     r7,#1
        inc     r7,#1
        lddb    @r7,@r6,r4      /* yes, copy last byte */
        lddb    @r7,@r6,r4      /* yes, copy last byte */
        jr      finish
        jr      finish
/* copy bytes */
/* copy bytes */
odd_copy:
odd_copy:
        lddrb   @r7,@r6,r5
        lddrb   @r7,@r6,r5
finish:
finish:
#ifdef __STD_CALL__
#ifdef __STD_CALL__
        ld      r7,r15(#2)
        ld      r7,r15(#2)
#endif
#endif
#endif  /* Z8002 */
#endif  /* Z8002 */
        ret
        ret
        .end
        .end
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.