Path: blob/21.2-virgl/src/gallium/auxiliary/gallivm/lp_bld_arit.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 arithmetic functions.30*31* @author Jose Fonseca <[email protected]>32*/333435#ifndef LP_BLD_ARIT_H36#define LP_BLD_ARIT_H373839#include "gallivm/lp_bld.h"40#include "pipe/p_compiler.h"414243struct lp_type;44struct lp_build_context;45struct gallivm_state;464748/**49* Complement, i.e., 1 - a.50*/51LLVMValueRef52lp_build_comp(struct lp_build_context *bld,53LLVMValueRef a);5455LLVMValueRef56lp_build_add(struct lp_build_context *bld,57LLVMValueRef a,58LLVMValueRef b);5960LLVMValueRef61lp_build_horizontal_add(struct lp_build_context *bld,62LLVMValueRef a);6364LLVMValueRef65lp_build_hadd_partial4(struct lp_build_context *bld,66LLVMValueRef vectors[],67unsigned num_vecs);6869LLVMValueRef70lp_build_sub(struct lp_build_context *bld,71LLVMValueRef a,72LLVMValueRef b);737475LLVMValueRef76lp_build_mul_norm(struct gallivm_state *gallivm,77struct lp_type wide_type,78LLVMValueRef a,79LLVMValueRef b);8081LLVMValueRef82lp_build_mul(struct lp_build_context *bld,83LLVMValueRef a,84LLVMValueRef b);8586LLVMValueRef87lp_build_mul_32_lohi_cpu(struct lp_build_context *bld,88LLVMValueRef a,89LLVMValueRef b,90LLVMValueRef *res_hi);9192LLVMValueRef93lp_build_mul_32_lohi(struct lp_build_context *bld,94LLVMValueRef a,95LLVMValueRef b,96LLVMValueRef *res_hi);9798LLVMValueRef99lp_build_mul_imm(struct lp_build_context *bld,100LLVMValueRef a,101int b);102103LLVMValueRef104lp_build_div(struct lp_build_context *bld,105LLVMValueRef a,106LLVMValueRef b);107108109/* llvm.fmuladd.* intrinsic */110LLVMValueRef111lp_build_fmuladd(LLVMBuilderRef builder,112LLVMValueRef a,113LLVMValueRef b,114LLVMValueRef c);115116/* a * b + c */117LLVMValueRef118lp_build_mad(struct lp_build_context *bld,119LLVMValueRef a,120LLVMValueRef b,121LLVMValueRef c);122123124/**125* Set when the weights for normalized are prescaled, that is, in range126* 0..2**n, as opposed to range 0..2**(n-1).127*/128#define LP_BLD_LERP_PRESCALED_WEIGHTS (1 << 0)129130/**131* Used internally when using wide intermediates for normalized lerps.132*133* Do not use.134*/135#define LP_BLD_LERP_WIDE_NORMALIZED (1 << 1)136137LLVMValueRef138lp_build_lerp(struct lp_build_context *bld,139LLVMValueRef x,140LLVMValueRef v0,141LLVMValueRef v1,142unsigned flags);143144LLVMValueRef145lp_build_lerp_2d(struct lp_build_context *bld,146LLVMValueRef x,147LLVMValueRef y,148LLVMValueRef v00,149LLVMValueRef v01,150LLVMValueRef v10,151LLVMValueRef v11,152unsigned flags);153154LLVMValueRef155lp_build_lerp_3d(struct lp_build_context *bld,156LLVMValueRef x,157LLVMValueRef y,158LLVMValueRef z,159LLVMValueRef v000,160LLVMValueRef v001,161LLVMValueRef v010,162LLVMValueRef v011,163LLVMValueRef v100,164LLVMValueRef v101,165LLVMValueRef v110,166LLVMValueRef v111,167unsigned flags);168169/**170* Specifies floating point NaN behavior.171*/172enum gallivm_nan_behavior {173/* Results are undefined with NaN. Results in fastest code */174GALLIVM_NAN_BEHAVIOR_UNDEFINED,175/* If one of the inputs is NaN, the other operand is returned */176GALLIVM_NAN_RETURN_OTHER,177/* If one of the inputs is NaN, the other operand is returned,178* but we guarantee the second operand is not a NaN.179* In min/max it will be as fast as undefined with sse opcodes,180* and archs having native return_other can benefit too. */181GALLIVM_NAN_RETURN_OTHER_SECOND_NONNAN,182/* If one of the inputs is NaN, NaN is returned,183* but we guarantee the first operand is not a NaN.184* In min/max it will be as fast as undefined with sse opcodes,185* and archs having native return_nan can benefit too. */186GALLIVM_NAN_RETURN_NAN_FIRST_NONNAN,187188};189190LLVMValueRef191lp_build_min(struct lp_build_context *bld,192LLVMValueRef a,193LLVMValueRef b);194195LLVMValueRef196lp_build_min_ext(struct lp_build_context *bld,197LLVMValueRef a,198LLVMValueRef b,199enum gallivm_nan_behavior nan_behavior);200201LLVMValueRef202lp_build_max(struct lp_build_context *bld,203LLVMValueRef a,204LLVMValueRef b);205206LLVMValueRef207lp_build_max_ext(struct lp_build_context *bld,208LLVMValueRef a,209LLVMValueRef b,210enum gallivm_nan_behavior nan_behavior);211212LLVMValueRef213lp_build_clamp(struct lp_build_context *bld,214LLVMValueRef a,215LLVMValueRef min,216LLVMValueRef max);217218LLVMValueRef219lp_build_clamp_zero_one_nanzero(struct lp_build_context *bld,220LLVMValueRef a);221222LLVMValueRef223lp_build_abs(struct lp_build_context *bld,224LLVMValueRef a);225226LLVMValueRef227lp_build_negate(struct lp_build_context *bld,228LLVMValueRef a);229230LLVMValueRef231lp_build_sgn(struct lp_build_context *bld,232LLVMValueRef a);233234LLVMValueRef235lp_build_set_sign(struct lp_build_context *bld,236LLVMValueRef a, LLVMValueRef sign);237238LLVMValueRef239lp_build_int_to_float(struct lp_build_context *bld,240LLVMValueRef a);241242LLVMValueRef243lp_build_round(struct lp_build_context *bld,244LLVMValueRef a);245246LLVMValueRef247lp_build_floor(struct lp_build_context *bld,248LLVMValueRef a);249250LLVMValueRef251lp_build_ceil(struct lp_build_context *bld,252LLVMValueRef a);253254LLVMValueRef255lp_build_trunc(struct lp_build_context *bld,256LLVMValueRef a);257258LLVMValueRef259lp_build_fract(struct lp_build_context *bld,260LLVMValueRef a);261262LLVMValueRef263lp_build_fract_safe(struct lp_build_context *bld,264LLVMValueRef a);265266LLVMValueRef267lp_build_ifloor(struct lp_build_context *bld,268LLVMValueRef a);269LLVMValueRef270lp_build_iceil(struct lp_build_context *bld,271LLVMValueRef a);272273LLVMValueRef274lp_build_iround(struct lp_build_context *bld,275LLVMValueRef a);276277LLVMValueRef278lp_build_itrunc(struct lp_build_context *bld,279LLVMValueRef a);280281void282lp_build_ifloor_fract(struct lp_build_context *bld,283LLVMValueRef a,284LLVMValueRef *out_ipart,285LLVMValueRef *out_fpart);286287void288lp_build_ifloor_fract_safe(struct lp_build_context *bld,289LLVMValueRef a,290LLVMValueRef *out_ipart,291LLVMValueRef *out_fpart);292293LLVMValueRef294lp_build_sqrt(struct lp_build_context *bld,295LLVMValueRef a);296297LLVMValueRef298lp_build_rcp(struct lp_build_context *bld,299LLVMValueRef a);300301LLVMValueRef302lp_build_rsqrt(struct lp_build_context *bld,303LLVMValueRef a);304305boolean306lp_build_fast_rsqrt_available(struct lp_type type);307308LLVMValueRef309lp_build_fast_rsqrt(struct lp_build_context *bld,310LLVMValueRef a);311312LLVMValueRef313lp_build_polynomial(struct lp_build_context *bld,314LLVMValueRef x,315const double *coeffs,316unsigned num_coeffs);317318LLVMValueRef319lp_build_cos(struct lp_build_context *bld,320LLVMValueRef a);321322LLVMValueRef323lp_build_sin(struct lp_build_context *bld,324LLVMValueRef a);325326LLVMValueRef327lp_build_pow(struct lp_build_context *bld,328LLVMValueRef a,329LLVMValueRef b);330331LLVMValueRef332lp_build_exp(struct lp_build_context *bld,333LLVMValueRef a);334335LLVMValueRef336lp_build_log(struct lp_build_context *bld,337LLVMValueRef a);338339LLVMValueRef340lp_build_log_safe(struct lp_build_context *bld,341LLVMValueRef a);342343LLVMValueRef344lp_build_exp2(struct lp_build_context *bld,345LLVMValueRef a);346347LLVMValueRef348lp_build_extract_exponent(struct lp_build_context *bld,349LLVMValueRef x,350int bias);351352LLVMValueRef353lp_build_extract_mantissa(struct lp_build_context *bld,354LLVMValueRef x);355356LLVMValueRef357lp_build_log2(struct lp_build_context *bld,358LLVMValueRef a);359360LLVMValueRef361lp_build_log2_safe(struct lp_build_context *bld,362LLVMValueRef a);363364LLVMValueRef365lp_build_fast_log2(struct lp_build_context *bld,366LLVMValueRef a);367368LLVMValueRef369lp_build_ilog2(struct lp_build_context *bld,370LLVMValueRef x);371372void373lp_build_log2_approx(struct lp_build_context *bld,374LLVMValueRef x,375LLVMValueRef *p_exp,376LLVMValueRef *p_floor_log2,377LLVMValueRef *p_log2,378boolean handle_nans);379380LLVMValueRef381lp_build_mod(struct lp_build_context *bld,382LLVMValueRef x,383LLVMValueRef y);384385LLVMValueRef386lp_build_isnan(struct lp_build_context *bld,387LLVMValueRef x);388389LLVMValueRef390lp_build_isfinite(struct lp_build_context *bld,391LLVMValueRef x);392393394LLVMValueRef395lp_build_is_inf_or_nan(struct gallivm_state *gallivm,396const struct lp_type type,397LLVMValueRef x);398399400LLVMValueRef401lp_build_fpstate_get(struct gallivm_state *gallivm);402403void404lp_build_fpstate_set_denorms_zero(struct gallivm_state *gallivm,405boolean zero);406void407lp_build_fpstate_set(struct gallivm_state *gallivm,408LLVMValueRef mxcsr);409410#endif /* !LP_BLD_ARIT_H */411412413