summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/llvmpipe
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/drivers/llvmpipe')
-rw-r--r--src/gallium/drivers/llvmpipe/SConscript1
-rw-r--r--src/gallium/drivers/llvmpipe/lp_bld_arit.c112
-rw-r--r--src/gallium/drivers/llvmpipe/lp_bld_arit.h94
-rw-r--r--src/gallium/drivers/llvmpipe/lp_bld_blend.c1
-rw-r--r--src/gallium/drivers/llvmpipe/lp_bld_type.c142
-rw-r--r--src/gallium/drivers/llvmpipe/lp_bld_type.h131
-rw-r--r--src/gallium/drivers/llvmpipe/lp_test_blend.c1
7 files changed, 278 insertions, 204 deletions
diff --git a/src/gallium/drivers/llvmpipe/SConscript b/src/gallium/drivers/llvmpipe/SConscript
index 8d4d6736fc..615a885cc5 100644
--- a/src/gallium/drivers/llvmpipe/SConscript
+++ b/src/gallium/drivers/llvmpipe/SConscript
@@ -18,6 +18,7 @@ llvmpipe = env.ConvenienceLibrary(
'lp_bld_loop.c',
'lp_bld_logicop.c',
'lp_bld_blend.c',
+ 'lp_bld_type.c',
'lp_clear.c',
'lp_context.c',
'lp_draw_arrays.c',
diff --git a/src/gallium/drivers/llvmpipe/lp_bld_arit.c b/src/gallium/drivers/llvmpipe/lp_bld_arit.c
index db0db02c15..36b266a45a 100644
--- a/src/gallium/drivers/llvmpipe/lp_bld_arit.c
+++ b/src/gallium/drivers/llvmpipe/lp_bld_arit.c
@@ -47,120 +47,10 @@
#include "pipe/p_state.h"
+#include "lp_bld_type.h"
#include "lp_bld_arit.h"
-LLVMTypeRef
-lp_build_elem_type(union lp_type type)
-{
- if (type.floating) {
- assert(type.sign);
- switch(type.width) {
- case 32:
- return LLVMFloatType();
- break;
- case 64:
- return LLVMDoubleType();
- break;
- default:
- assert(0);
- return LLVMFloatType();
- }
- }
- else {
- return LLVMIntType(type.width);
- }
-}
-
-
-LLVMTypeRef
-lp_build_vec_type(union lp_type type)
-{
- LLVMTypeRef elem_type = lp_build_elem_type(type);
- return LLVMVectorType(elem_type, type.length);
-}
-
-
-/**
- * This function is a mirrot of lp_build_elem_type() above.
- *
- * XXX: I'm not sure if it wouldn't be easier/efficient to just recreate the
- * type and check for identity.
- */
-boolean
-lp_check_elem_type(union lp_type type, LLVMTypeRef elem_type)
-{
- LLVMTypeKind elem_kind;
-
- assert(elem_type);
- if(!elem_type)
- return FALSE;
-
- elem_kind = LLVMGetTypeKind(elem_type);
-
- if (type.floating) {
- switch(type.width) {
- case 32:
- if(elem_kind != LLVMFloatTypeKind)
- return FALSE;
- break;
- case 64:
- if(elem_kind != LLVMDoubleTypeKind)
- return FALSE;
- break;
- default:
- assert(0);
- return FALSE;
- }
- }
- else {
- if(elem_kind != LLVMIntegerTypeKind)
- return FALSE;
-
- if(LLVMGetIntTypeWidth(elem_type) != type.width)
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-boolean
-lp_check_vec_type(union lp_type type, LLVMTypeRef vec_type)
-{
- LLVMTypeRef elem_type;
-
- assert(vec_type);
- if(!vec_type)
- return FALSE;
-
- if(LLVMGetTypeKind(vec_type) != LLVMVectorTypeKind)
- return FALSE;
-
- if(LLVMGetVectorSize(vec_type) != type.length)
- return FALSE;
-
- elem_type = LLVMGetElementType(vec_type);
-
- return lp_check_elem_type(type, elem_type);
-}
-
-
-boolean
-lp_check_value(union lp_type type, LLVMValueRef val)
-{
- LLVMTypeRef vec_type;
-
- assert(val);
- if(!val)
- return FALSE;
-
- vec_type = LLVMTypeOf(val);
-
- return lp_check_vec_type(type, vec_type);
-}
-
-
LLVMValueRef
lp_build_undef(union lp_type type)
{
diff --git a/src/gallium/drivers/llvmpipe/lp_bld_arit.h b/src/gallium/drivers/llvmpipe/lp_bld_arit.h
index 795b816507..c437d2bcd0 100644
--- a/src/gallium/drivers/llvmpipe/lp_bld_arit.h
+++ b/src/gallium/drivers/llvmpipe/lp_bld_arit.h
@@ -39,100 +39,8 @@
#include <llvm-c/Core.h>
-
-#define LP_MAX_VECTOR_LENGTH 16
-
-/*
- * Types
- */
-
-
-enum lp_type_kind {
- LP_TYPE_INTEGER = 0,
- LP_TYPE_FLOAT = 1,
- LP_TYPE_FIXED = 2
-};
-
-
-/**
- * The LLVM type system can't conveniently express all the things we care about
- * on the types used for intermediate computations, such as signed vs unsigned,
- * normalized values, or fixed point.
- */
-union lp_type {
- struct {
- /**
- * Integer. floating-point, or fixed point as established by the
- * lp_build_type_kind enum above.
- */
- unsigned floating:1;
-
- /**
- * Integer. floating-point, or fixed point as established by the
- * lp_build_type_kind enum above.
- */
- unsigned fixed:1;
-
- /**
- * Whether it can represent negative values or not.
- *
- * Floating point values
- */
- unsigned sign:1;
-
- /**
- * Whether values are normalized to fit [0, 1] interval, or [-1, 1] interval for
- * signed types.
- *
- * For integer types it means the representable integer range should be
- * interpreted as the interval above.
- *
- * For floating and fixed point formats it means the values should be
- * clamped to the interval above.
- */
- unsigned norm:1;
-
- /**
- * Element width.
- *
- * For fixed point values, the fixed point is assumed to be at half the width.
- */
- unsigned width:14;
-
- /**
- * Vector length.
- *
- * width*length should be a power of two greater or equal to height.
- *
- * Several functions can only cope with vectors of length up to
- * LP_MAX_VECTOR_LENGTH, so you may need to increase that value if you
- * want to represent bigger vectors.
- */
- unsigned length:14;
- };
- uint32_t value;
-};
-
-
-LLVMTypeRef
-lp_build_elem_type(union lp_type type);
-
-
-LLVMTypeRef
-lp_build_vec_type(union lp_type type);
-
-
-boolean
-lp_check_elem_type(union lp_type type, LLVMTypeRef elem_type);
-
-
-boolean
-lp_check_vec_type(union lp_type type, LLVMTypeRef vec_type);
-
-
-boolean
-lp_check_value(union lp_type type, LLVMValueRef val);
+union lp_type type;
/*
diff --git a/src/gallium/drivers/llvmpipe/lp_bld_blend.c b/src/gallium/drivers/llvmpipe/lp_bld_blend.c
index 31dbee7d6e..2c5e67418f 100644
--- a/src/gallium/drivers/llvmpipe/lp_bld_blend.c
+++ b/src/gallium/drivers/llvmpipe/lp_bld_blend.c
@@ -40,6 +40,7 @@
#include "pipe/p_state.h"
#include "lp_bld.h"
+#include "lp_bld_type.h"
#include "lp_bld_arit.h"
diff --git a/src/gallium/drivers/llvmpipe/lp_bld_type.c b/src/gallium/drivers/llvmpipe/lp_bld_type.c
new file mode 100644
index 0000000000..e2abd04f60
--- /dev/null
+++ b/src/gallium/drivers/llvmpipe/lp_bld_type.c
@@ -0,0 +1,142 @@
+/**************************************************************************
+ *
+ * Copyright 2009 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+
+#include "util/u_debug.h"
+
+#include "lp_bld_type.h"
+
+
+LLVMTypeRef
+lp_build_elem_type(union lp_type type)
+{
+ if (type.floating) {
+ assert(type.sign);
+ switch(type.width) {
+ case 32:
+ return LLVMFloatType();
+ break;
+ case 64:
+ return LLVMDoubleType();
+ break;
+ default:
+ assert(0);
+ return LLVMFloatType();
+ }
+ }
+ else {
+ return LLVMIntType(type.width);
+ }
+}
+
+
+LLVMTypeRef
+lp_build_vec_type(union lp_type type)
+{
+ LLVMTypeRef elem_type = lp_build_elem_type(type);
+ return LLVMVectorType(elem_type, type.length);
+}
+
+
+/**
+ * This function is a mirrot of lp_build_elem_type() above.
+ *
+ * XXX: I'm not sure if it wouldn't be easier/efficient to just recreate the
+ * type and check for identity.
+ */
+boolean
+lp_check_elem_type(union lp_type type, LLVMTypeRef elem_type)
+{
+ LLVMTypeKind elem_kind;
+
+ assert(elem_type);
+ if(!elem_type)
+ return FALSE;
+
+ elem_kind = LLVMGetTypeKind(elem_type);
+
+ if (type.floating) {
+ switch(type.width) {
+ case 32:
+ if(elem_kind != LLVMFloatTypeKind)
+ return FALSE;
+ break;
+ case 64:
+ if(elem_kind != LLVMDoubleTypeKind)
+ return FALSE;
+ break;
+ default:
+ assert(0);
+ return FALSE;
+ }
+ }
+ else {
+ if(elem_kind != LLVMIntegerTypeKind)
+ return FALSE;
+
+ if(LLVMGetIntTypeWidth(elem_type) != type.width)
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+boolean
+lp_check_vec_type(union lp_type type, LLVMTypeRef vec_type)
+{
+ LLVMTypeRef elem_type;
+
+ assert(vec_type);
+ if(!vec_type)
+ return FALSE;
+
+ if(LLVMGetTypeKind(vec_type) != LLVMVectorTypeKind)
+ return FALSE;
+
+ if(LLVMGetVectorSize(vec_type) != type.length)
+ return FALSE;
+
+ elem_type = LLVMGetElementType(vec_type);
+
+ return lp_check_elem_type(type, elem_type);
+}
+
+
+boolean
+lp_check_value(union lp_type type, LLVMValueRef val)
+{
+ LLVMTypeRef vec_type;
+
+ assert(val);
+ if(!val)
+ return FALSE;
+
+ vec_type = LLVMTypeOf(val);
+
+ return lp_check_vec_type(type, vec_type);
+}
diff --git a/src/gallium/drivers/llvmpipe/lp_bld_type.h b/src/gallium/drivers/llvmpipe/lp_bld_type.h
new file mode 100644
index 0000000000..4623183223
--- /dev/null
+++ b/src/gallium/drivers/llvmpipe/lp_bld_type.h
@@ -0,0 +1,131 @@
+/**************************************************************************
+ *
+ * Copyright 2009 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/**
+ * @file
+ * Convenient representation of SIMD types.
+ *
+ * @author Jose Fonseca <jfonseca@vmware.com>
+ */
+
+
+#ifndef LP_BLD_TYPE_H
+#define LP_BLD_TYPE_H
+
+
+#include <llvm-c/Core.h>
+
+#include <pipe/p_compiler.h>
+
+
+/**
+ * Several functions can only cope with vectors of length up to this value.
+ * You may need to increase that value if you want to represent bigger vectors.
+ */
+#define LP_MAX_VECTOR_LENGTH 16
+
+
+/**
+ * The LLVM type system can't conveniently express all the things we care about
+ * on the types used for intermediate computations, such as signed vs unsigned,
+ * normalized values, or fixed point.
+ */
+union lp_type {
+ struct {
+ /**
+ * Floating-point. Cannot be used with fixed. Integer numbers are
+ * represented by this zero.
+ */
+ unsigned floating:1;
+
+ /**
+ * Fixed-point. Cannot be used with floating. Integer numbers are
+ * represented by this zero.
+ */
+ unsigned fixed:1;
+
+ /**
+ * Whether it can represent negative values or not.
+ *
+ * Floating point values should always have this bit set.
+ */
+ unsigned sign:1;
+
+ /**
+ * Whether values are normalized to fit [0, 1] interval, or [-1, 1]
+ * interval for signed types.
+ *
+ * For integer types it means the representable integer range should be
+ * interpreted as the interval above.
+ *
+ * For floating and fixed point formats it means the values should be
+ * clamped to the interval above.
+ */
+ unsigned norm:1;
+
+ /**
+ * Element width.
+ *
+ * For fixed point values, the fixed point is assumed to be at half the
+ * width.
+ */
+ unsigned width:14;
+
+ /**
+ * Vector length.
+ *
+ * width*length should be a power of two greater or equal to eight.
+ *
+ * @sa LP_MAX_VECTOR_LENGTH
+ */
+ unsigned length:14;
+ };
+ uint32_t value;
+};
+
+
+LLVMTypeRef
+lp_build_elem_type(union lp_type type);
+
+
+LLVMTypeRef
+lp_build_vec_type(union lp_type type);
+
+
+boolean
+lp_check_elem_type(union lp_type type, LLVMTypeRef elem_type);
+
+
+boolean
+lp_check_vec_type(union lp_type type, LLVMTypeRef vec_type);
+
+
+boolean
+lp_check_value(union lp_type type, LLVMValueRef val);
+
+
+#endif /* !LP_BLD_TYPE_H */
diff --git a/src/gallium/drivers/llvmpipe/lp_test_blend.c b/src/gallium/drivers/llvmpipe/lp_test_blend.c
index cf641c1b67..60ba8d839c 100644
--- a/src/gallium/drivers/llvmpipe/lp_test_blend.c
+++ b/src/gallium/drivers/llvmpipe/lp_test_blend.c
@@ -53,6 +53,7 @@
#include "util/u_math.h"
#include "lp_bld.h"
+#include "lp_bld_type.h"
#include "lp_bld_arit.h"