1#pragma version(1)
2
3#pragma rs java_package_name(com.android.rs.rsov.test)
4
5typedef struct TestResult_s {
6    rs_allocation name;
7    bool pass;
8    float score;
9    int64_t time;
10} TestResult;
11//TestResult *g_results;
12
13static int64_t g_time;
14
15static inline void start(void) {
16    g_time = rsUptimeMillis();
17}
18
19static inline float end(uint32_t idx) {
20    int64_t t = rsUptimeMillis() - g_time;
21    //g_results[idx].time = t;
22    //rsDebug("test time", (int)t);
23    return ((float)t) / 1000.f;
24}
25
26#define _RS_ASSERT(b) \
27do { \
28    if (!(b)) { \
29        failed = true; \
30        rsDebug(#b " FAILED", 0); \
31    } \
32\
33} while (0)
34
35#define _RS_ASSERT_EQU(e1, e2) \
36  (((e1) != (e2)) ? (failed = true, rsDebug(#e1 " != " #e2, (e1), (e2)), false) : true)
37
38static const int iposinf = 0x7f800000;
39static const int ineginf = 0xff800000;
40
41static inline const float posinf() {
42    float f = *((float*)&iposinf);
43    return f;
44}
45
46static inline const float neginf() {
47    float f = *((float*)&ineginf);
48    return f;
49}
50
51static inline bool isposinf(float f) {
52    int i = *((int*)(void*)&f);
53    return (i == iposinf);
54}
55
56static inline bool isneginf(float f) {
57    int i = *((int*)(void*)&f);
58    return (i == ineginf);
59}
60
61static inline bool isnan(float f) {
62    int i = *((int*)(void*)&f);
63    return (((i & 0x7f800000) == 0x7f800000) && (i & 0x007fffff));
64}
65
66static inline bool isposzero(float f) {
67    int i = *((int*)(void*)&f);
68    return (i == 0x00000000);
69}
70
71static inline bool isnegzero(float f) {
72    int i = *((int*)(void*)&f);
73    return (i == 0x80000000);
74}
75
76static inline bool iszero(float f) {
77    return isposzero(f) || isnegzero(f);
78}
79
80/* Absolute epsilon used for floats.  Value is similar to float.h. */
81#ifndef FLT_EPSILON
82#define FLT_EPSILON 1.19e7f
83#endif
84/* Max ULPs while still being considered "equal".  Only used when this number
85   of ULPs is of a greater size than FLT_EPSILON. */
86#define FLT_MAX_ULP 1
87
88/* Calculate the difference in ULPs between the two values.  (Return zero on
89   perfect equality.) */
90static inline int float_dist(float f1, float f2) {
91    return *((int *)(&f1)) - *((int *)(&f2));
92}
93
94/* Check if two floats are essentially equal.  Will fail with some values
95   due to design.  (Validate using FLT_EPSILON or similar if necessary.) */
96static inline bool float_almost_equal(float f1, float f2) {
97    int *i1 = (int*)(&f1);
98    int *i2 = (int*)(&f2);
99
100    // Check for sign equality
101    if ( ((*i1 >> 31) == 0) != ((*i2 >> 31) == 0) ) {
102        // Handle signed zeroes
103        if (f1 == f2)
104            return true;
105        return false;
106    }
107
108    // Check with ULP distance
109    if (float_dist(f1, f2) > FLT_MAX_ULP)
110        return false;
111    return true;
112}
113
114/* These constants must match those in UnitTest.java */
115static const int RS_MSG_TEST_PASSED = 100;
116static const int RS_MSG_TEST_FAILED = 101;
117