1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 * SPU functions accessed by shaders.
41 #include "cell/common.h"
43 #include "spu_funcs.h"
46 #define M_PI 3.1415926
50 spu_cos(vector
float x
)
53 static const float scale
= 1.0 / (2.0 * M_PI
);
54 x
= x
* spu_splats(scale
); /* normalize */
57 /* just pass-through to avoid trashing caller's stack */
63 spu_sin(vector
float x
)
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?? */
70 /* just pass-through to avoid trashing caller's stack */
77 add_func(struct cell_spu_function_info
*spu_functions
,
78 const char *name
, void *addr
)
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
;
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.
94 return_function_info(void)
96 struct cell_spu_function_info funcs ALIGN16_ATTRIB
;
99 ASSERT(sizeof(funcs
) == 256); /* must be multiple of 16 bytes */
102 add_func(&funcs
, "spu_cos", &spu_cos
);
103 add_func(&funcs
, "spu_sin", &spu_sin
);
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 */
112 wait_on_mask(1 << tag
);