streaming-memcpy: move to src/util/ and compile unconditionally
this is useful, so make it available for general use Reviewed-by: Emma Anholt <emma@anholt.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16732>
This commit is contained in:
committed by
Marge Bot
parent
c370fa362b
commit
a7831c5f6e
@@ -249,12 +249,20 @@ u_unfilled_gen_c = custom_target(
|
||||
capture : true,
|
||||
)
|
||||
|
||||
libmesa_util_sse41 = static_library(
|
||||
'mesa_util_sse41',
|
||||
files('streaming-load-memcpy.c'),
|
||||
c_args : [c_msvc_compat_args, sse41_args],
|
||||
include_directories : [inc_include, inc_src, inc_mesa],
|
||||
gnu_symbol_visibility : 'hidden',
|
||||
)
|
||||
|
||||
_libmesa_util = static_library(
|
||||
'mesa_util',
|
||||
[files_mesa_util, files_debug_stack, format_srgb, u_indices_gen_c, u_unfilled_gen_c],
|
||||
include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
|
||||
dependencies : deps_for_libmesa_util,
|
||||
link_with: libmesa_format,
|
||||
link_with: [libmesa_format, libmesa_util_sse41],
|
||||
c_args : [c_msvc_compat_args],
|
||||
gnu_symbol_visibility : 'hidden',
|
||||
build_by_default : false
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright © 2013 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Eric Anholt <eric@anholt.net>
|
||||
* Matt Turner <mattst88@gmail.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "main/macros.h"
|
||||
#include "util/streaming-load-memcpy.h"
|
||||
#include "x86/common_x86_asm.h"
|
||||
#ifdef USE_SSE41
|
||||
#include <smmintrin.h>
|
||||
#endif
|
||||
|
||||
/* Copies memory from src to dst, using SSE 4.1's MOVNTDQA to get streaming
|
||||
* read performance from uncached memory.
|
||||
*/
|
||||
void
|
||||
util_streaming_load_memcpy(void *restrict dst, void *restrict src, size_t len)
|
||||
{
|
||||
char *restrict d = dst;
|
||||
char *restrict s = src;
|
||||
|
||||
#ifdef USE_SSE41
|
||||
/* If dst and src are not co-aligned, or if SSE4.1 is not present, fallback to memcpy(). */
|
||||
if (((uintptr_t)d & 15) != ((uintptr_t)s & 15) || !cpu_has_sse4_1) {
|
||||
memcpy(d, s, len);
|
||||
return;
|
||||
}
|
||||
|
||||
/* memcpy() the misaligned header. At the end of this if block, <d> and <s>
|
||||
* are aligned to a 16-byte boundary or <len> == 0.
|
||||
*/
|
||||
if ((uintptr_t)d & 15) {
|
||||
uintptr_t bytes_before_alignment_boundary = 16 - ((uintptr_t)d & 15);
|
||||
assert(bytes_before_alignment_boundary < 16);
|
||||
|
||||
memcpy(d, s, MIN2(bytes_before_alignment_boundary, len));
|
||||
|
||||
d = (char *)ALIGN((uintptr_t)d, 16);
|
||||
s = (char *)ALIGN((uintptr_t)s, 16);
|
||||
len -= MIN2(bytes_before_alignment_boundary, len);
|
||||
}
|
||||
|
||||
if (len >= 64)
|
||||
_mm_mfence();
|
||||
|
||||
while (len >= 64) {
|
||||
__m128i *dst_cacheline = (__m128i *)d;
|
||||
__m128i *src_cacheline = (__m128i *)s;
|
||||
|
||||
__m128i temp1 = _mm_stream_load_si128(src_cacheline + 0);
|
||||
__m128i temp2 = _mm_stream_load_si128(src_cacheline + 1);
|
||||
__m128i temp3 = _mm_stream_load_si128(src_cacheline + 2);
|
||||
__m128i temp4 = _mm_stream_load_si128(src_cacheline + 3);
|
||||
|
||||
_mm_store_si128(dst_cacheline + 0, temp1);
|
||||
_mm_store_si128(dst_cacheline + 1, temp2);
|
||||
_mm_store_si128(dst_cacheline + 2, temp3);
|
||||
_mm_store_si128(dst_cacheline + 3, temp4);
|
||||
|
||||
d += 64;
|
||||
s += 64;
|
||||
len -= 64;
|
||||
}
|
||||
#endif
|
||||
/* memcpy() the tail. */
|
||||
if (len) {
|
||||
memcpy(d, s, len);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright © 2013 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Eric Anholt <eric@anholt.net>
|
||||
* Matt Turner <mattst88@gmail.com>
|
||||
*
|
||||
*/
|
||||
|
||||
/* Copies memory from src to dst, using SSE 4.1's MOVNTDQA to get streaming
|
||||
* read performance from uncached memory.
|
||||
*/
|
||||
|
||||
#ifndef STREAMING_LOAD_MEMCPY_H
|
||||
#define STREAMING_LOAD_MEMCPY_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void
|
||||
util_streaming_load_memcpy(void *restrict dst, void *restrict src, size_t len);
|
||||
|
||||
#endif /* STREAMING_LOAD_MEMCPY_H */
|
||||
Reference in New Issue
Block a user