cell: stub-out sin/cos function bodies to avoid trashing caller's stack for now
[mesa.git] / src / gallium / drivers / cell / spu / spu_funcs.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 /**
30 * SPU functions accessed by shaders.
31 *
32 * Authors: Brian Paul
33 */
34
35
36 #include <string.h>
37 #include <libmisc.h>
38 #include <cos8_v.h>
39 #include <sin8_v.h>
40
41 #include "cell/common.h"
42 #include "spu_main.h"
43 #include "spu_funcs.h"
44
45
46 #define M_PI 3.1415926
47
48
49 static vector float
50 spu_cos(vector float x)
51 {
52 #if 0
53 static const float scale = 1.0 / (2.0 * M_PI);
54 x = x * spu_splats(scale); /* normalize */
55 return _cos8_v(x);
56 #else
57 /* just pass-through to avoid trashing caller's stack */
58 return x;
59 #endif
60 }
61
62 static vector float
63 spu_sin(vector float x)
64 {
65 #if 0
66 static const float scale = 1.0 / (2.0 * M_PI);
67 x = x * spu_splats(scale); /* normalize */
68 return _sin8_v(x); /* 8-bit accuracy enough?? */
69 #else
70 /* just pass-through to avoid trashing caller's stack */
71 return x;
72 #endif
73 }
74
75
76 static void
77 add_func(struct cell_spu_function_info *spu_functions,
78 const char *name, void *addr)
79 {
80 uint n = spu_functions->num;
81 ASSERT(strlen(name) < 16);
82 strcpy(spu_functions->names[n], name);
83 spu_functions->addrs[n] = (uint) addr;
84 spu_functions->num++;
85 }
86
87
88 /**
89 * Return info about the SPU's function to the PPU / main memory.
90 * The PPU needs to know the address of some SPU-side functions so
91 * that we can generate shader code with function calls.
92 */
93 void
94 return_function_info(void)
95 {
96 struct cell_spu_function_info funcs ALIGN16_ATTRIB;
97 int tag = TAG_MISC;
98
99 ASSERT(sizeof(funcs) == 256); /* must be multiple of 16 bytes */
100
101 funcs.num = 0;
102 add_func(&funcs, "spu_cos", &spu_cos);
103 add_func(&funcs, "spu_sin", &spu_sin);
104
105 /* Send the function info back to the PPU / main memory */
106 mfc_put((void *) &funcs, /* src in local store */
107 (unsigned int) spu.init.spu_functions, /* dst in main memory */
108 sizeof(funcs), /* bytes */
109 tag,
110 0, /* tid */
111 0 /* rid */);
112 wait_on_mask(1 << tag);
113 }
114
115
116