|
| 1 | +#include <stdbool.h> |
| 2 | +#include <stddef.h> |
| 3 | +#include <stdint.h> |
| 4 | +#include <stdio.h> |
| 5 | +#include <assert.h> |
| 6 | +#include <ti/screen.h> |
| 7 | +#include <ti/getcsc.h> |
| 8 | +#include <sys/util.h> |
| 9 | + |
| 10 | +#include "ultof_lut.h" |
| 11 | + |
| 12 | +typedef union F32_pun { |
| 13 | + float flt; |
| 14 | + uint32_t bin; |
| 15 | +} F32_pun; |
| 16 | + |
| 17 | +#define ARRAY_LENGTH(x) (sizeof(x) / sizeof(x[0])) |
| 18 | + |
| 19 | +void print_failed(uint32_t input, uint32_t guess, uint32_t truth) { |
| 20 | + printf( |
| 21 | + "I: %lu\nU: %08lX -->\nG: %08lX !=\nT: %08lX\n", |
| 22 | + input, input, guess, truth |
| 23 | + ); |
| 24 | +} |
| 25 | + |
| 26 | +size_t run_test(void) { |
| 27 | + typedef uint32_t input_t; |
| 28 | + typedef F32_pun output_t; |
| 29 | + |
| 30 | + const size_t length = ARRAY_LENGTH(ultof_LUT_input); |
| 31 | + const input_t *input = (const input_t* )((const void*)ultof_LUT_input ); |
| 32 | + const output_t *output = (const output_t*)((const void*)ultof_LUT_output); |
| 33 | + |
| 34 | + for (size_t i = 0; i < length; i++) { |
| 35 | + F32_pun result; |
| 36 | + |
| 37 | + result.flt = (float)input[i]; |
| 38 | + if (result.bin != output[i].bin) { |
| 39 | + // ignore round to maximum magnitude errors from __ltof |
| 40 | + bool ignore_ltof_failure = |
| 41 | + (input[i] <= INT32_MAX) && |
| 42 | + (result.bin == output[i].bin + 1); |
| 43 | + if (ignore_ltof_failure == false) { |
| 44 | + print_failed(input[i], result.bin, output[i].bin); |
| 45 | + return i; |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + /* passed all */ |
| 51 | + return SIZE_MAX; |
| 52 | +} |
| 53 | + |
| 54 | +int main(void) { |
| 55 | + os_ClrHome(); |
| 56 | + size_t fail_index = run_test(); |
| 57 | + if (fail_index == SIZE_MAX) { |
| 58 | + printf("All tests passed"); |
| 59 | + } else { |
| 60 | + printf("Failed test: %zu", fail_index); |
| 61 | + } |
| 62 | + |
| 63 | + while (!os_GetCSC()); |
| 64 | + |
| 65 | + return 0; |
| 66 | +} |
0 commit comments