From 0023b742e4c4c48642247a4cb55962f9141dfb98 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Wed, 19 Mar 2014 17:47:26 -0600 Subject: [PATCH] genlib/coding: gracefully handle flen(i) < 2 --- migen/genlib/coding.py | 6 +++--- migen/test/test_coding.py | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/migen/genlib/coding.py b/migen/genlib/coding.py index ed031557..df89f6cc 100644 --- a/migen/genlib/coding.py +++ b/migen/genlib/coding.py @@ -26,7 +26,7 @@ class Encoder(Module): """ def __init__(self, width): self.i = Signal(width) # one-hot - self.o = Signal(max=width) # binary + self.o = Signal(max=max(2, width)) # binary self.n = Signal() # invalid: none or multiple act = dict((1< 0: + self.assertEqual(i & 1<<(o - 1), 0) + self.assertGreaterEqual(i, 1<