Path: blob/21.2-virgl/src/gallium/auxiliary/gallivm/lp_bld_const.h
4565 views
/**************************************************************************1*2* Copyright 2009 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627/**28* @file29* Helper functions for constant building.30*31* @author Jose Fonseca <[email protected]>32*/333435#ifndef LP_BLD_CONST_H36#define LP_BLD_CONST_H373839#include "pipe/p_compiler.h"40#include "gallivm/lp_bld.h"41#include "gallivm/lp_bld_init.h"42434445struct lp_type;464748unsigned49lp_mantissa(struct lp_type type);505152unsigned53lp_const_shift(struct lp_type type);545556unsigned57lp_const_offset(struct lp_type type);585960double61lp_const_scale(struct lp_type type);6263double64lp_const_min(struct lp_type type);656667double68lp_const_max(struct lp_type type);697071double72lp_const_eps(struct lp_type type);737475LLVMValueRef76lp_build_undef(struct gallivm_state *gallivm, struct lp_type type);777879LLVMValueRef80lp_build_zero(struct gallivm_state *gallivm, struct lp_type type);818283LLVMValueRef84lp_build_one(struct gallivm_state *gallivm, struct lp_type type);858687LLVMValueRef88lp_build_const_elem(struct gallivm_state *gallivm, struct lp_type type,89double val);9091LLVMValueRef92lp_build_const_vec(struct gallivm_state *gallivm, struct lp_type type,93double val);949596LLVMValueRef97lp_build_const_int_vec(struct gallivm_state *gallivm,98struct lp_type type, long long val);99100101LLVMValueRef102lp_build_const_aos(struct gallivm_state *gallivm, struct lp_type type,103double r, double g, double b, double a,104const unsigned char *swizzle);105106107LLVMValueRef108lp_build_const_mask_aos(struct gallivm_state *gallivm,109struct lp_type type,110unsigned mask,111unsigned channels);112113114LLVMValueRef115lp_build_const_mask_aos_swizzled(struct gallivm_state *gallivm,116struct lp_type type,117unsigned mask,118unsigned channels,119const unsigned char *swizzle);120121122static inline LLVMValueRef123lp_build_const_int32(struct gallivm_state *gallivm, int i)124{125return LLVMConstInt(LLVMInt32TypeInContext(gallivm->context), i, 0);126}127128static inline LLVMValueRef129lp_build_const_int64(struct gallivm_state *gallivm, int64_t i)130{131return LLVMConstInt(LLVMInt64TypeInContext(gallivm->context), i, 0);132}133134static inline LLVMValueRef135lp_build_const_float(struct gallivm_state *gallivm, float x)136{137return LLVMConstReal(LLVMFloatTypeInContext(gallivm->context), x);138}139140static inline LLVMValueRef141lp_build_const_double(struct gallivm_state *gallivm, float x)142{143return LLVMConstReal(LLVMDoubleTypeInContext(gallivm->context), x);144}145146147/** Return constant-valued pointer to int */148static inline LLVMValueRef149lp_build_const_int_pointer(struct gallivm_state *gallivm, const void *ptr)150{151LLVMTypeRef int_type;152LLVMValueRef v;153154/* int type large enough to hold a pointer */155int_type = LLVMIntTypeInContext(gallivm->context, 8 * sizeof(void *));156v = LLVMConstInt(int_type, (uintptr_t) ptr, 0);157v = LLVMBuildIntToPtr(gallivm->builder, v,158LLVMPointerType(int_type, 0),159"cast int to ptr");160return v;161}162163164LLVMValueRef165lp_build_const_string(struct gallivm_state *gallivm,166const char *str);167168169LLVMValueRef170lp_build_const_func_pointer(struct gallivm_state *gallivm,171const void *ptr,172LLVMTypeRef ret_type,173LLVMTypeRef *arg_types,174unsigned num_args,175const char *name);176177178#endif /* !LP_BLD_CONST_H */179180181