From c87fab0008453567b45dd5e5eb7dd5d026990071 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Mon, 3 Aug 2009 22:24:01 +0100 Subject: [PATCH] llvmpipe: Move type support functions into a separate file. --- src/gallium/drivers/llvmpipe/SConscript | 1 + src/gallium/drivers/llvmpipe/lp_bld_arit.c | 112 +-------------- src/gallium/drivers/llvmpipe/lp_bld_arit.h | 94 +----------- src/gallium/drivers/llvmpipe/lp_bld_blend.c | 1 + src/gallium/drivers/llvmpipe/lp_bld_type.c | 142 +++++++++++++++++++ src/gallium/drivers/llvmpipe/lp_bld_type.h | 131 +++++++++++++++++ src/gallium/drivers/llvmpipe/lp_test_blend.c | 1 + 7 files changed, 278 insertions(+), 204 deletions(-) create mode 100644 src/gallium/drivers/llvmpipe/lp_bld_type.c create mode 100644 src/gallium/drivers/llvmpipe/lp_bld_type.h diff --git a/src/gallium/drivers/llvmpipe/SConscript b/src/gallium/drivers/llvmpipe/SConscript index 8d4d6736fcc..615a885cc5f 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 db0db02c152..36b266a45a6 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 795b8165071..c437d2bcd00 100644 --- a/src/gallium/drivers/llvmpipe/lp_bld_arit.h +++ b/src/gallium/drivers/llvmpipe/lp_bld_arit.h @@ -39,100 +39,8 @@ #include - -#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 31dbee7d6ec..2c5e67418fb 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 00000000000..e2abd04f608 --- /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 00000000000..46231832236 --- /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 + */ + + +#ifndef LP_BLD_TYPE_H +#define LP_BLD_TYPE_H + + +#include + +#include + + +/** + * 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 cf641c1b679..60ba8d839c6 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" -- 2.30.2