| 240 | } |
| 241 | |
| 242 | static int |
| 243 | test_log2(void) |
| 244 | { |
| 245 | uint32_t i, base, compare; |
| 246 | const uint32_t max = 0x10000; |
| 247 | const uint32_t step = 1; |
| 248 | |
| 249 | compare = rte_log2_u32(0); |
| 250 | if (compare != 0) { |
| 251 | printf("Wrong rte_log2_u32(0) val %x, expected 0\n", compare); |
| 252 | return TEST_FAILED; |
| 253 | } |
| 254 | |
| 255 | compare = rte_log2_u64(0); |
| 256 | if (compare != 0) { |
| 257 | printf("Wrong rte_log2_u64(0) val %x, expected 0\n", compare); |
| 258 | return TEST_FAILED; |
| 259 | } |
| 260 | |
| 261 | for (i = 1; i < max; i = i + step) { |
| 262 | uint64_t i64; |
| 263 | |
| 264 | /* extend range for 64-bit */ |
| 265 | i64 = (uint64_t)i << 32; |
| 266 | base = (uint32_t)ceilf(log2(i64)); |
| 267 | compare = rte_log2_u64(i64); |
| 268 | if (base != compare) { |
| 269 | printf("Wrong rte_log2_u64(%" PRIx64 ") val %x, expected %x\n", |
| 270 | i64, compare, base); |
| 271 | return TEST_FAILED; |
| 272 | } |
| 273 | |
| 274 | base = (uint32_t)ceilf(log2((uint32_t)i)); |
| 275 | compare = rte_log2_u32((uint32_t)i); |
| 276 | if (base != compare) { |
| 277 | printf("Wrong rte_log2_u32(%x) val %x, expected %x\n", |
| 278 | i, compare, base); |
| 279 | return TEST_FAILED; |
| 280 | } |
| 281 | compare = rte_log2_u64((uint64_t)i); |
| 282 | if (base != compare) { |
| 283 | printf("Wrong rte_log2_u64(%x) val %x, expected %x\n", |
| 284 | i, compare, base); |
| 285 | return TEST_FAILED; |
| 286 | } |
| 287 | } |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | static int |
| 292 | test_fls(void) |
no test coverage detected