FS#11417 by Joe Balough: fix audio/tuner on philips hdd6330
[kugel-rb.git] / firmware / target / arm / memmove-arm.S
blobd8cab048be2af8d4e8e4f24fad1b41abe6f7b479
1 /***************************************************************************
2  *             __________               __   ___.
3  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
4  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
5  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
6  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
7  *                     \/            \/     \/    \/            \/
8  * $Id$
9  *
10  * Copyright (C) 2006 Free Software Foundation, Inc.
11  * This file was originally part of the GNU C Library
12  * Contributed to glibc by MontaVista Software, Inc. (written by Nicolas Pitre)
13  * Adapted for Rockbox by Daniel Ankers
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21  * KIND, either express or implied.
22  *
23  ****************************************************************************/
25 #include "config.h"
28  * Endian independent macros for shifting bytes within registers.
29  */
30 #ifndef __ARMEB__
31 #define pull            lsr
32 #define push            lsl
33 #else
34 #define pull            lsl
35 #define push            lsr
36 #endif
38         .text
41  * Prototype: void *memmove(void *dest, const void *src, size_t n);
42  *
43  * Note:
44  *
45  * If the memory regions don't overlap, we simply branch to memcpy which is
46  * normally a bit faster. Otherwise the copy is done going downwards.
47  */
49     .section    .icode,"ax",%progbits
51     .align      2
52     .global     memmove
53     .type       memmove,%function
55 memmove:
57         subs    ip, r0, r1
58         cmphi   r2, ip
59         bls memcpy
61         stmfd   sp!, {r0, r4, lr}
62         add r1, r1, r2
63         add r0, r0, r2
64         subs    r2, r2, #4
65         blt 8f
66         ands    ip, r0, #3
67         bne 9f
68         ands    ip, r1, #3
69         bne 10f
71 1:      subs    r2, r2, #(28)
72         stmfd   sp!, {r5 - r8}
73         blt 5f
77 4:      ldmdb   r1!, {r3, r4, r5, r6, r7, r8, ip, lr}
78         subs    r2, r2, #32
79         stmdb   r0!, {r3, r4, r5, r6, r7, r8, ip, lr}
80         bge 3b
82 5:      ands    ip, r2, #28
83         rsb ip, ip, #32
84         addne   pc, pc, ip      @ C is always clear here
85         b   7f
86 6:      nop
87         ldr r3, [r1, #-4]!
88         ldr r4, [r1, #-4]!
89         ldr r5, [r1, #-4]!
90         ldr r6, [r1, #-4]!
91         ldr r7, [r1, #-4]!
92         ldr r8, [r1, #-4]!
93         ldr lr, [r1, #-4]!
95         add pc, pc, ip
96         nop
97         nop
98         str r3, [r0, #-4]!
99         str r4, [r0, #-4]!
100         str r5, [r0, #-4]!
101         str r6, [r0, #-4]!
102         str r7, [r0, #-4]!
103         str r8, [r0, #-4]!
104         str lr, [r0, #-4]!
106 7:      ldmfd   sp!, {r5 - r8}
108 8:      movs    r2, r2, lsl #31
109         ldrneb  r3, [r1, #-1]!
110         ldrcsb  r4, [r1, #-1]!
111         ldrcsb  ip, [r1, #-1]
112         strneb  r3, [r0, #-1]!
113         strcsb  r4, [r0, #-1]!
114         strcsb  ip, [r0, #-1]
115         ldmpc   regs="r0, r4"
117 9:      cmp ip, #2
118         ldrgtb  r3, [r1, #-1]!
119         ldrgeb  r4, [r1, #-1]!
120         ldrb    lr, [r1, #-1]!
121         strgtb  r3, [r0, #-1]!
122         strgeb  r4, [r0, #-1]!
123         subs    r2, r2, ip
124         strb    lr, [r0, #-1]!
125         blt 8b
126         ands    ip, r1, #3
127         beq 1b
129 10:     bic r1, r1, #3
130         cmp ip, #2
131         ldr r3, [r1, #0]
132         beq 17f
133         blt 18f
136         .macro  backward_copy_shift push pull
138         subs    r2, r2, #28
139         blt 14f
141 11:     stmfd   sp!, {r5 - r9}
144 13:     ldmdb   r1!, {r7, r8, r9, ip}
145         mov     lr, r3, push #\push
146         subs    r2, r2, #32
147         ldmdb   r1!, {r3, r4, r5, r6}
148         orr     lr, lr, ip, pull #\pull
149         mov     ip, ip, push #\push
150         orr     ip, ip, r9, pull #\pull
151         mov     r9, r9, push #\push
152         orr     r9, r9, r8, pull #\pull
153         mov     r8, r8, push #\push
154         orr     r8, r8, r7, pull #\pull
155         mov     r7, r7, push #\push
156         orr     r7, r7, r6, pull #\pull
157         mov     r6, r6, push #\push
158         orr     r6, r6, r5, pull #\pull
159         mov     r5, r5, push #\push
160         orr     r5, r5, r4, pull #\pull
161         mov     r4, r4, push #\push
162         orr     r4, r4, r3, pull #\pull
163         stmdb   r0!, {r4 - r9, ip, lr}
164         bge 12b
166         ldmfd   sp!, {r5 - r9}
168 14:     ands    ip, r2, #28
169         beq 16f
171 15:     mov     lr, r3, push #\push
172         ldr r3, [r1, #-4]!
173         subs    ip, ip, #4
174         orr lr, lr, r3, pull #\pull
175         str lr, [r0, #-4]!
176         bgt 15b
178 16:     add r1, r1, #(\pull / 8)
179         b   8b
181         .endm
184         backward_copy_shift push=8  pull=24
186 17:     backward_copy_shift push=16 pull=16
188 18:     backward_copy_shift push=24 pull=8