1#pragma version(1) 2 3#pragma rs java_package_name(com.android.rs.test_compatlegacy) 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 35static const int iposinf = 0x7f800000; 36static const int ineginf = 0xff800000; 37 38static inline const float posinf() { 39 float f = *((float*)&iposinf); 40 return f; 41} 42 43static inline const float neginf() { 44 float f = *((float*)&ineginf); 45 return f; 46} 47 48static inline bool isposinf(float f) { 49 int i = *((int*)(void*)&f); 50 return (i == iposinf); 51} 52 53static inline bool isneginf(float f) { 54 int i = *((int*)(void*)&f); 55 return (i == ineginf); 56} 57 58static inline bool isnan(float f) { 59 int i = *((int*)(void*)&f); 60 return (((i & 0x7f800000) == 0x7f800000) && (i & 0x007fffff)); 61} 62 63static inline bool isposzero(float f) { 64 int i = *((int*)(void*)&f); 65 return (i == 0x00000000); 66} 67 68static inline bool isnegzero(float f) { 69 int i = *((int*)(void*)&f); 70 return (i == 0x80000000); 71} 72 73static inline bool iszero(float f) { 74 return isposzero(f) || isnegzero(f); 75} 76 77/* Absolute epsilon used for floats. Value is similar to float.h. */ 78#ifndef FLT_EPSILON 79#define FLT_EPSILON 1.19e7f 80#endif 81/* Max ULPs while still being considered "equal". Only used when this number 82 of ULPs is of a greater size than FLT_EPSILON. */ 83#define FLT_MAX_ULP 1 84 85/* Calculate the difference in ULPs between the two values. (Return zero on 86 perfect equality.) */ 87static inline int float_dist(float f1, float f2) { 88 return *((int *)(&f1)) - *((int *)(&f2)); 89} 90 91/* Check if two floats are essentially equal. Will fail with some values 92 due to design. (Validate using FLT_EPSILON or similar if necessary.) */ 93static inline bool float_almost_equal(float f1, float f2) { 94 int *i1 = (int*)(&f1); 95 int *i2 = (int*)(&f2); 96 97 // Check for sign equality 98 if ( ((*i1 >> 31) == 0) != ((*i2 >> 31) == 0) ) { 99 // Handle signed zeroes 100 if (f1 == f2) 101 return true; 102 return false; 103 } 104 105 // Check with ULP distance 106 if (float_dist(f1, f2) > FLT_MAX_ULP) 107 return false; 108 return true; 109} 110 111/* These constants must match those in UnitTest.java */ 112static const int RS_MSG_TEST_PASSED = 100; 113static const int RS_MSG_TEST_FAILED = 101; 114