Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Count coalesced memory segments

Hardware interview practice

Count coalesced memory segments

MediumFirmwareC++

A validation model must count the 32-byte memory segments touched by one warp's active four-byte loads. Write the C++ function that returns the number of distinct aligned segments.

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

int segment_count(const uint32_t addr[32], uint32_t active_mask);
Reviewed example

Work through one case

Input
Activate aligned addresses 0x100, 0x104, and 0x11C in three warp lanes.
Expected output
segment_count returns 1.

Masking each address to a 32-byte base produces the same segment address 0x100.

What to cover

Requirements

  1. Each active lane performs one four-byte load and every active address is four-byte aligned.
  2. A segment is identified by addr[lane] & ~uint32_t(31); count each distinct segment once.
  3. Return zero for active_mask=0; addr may be NULL only in that case, otherwise return -1 for NULL or misalignment.
  4. Use fixed storage only, with no allocation and no reads from inactive lanes.
asic.fyi · Learn silicon end to end.info@asic.fyi