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 /**************************************************************************
4 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
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.
27 **************************************************************************/
31 * Zack Rusin zack@tungstengraphics.com
33 typedef __attribute__(( ocu_vector_type(4) )) float float4
;
35 extern float powf(float a
, float b
);
37 inline float approx(float a
, float b
)
39 if (b
< -128.0f
) b
= -128.0f
;
40 if (b
> 128.0f
) b
= 128.0f
;
45 inline float4
lit(float4 tmp
)
52 result
.z
= approx(tmp
.y
, tmp
.w
);
60 inline float4
cmp(float4 tmp0
, float4 tmp1
, float4 tmp2
)
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
;
72 extern float cosf(float val
);
73 extern float sinf(float val
);
75 inline float4
vcos(float4 val
)
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
);
87 inline float4
scs(float4 val
)
97 inline float4
vsin(float4 val
)
101 float res
= sinf(tmp
);
109 inline int kilp(float4 val
)
111 if (val
.x
< 0 || val
.y
< 0 || val
.z
< 0 || val
.w
< 0)