Skip to content

Commit

Permalink
fix: use elsif in lookup table
Browse files Browse the repository at this point in the history
  • Loading branch information
julianhoever committed Jun 9, 2023
1 parent c0756b3 commit f375ba3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ def save_to(self, destination: Path) -> None:
process_content = []

pairs = list(self._compute_io_pairs().items())
for input, output in pairs[:-1]:
input_value, output_value = pairs[0]
process_content.append(
f"if signed_x <= {input_value} then "
f"signed_y <= to_signed({output_value}, {self._width});"
)
for input_value, output_value in pairs[1:-1]:
process_content.append(
f"if signed_x <= {input} then signed_y <= to_signed({output},"
f" {self._width});"
f"elsif signed_x <= {input_value} then "
f"signed_y <= to_signed({output_value}, {self._width});"
)
_, output = pairs[-1]
process_content.append(f"else signed_y <= to_signed({output}, {self._width});")
Expand Down
12 changes: 6 additions & 6 deletions tests/vhdl/designs/test_fp_monotonously_increasing_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def test_vhdl_code_matches_expected_for_tanh_as_base_module() -> None:
tanh_process : process(x)
begin
if signed_x <= 20 then signed_y <= to_signed(3, 8);
if signed_x <= 10 then signed_y <= to_signed(3, 8);
if signed_x <= 0 then signed_y <= to_signed(0, 8);
if signed_x <= -10 then signed_y <= to_signed(-3, 8);
elsif signed_x <= 10 then signed_y <= to_signed(3, 8);
elsif signed_x <= 0 then signed_y <= to_signed(0, 8);
elsif signed_x <= -10 then signed_y <= to_signed(-3, 8);
else signed_y <= to_signed(-3, 8);
end if;
end process;
Expand Down Expand Up @@ -74,9 +74,9 @@ def test_vhdl_code_matches_expected_for_sigmoid_as_base_module() -> None:
sigmoid_process : process(x)
begin
if signed_x <= 20 then signed_y <= to_signed(3, 8);
if signed_x <= 10 then signed_y <= to_signed(3, 8);
if signed_x <= 0 then signed_y <= to_signed(2, 8);
if signed_x <= -10 then signed_y <= to_signed(0, 8);
elsif signed_x <= 10 then signed_y <= to_signed(3, 8);
elsif signed_x <= 0 then signed_y <= to_signed(2, 8);
elsif signed_x <= -10 then signed_y <= to_signed(0, 8);
else signed_y <= to_signed(0, 8);
end if;
end process;
Expand Down

0 comments on commit f375ba3

Please sign in to comment.