llvm_builtins.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  *
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  *
00026  **************************************************************************/
00027 
00028  /*
00029   * Authors:
00030   *   Zack Rusin zack@tungstengraphics.com
00031   */
00032 typedef __attribute__(( ext_vector_type(4) )) float float4;
00033 
00034 extern float powf(float a, float b);
00035 
00036 inline float approx(float a, float b)
00037 {
00038     if (b < -128.0f) b = -128.0f;
00039     if (b > 128.0f)   b = 128.0f;
00040     if (a < 0) a = 0;
00041     return powf(a, b);
00042 }
00043 
00044 inline float4 lit(float4 tmp)
00045 {
00046     float4 result;
00047     result.x = 1.0;
00048     result.w = 1.0;
00049     if (tmp.x > 0) {
00050         result.y = tmp.x;
00051         result.z = approx(tmp.y, tmp.w);
00052     } else {
00053         result.y = 0;
00054         result.z = 0;
00055     }
00056     return result;
00057 }
00058 
00059 inline float4 cmp(float4 tmp0, float4 tmp1, float4 tmp2)
00060 {
00061    float4 result;
00062 
00063    result.x = (tmp0.x < 0.0) ? tmp1.x : tmp2.x;
00064    result.y = (tmp0.y < 0.0) ? tmp1.y : tmp2.y;
00065    result.z = (tmp0.z < 0.0) ? tmp1.z : tmp2.z;
00066    result.w = (tmp0.w < 0.0) ? tmp1.w : tmp2.w;
00067 
00068    return result;
00069 }
00070 
00071 extern float cosf(float  val);
00072 extern float sinf(float  val);
00073 
00074 inline float4 vcos(float4 val)
00075 {
00076    float4 result;
00077    printf("VEC IN   is %f %f %f %f\n", val.x, val.y, val.z, val.w);
00078    result.x = cosf(val.x);
00079    result.y = cosf(val.x);
00080    result.z = cosf(val.x);
00081    result.w = cosf(val.x);
00082    printf("VEC OUT  is %f %f %f %f\n", result.x, result.y, result.z, result.w);
00083    return result;
00084 }
00085 
00086 inline float4 scs(float4 val)
00087 {
00088    float4 result;
00089    float tmp = val.x;
00090    result.x = cosf(tmp);
00091    result.y = sinf(tmp);
00092    return result;
00093 }
00094 
00095 
00096 inline float4 vsin(float4 val)
00097 {
00098    float4 result;
00099    float tmp = val.x;
00100    float res = sinf(tmp);
00101    result.x = res;
00102    result.y = res;
00103    result.z = res;
00104    result.w = res;
00105    return result;
00106 }
00107 
00108 inline int kil(float4 val)
00109 {
00110    if (val.x < 0 || val.y < 0 || val.z < 0 || val.w < 0)
00111       return 1;
00112    else
00113       return 0;
00114 }

Generated on Tue Sep 29 06:25:14 2009 for Gallium3D by  doxygen 1.5.4