struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / device / lib / stm8 / memcpy.s
blobe8af3e19a0a22c62b2019fc6ac2db6919dc6a755
1 ;--------------------------------------------------------------------------
2 ; memcpy.s
4 ; Copyright (C) 2018, Benedikt Freisen
5 ; Copyright (C) 2021, Philipp Klaus Krause
7 ; This library is free software; you can redistribute it and/or modify it
8 ; under the terms of the GNU General Public License as published by the
9 ; Free Software Foundation; either version 2, or (at your option) any
10 ; later version.
12 ; This library is distributed in the hope that it will be useful,
13 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ; GNU General Public License for more details.
17 ; You should have received a copy of the GNU General Public License
18 ; along with this library; see the file COPYING. If not, write to the
19 ; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
20 ; MA 02110-1301, USA.
22 ; As a special exception, if you link this library with other files,
23 ; some of which are compiled with SDCC, to produce an executable,
24 ; this library does not by itself cause the resulting executable to
25 ; be covered by the GNU General Public License. This exception does
26 ; not however invalidate any other reasons why the executable file
27 ; might be covered by the GNU General Public License.
28 ;--------------------------------------------------------------------------
30 ; This memcpy() implementation has been optimized for speed using 4x loop
31 ; unrolling and index relative addressing.
33 ; void *memcpy(void *dest, const void *src, size_t n);
35 .globl ___memcpy
36 .globl _memcpy
38 .area CODE
40 ___memcpy:
41 _memcpy:
42 pushw x
43 ldw y, (5, sp)
45 srl (7, sp)
46 rrc (8, sp)
47 jrnc n_x0
48 ld a, (y)
49 ld (x), a
50 incw y
51 incw x
52 n_x0:
53 srl (7, sp)
54 rrc (8, sp)
55 jrnc n_00
56 ld a, (y)
57 ld (x), a
58 incw y
59 incw x
60 ld a, (y)
61 ld (x), a
62 incw y
63 incw x
64 n_00:
65 tnz (8, sp)
66 jrne loop_ent
67 dec (7, sp)
68 jrmi end
69 jra loop_ent
71 loop:
72 addw y, #4
73 addw x, #4
74 loop_ent:
75 ld a, (y)
76 ld (x), a
77 ld a, (1, y)
78 ld (1, x), a
79 ld a, (2, y)
80 ld (2, x), a
81 ld a, (3, y)
82 ld (3, x), a
84 dec (8, sp)
85 jrne loop
86 dec (7, sp)
87 jrpl loop
89 end:
90 popw x
91 popw y
92 addw sp, #4
93 jp (y)