Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Compute wrapped performance-counter deltas

Hardware interview practice

Compute wrapped performance-counter deltas

MediumPost-Silicon & ReliabilityC++

Validation takes two snapshots of four free-running 32-bit hardware counters. Write a C++ function that returns modulo-2^32 deltas and the busiest counter.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Starting point

Question code

bool counter_delta(const uint32_t before[4],
const uint32_t after[4], uint32_t delta[4],
unsigned *max_i);
Reviewed example

Work through one case

Input
before={100,0xFFFFFFFE,8,2} and after={125,1,17,11}.
Expected output
delta={25,3,9,9} and max_i=0.

Unsigned subtraction handles the wrapped second counter, and the largest delta is 25 at the lowest matching index 0.

What to cover

Requirements

  1. Require every pointer; return false without writing outputs if any is null.
  2. For each index compute delta[i]=after[i]-before[i] using uint32_t modulo arithmetic.
  3. Set max_i to the index of the largest delta; on a tie choose the lower index.
  4. Compute all temporary results before writing outputs so aliased before/after and delta arrays still work.
asic.fyi · Learn silicon end to end.info@asic.fyi