diff options
| author | 2015-09-09 23:23:44 -0400 | |
|---|---|---|
| committer | 2015-09-10 00:09:55 -0400 | |
| commit | 9cf1cfe3fdfc6a992b81d04cb2d9420deefc6244 (patch) | |
| tree | de78e9052b63c0e791de8c81bacf9e19f4475dfa /src/core/memory.cpp | |
| parent | Merge pull request #1020 from yuriks/qt-binaries (diff) | |
| download | yuzu-9cf1cfe3fdfc6a992b81d04cb2d9420deefc6244.tar.gz yuzu-9cf1cfe3fdfc6a992b81d04cb2d9420deefc6244.tar.xz yuzu-9cf1cfe3fdfc6a992b81d04cb2d9420deefc6244.zip | |
memory: Get rid of pointer casts
Diffstat (limited to 'src/core/memory.cpp')
| -rw-r--r-- | src/core/memory.cpp | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index cde390b8a..b80795e0c 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <array> | 5 | #include <array> |
| 6 | #include <cstring> | ||
| 6 | 7 | ||
| 7 | #include "common/assert.h" | 8 | #include "common/assert.h" |
| 8 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| @@ -95,7 +96,9 @@ template <typename T> | |||
| 95 | T Read(const VAddr vaddr) { | 96 | T Read(const VAddr vaddr) { |
| 96 | const u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS]; | 97 | const u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS]; |
| 97 | if (page_pointer) { | 98 | if (page_pointer) { |
| 98 | return *reinterpret_cast<const T*>(page_pointer + (vaddr & PAGE_MASK)); | 99 | T value; |
| 100 | std::memcpy(&value, &page_pointer[vaddr & PAGE_MASK], sizeof(T)); | ||
| 101 | return value; | ||
| 99 | } | 102 | } |
| 100 | 103 | ||
| 101 | PageType type = current_page_table->attributes[vaddr >> PAGE_BITS]; | 104 | PageType type = current_page_table->attributes[vaddr >> PAGE_BITS]; |
| @@ -117,7 +120,7 @@ template <typename T> | |||
| 117 | void Write(const VAddr vaddr, const T data) { | 120 | void Write(const VAddr vaddr, const T data) { |
| 118 | u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS]; | 121 | u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS]; |
| 119 | if (page_pointer) { | 122 | if (page_pointer) { |
| 120 | *reinterpret_cast<T*>(page_pointer + (vaddr & PAGE_MASK)) = data; | 123 | std::memcpy(&page_pointer[vaddr & PAGE_MASK], &data, sizeof(T)); |
| 121 | return; | 124 | return; |
| 122 | } | 125 | } |
| 123 | 126 | ||
| @@ -183,19 +186,9 @@ void Write64(const VAddr addr, const u64 data) { | |||
| 183 | } | 186 | } |
| 184 | 187 | ||
| 185 | void WriteBlock(const VAddr addr, const u8* data, const size_t size) { | 188 | void WriteBlock(const VAddr addr, const u8* data, const size_t size) { |
| 186 | u32 offset = 0; | 189 | for (u32 offset = 0; offset < size; offset++) { |
| 187 | while (offset < (size & ~3)) { | ||
| 188 | Write32(addr + offset, *(u32*)&data[offset]); | ||
| 189 | offset += 4; | ||
| 190 | } | ||
| 191 | |||
| 192 | if (size & 2) { | ||
| 193 | Write16(addr + offset, *(u16*)&data[offset]); | ||
| 194 | offset += 2; | ||
| 195 | } | ||
| 196 | |||
| 197 | if (size & 1) | ||
| 198 | Write8(addr + offset, data[offset]); | 190 | Write8(addr + offset, data[offset]); |
| 191 | } | ||
| 199 | } | 192 | } |
| 200 | 193 | ||
| 201 | PAddr VirtualToPhysicalAddress(const VAddr addr) { | 194 | PAddr VirtualToPhysicalAddress(const VAddr addr) { |