}
+/*
+ * Average two byte vectors. (Will always round up.)
+ */
+static LLVMValueRef
+lp_build_pavgb(struct lp_build_context *bld8,
+ LLVMValueRef v0,
+ LLVMValueRef v1)
+{
+ struct gallivm_state *gallivm = bld8->gallivm;
+ LLVMBuilderRef builder = gallivm->builder;
+ assert(bld8->type.width == 8);
+ assert(bld8->type.length == 16 || bld8->type.length == 32);
+ if (HAVE_LLVM < 0x0600) {
+ LLVMValueRef intrargs[2];
+ char *intr_name = bld8->type.length == 32 ? "llvm.x86.avx2.pavg.b" :
+ "llvm.x86.sse2.pavg.b";
+ intrargs[0] = v0;
+ intrargs[1] = v1;
+ return lp_build_intrinsic(builder, intr_name,
+ bld8->vec_type, intrargs, 2, 0);
+ } else {
+ /*
+ * Must match llvm's autoupgrade of pavg.b intrinsic to be useful.
+ * You better hope the backend code manages to detect the pattern, and
+ * the pattern doesn't change there...
+ */
+ struct lp_type type_ext = bld8->type;
+ LLVMTypeRef vec_type_ext;
+ LLVMValueRef res;
+ LLVMValueRef ext_one;
+ type_ext.width = 16;
+ vec_type_ext = lp_build_vec_type(gallivm, type_ext);
+ ext_one = lp_build_const_vec(gallivm, type_ext, 1);
+
+ v0 = LLVMBuildZExt(builder, v0, vec_type_ext, "");
+ v1 = LLVMBuildZExt(builder, v1, vec_type_ext, "");
+ res = LLVMBuildAdd(builder, v0, v1, "");
+ res = LLVMBuildAdd(builder, res, ext_one, "");
+ res = LLVMBuildLShr(builder, res, ext_one, "");
+ res = LLVMBuildTrunc(builder, res, bld8->vec_type, "");
+ return res;
+ }
+}
+
/**
* Calculate 1/3(v1-v0) + v0
* and 2*1/3(v1-v0) + v0
*/
if ((util_cpu_caps.has_sse2 && n == 4) ||
(util_cpu_caps.has_avx2 && n == 8)) {
- LLVMValueRef intrargs[2];
- char *intr_name = n == 8 ? "llvm.x86.avx2.pavg.b" :
- "llvm.x86.sse2.pavg.b";
- intrargs[0] = colors0;
- intrargs[1] = colors1;
- color2_2 = lp_build_intrinsic(builder, intr_name,
- bld8.vec_type, intrargs, 2, 0);
+ color2_2 = lp_build_pavgb(&bld8, colors0, colors1);
color2_2 = LLVMBuildBitCast(builder, color2_2, bld32.vec_type, "");
}
else {
/* same interleave as for lerp23 - correct result in 2nd element */
intrargs[1] = lp_build_interleave2(gallivm, type32, color01, color01, 0);
intrargs[1] = LLVMBuildBitCast(builder, intrargs[1], bld8.vec_type, "");
- color2_2 = lp_build_intrinsic(builder, "llvm.x86.sse2.pavg.b",
- bld8.vec_type, intrargs, 2, 0);
+ color2_2 = lp_build_pavgb(&bld8, intrargs[0], intrargs[1]);
}
else {
LLVMValueRef v01, v0, v1, vhalf;
#include "lp_test.h"
-#define USE_TEXTURE_CACHE 1
-
static struct lp_build_format_cache *cache_ptr;
void
static LLVMValueRef
add_fetch_rgba_test(struct gallivm_state *gallivm, unsigned verbose,
const struct util_format_description *desc,
- struct lp_type type)
+ struct lp_type type,
+ unsigned use_cache)
{
char name[256];
LLVMContextRef context = gallivm->context;
i = LLVMGetParam(func, 2);
j = LLVMGetParam(func, 3);
- if (cache_ptr) {
+ if (use_cache) {
cache = LLVMGetParam(func, 4);
}
PIPE_ALIGN_STACK
static boolean
test_format_float(unsigned verbose, FILE *fp,
- const struct util_format_description *desc)
+ const struct util_format_description *desc,
+ unsigned use_cache)
{
LLVMContextRef context;
struct gallivm_state *gallivm;
context = LLVMContextCreate();
gallivm = gallivm_create("test_module_float", context);
- fetch = add_fetch_rgba_test(gallivm, verbose, desc, lp_float32_vec4_type());
+ fetch = add_fetch_rgba_test(gallivm, verbose, desc,
+ lp_float32_vec4_type(), use_cache);
gallivm_compile_module(gallivm);
memset(unpacked, 0, sizeof unpacked);
- fetch_ptr(unpacked, packed, j, i, cache_ptr);
+ fetch_ptr(unpacked, packed, j, i, use_cache ? cache_ptr : NULL);
for(k = 0; k < 4; ++k) {
if (util_double_inf_sign(test->unpacked[i][j][k]) != util_inf_sign(unpacked[k])) {
PIPE_ALIGN_STACK
static boolean
test_format_unorm8(unsigned verbose, FILE *fp,
- const struct util_format_description *desc)
+ const struct util_format_description *desc,
+ unsigned use_cache)
{
LLVMContextRef context;
struct gallivm_state *gallivm;
context = LLVMContextCreate();
gallivm = gallivm_create("test_module_unorm8", context);
- fetch = add_fetch_rgba_test(gallivm, verbose, desc, lp_unorm8_vec4_type());
+ fetch = add_fetch_rgba_test(gallivm, verbose, desc,
+ lp_unorm8_vec4_type(), use_cache);
gallivm_compile_module(gallivm);
memset(unpacked, 0, sizeof unpacked);
- fetch_ptr(unpacked, packed, j, i, cache_ptr);
+ fetch_ptr(unpacked, packed, j, i, use_cache ? cache_ptr : NULL);
match = TRUE;
for(k = 0; k < 4; ++k) {
static boolean
test_one(unsigned verbose, FILE *fp,
- const struct util_format_description *format_desc)
+ const struct util_format_description *format_desc,
+ unsigned use_cache)
{
boolean success = TRUE;
- if (!test_format_float(verbose, fp, format_desc)) {
+ if (!test_format_float(verbose, fp, format_desc, use_cache)) {
success = FALSE;
}
- if (!test_format_unorm8(verbose, fp, format_desc)) {
+ if (!test_format_unorm8(verbose, fp, format_desc, use_cache)) {
success = FALSE;
}
{
enum pipe_format format;
boolean success = TRUE;
+ unsigned use_cache;
-#if USE_TEXTURE_CACHE
cache_ptr = align_malloc(sizeof(struct lp_build_format_cache), 16);
-#endif
- for (format = 1; format < PIPE_FORMAT_COUNT; ++format) {
- const struct util_format_description *format_desc;
+ for (use_cache = 0; use_cache < 2; use_cache++) {
+ for (format = 1; format < PIPE_FORMAT_COUNT; ++format) {
+ const struct util_format_description *format_desc;
- format_desc = util_format_description(format);
- if (!format_desc) {
- continue;
- }
+ format_desc = util_format_description(format);
+ if (!format_desc) {
+ continue;
+ }
+ /*
+ * TODO: test more
+ */
- /*
- * TODO: test more
- */
+ if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) {
+ continue;
+ }
- if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) {
- continue;
- }
+ if (util_format_is_pure_integer(format))
+ continue;
- if (util_format_is_pure_integer(format))
- continue;
+ /* only have util fetch func for etc1 */
+ if (format_desc->layout == UTIL_FORMAT_LAYOUT_ETC &&
+ format != PIPE_FORMAT_ETC1_RGB8) {
+ continue;
+ }
- /* only have util fetch func for etc1 */
- if (format_desc->layout == UTIL_FORMAT_LAYOUT_ETC &&
- format != PIPE_FORMAT_ETC1_RGB8) {
- continue;
- }
+ /* missing fetch funcs */
+ if (format_desc->layout == UTIL_FORMAT_LAYOUT_ASTC) {
+ continue;
+ }
- /* missing fetch funcs */
- if (format_desc->layout == UTIL_FORMAT_LAYOUT_ASTC) {
- continue;
- }
+ /* only test twice with formats which can use cache */
+ if (format_desc->layout != UTIL_FORMAT_LAYOUT_S3TC && use_cache) {
+ continue;
+ }
- if (!test_one(verbose, fp, format_desc)) {
- success = FALSE;
+ if (!test_one(verbose, fp, format_desc, use_cache)) {
+ success = FALSE;
+ }
}
}
-#if USE_TEXTURE_CACHE
align_free(cache_ptr);
-#endif
return success;
}