ScummVM API documentation
memory.h
1
2/* ScummVM - Graphic Adventure Engine
3 *
4 * ScummVM is the legal property of its developers, whose names
5 * are too numerous to list here. Please refer to the COPYRIGHT
6 * file distributed with this source distribution.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef PSP_MEMORY_H
24#define PSP_MEMORY_H
25
26#define MIN_AMOUNT_FOR_COMPLEX_COPY 8
27#define MIN_AMOUNT_FOR_MISALIGNED_COPY 8
28
29//#define __PSP_DEBUG_PRINT__
30
31//#include "backends/platform/psp/trace.h"
32
33// These instructions don't generate automatically but are faster then copying byte by byte
34inline void lwl_copy(byte *dst, const byte *src) {
35 uint32 data;
36 asm volatile ("lwr %0,0(%1)\n\t"
37 "lwl %0,3(%1)\n\t"
38 : "=&r" (data) : "r" (src), "m" (*src));
39
40 asm volatile ("swr %1,0(%2)\n\t"
41 "swl %1,3(%2)\n\t"
42 : "=m" (*dst) : "r" (data), "r" (dst));
43}
44
48class PspMemory {
49private:
50 static void testCopy(const byte *debugDst, const byte *debugSrc, uint32 debugBytes);
51 static void copy(byte *dst, const byte *src, uint32 bytes);
52 static void copy32Aligned(uint32 *dst32, const uint32 *src32, uint32 bytes);
53 static void copy32Misaligned(uint32 *dst32, const byte *src, uint32 bytes, uint32 alignSrc);
54
55 static inline void copy8(byte *dst, const byte *src, int32 bytes) {
56 //PSP_DEBUG_PRINT("copy8 called with dst[%p], src[%p], bytes[%d]\n", dst, src, bytes);
57 uint32 words = bytes >> 2;
58 for (; words; words--) {
59 lwl_copy(dst, src);
60 dst += 4;
61 src += 4;
62 }
63
64 uint32 bytesLeft = bytes & 0x3;
65 for (; bytesLeft; bytesLeft--) {
66 *dst++ = *src++;
67 }
68 }
69
70public:
71 // This is the interface to the outside world
72 static void *fastCopy(void *dstv, const void *srcv, int32 bytes) {
73 byte *dst = (byte *)dstv;
74 const byte *src = (const byte *)srcv;
75
76 if (bytes < MIN_AMOUNT_FOR_COMPLEX_COPY) {
77 copy8(dst, src, bytes);
78 } else { // go to more powerful copy
79 copy(dst, src, bytes);
80 }
81
82 return dstv;
83 }
84};
85
86inline void *psp_memcpy(void *dst, const void *src, int32 bytes) {
87 return PspMemory::fastCopy(dst, src, bytes);
88}
89
90#endif /* PSP_MEMORY_H */
Definition: memory.h:48