| 97 | /* AUTOGENERATED MOCKS END */ |
| 98 | |
| 99 | int main(int argc, char *argv[]) |
| 100 | { |
| 101 | /* 5 bit exponent, 11 bit mantissa. */ |
| 102 | u32 exponent, mantissa; |
| 103 | |
| 104 | common_setup(argv[0]); |
| 105 | |
| 106 | /* These can be represented exactly. */ |
| 107 | for (exponent = 0; exponent < (1 << 5); exponent++) { |
| 108 | for (mantissa = 0; mantissa < (1 << 11); mantissa++) { |
| 109 | u64 v = ((u64)mantissa << exponent); |
| 110 | assert(fp16_to_u64(u64_to_fp16(v, false)) == v); |
| 111 | assert(fp16_to_u64(u64_to_fp16(v, true)) == v); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | /* Now check round up vs down (don't use exponent 32, since that will |
| 116 | * overflow). */ |
| 117 | for (exponent = 1; exponent < (1 << 5) - 1; exponent++) { |
| 118 | /* Too many bits: will require rounding */ |
| 119 | mantissa = (1 << 11) + 1; |
| 120 | u64 v = ((u64)mantissa << exponent); |
| 121 | |
| 122 | assert(fp16_to_u64(u64_to_fp16(v, false)) |
| 123 | == ((u64)(mantissa - 1) << exponent)); |
| 124 | assert(fp16_to_u64(u64_to_fp16(v, true)) |
| 125 | == ((u64)(mantissa + 1) << exponent)); |
| 126 | } |
| 127 | |
| 128 | assert(u64_to_fp16((1ULL << (31 + 11)), false) == 65535); |
| 129 | assert(u64_to_fp16((1ULL << (31 + 11)), true) == 65535); |
| 130 | |
| 131 | /* Round up works, even if it causes overflow. */ |
| 132 | assert(fp16_to_u64(u64_to_fp16(0xffffffff, true)) == (1ULL << 32)); |
| 133 | |
| 134 | common_shutdown(); |
| 135 | } |
nothing calls this directly
no test coverage detected