Code reorganization: s/aux/auxiliary/.
[mesa.git] / src / gallium / auxiliary / llvm / llvm_builtins.c
1 /*clang --emit-llvm llvm_builtins.c |llvm-as|opt -std-compile-opts|llvm2cpp -gen-contents -o=gallivm_builtins.cpp -f -for=shader -funcname=createGallivmBuiltins*/
2 /**************************************************************************
3 *
4 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29 /*
30 * Authors:
31 * Zack Rusin zack@tungstengraphics.com
32 */
33 typedef __attribute__(( ocu_vector_type(4) )) float float4;
34
35 extern float powf(float a, float b);
36
37 inline float approx(float a, float b)
38 {
39 if (b < -128.0f) b = -128.0f;
40 if (b > 128.0f) b = 128.0f;
41 if (a < 0) a = 0;
42 return powf(a, b);
43 }
44
45 inline float4 lit(float4 tmp)
46 {
47 float4 result;
48 result.x = 1.0;
49 result.w = 1.0;
50 if (tmp.x > 0) {
51 result.y = tmp.x;
52 result.z = approx(tmp.y, tmp.w);
53 } else {
54 result.y = 0;
55 result.z = 0;
56 }
57 return result;
58 }
59
60 inline float4 cmp(float4 tmp0, float4 tmp1, float4 tmp2)
61 {
62 float4 result;
63
64 result.x = (tmp0.x < 0.0) ? tmp1.x : tmp2.x;
65 result.y = (tmp0.y < 0.0) ? tmp1.y : tmp2.y;
66 result.z = (tmp0.z < 0.0) ? tmp1.z : tmp2.z;
67 result.w = (tmp0.w < 0.0) ? tmp1.w : tmp2.w;
68
69 return result;
70 }
71
72 extern float cosf(float val);
73 extern float sinf(float val);
74
75 inline float4 vcos(float4 val)
76 {
77 float4 result;
78 printf("VEC IN is %f %f %f %f\n", val.x, val.y, val.z, val.w);
79 result.x = cosf(val.x);
80 result.y = cosf(val.x);
81 result.z = cosf(val.x);
82 result.w = cosf(val.x);
83 printf("VEC OUT is %f %f %f %f\n", result.x, result.y, result.z, result.w);
84 return result;
85 }
86
87 inline float4 scs(float4 val)
88 {
89 float4 result;
90 float tmp = val.x;
91 result.x = cosf(tmp);
92 result.y = sinf(tmp);
93 return result;
94 }
95
96
97 inline float4 vsin(float4 val)
98 {
99 float4 result;
100 float tmp = val.x;
101 float res = sinf(tmp);
102 result.x = res;
103 result.y = res;
104 result.z = res;
105 result.w = res;
106 return result;
107 }
108
109 inline int kilp(float4 val)
110 {
111 if (val.x < 0 || val.y < 0 || val.z < 0 || val.w < 0)
112 return 1;
113 else
114 return 0;
115 }