Skip to content

Instantly share code, notes, and snippets.

@soronpo
Created August 5, 2026 13:10
Show Gist options
  • Select an option

  • Save soronpo/3d676c5059f0f66dc6d1fc1c92a8a09d to your computer and use it in GitHub Desktop.

Select an option

Save soronpo/3d676c5059f0f66dc6d1fc1c92a8a09d to your computer and use it in GitHub Desktop.
DFHDL #449 minimized - 2 designs, 31 lines
import dfhdl.*
class cell_histogram(
val IMAGE_WIDTH: Int <> CONST = 640,
val INPUT_BIN_WIDTH: Int <> CONST = 11,
val OUTPUT_BIN_WIDTH: Int <> CONST = 14
) extends EDDesign:
val BINS: Int <> CONST = 9 + 1
val PARTIAL_HISTOGRAM_WIDTH: Int <> CONST = INPUT_BIN_WIDTH * BINS
val CELLS_PER_ROW: Int <> CONST = IMAGE_WIDTH / 8
val histogram_adder = new partial_histogram_add(
INPUT_BIN_WIDTH = INPUT_BIN_WIDTH, OUTPUT_BIN_WIDTH = OUTPUT_BIN_WIDTH, BINS = BINS)
import dfhdl.*
class partial_histogram_add(
val INPUT_BIN_WIDTH: Int <> CONST = 11,
val OUTPUT_BIN_WIDTH: Int <> CONST = 14,
val BINS: Int <> CONST = 9,
val CELL_ROWS: Int <> CONST = 8
) extends EDDesign:
val INPUT_WIDTH = INPUT_BIN_WIDTH * BINS * CELL_ROWS
val OUTPUT_WIDTH = OUTPUT_BIN_WIDTH * BINS
val partial_histogram = Bits(INPUT_WIDTH) <> VAR
val full_histogram = Bits(OUTPUT_WIDTH) <> VAR
partial_histogram <> all(0)
val ROW_OFFSETS = List(0, 99)
process(all):
for (i <- 0 until BINS)
full_histogram.lsbitsAt(i * OUTPUT_BIN_WIDTH, OUTPUT_BIN_WIDTH) :=
ROW_OFFSETS.map(off =>
partial_histogram.lsbitsAt(i * INPUT_BIN_WIDTH + off, INPUT_BIN_WIDTH)
.resize(OUTPUT_BIN_WIDTH)).reduce(_ + _)
#!/bin/bash
# DFHDL #449 minimized: 2 designs, 2 files, 31 lines.
#
# MUST run in a directory that has never been compiled before -- copy this tree
# to a NEW path per attempt (bloop keys incremental state by project path, so
# deleting src/.scala-build is NOT sufficient).
set -u
V=$(cat ~/.dfhdl_version)
b(){ scala run src/ --scala 3.8.4 --dep "io.github.dfianthdl::dfhdl::$V" \
--compiler-plugin "io.github.dfianthdl:::dfhdl-plugin::$V" -O -deprecation \
-M cell_histogram -- commit 2>&1; }
echo "1. build"; b >/tmp/1.log 2>&1 && echo " ok" || { tail -3 /tmp/1.log; exit 1; }
echo "2. build again (populates the elaboration cache)"
b >/tmp/2.log 2>&1 && echo " ok" || { tail -3 /tmp/2.log; exit 1; }
echo "3. change one parameter default"
sed -i 's/IMAGE_WIDTH: Int <> CONST = 640/IMAGE_WIDTH: Int <> CONST = 64/' src/cell_histogram.scala
echo "4. rebuild"
if b >/tmp/3.log 2>&1; then echo " ok (did NOT reproduce - was this path used before?)"
else grep -m1 'NoSuchElementException: key not found: "TW_' /tmp/3.log && echo " REPRODUCED"; fi
echo "5. clear dfhdl-cache, rebuild identical source"
find src/.scala-build -name dfhdl-cache -type d -exec rm -rf {} + 2>/dev/null
b >/tmp/4.log 2>&1 && echo " ok - same source is fine once the cache is gone"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment