summaryrefslogtreecommitdiff
path: root/lib/mesa/src/gallium/auxiliary/gallivm
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2020-01-22 02:13:18 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2020-01-22 02:13:18 +0000
commitfdcc03929065b5bf5dd93553db219ea3e05c8c34 (patch)
treeca90dc8d9e89febdcd4160956c1b8ec098a4efc9 /lib/mesa/src/gallium/auxiliary/gallivm
parent3c9de4a7e13712b5696750bbd59a18c848742022 (diff)
Import Mesa 19.2.8
Diffstat (limited to 'lib/mesa/src/gallium/auxiliary/gallivm')
-rw-r--r--lib/mesa/src/gallium/auxiliary/gallivm/f.cpp101
-rw-r--r--lib/mesa/src/gallium/auxiliary/gallivm/lp_bld.h1
-rw-r--r--lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_arit_overflow.c4
-rw-r--r--lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp4
-rw-r--r--lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_debug.h11
-rw-r--r--lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c40
-rw-r--r--lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_printf.c8
7 files changed, 134 insertions, 35 deletions
diff --git a/lib/mesa/src/gallium/auxiliary/gallivm/f.cpp b/lib/mesa/src/gallium/auxiliary/gallivm/f.cpp
new file mode 100644
index 000000000..4b33e49b4
--- /dev/null
+++ b/lib/mesa/src/gallium/auxiliary/gallivm/f.cpp
@@ -0,0 +1,101 @@
+/**************************************************************************
+ *
+ * (C) Copyright VMware, Inc 2010.
+ * (C) Copyright John Maddock 2006.
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ **************************************************************************/
+
+
+/*
+ * This file allows to compute the minimax polynomial coefficients we use
+ * for fast exp2/log2.
+ *
+ * How to use this source:
+ *
+ * - Download and build the NTL library from
+ * http://shoup.net/ntl/download.html , or install libntl-dev package if on
+ * Debian.
+ *
+ * - Download boost source code matching to your distro.
+ *
+ * - Goto libs/math/minimax and replace f.cpp with this file.
+ *
+ * - Build as
+ *
+ * g++ -o minimax -I /path/to/ntl/include main.cpp f.cpp /path/to/ntl/src/ntl.a
+ *
+ * - Run as
+ *
+ * ./minimax
+ *
+ * - For example, to compute exp2 5th order polynomial between [0, 1] do:
+ *
+ * variant 0
+ * range 0 1
+ * order 5 0
+ * step 200
+ * info
+ *
+ * and take the coefficients from the P = { ... } array.
+ *
+ * - To compute log2 4th order polynomial between [0, 1/9] do:
+ *
+ * variant 1
+ * range 0 0.111111112
+ * order 4 0
+ * step 200
+ * info
+ *
+ * - For more info see
+ * http://www.boost.org/doc/libs/1_47_0/libs/math/doc/sf_and_dist/html/math_toolkit/toolkit/internals2/minimax.html
+ */
+
+#define L22
+#include <boost/math/bindings/rr.hpp>
+#include <boost/math/tools/polynomial.hpp>
+
+#include <cmath>
+
+boost::math::ntl::RR exp2(const boost::math::ntl::RR& x)
+{
+ return exp(x*log(2.0));
+}
+
+boost::math::ntl::RR log2(const boost::math::ntl::RR& x)
+{
+ return log(x)/log(2.0);
+}
+
+boost::math::ntl::RR f(const boost::math::ntl::RR& x, int variant)
+{
+ switch(variant)
+ {
+ case 0:
+ return exp2(x);
+
+ case 1:
+ return log2((1.0 + sqrt(x))/(1.0 - sqrt(x)))/sqrt(x);
+ }
+
+ return 0;
+}
+
+
+void show_extra(
+ const boost::math::tools::polynomial<boost::math::ntl::RR>& n,
+ const boost::math::tools::polynomial<boost::math::ntl::RR>& d,
+ const boost::math::ntl::RR& x_offset,
+ const boost::math::ntl::RR& y_offset,
+ int variant)
+{
+ switch(variant)
+ {
+ default:
+ // do nothing here...
+ ;
+ }
+}
+
diff --git a/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld.h b/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld.h
index 239c27e3c..ca23005b8 100644
--- a/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld.h
+++ b/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld.h
@@ -108,5 +108,4 @@ typedef void *LLVMMCJITMemoryManagerRef;
# define LLVMSetAlignment LLVMSetAlignmentBackport
#endif
-
#endif /* LP_BLD_H */
diff --git a/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_arit_overflow.c b/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_arit_overflow.c
index 152ad5734..ab931190c 100644
--- a/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_arit_overflow.c
+++ b/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_arit_overflow.c
@@ -80,8 +80,8 @@ build_binary_int_overflow(struct gallivm_state *gallivm,
debug_assert(type_width == 16 || type_width == 32 || type_width == 64);
- util_snprintf(intr_str, sizeof intr_str, "%s.i%u",
- intr_prefix, type_width);
+ snprintf(intr_str, sizeof intr_str, "%s.i%u",
+ intr_prefix, type_width);
oelems[0] = type_ref;
oelems[1] = LLVMInt1TypeInContext(gallivm->context);
diff --git a/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp b/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp
index 23ada3d04..1bada6ff3 100644
--- a/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp
+++ b/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp
@@ -241,9 +241,9 @@ lp_profile(LLVMValueRef func, const void *code)
if (getenv("PERF_BUILDID_DIR")) {
pid_t pid = getpid();
char filename[256];
- util_snprintf(filename, sizeof filename, "/tmp/perf-%llu.map", (unsigned long long)pid);
+ snprintf(filename, sizeof filename, "/tmp/perf-%llu.map", (unsigned long long)pid);
perf_map_file = fopen(filename, "wt");
- util_snprintf(filename, sizeof filename, "/tmp/perf-%llu.map.asm", (unsigned long long)pid);
+ snprintf(filename, sizeof filename, "/tmp/perf-%llu.map.asm", (unsigned long long)pid);
perf_asm_file.open(filename);
}
first_time = FALSE;
diff --git a/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_debug.h b/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_debug.h
index eeef0d6ba..1ea133264 100644
--- a/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_debug.h
+++ b/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_debug.h
@@ -43,10 +43,11 @@
#define GALLIVM_DEBUG_GC (1 << 4)
#define GALLIVM_DEBUG_DUMP_BC (1 << 5)
-#define GALLIVM_PERF_NO_BRILINEAR (1 << 0)
-#define GALLIVM_PERF_NO_RHO_APPROX (1 << 1)
-#define GALLIVM_PERF_NO_QUAD_LOD (1 << 2)
-#define GALLIVM_PERF_NO_OPT (1 << 3)
+#define GALLIVM_PERF_NO_BRILINEAR (1 << 0)
+#define GALLIVM_PERF_NO_RHO_APPROX (1 << 1)
+#define GALLIVM_PERF_NO_QUAD_LOD (1 << 2)
+#define GALLIVM_PERF_NO_OPT (1 << 3)
+#define GALLIVM_PERF_NO_AOS_SAMPLING (1 << 4)
#ifdef __cplusplus
extern "C" {
@@ -69,7 +70,7 @@ lp_build_name(LLVMValueRef val, const char *format, ...)
char name[32];
va_list ap;
va_start(ap, format);
- util_vsnprintf(name, sizeof name, format, ap);
+ vsnprintf(name, sizeof name, format, ap);
va_end(ap);
LLVMSetValueName(val, name);
#else
diff --git a/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c b/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c
index 9561c349d..6d934891c 100644
--- a/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c
+++ b/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c
@@ -77,24 +77,17 @@ lp_build_uninterleave2_half(struct gallivm_state *gallivm,
unsigned lo_hi)
{
LLVMValueRef shuffle, elems[LP_MAX_VECTOR_LENGTH];
- unsigned i, j;
+ unsigned i;
assert(type.length <= LP_MAX_VECTOR_LENGTH);
assert(lo_hi < 2);
if (type.length * type.width == 256) {
- assert(type.length >= 4);
- for (i = 0, j = 0; i < type.length; ++i) {
- if (i == type.length / 4) {
- j = type.length;
- } else if (i == type.length / 2) {
- j = type.length / 2;
- } else if (i == 3 * type.length / 4) {
- j = 3 * type.length / 4;
- } else {
- j += 2;
- }
- elems[i] = lp_build_const_int32(gallivm, j + lo_hi);
+ assert(type.length == 8);
+ assert(type.width == 32);
+ static const unsigned shufvals[8] = {0, 2, 8, 10, 4, 6, 12, 14};
+ for (i = 0; i < type.length; ++i) {
+ elems[i] = lp_build_const_int32(gallivm, shufvals[i] + lo_hi);
}
} else {
for (i = 0; i < type.length; ++i) {
@@ -277,7 +270,7 @@ lp_build_gather_s3tc(struct gallivm_state *gallivm,
}
else {
LLVMValueRef tmp[4], cc01, cc23;
- struct lp_type lp_type32, lp_type64, lp_type32dxt;
+ struct lp_type lp_type32, lp_type64;
memset(&lp_type32, 0, sizeof lp_type32);
lp_type32.width = 32;
lp_type32.length = length;
@@ -309,10 +302,13 @@ lp_build_gather_s3tc(struct gallivm_state *gallivm,
lp_build_const_extend_shuffle(gallivm, 2, 4), "");
}
if (length == 8) {
+ struct lp_type lp_type32_4 = {0};
+ lp_type32_4.width = 32;
+ lp_type32_4.length = 4;
for (i = 0; i < 4; ++i) {
tmp[0] = elems[i];
tmp[1] = elems[i+4];
- elems[i] = lp_build_concat(gallivm, tmp, lp_type32, 2);
+ elems[i] = lp_build_concat(gallivm, tmp, lp_type32_4, 2);
}
}
cc01 = lp_build_interleave2_half(gallivm, lp_type32, elems[0], elems[1], 0);
@@ -811,7 +807,7 @@ s3tc_dxt3_to_rgba_aos(struct gallivm_state *gallivm,
tmp = lp_build_select(&bld, sel_mask, alpha_low, alpha_hi);
bit_pos = LLVMBuildAnd(builder, bit_pos,
lp_build_const_int_vec(gallivm, type, 0xffffffdf), "");
- /* Warning: slow shift with per element count */
+ /* Warning: slow shift with per element count (without avx2) */
/*
* Could do pshufb here as well - just use appropriate 2 bits in bit_pos
* to select the right byte with pshufb. Then for the remaining one bit
@@ -1640,7 +1636,6 @@ s3tc_decode_block_dxt5(struct gallivm_state *gallivm,
lp_build_const_int_vec(gallivm, type16, 8), "");
alpha = LLVMBuildBitCast(builder, alpha, i64t, "");
shuffle1 = lp_build_const_shuffle1(gallivm, 0, 8);
- /* XXX this shuffle broken with LLVM 2.8 */
alpha0 = LLVMBuildShuffleVector(builder, alpha0, alpha0, shuffle1, "");
alpha1 = LLVMBuildShuffleVector(builder, alpha1, alpha1, shuffle1, "");
@@ -1953,8 +1948,8 @@ update_cached_block(struct gallivm_state *gallivm,
LLVMBasicBlockRef bb;
LLVMValueRef args[3];
- util_snprintf(name, sizeof name, "%s_update_cache_one_block",
- format_desc->short_name);
+ snprintf(name, sizeof name, "%s_update_cache_one_block",
+ format_desc->short_name);
function = LLVMGetNamedFunction(module, name);
if (!function) {
@@ -2176,6 +2171,9 @@ lp_build_fetch_s3tc_rgba_aos(struct gallivm_state *gallivm,
return rgba;
}
+ /*
+ * Could use n > 8 here with avx2, but doesn't seem faster.
+ */
if (n > 4) {
unsigned count;
LLVMTypeRef i8_vectype = LLVMVectorType(i8t, 4 * n);
@@ -2191,7 +2189,7 @@ lp_build_fetch_s3tc_rgba_aos(struct gallivm_state *gallivm,
rgba = LLVMGetUndef(i128_vectype);
for (count = 0; count < n / 4; count++) {
- LLVMValueRef colors, codewords, alpha_lo, alpha_hi;
+ LLVMValueRef colors, codewords, alpha_lo = NULL, alpha_hi = NULL;
i4 = lp_build_extract_range(gallivm, i, count * 4, 4);
j4 = lp_build_extract_range(gallivm, j, count * 4, 4);
@@ -2230,7 +2228,7 @@ lp_build_fetch_s3tc_rgba_aos(struct gallivm_state *gallivm,
rgba = LLVMBuildBitCast(builder, rgba, i8_vectype, "");
}
else {
- LLVMValueRef colors, codewords, alpha_lo, alpha_hi;
+ LLVMValueRef colors, codewords, alpha_lo = NULL, alpha_hi = NULL;
lp_build_gather_s3tc(gallivm, n, format_desc, &colors, &codewords,
&alpha_lo, &alpha_hi, base_ptr, offset);
diff --git a/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_printf.c b/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_printf.c
index 53c4d3cde..a4233a24e 100644
--- a/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_printf.c
+++ b/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_printf.c
@@ -108,7 +108,7 @@ lp_build_print_value(struct gallivm_state *gallivm,
type_fmt[5] = '\0';
} else if (type_kind == LLVMIntegerTypeKind) {
if (LLVMGetIntTypeWidth(type_ref) == 64) {
- util_snprintf(type_fmt + 2, 3, "%s", PRId64);
+ snprintf(type_fmt + 2, 3, "%s", PRId64);
} else if (LLVMGetIntTypeWidth(type_ref) == 8) {
type_fmt[2] = 'u';
} else {
@@ -126,12 +126,12 @@ lp_build_print_value(struct gallivm_state *gallivm,
params[1] = lp_build_const_string(gallivm, msg);
if (length == 1) {
- util_strncat(format, type_fmt, sizeof(format) - strlen(format) - 1);
+ strncat(format, type_fmt, sizeof(format) - strlen(format) - 1);
params[2] = value;
} else {
for (i = 0; i < length; ++i) {
LLVMValueRef param;
- util_strncat(format, type_fmt, sizeof(format) - strlen(format) - 1);
+ strncat(format, type_fmt, sizeof(format) - strlen(format) - 1);
param = LLVMBuildExtractElement(builder, value, lp_build_const_int32(gallivm, i), "");
if (type_kind == LLVMIntegerTypeKind &&
LLVMGetIntTypeWidth(type_ref) < sizeof(int) * 8) {
@@ -146,7 +146,7 @@ lp_build_print_value(struct gallivm_state *gallivm,
}
}
- util_strncat(format, "\n", sizeof(format) - strlen(format) - 1);
+ strncat(format, "\n", sizeof(format) - strlen(format) - 1);
params[0] = lp_build_const_string(gallivm, format);
return lp_build_print_args(gallivm, 2 + length, params);