1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "nel/misc/fast_mem.h"
20 #include "nel/misc/system_info.h"
29 #if defined(NL_OS_WINDOWS) && !defined(NL_NO_ASM)
32 // ***************************************************************************
33 void *CFastMem::memcpySSE(void *dest
, const void *src
, size_t nbytes
)
41 // edx takes number of bytes%64
45 // ebx takes number of bytes/64
50 loop4k
: // flush 4k into temporary buffer
53 // copy per block of 64 bytes. Must not override 64*64= 4096 bytes.
58 // eax takes the number of 64bytes packet for this block.
62 prefetchnta
64[ESI
] // Prefetch next loop, non-temporal
65 movq mm1
, 0[ESI
] // Read in source data
78 pop esi
// Now copy from L1 to system memory
82 movq mm1
, 0[ESI
] // Read in source data from L1
91 movntq
0[EDI
], mm1
// Non-temporal stores
112 // Do last bytes with std cpy
119 // ***************************************************************************
120 void CFastMem::precacheSSE(const void *src
, uint nbytes
)
131 prefetchnta
64[ESI
] // Prefetch next loop, non-temporal
134 movq mm1
, 0[ESI
] // Read in source data
153 // ***************************************************************************
154 void CFastMem::precacheMMX(const void *src
, uint nbytes
)
165 movq mm1
, 0[ESI
] // Read in source data
185 // ***************************************************************************
186 void CFastMem::precache(const void *src
, uint nbytes
)
188 if(NLMISC::CSystemInfo::hasSSE())
189 precacheSSE(src
, nbytes
);
190 else if(NLMISC::CSystemInfo::hasMMX())
191 precacheMMX(src
, nbytes
);
198 // ***************************************************************************
199 void *CFastMem::memcpySSE(void *dst
, const void *src
, size_t nbytes
)
202 return memcpy(dst
, src
, nbytes
);
204 void CFastMem::precacheSSE(const void *src
, uint nbytes
)
208 void CFastMem::precacheMMX(const void *src
, uint nbytes
)
212 void CFastMem::precache(const void *src
, uint nbytes
)
219 typedef void *(*memcpyPtr
)(void *dts
, const void *src
, size_t nbytes
);
221 static memcpyPtr
findBestmemcpy ()
223 #if defined(NL_OS_WINDOWS) && !defined(NL_NO_ASM)
224 if (CSystemInfo::hasSSE ())
225 return CFastMem::memcpySSE
;
228 #else // NL_OS_WINDOWS
230 #endif // NL_OS_WINDOWS
233 void *(*CFastMem::memcpy
)(void *dts
, const void *src
, size_t nbytes
) = findBestmemcpy ();