From 99f2734d28e2fef5161c9b4947323b9668f84d6b Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 9 Feb 2020 17:13:44 +0100 Subject: [PATCH] Remove stack dependency. --- common/tracy_lz4.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/common/tracy_lz4.cpp b/common/tracy_lz4.cpp index 31a0cd54..0b347a90 100644 --- a/common/tracy_lz4.cpp +++ b/common/tracy_lz4.cpp @@ -367,16 +367,35 @@ LZ4_memcpy_using_offset(BYTE* dstPtr, const BYTE* srcPtr, BYTE* dstEnd, const si BYTE v[8]; switch(offset) { case 1: - memset(v, *srcPtr, 8); + if(sizeof(void*) == 8) { + U64 m = *srcPtr * 0x0101010101010101; + memcpy(v, &m, 8); + } else { + memset(v, *srcPtr, 8); + } goto copy_loop; case 2: - memcpy(v, srcPtr, 2); - memcpy(&v[2], srcPtr, 2); - memcpy(&v[4], &v[0], 4); + if(sizeof(void*) == 8) { + U16 m; + memcpy(&m, srcPtr, 2); + U64 n = m * 0x0001000100010001; + memcpy(v, &n, 8); + } else { + memcpy(v, srcPtr, 2); + memcpy(&v[2], srcPtr, 2); + memcpy(&v[4], &v[0], 4); + } goto copy_loop; case 4: - memcpy(v, srcPtr, 4); - memcpy(&v[4], srcPtr, 4); + if(sizeof(void*) == 8) { + U32 m; + memcpy(&m, srcPtr, 4); + U64 n = m | (U64(m) << 32); + memcpy(v, &n, 8); + } else { + memcpy(v, srcPtr, 4); + memcpy(&v[4], srcPtr, 4); + } goto copy_loop; default: LZ4_memcpy_using_offset_base(dstPtr, srcPtr, dstEnd, offset);