Hardware interview practice
Count unique detected faults
Each test reports a bit mask of detected stuck-at faults. Several tests may detect the same fault. Write a C++ function that computes unique coverage in parts per million.
Starting point
Question code
int fault_coverage(const uint64_t *masks, size_t tests,
unsigned total_faults,
unsigned *detected, unsigned *ppm);Reviewed example
Work through one case
Input
masks = {0b0011, 0b0110}, tests = 2, total_faults = 4.Expected output
detected = 3 and ppm = 750000.The union mask is 0b0111 with three unique faults, and floor(3 * 1,000,000 / 4) is 750000.
What to cover
Requirements
- Require detected and ppm, total_faults in 1..64, and masks nonnull when tests>0; return -1 and preserve outputs otherwise.
- OR all test masks, then ignore bits at indices total_faults and above.
- Set detected to the population count of the remaining union and ppm=floor(detected*1000000/total_faults).
- Use a wide enough intermediate for the multiplication; on success return 0.
