[Scummvm-cvs-logs] SF.net SVN: scummvm:[52873] scummvm/branches/branch-1-2-0
bluddy at users.sourceforge.net
bluddy at users.sourceforge.net
Fri Sep 24 11:05:32 CEST 2010
Revision: 52873
http://scummvm.svn.sourceforge.net/scummvm/?rev=52873&view=rev
Author: bluddy
Date: 2010-09-24 09:05:32 +0000 (Fri, 24 Sep 2010)
Log Message:
-----------
PSP: backported from trunk
PSP: moved VramAllocator to display_manager.cpp.
It didn't really belong in memory.cpp and we're going to want to include memory.h everywhere.
* * *
PSP: more Vram Allocator cleanup
* * *
PSP: Split up PspMemory class.
PspMemorySwap is more specific ie. it only needs to be known by PSP files. It could be put in another file, but not worth the effort.
* * *
PSP: switch from wrapping memcpy to defining our own memcpy
The advantage is that we get to do inlining and even use lwl and lwr instructions where appropriate. We have to do it ourselves because the PSP doesn't tolerate built-in instructions, but also we have a more efficient memcpy than the lib's.
Modified Paths:
--------------
scummvm/branches/branch-1-2-0/backends/platform/psp/display_client.cpp
scummvm/branches/branch-1-2-0/backends/platform/psp/display_manager.cpp
scummvm/branches/branch-1-2-0/backends/platform/psp/display_manager.h
scummvm/branches/branch-1-2-0/backends/platform/psp/memory.cpp
scummvm/branches/branch-1-2-0/backends/platform/psp/memory.h
scummvm/branches/branch-1-2-0/common/scummsys.h
scummvm/branches/branch-1-2-0/configure
Property Changed:
----------------
scummvm/branches/branch-1-2-0/configure
Modified: scummvm/branches/branch-1-2-0/backends/platform/psp/display_client.cpp
===================================================================
--- scummvm/branches/branch-1-2-0/backends/platform/psp/display_client.cpp 2010-09-24 01:02:07 UTC (rev 52872)
+++ scummvm/branches/branch-1-2-0/backends/platform/psp/display_client.cpp 2010-09-24 09:05:32 UTC (rev 52873)
@@ -32,6 +32,7 @@
#include "backends/platform/psp/psppixelformat.h"
#include "backends/platform/psp/display_client.h"
#include "backends/platform/psp/display_manager.h"
+#define PSP_INCLUDE_SWAP
#include "backends/platform/psp/memory.h"
//#define __PSP_DEBUG_FUNCS__ /* For debugging the stack */
@@ -341,14 +342,14 @@
if (pitch == realWidthInBytes && pitch == recWidthInBytes) {
//memcpy(dst, buf, _pixelFormat.pixelsToBytes(recHeight * recWidth));
if (_pixelFormat.swapRB)
- PspMemory::fastSwap(dst, buf, _pixelFormat.pixelsToBytes(recHeight * recWidth), _pixelFormat);
+ PspMemorySwap::fastSwap(dst, buf, _pixelFormat.pixelsToBytes(recHeight * recWidth), _pixelFormat);
else
PspMemory::fastCopy(dst, buf, _pixelFormat.pixelsToBytes(recHeight * recWidth));
} else {
do {
//memcpy(dst, buf, recWidthInBytes);
if (_pixelFormat.swapRB)
- PspMemory::fastSwap(dst, buf, recWidthInBytes, _pixelFormat);
+ PspMemorySwap::fastSwap(dst, buf, recWidthInBytes, _pixelFormat);
else
PspMemory::fastCopy(dst, buf, recWidthInBytes);
buf += pitch;
@@ -370,7 +371,7 @@
do {
//memcpy(dst, src, sourceWidthInBytes);
if (_pixelFormat.swapRB)
- PspMemory::fastSwap(dst, src, sourceWidthInBytes, _pixelFormat);
+ PspMemorySwap::fastSwap(dst, src, sourceWidthInBytes, _pixelFormat);
else
PspMemory::fastCopy(dst, src, sourceWidthInBytes);
src += realWidthInBytes;
Modified: scummvm/branches/branch-1-2-0/backends/platform/psp/display_manager.cpp
===================================================================
--- scummvm/branches/branch-1-2-0/backends/platform/psp/display_manager.cpp 2010-09-24 01:02:07 UTC (rev 52872)
+++ scummvm/branches/branch-1-2-0/backends/platform/psp/display_manager.cpp 2010-09-24 09:05:32 UTC (rev 52873)
@@ -59,6 +59,71 @@
{0, 0, 0}
};
+
+// Class VramAllocator -----------------------------------
+
+DECLARE_SINGLETON(VramAllocator)
+
+//#define __PSP_DEBUG_FUNCS__ /* For debugging the stack */
+//#define __PSP_DEBUG_PRINT__
+
+#include "backends/platform/psp/trace.h"
+
+
+void *VramAllocator::allocate(int32 size, bool smallAllocation /* = false */) {
+ DEBUG_ENTER_FUNC();
+ assert(size > 0);
+
+ byte *lastAddress = smallAllocation ? (byte *)VRAM_SMALL_ADDRESS : (byte *)VRAM_START_ADDRESS;
+ Common::List<Allocation>::iterator i;
+
+ // Find a block that fits, starting from the beginning
+ for (i = _allocList.begin(); i != _allocList.end(); ++i) {
+ byte *currAddress = (*i).address;
+
+ if (currAddress - lastAddress >= size) // We found a match
+ break;
+
+ if ((*i).getEnd() > lastAddress)
+ lastAddress = (byte *)(*i).getEnd();
+ }
+
+ if (lastAddress + size > (byte *)VRAM_END_ADDRESS) {
+ PSP_DEBUG_PRINT("No space for allocation of %d bytes. %d bytes already allocated.\n",
+ size, _bytesAllocated);
+ return NULL;
+ }
+
+ _allocList.insert(i, Allocation(lastAddress, size));
+ _bytesAllocated += size;
+
+ PSP_DEBUG_PRINT("Allocated in VRAM, size %u at %p.\n", size, lastAddress);
+ PSP_DEBUG_PRINT("Total allocated %u, remaining %u.\n", _bytesAllocated, (2 * 1024 * 1024) - _bytesAllocated);
+
+ return lastAddress;
+}
+
+// Deallocate a block from VRAM
+void VramAllocator::deallocate(void *address) {
+ DEBUG_ENTER_FUNC();
+ address = (byte *)CACHED(address); // Make sure all addresses are the same
+
+ Common::List<Allocation>::iterator i;
+
+ // Find the Allocator to deallocate
+ for (i = _allocList.begin(); i != _allocList.end(); ++i) {
+ if ((*i).address == address) {
+ _bytesAllocated -= (*i).size;
+ _allocList.erase(i);
+ PSP_DEBUG_PRINT("Deallocated address[%p], size[%u]\n", (*i).address, (*i).size);
+ return;
+ }
+ }
+
+ PSP_DEBUG_PRINT("Address[%p] not allocated.\n", address);
+}
+
+
// Class MasterGuRenderer ----------------------------------------------
void MasterGuRenderer::setupCallbackThread() {
Modified: scummvm/branches/branch-1-2-0/backends/platform/psp/display_manager.h
===================================================================
--- scummvm/branches/branch-1-2-0/backends/platform/psp/display_manager.h 2010-09-24 01:02:07 UTC (rev 52872)
+++ scummvm/branches/branch-1-2-0/backends/platform/psp/display_manager.h 2010-09-24 09:05:32 UTC (rev 52873)
@@ -27,8 +27,50 @@
#define PSP_DISPLAY_MAN_H
#include "backends/platform/psp/thread.h"
+#include "common/list.h"
+#define UNCACHED(x) ((byte *)(((uint32)(x)) | 0x40000000)) /* make an uncached access */
+#define CACHED(x) ((byte *)(((uint32)(x)) & 0xBFFFFFFF)) /* make an uncached access into a cached one */
+
/**
+ * Class that allocates memory in the VRAM
+ */
+class VramAllocator : public Common::Singleton<VramAllocator> {
+public:
+ VramAllocator() : _bytesAllocated(0) {}
+ void *allocate(int32 size, bool smallAllocation = false); // smallAllocation e.g. palettes
+ void deallocate(void *pointer);
+
+ static inline bool isAddressInVram(void *address) {
+ if ((uint32)(CACHED(address)) >= VRAM_START_ADDRESS && (uint32)(CACHED(address)) < VRAM_END_ADDRESS)
+ return true;
+ return false;
+ }
+
+
+private:
+ /**
+ * Used to allocate in VRAM
+ */
+ struct Allocation {
+ byte *address;
+ uint32 size;
+ void *getEnd() { return address + size; }
+ Allocation(void *Address, uint32 Size) : address((byte *)Address), size(Size) {}
+ Allocation() : address(0), size(0) {}
+ };
+
+ enum {
+ VRAM_START_ADDRESS = 0x04000000,
+ VRAM_END_ADDRESS = 0x04200000,
+ VRAM_SMALL_ADDRESS = VRAM_END_ADDRESS - (4 * 1024) // 4K in the end for small allocations
+ };
+ Common::List <Allocation> _allocList; // List of allocations
+ uint32 _bytesAllocated;
+};
+
+
+/**
* Class used only by DisplayManager to start/stop GU rendering
*/
class MasterGuRenderer : public PspThreadable {
Modified: scummvm/branches/branch-1-2-0/backends/platform/psp/memory.cpp
===================================================================
--- scummvm/branches/branch-1-2-0/backends/platform/psp/memory.cpp 2010-09-24 01:02:07 UTC (rev 52872)
+++ scummvm/branches/branch-1-2-0/backends/platform/psp/memory.cpp 2010-09-24 09:05:32 UTC (rev 52873)
@@ -25,8 +25,8 @@
#include "common/scummsys.h"
#include "common/singleton.h"
-#include "common/list.h"
#include "backends/platform/psp/psppixelformat.h"
+#define PSP_INCLUDE_SWAP
#include "backends/platform/psp/memory.h"
// Class Copier --------------------------------------------------------------------------
@@ -37,23 +37,6 @@
//#define TEST_MEMORY_COPY
-extern "C" {
-
-#ifdef TEST_MEMORY_COPY /* we won't be able to run in this case b/c of printouts */
-extern void *__real_memcpy(void *dst, void *src, size_t bytes);
-#endif
-
-void *__wrap_memcpy(void *dst, void *src, size_t bytes) {
-#ifdef TEST_MEMORY_COPY /* we won't be able to run in this case */
- return __real_memcpy(dst, src, bytes);
-#else
- PspMemory::fastCopy((byte *)dst, (byte *)src, bytes);
- return dst;
-#endif
-}
-
-}
-
void PspMemory::copy(byte *dst, const byte *src, uint32 bytes) {
DEBUG_ENTER_FUNC();
@@ -100,96 +83,6 @@
#endif
}
-void PspMemory::testCopy(const byte *debugDst, const byte *debugSrc, uint32 debugBytes) {
-
- bool mismatch = false;
- PSP_INFO_PRINT("testing fastCopy...");
-
- for (uint32 i = 0; i < debugBytes; i++) {
- if (debugDst[i] != debugSrc[i]) {
- if (!mismatch) {
- PSP_INFO_PRINT("**** mismatch in copy! ****\n");
- PSP_INFO_PRINT("dst[%p], src[%p], bytes[%u]\n", debugDst, debugSrc, debugBytes);
- mismatch = true;
- }
- PSP_INFO_PRINT("[%d]%x!=%x ", i, debugSrc[i], debugDst[i]);
- }
- }
- if (mismatch) {
- PSP_INFO_PRINT("\n");
- } else {
- PSP_INFO_PRINT("ok\n");
- }
-}
-
-//
-// used to swap red and blue
-void PspMemory::swap(uint16 *dst16, const uint16 *src16, uint32 bytes, PSPPixelFormat &format) {
- DEBUG_ENTER_FUNC();
-
-#ifdef TEST_MEMORY_COPY
- uint32 debugBytes = bytes;
- const uint16 *debugDst = dst16, *debugSrc = src16;
-#endif
-
- // align the destination pointer first
- uint32 prefixDst = (((uint32)dst16) & 0x3); // for swap, we can only have 2 or 0 as our prefix
-
- if (prefixDst) {
- bytes -= prefixDst; // remember we assume bytes > 4
- *dst16++ = format.swapRedBlue16(*src16++);
-
- if (bytes < MIN_AMOUNT_FOR_COMPLEX_COPY) { // check if it's worthwhile to continue
- swap16(dst16, src16, bytes, format);
-
-#ifdef TEST_MEMORY_COPY
- testSwap(debugDst, debugSrc, debugBytes, format);
-#endif
- return;
- }
- }
-
- // check the source pointer alignment now
- uint32 alignSrc = (((uint32)src16) & 0x3);
-
- if (alignSrc) { // we'll need to realign our reads
- PSP_DEBUG_PRINT("misaligned copy of %u bytes from %p to %p\n", bytes, src16, dst16);
- swap32Misaligned((uint32 *)dst16, src16, bytes, format);
- } else {
- swap32Aligned((uint32 *)dst16, (const uint32 *)src16, bytes, format);
- }
-
-#ifdef TEST_MEMORY_COPY
- testSwap(debugDst, debugSrc, debugBytes, format);
-#endif
-
-}
-
-void PspMemory::testSwap(const uint16 *debugDst, const uint16 *debugSrc, uint32 debugBytes, PSPPixelFormat &format) {
-
- bool mismatch = false;
- PSP_INFO_PRINT("testing fastSwap...");
-
- uint32 shorts = debugBytes >> 1;
-
- for (uint32 i = 0; i < shorts; i++) {
- if (debugDst[i] != format.swapRedBlue16(debugSrc[i])) {
- if (!mismatch) {
- PSP_INFO_PRINT("**** mismatch in swap! ****\n");
- PSP_INFO_PRINT("dst[%p], src[%p], bytes[%u]\n", debugDst, debugSrc, debugBytes);
- mismatch = true;
- }
- PSP_INFO_PRINT("[%d]%x!=%x ", i<<1, format.swapRedBlue16(debugSrc[i]), debugDst[i]);
- }
- }
- if (mismatch) {
- PSP_INFO_PRINT("\n");
- } else {
- PSP_INFO_PRINT("ok\n");
- }
-}
-
-
void PspMemory::copy32Aligned(uint32 *dst32, const uint32 *src32, uint32 bytes) {
PSP_DEBUG_PRINT("copy32Aligned(): dst32[%p], src32[%p], bytes[%d]\n", dst32, src32, bytes);
@@ -258,41 +151,6 @@
}
}
-void PspMemory::swap32Aligned(uint32 *dst32, const uint32 *src32, uint32 bytes, PSPPixelFormat &format) {
- DEBUG_ENTER_FUNC();
- int words4 = bytes >> 4;
-
- // try blocks of 4 words at a time
- while (words4--) {
- uint32 a, b, c, d;
- a = format.swapRedBlue32(src32[0]);
- b = format.swapRedBlue32(src32[1]);
- c = format.swapRedBlue32(src32[2]);
- d = format.swapRedBlue32(src32[3]);
- dst32[0] = a;
- dst32[1] = b;
- dst32[2] = c;
- dst32[3] = d;
- dst32 += 4;
- src32 += 4;
- }
-
- uint32 bytesLeft = bytes & 0xF;
- uint32 words = bytesLeft >> 2;
-
- // now just do words
- while (words--) {
- *dst32++ = format.swapRedBlue32(*src32++);
- }
-
- bytesLeft = bytes & 0x3;
-
- if (bytesLeft) { // for swap, can only be 1 short left
- *((uint16 *)dst32) = format.swapRedBlue16(*((uint16 *)src32));
- }
-}
-
-
// More challenging -- need to shift
// Assume dst is aligned
void PspMemory::copy32Misaligned(uint32 *dst32, const byte *src, uint32 bytes, uint32 alignSrc) {
@@ -369,9 +227,132 @@
}
}
+void PspMemory::testCopy(const byte *debugDst, const byte *debugSrc, uint32 debugBytes) {
+
+ bool mismatch = false;
+ PSP_INFO_PRINT("testing fastCopy...");
+
+ for (uint32 i = 0; i < debugBytes; i++) {
+ if (debugDst[i] != debugSrc[i]) {
+ if (!mismatch) {
+ PSP_INFO_PRINT("**** mismatch in copy! ****\n");
+ PSP_INFO_PRINT("dst[%p], src[%p], bytes[%u]\n", debugDst, debugSrc, debugBytes);
+ mismatch = true;
+ }
+ PSP_INFO_PRINT("[%d]%x!=%x ", i, debugSrc[i], debugDst[i]);
+ }
+ }
+ if (mismatch) {
+ PSP_INFO_PRINT("\n");
+ } else {
+ PSP_INFO_PRINT("ok\n");
+ }
+}
+
+//
+// used to swap red and blue
+void PspMemorySwap::swap(uint16 *dst16, const uint16 *src16, uint32 bytes, PSPPixelFormat &format) {
+ DEBUG_ENTER_FUNC();
+
+#ifdef TEST_MEMORY_COPY
+ uint32 debugBytes = bytes;
+ const uint16 *debugDst = dst16, *debugSrc = src16;
+#endif
+
+ // align the destination pointer first
+ uint32 prefixDst = (((uint32)dst16) & 0x3); // for swap, we can only have 2 or 0 as our prefix
+
+ if (prefixDst) {
+ bytes -= prefixDst; // remember we assume bytes > 4
+ *dst16++ = format.swapRedBlue16(*src16++);
+
+ if (bytes < MIN_AMOUNT_FOR_COMPLEX_COPY) { // check if it's worthwhile to continue
+ swap16(dst16, src16, bytes, format);
+
+#ifdef TEST_MEMORY_COPY
+ testSwap(debugDst, debugSrc, debugBytes, format);
+#endif
+ return;
+ }
+ }
+
+ // check the source pointer alignment now
+ uint32 alignSrc = (((uint32)src16) & 0x3);
+
+ if (alignSrc) { // we'll need to realign our reads
+ PSP_DEBUG_PRINT("misaligned copy of %u bytes from %p to %p\n", bytes, src16, dst16);
+ swap32Misaligned((uint32 *)dst16, src16, bytes, format);
+ } else {
+ swap32Aligned((uint32 *)dst16, (const uint32 *)src16, bytes, format);
+ }
+
+#ifdef TEST_MEMORY_COPY
+ testSwap(debugDst, debugSrc, debugBytes, format);
+#endif
+
+}
+
+void PspMemorySwap::testSwap(const uint16 *debugDst, const uint16 *debugSrc, uint32 debugBytes, PSPPixelFormat &format) {
+
+ bool mismatch = false;
+ PSP_INFO_PRINT("testing fastSwap...");
+
+ uint32 shorts = debugBytes >> 1;
+
+ for (uint32 i = 0; i < shorts; i++) {
+ if (debugDst[i] != format.swapRedBlue16(debugSrc[i])) {
+ if (!mismatch) {
+ PSP_INFO_PRINT("**** mismatch in swap! ****\n");
+ PSP_INFO_PRINT("dst[%p], src[%p], bytes[%u]\n", debugDst, debugSrc, debugBytes);
+ mismatch = true;
+ }
+ PSP_INFO_PRINT("[%d]%x!=%x ", i<<1, format.swapRedBlue16(debugSrc[i]), debugDst[i]);
+ }
+ }
+ if (mismatch) {
+ PSP_INFO_PRINT("\n");
+ } else {
+ PSP_INFO_PRINT("ok\n");
+ }
+}
+
+void PspMemorySwap::swap32Aligned(uint32 *dst32, const uint32 *src32, uint32 bytes, PSPPixelFormat &format) {
+ DEBUG_ENTER_FUNC();
+ int words4 = bytes >> 4;
+
+ // try blocks of 4 words at a time
+ while (words4--) {
+ uint32 a, b, c, d;
+ a = format.swapRedBlue32(src32[0]);
+ b = format.swapRedBlue32(src32[1]);
+ c = format.swapRedBlue32(src32[2]);
+ d = format.swapRedBlue32(src32[3]);
+ dst32[0] = a;
+ dst32[1] = b;
+ dst32[2] = c;
+ dst32[3] = d;
+ dst32 += 4;
+ src32 += 4;
+ }
+
+ uint32 bytesLeft = bytes & 0xF;
+ uint32 words = bytesLeft >> 2;
+
+ // now just do words
+ while (words--) {
+ *dst32++ = format.swapRedBlue32(*src32++);
+ }
+
+ bytesLeft = bytes & 0x3;
+
+ if (bytesLeft) { // for swap, can only be 1 short left
+ *((uint16 *)dst32) = format.swapRedBlue16(*((uint16 *)src32));
+ }
+}
+
// More challenging -- need to shift
// We assume dst is aligned
-void PspMemory::swap32Misaligned(uint32 *dst32, const uint16 *src16, uint32 bytes, PSPPixelFormat &format) {
+void PspMemorySwap::swap32Misaligned(uint32 *dst32, const uint16 *src16, uint32 bytes, PSPPixelFormat &format) {
DEBUG_ENTER_FUNC();
const uint32 shiftValue = 16;
@@ -424,79 +405,3 @@
*((uint16 *)dst32) = format.swapRedBlue16((uint16)(srcWord >> shiftValue));
}
}
-
-inline void PspMemory::copy16(uint16 *dst16, const uint16 *src16, uint32 bytes) {
- PSP_DEBUG_PRINT("copy16(): dst16[%p], src16[%p], bytes[%d]\n", dst16, src16, bytes);
-
- uint32 shorts = bytes >> 1;
- uint32 remainingBytes = bytes & 1;
-
- for (; shorts > 0 ; shorts--) {
- *dst16++ = *src16++;
- }
- if (remainingBytes)
- *(byte *)dst16 = *(byte *)src16;
-}
-
-// Class VramAllocator -----------------------------------
-
-DECLARE_SINGLETON(VramAllocator)
-
-//#define __PSP_DEBUG_FUNCS__ /* For debugging the stack */
-//#define __PSP_DEBUG_PRINT__
-
-#include "backends/platform/psp/trace.h"
-
-
-void *VramAllocator::allocate(int32 size, bool smallAllocation /* = false */) {
- DEBUG_ENTER_FUNC();
- assert(size > 0);
-
- byte *lastAddress = smallAllocation ? (byte *)VRAM_SMALL_ADDRESS : (byte *)VRAM_START_ADDRESS;
- Common::List<Allocation>::iterator i;
-
- // Find a block that fits, starting from the beginning
- for (i = _allocList.begin(); i != _allocList.end(); ++i) {
- byte *currAddress = (*i).address;
-
- if (currAddress - lastAddress >= size) // We found a match
- break;
-
- if ((*i).getEnd() > lastAddress)
- lastAddress = (byte *)(*i).getEnd();
- }
-
- if (lastAddress + size > (byte *)VRAM_END_ADDRESS) {
- PSP_DEBUG_PRINT("No space for allocation of %d bytes. %d bytes already allocated.\n",
- size, _bytesAllocated);
- return NULL;
- }
-
- _allocList.insert(i, Allocation(lastAddress, size));
- _bytesAllocated += size;
-
- PSP_DEBUG_PRINT("Allocated in VRAM, size %u at %p.\n", size, lastAddress);
- PSP_DEBUG_PRINT("Total allocated %u, remaining %u.\n", _bytesAllocated, (2 * 1024 * 1024) - _bytesAllocated);
-
- return lastAddress;
-}
-
-// Deallocate a block from VRAM
-void VramAllocator::deallocate(void *address) {
- DEBUG_ENTER_FUNC();
- address = (byte *)CACHED(address); // Make sure all addresses are the same
-
- Common::List<Allocation>::iterator i;
-
- // Find the Allocator to deallocate
- for (i = _allocList.begin(); i != _allocList.end(); ++i) {
- if ((*i).address == address) {
- _bytesAllocated -= (*i).size;
- _allocList.erase(i);
- PSP_DEBUG_PRINT("Deallocated address[%p], size[%u]\n", (*i).address, (*i).size);
- return;
- }
- }
-
- PSP_DEBUG_PRINT("Address[%p] not allocated.\n", address);
-}
Modified: scummvm/branches/branch-1-2-0/backends/platform/psp/memory.h
===================================================================
--- scummvm/branches/branch-1-2-0/backends/platform/psp/memory.h 2010-09-24 01:02:07 UTC (rev 52872)
+++ scummvm/branches/branch-1-2-0/backends/platform/psp/memory.h 2010-09-24 09:05:32 UTC (rev 52873)
@@ -27,61 +27,94 @@
#ifndef PSP_MEMORY_H
#define PSP_MEMORY_H
-#include "backends/platform/psp/psppixelformat.h"
-#include "common/list.h"
-
-#define UNCACHED(x) ((byte *)(((uint32)(x)) | 0x40000000)) /* make an uncached access */
-#define CACHED(x) ((byte *)(((uint32)(x)) & 0xBFFFFFFF)) /* make an uncached access into a cached one */
-
#define MIN_AMOUNT_FOR_COMPLEX_COPY 8
#define MIN_AMOUNT_FOR_MISALIGNED_COPY 8
//#define __PSP_DEBUG_PRINT__
-#include "backends/platform/psp/trace.h"
+//#include "backends/platform/psp/trace.h"
+// These instructions don't generate automatically but are faster then copying byte by byte
+inline void lwl_copy(byte *dst, const byte *src) {
+ register uint32 data;
+ asm volatile ("lwr %0,0(%1)\n\t"
+ "lwl %0,3(%1)\n\t"
+ : "=&r" (data) : "r" (src), "m" (*src));
+
+ asm volatile ("swr %1,0(%2)\n\t"
+ "swl %1,3(%2)\n\t"
+ : "=m" (*dst) : "r" (data), "r" (dst));
+}
+
/**
* Class that does memory copying and swapping if needed
*/
class PspMemory {
private:
static void testCopy(const byte *debugDst, const byte *debugSrc, uint32 debugBytes);
- static void testSwap(const uint16 *debugDst, const uint16 *debugSrc, uint32 debugBytes, PSPPixelFormat &format);
static void copy(byte *dst, const byte *src, uint32 bytes);
- static void swap(uint16 *dst16, const uint16 *src16, uint32 bytes, PSPPixelFormat &format);
static void copy32Aligned(uint32 *dst32, const uint32 *src32, uint32 bytes);
- static void swap32Aligned(uint32 *dst32, const uint32 *src32, uint32 bytes, PSPPixelFormat &format);
static void copy32Misaligned(uint32 *dst32, const byte *src, uint32 bytes, uint32 alignSrc);
- static void swap32Misaligned(uint32 *dst32, const uint16 *src16, uint32 bytes, PSPPixelFormat &format);
- static void copy16(uint16 *dst, const uint16 *src, uint32 bytes);
-
- // For swapping, we know that we have multiples of 16 bits
- static void swap16(uint16 *dst16, const uint16 *src16, uint32 bytes, PSPPixelFormat &format) {
- PSP_DEBUG_PRINT("swap16 called with dst16[%p], src16[%p], bytes[%d]\n", dst16, src16, bytes);
- uint32 shorts = bytes >> 1;
-
- while (shorts--) {
- *dst16++ = format.swapRedBlue16(*src16++);
- }
- }
- static void copy8(byte *dst, const byte *src, uint32 bytes) {
- PSP_DEBUG_PRINT("copy8 called with dst[%p], src[%p], bytes[%d]\n", dst, src, bytes);
- while (bytes--) {
+ static inline void copy8(byte *dst, const byte *src, int32 bytes) {
+ //PSP_DEBUG_PRINT("copy8 called with dst[%p], src[%p], bytes[%d]\n", dst, src, bytes);
+ uint32 words = bytes >> 2;
+ for (; words; words--) {
+ lwl_copy(dst, src);
+ dst += 4;
+ src += 4;
+ }
+
+ uint32 bytesLeft = bytes & 0x3;
+ for (; bytesLeft; bytesLeft--) {
*dst++ = *src++;
}
}
public:
// This is the interface to the outside world
- static void fastCopy(byte *dst, const byte *src, uint32 bytes) {
+ static void *fastCopy(void *dstv, const void *srcv, int32 bytes) {
+ byte *dst = (byte *)dstv;
+ byte *src = (byte *)srcv;
+
if (bytes < MIN_AMOUNT_FOR_COMPLEX_COPY) {
copy8(dst, src, bytes);
} else { // go to more powerful copy
copy(dst, src, bytes);
}
+
+ return dstv;
}
+};
+inline void *psp_memcpy(void *dst, const void *src, int32 bytes) {
+ return PspMemory::fastCopy(dst, src, bytes);
+}
+
+#endif /* PSP_MEMORY_H */
+
+#if defined(PSP_INCLUDE_SWAP) && !defined(PSP_MEMORY_SWAP_H)
+#define PSP_MEMORY_SWAP_H
+
+//#include "backends/platform/psp/psppixelformat.h"
+
+class PspMemorySwap {
+private:
+ static void testSwap(const uint16 *debugDst, const uint16 *debugSrc, uint32 debugBytes, PSPPixelFormat &format);
+ static void swap(uint16 *dst16, const uint16 *src16, uint32 bytes, PSPPixelFormat &format);
+ static void swap32Aligned(uint32 *dst32, const uint32 *src32, uint32 bytes, PSPPixelFormat &format);
+ static void swap32Misaligned(uint32 *dst32, const uint16 *src16, uint32 bytes, PSPPixelFormat &format);
+ // For swapping, we know that we have multiples of 16 bits
+ static void swap16(uint16 *dst16, const uint16 *src16, uint32 bytes, PSPPixelFormat &format) {
+ PSP_DEBUG_PRINT("swap16 called with dst16[%p], src16[%p], bytes[%d]\n", dst16, src16, bytes);
+ uint32 shorts = bytes >> 1;
+
+ while (shorts--) {
+ *dst16++ = format.swapRedBlue16(*src16++);
+ }
+}
+
+public:
static void fastSwap(byte *dst, const byte *src, uint32 bytes, PSPPixelFormat &format) {
if (bytes < MIN_AMOUNT_FOR_COMPLEX_COPY * 2) {
swap16((uint16 *)dst, (uint16 *)src, bytes, format);
@@ -91,41 +124,6 @@
}
};
-/**
- * Class that allocates memory in the VRAM
- */
-class VramAllocator : public Common::Singleton<VramAllocator> {
-public:
- VramAllocator() : _bytesAllocated(0) {}
- void *allocate(int32 size, bool smallAllocation = false); // smallAllocation e.g. palettes
- void deallocate(void *pointer);
+#endif /* PSP_INCLUDE_SWAP */
- static inline bool isAddressInVram(void *address) {
- if ((uint32)(CACHED(address)) >= VRAM_START_ADDRESS && (uint32)(CACHED(address)) < VRAM_END_ADDRESS)
- return true;
- return false;
- }
-
-private:
- /**
- * Used to allocate in VRAM
- */
- struct Allocation {
- byte *address;
- uint32 size;
- void *getEnd() { return address + size; }
- Allocation(void *Address, uint32 Size) : address((byte *)Address), size(Size) {}
- Allocation() : address(0), size(0) {}
- };
-
- enum {
- VRAM_START_ADDRESS = 0x04000000,
- VRAM_END_ADDRESS = 0x04200000,
- VRAM_SMALL_ADDRESS = VRAM_END_ADDRESS - (4 * 1024) // 4K in the end for small allocations
- };
- Common::List <Allocation> _allocList; // List of allocations
- uint32 _bytesAllocated;
-};
-
-#endif /* PSP_MEMORY_H */
Modified: scummvm/branches/branch-1-2-0/common/scummsys.h
===================================================================
--- scummvm/branches/branch-1-2-0/common/scummsys.h 2010-09-24 01:02:07 UTC (rev 52872)
+++ scummvm/branches/branch-1-2-0/common/scummsys.h 2010-09-24 09:05:32 UTC (rev 52873)
@@ -315,12 +315,16 @@
#elif defined(__PSP__)
#include <malloc.h>
+ #include "backends/platform/psp/memory.h"
#define scumm_stricmp strcasecmp
#define scumm_strnicmp strncasecmp
#define SCUMM_LITTLE_ENDIAN
#define SCUMM_NEED_ALIGNMENT
+
+ /* to make an efficient, inlined memcpy implementation */
+ #define memcpy(dst, src, size) psp_memcpy(dst, src, size)
#elif defined(__amigaos4__)
Modified: scummvm/branches/branch-1-2-0/configure
===================================================================
--- scummvm/branches/branch-1-2-0/configure 2010-09-24 01:02:07 UTC (rev 52872)
+++ scummvm/branches/branch-1-2-0/configure 2010-09-24 09:05:32 UTC (rev 52873)
@@ -2160,7 +2160,7 @@
PLUGIN_EXTRA_DEPS = $(EXECUTABLE)
CXXFLAGS += -DDYNAMIC_MODULES
LDFLAGS += -Wl,-T$(srcdir)/backends/platform/psp/main_prog.ld
-PLUGIN_LDFLAGS = -nostartfiles -Wl,-q,--just-symbols,$(EXECUTABLE),--retain-symbols-file,$(srcdir)/backends/platform/psp/plugin.syms,-T$(srcdir)/backends/platform/psp/plugin.ld -lstdc++ -lc -lm -Wl,--wrap,memcpy
+PLUGIN_LDFLAGS = -nostartfiles -Wl,-q,--just-symbols,$(EXECUTABLE),--retain-symbols-file,$(srcdir)/backends/platform/psp/plugin.syms,-T$(srcdir)/backends/platform/psp/plugin.ld -lstdc++ -lc -lm
PRE_OBJS_FLAGS := -Wl,--whole-archive
POST_OBJS_FLAGS := -Wl,--no-whole-archive
'
@@ -2727,7 +2727,6 @@
psp)
DEFINES="$DEFINES -D__PSP__ -DDISABLE_TEXT_CONSOLE -DDISABLE_COMMAND_LINE -DDISABLE_DOSBOX_OPL"
LIBS="$LIBS -lpng -Wl,-Map,mapfile.txt"
- LDFLAGS="$LDFLAGS -Wl,--wrap,memcpy"
;;
samsungtv)
find_sdlconfig
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list