1/************************************************************************** 2 * 3 * Copyright 2009 VMware, Inc. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28/** 29 * @file 30 * Helper functions for constant building. 31 * 32 * @author Jose Fonseca <jfonseca@vmware.com> 33 */ 34 35 36#ifndef LP_BLD_CONST_H 37#define LP_BLD_CONST_H 38 39 40#include "pipe/p_compiler.h" 41#include "gallivm/lp_bld.h" 42#include "gallivm/lp_bld_init.h" 43 44 45 46struct lp_type; 47 48 49unsigned 50lp_mantissa(struct lp_type type); 51 52 53unsigned 54lp_const_shift(struct lp_type type); 55 56 57unsigned 58lp_const_offset(struct lp_type type); 59 60 61double 62lp_const_scale(struct lp_type type); 63 64double 65lp_const_min(struct lp_type type); 66 67 68double 69lp_const_max(struct lp_type type); 70 71 72double 73lp_const_eps(struct lp_type type); 74 75 76LLVMValueRef 77lp_build_undef(struct gallivm_state *gallivm, struct lp_type type); 78 79 80LLVMValueRef 81lp_build_zero(struct gallivm_state *gallivm, struct lp_type type); 82 83 84LLVMValueRef 85lp_build_one(struct gallivm_state *gallivm, struct lp_type type); 86 87 88LLVMValueRef 89lp_build_const_elem(struct gallivm_state *gallivm, struct lp_type type, 90 double val); 91 92LLVMValueRef 93lp_build_const_vec(struct gallivm_state *gallivm, struct lp_type type, 94 double val); 95 96 97LLVMValueRef 98lp_build_const_int_vec(struct gallivm_state *gallivm, 99 struct lp_type type, long long val); 100 101 102LLVMValueRef 103lp_build_const_aos(struct gallivm_state *gallivm, struct lp_type type, 104 double r, double g, double b, double a, 105 const unsigned char *swizzle); 106 107 108LLVMValueRef 109lp_build_const_mask_aos(struct gallivm_state *gallivm, 110 struct lp_type type, 111 unsigned mask, 112 unsigned channels); 113 114 115LLVMValueRef 116lp_build_const_mask_aos_swizzled(struct gallivm_state *gallivm, 117 struct lp_type type, 118 unsigned mask, 119 unsigned channels, 120 const unsigned char *swizzle); 121 122 123static inline LLVMValueRef 124lp_build_const_int32(struct gallivm_state *gallivm, int i) 125{ 126 return LLVMConstInt(LLVMInt32TypeInContext(gallivm->context), i, 0); 127} 128 129 130static inline LLVMValueRef 131lp_build_const_float(struct gallivm_state *gallivm, float x) 132{ 133 return LLVMConstReal(LLVMFloatTypeInContext(gallivm->context), x); 134} 135 136 137/** Return constant-valued pointer to int */ 138static inline LLVMValueRef 139lp_build_const_int_pointer(struct gallivm_state *gallivm, const void *ptr) 140{ 141 LLVMTypeRef int_type; 142 LLVMValueRef v; 143 144 /* int type large enough to hold a pointer */ 145 int_type = LLVMIntTypeInContext(gallivm->context, 8 * sizeof(void *)); 146 v = LLVMConstInt(int_type, (uintptr_t) ptr, 0); 147 v = LLVMBuildIntToPtr(gallivm->builder, v, 148 LLVMPointerType(int_type, 0), 149 "cast int to ptr"); 150 return v; 151} 152 153 154LLVMValueRef 155lp_build_const_string(struct gallivm_state *gallivm, 156 const char *str); 157 158 159LLVMValueRef 160lp_build_const_func_pointer(struct gallivm_state *gallivm, 161 const void *ptr, 162 LLVMTypeRef ret_type, 163 LLVMTypeRef *arg_types, 164 unsigned num_args, 165 const char *name); 166 167 168#endif /* !LP_BLD_CONST_H */ 169