2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
21 #include "../SDL_internal.h"
23 #include "SDL_video.h"
25 #include "SDL_blit_copy.h"
29 /* This assumes 16-byte aligned src and dst */
30 static SDL_INLINE void
31 SDL_memcpySSE(Uint8 * dst, const Uint8 * src, int len)
36 for (i = len / 64; i--;) {
37 _mm_prefetch(src, _MM_HINT_NTA);
38 values[0] = *(__m128 *) (src + 0);
39 values[1] = *(__m128 *) (src + 16);
40 values[2] = *(__m128 *) (src + 32);
41 values[3] = *(__m128 *) (src + 48);
42 _mm_stream_ps((float *) (dst + 0), values[0]);
43 _mm_stream_ps((float *) (dst + 16), values[1]);
44 _mm_stream_ps((float *) (dst + 32), values[2]);
45 _mm_stream_ps((float *) (dst + 48), values[3]);
51 SDL_memcpy(dst, src, len & 63);
57 #pragma warning(disable:4799)
59 static SDL_INLINE void
60 SDL_memcpyMMX(Uint8 * dst, const Uint8 * src, int len)
62 const int remain = (len & 63);
65 __m64* d64 = (__m64*)dst;
66 __m64* s64 = (__m64*)src;
68 for(i= len / 64; i--;) {
84 const int skip = len - remain;
85 SDL_memcpy(dst + skip, src + skip, remain);
91 SDL_BlitCopy(SDL_BlitInfo * info)
98 w = info->dst_w * info->dst_fmt->BytesPerPixel;
102 srcskip = info->src_pitch;
103 dstskip = info->dst_pitch;
105 /* Properly handle overlapping blits */
107 overlap = (dst < (src + h*srcskip));
109 overlap = (src < (dst + h*dstskip));
113 SDL_memmove(dst, src, w);
122 !((uintptr_t) src & 15) && !(srcskip & 15) &&
123 !((uintptr_t) dst & 15) && !(dstskip & 15)) {
125 SDL_memcpySSE(dst, src, w);
134 if (SDL_HasMMX() && !(srcskip & 7) && !(dstskip & 7)) {
136 SDL_memcpyMMX(dst, src, w);
146 SDL_memcpy(dst, src, w);
152 /* vi: set ts=4 sw=4 expandtab: */