Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Compile, program, and verify a bounded pattern matcher

Hardware interview practice

Compile, program, and verify a bounded pattern matcher

HardReference ModelsSystemVerilog

Write the bounded pattern compiler, whole-record oracle, and transaction checks for literals, dot, and postfix star.

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

typedef enum {
  PAT_OK, PAT_BAD_ARG, PAT_FULL, PAT_MMIO, PAT_TIMEOUT
} pat_status_t;
pat_status_t pat_program(const char *pattern, size_t length,
                         uint32_t timeout);

typedef struct packed {
  byte unsigned literal;
  bit any;
  bit star;
} pattern_token_t;

function automatic bit whole_record_match(
  input byte unsigned record[$],
  input pattern_token_t token[$]
);
Reviewed example

Work through one case

Input
compile pattern="A.*B"; record="AXYB"
Expected output
shadow tokens=[literal A, dot-star, literal B]; whole-record match=1

The star binds only to the preceding dot, which consumes XY while the leading A and trailing B anchor the entire record.

What to cover

Requirements

  1. Reject a leading or repeated star, patterns above 48 bytes, and more than 24 compiled tokens before MMIO; an empty pattern is a valid committed program.
  2. Use canonical token encoding, zero unused shadow slots, issue a release barrier, and preserve the active program after rejected commit, bus error, or timeout.
  3. Build an independent prefix table for whole-record matching where star repeats only its preceding literal or dot zero or more times.
  4. Enforce command and frame error priority, bounded responses, stable stalls, silent abort, and reset that clears both active and shadow configurations.
Continue practicing

Related questions

Reference ModelsVerify a longest rising-trend accelerator→Reference ModelsVerify a bounded step-sequence counter→Reference ModelsVerify a tagged grid-path counter→
asic.fyi · Learn silicon end to end.info@asic.fyi