OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
SPUAssert.h
1#ifndef __SPU_ASSERT_H__
2#define __SPU_ASSERT_H__
3
4// Author: Sauce
5// 1/18/2006
6// Better assert on SPU side, but it assumes spu_printf works.
7
8#ifdef _DEBUG
9
10#ifdef __CELLOS_LV2__
11#include <spu_printf.h>
12#define SPU_ASSERT(cond) do { if (__builtin_expect(!(cond), 0)) { spu_printf("SPU: Assertion failed! Expression: " #cond "\n in %s at " __FILE__ ":%i\n", __FUNCTION__, __LINE__); spu_hcmpeq((cond), 0); } } while (0)
13#else // __CELLOS_LV2__
14#define SPU_ASSERT(cond) assert(cond)
15#endif //__CELLOS_LV2__
16
17#else // _DEBUG
18
19#ifdef __CELLOS_LV2__
20#include <spu_printf.h>
21#define SPU_ASSERT(cond) do { if (__builtin_expect(!(cond), 0)) { spu_printf("SPU: Assertion failed! Expression: " #cond "\n in %s at " __FILE__ ":%i\n", __FUNCTION__, __LINE__); spu_hcmpeq((cond), 0); } } while (0)
22// Sauce
23// Later on we'll want no asserts in release builds
24//#define SPU_ASSERT(cond) do {} while (0)
25#else // __CELLOS_LV2__
26#define SPU_ASSERT(cond) assert(cond)
27#endif // __CELLOS_LV2__
28
29#endif // _DEBUG
30
31// Usage:
32// SPU_COMPILE_TIME_ASSERT(sizeof(MyStructure) <= 128);
33// Gives the following error message if it fails:
34// error: size of array `spu_compile_time_assert_failed' is negative
35#define SPU_COMPILE_TIME_ASSERT(cond) extern char spu_compile_time_assert_failed[cond ? 1 : -1]
36
37// Usage:
38// SPU_NAMED_COMPILE_TIME_ASSERT(MyStructure_is_more_than_128_bytes, sizeof(MyStructure) <= 128);
39// Gives the following error message if it fails:
40// error: size of array `MyStructure_is_more_than_128_bytes' is negative
41#define SPU_NAMED_COMPILE_TIME_ASSERT(name, cond) extern char name[cond ? 1 : -1]
42
43
44#endif