name: "64-bit Popcount with Threshold Flag"
category: "Algorithmic Hardware Primitives"
complexity: "Medium"
description: >
  Implement a fixed-latency population-count unit for 64-bit input data.

  On every rising edge of `clk` when `rst` is low, the module samples
  `data_in` and `threshold`. The module must produce two aligned outputs
  exactly 2 clock cycles later:

  - `count_out`: the number of bits set to 1 in the sampled 64-bit input
    word. The result range is 0 to 64.
  - `threshold_exceeded`: asserted when the sampled population count is
    strictly greater than the sampled threshold value.

  INTERFACE BEHAVIOUR:
  - The interface is fully synchronous and accepts a new input every
    cycle.
  - There is no valid or ready signal. Outputs are produced every cycle
    after the 2-cycle pipeline delay.
  - `threshold_exceeded` must be aligned with the corresponding
    `count_out` result from the same sampled input pair.
  - `threshold` is an unsigned 6-bit value in the range 0 to 63.

  RESET:
  - `rst` is synchronous and active-high.
  - On reset, clear any in-flight pipeline state and drive both outputs
    to zero.
  - After reset is deasserted, the first result corresponding to a new
    input appears 2 clock cycles later.

interface:
  module_name: "popcount64_threshold"
  clocked: true
  ports:
    - name: "clk"
      type: "input"
      width: "1"
      description: "Clock"
    - name: "rst"
      type: "input"
      width: "1"
      description: "Synchronous active-high reset"
    - name: "data_in"
      type: "input"
      width: "64"
      description: "64-bit input word"
    - name: "threshold"
      type: "input"
      width: "6"
      description: "Unsigned comparison threshold"
    - name: "count_out"
      type: "output"
      width: "7"
      description: "Population count result, aligned 2 cycles after input"
    - name: "threshold_exceeded"
      type: "output"
      width: "1"
      description: "High when the aligned count is strictly greater than the aligned threshold"

target_platform:
  device_family: "AMD Xilinx Zynq-7000"

tasks:
  - name: "High-Frequency 64-bit Popcount"
    constraints:
      max_lut: 120
      max_ff: 160
      max_bram: 0
      max_dsp: 0
      min_frequency: 250
    objective:
      goal: "maximise"
      target: "Fmax"
