| 537 | } |
| 538 | |
| 539 | const unsigned char* get_lut(const float* code) { |
| 540 | float fp[4]; |
| 541 | compute_fingerprint(code, fp); |
| 542 | for (int i = 0; i < kLUTCacheSlots; ++i) { |
| 543 | if (cached_codes[i] == code && cached_fingerprints[i][0] == fp[0] && cached_fingerprints[i][1] == fp[1] && |
| 544 | cached_fingerprints[i][2] == fp[2] && cached_fingerprints[i][3] == fp[3]) { |
| 545 | return luts[i]; |
| 546 | } |
| 547 | } |
| 548 | // Cache miss: build and store in next slot (round-robin) |
| 549 | int slot = next_slot; |
| 550 | next_slot = (next_slot + 1) % kLUTCacheSlots; |
| 551 | build_quantize_lut(code, luts[slot]); |
| 552 | cached_codes[slot] = code; |
| 553 | for (int j = 0; j < 4; ++j) |
| 554 | cached_fingerprints[slot][j] = fp[j]; |
| 555 | return luts[slot]; |
| 556 | } |
| 557 | }; |
| 558 | |
| 559 | // Single global LUT cache (protected by mutex for thread safety during build) |
no test coverage detected