gallivm: asst. clean-ups in lp_bld_const.c

Signed-off-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17561>
This commit is contained in:
Brian Paul 2022-06-22 09:57:47 -06:00 committed by Marge Bot
parent 0e9cf32059
commit 49966374c8

View file

@ -44,6 +44,7 @@
#include "lp_bld_init.h" #include "lp_bld_init.h"
#include "lp_bld_limits.h" #include "lp_bld_limits.h"
unsigned unsigned
lp_mantissa(struct lp_type type) lp_mantissa(struct lp_type type)
{ {
@ -61,8 +62,7 @@ lp_mantissa(struct lp_type type)
assert(0); assert(0);
return 0; return 0;
} }
} } else {
else {
if (type.sign) if (type.sign)
return type.width - 1; return type.width - 1;
else else
@ -129,8 +129,6 @@ lp_const_scale(struct lp_type type)
double double
lp_const_min(struct lp_type type) lp_const_min(struct lp_type type)
{ {
unsigned bits;
if (!type.sign) if (!type.sign)
return 0.0; return 0.0;
@ -151,6 +149,7 @@ lp_const_min(struct lp_type type)
} }
} }
unsigned bits;
if (type.fixed) if (type.fixed)
/* FIXME: consider the fractional bits? */ /* FIXME: consider the fractional bits? */
bits = type.width / 2 - 1; bits = type.width / 2 - 1;
@ -167,8 +166,6 @@ lp_const_min(struct lp_type type)
double double
lp_const_max(struct lp_type type) lp_const_max(struct lp_type type)
{ {
unsigned bits;
if (type.norm) if (type.norm)
return 1.0; return 1.0;
@ -186,6 +183,7 @@ lp_const_max(struct lp_type type)
} }
} }
unsigned bits;
if (type.fixed) if (type.fixed)
bits = type.width / 2; bits = type.width / 2;
else else
@ -213,8 +211,7 @@ lp_const_eps(struct lp_type type)
assert(0); assert(0);
return 0.0; return 0.0;
} }
} } else {
else {
double scale = lp_const_scale(type); double scale = lp_const_scale(type);
return 1.0/scale; return 1.0/scale;
} }
@ -237,8 +234,7 @@ lp_build_zero(struct gallivm_state *gallivm, struct lp_type type)
return lp_build_const_float(gallivm, 0.0); return lp_build_const_float(gallivm, 0.0);
else else
return LLVMConstInt(LLVMIntTypeInContext(gallivm->context, type.width), 0, 0); return LLVMConstInt(LLVMIntTypeInContext(gallivm->context, type.width), 0, 0);
} } else {
else {
LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type); LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type);
return LLVMConstNull(vec_type); return LLVMConstNull(vec_type);
} }
@ -250,7 +246,6 @@ lp_build_one(struct gallivm_state *gallivm, struct lp_type type)
{ {
LLVMTypeRef elem_type; LLVMTypeRef elem_type;
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i;
assert(type.length <= LP_MAX_VECTOR_LENGTH); assert(type.length <= LP_MAX_VECTOR_LENGTH);
@ -282,7 +277,7 @@ lp_build_one(struct gallivm_state *gallivm, struct lp_type type)
return vec; return vec;
} }
for(i = 1; i < type.length; ++i) for (unsigned i = 1; i < type.length; ++i)
elems[i] = elems[0]; elems[i] = elems[0];
if (type.length == 1) if (type.length == 1)
@ -307,8 +302,7 @@ lp_build_const_elem(struct gallivm_state *gallivm,
elem = LLVMConstInt(elem_type, _mesa_float_to_half((float)val), 0); elem = LLVMConstInt(elem_type, _mesa_float_to_half((float)val), 0);
} else if (type.floating) { } else if (type.floating) {
elem = LLVMConstReal(elem_type, val); elem = LLVMConstReal(elem_type, val);
} } else {
else {
double dscale = lp_const_scale(type); double dscale = lp_const_scale(type);
elem = LLVMConstInt(elem_type, (long long) round(val*dscale), 0); elem = LLVMConstInt(elem_type, (long long) round(val*dscale), 0);
@ -329,9 +323,8 @@ lp_build_const_vec(struct gallivm_state *gallivm, struct lp_type type,
return lp_build_const_elem(gallivm, type, val); return lp_build_const_elem(gallivm, type, val);
} else { } else {
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i;
elems[0] = lp_build_const_elem(gallivm, type, val); elems[0] = lp_build_const_elem(gallivm, type, val);
for(i = 1; i < type.length; ++i) for (unsigned i = 1; i < type.length; ++i)
elems[i] = elems[0]; elems[i] = elems[0];
return LLVMConstVector(elems, type.length); return LLVMConstVector(elems, type.length);
} }
@ -344,11 +337,10 @@ lp_build_const_int_vec(struct gallivm_state *gallivm, struct lp_type type,
{ {
LLVMTypeRef elem_type = lp_build_int_elem_type(gallivm, type); LLVMTypeRef elem_type = lp_build_int_elem_type(gallivm, type);
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i;
assert(type.length <= LP_MAX_VECTOR_LENGTH); assert(type.length <= LP_MAX_VECTOR_LENGTH);
for(i = 0; i < type.length; ++i) for (unsigned i = 0; i < type.length; ++i)
elems[i] = LLVMConstInt(elem_type, val, type.sign ? 1 : 0); elems[i] = LLVMConstInt(elem_type, val, type.sign ? 1 : 0);
if (type.length == 1) if (type.length == 1)
@ -366,7 +358,6 @@ lp_build_const_aos(struct gallivm_state *gallivm,
{ {
const unsigned char default_swizzle[4] = {0, 1, 2, 3}; const unsigned char default_swizzle[4] = {0, 1, 2, 3};
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i;
assert(type.length % 4 == 0); assert(type.length % 4 == 0);
assert(type.length <= LP_MAX_VECTOR_LENGTH); assert(type.length <= LP_MAX_VECTOR_LENGTH);
@ -381,7 +372,7 @@ lp_build_const_aos(struct gallivm_state *gallivm,
elems[swizzle[2]] = lp_build_const_elem(gallivm, type, b); elems[swizzle[2]] = lp_build_const_elem(gallivm, type, b);
elems[swizzle[3]] = lp_build_const_elem(gallivm, type, a); elems[swizzle[3]] = lp_build_const_elem(gallivm, type, a);
for(i = 4; i < type.length; ++i) for (unsigned i = 4; i < type.length; ++i)
elems[i] = elems[i % 4]; elems[i] = elems[i % 4];
return LLVMConstVector(elems, type.length); return LLVMConstVector(elems, type.length);
@ -399,12 +390,11 @@ lp_build_const_mask_aos(struct gallivm_state *gallivm,
{ {
LLVMTypeRef elem_type = LLVMIntTypeInContext(gallivm->context, type.width); LLVMTypeRef elem_type = LLVMIntTypeInContext(gallivm->context, type.width);
LLVMValueRef masks[LP_MAX_VECTOR_LENGTH]; LLVMValueRef masks[LP_MAX_VECTOR_LENGTH];
unsigned i, j;
assert(type.length <= LP_MAX_VECTOR_LENGTH); assert(type.length <= LP_MAX_VECTOR_LENGTH);
for (j = 0; j < type.length; j += channels) { for (unsigned j = 0; j < type.length; j += channels) {
for( i = 0; i < channels; ++i) { for (unsigned i = 0; i < channels; ++i) {
masks[j + i] = LLVMConstInt(elem_type, masks[j + i] = LLVMConstInt(elem_type,
mask & (1 << i) ? ~0ULL : 0, mask & (1 << i) ? ~0ULL : 0,
1); 1);
@ -425,10 +415,9 @@ lp_build_const_mask_aos_swizzled(struct gallivm_state *gallivm,
unsigned channels, unsigned channels,
const unsigned char *swizzle) const unsigned char *swizzle)
{ {
unsigned i, mask_swizzled; unsigned mask_swizzled = 0;
mask_swizzled = 0;
for (i = 0; i < channels; ++i) { for (unsigned i = 0; i < channels; ++i) {
if (swizzle[i] < 4) { if (swizzle[i] < 4) {
mask_swizzled |= ((mask & (1 << swizzle[i])) >> swizzle[i]) << i; mask_swizzled |= ((mask & (1 << swizzle[i])) >> swizzle[i]) << i;
} }
@ -455,6 +444,7 @@ lp_build_const_string(struct gallivm_state *gallivm,
return string; return string;
} }
LLVMValueRef LLVMValueRef
lp_build_const_func_pointer_from_type(struct gallivm_state *gallivm, lp_build_const_func_pointer_from_type(struct gallivm_state *gallivm,
const void *ptr, const void *ptr,
@ -467,6 +457,7 @@ lp_build_const_func_pointer_from_type(struct gallivm_state *gallivm,
name); name);
} }
/** /**
* Build a callable function pointer. * Build a callable function pointer.
* *