amaranth icon indicating copy to clipboard operation
amaranth copied to clipboard

Support division of negative numbers?

Open pepijndevos opened this issue 5 years ago • 4 comments

It appears that Yosys now supports $divfloor as of https://github.com/YosysHQ/yosys/commit/edd8ff2c0778d97808869488cc7394151456c4ca

In ast.py it is mentioned that the different semantics mean it's not supported: https://github.com/nmigen/nmigen/blob/e46118dac0df315694b0fc6b9367d285a8fc12dd/nmigen/hdl/ast.py#L173-L179

I'm not sure what division synthesizes to in Yosys in general, or if it supports the general case at all, but it seems that on the nMigen side we can now emit $divfloor and fully support division with correct semantics. I'd be happy to put together a PR for this at some point.

pepijndevos avatar Aug 17 '20 08:08 pepijndevos

Reasonable. I think we might want to wait until there's a Yosys release, because we can't shim over the lack of $divfloor in older Yosys in back.verilog, like we do for other Yosys-related variability.

whitequark avatar Aug 17 '20 08:08 whitequark

The verilog backend in that commit (which I do not claim to fully understand) does seem to "shim" over the lack of flooring division in Verilog, so I think it might technically be possible to work around it, but I agree waiting for a Yosys release is easier. Bit unfortunate that Yosys releases are not exactly frequent.

pepijndevos avatar Aug 17 '20 08:08 pepijndevos

I think it might technically be possible to work around it

I guess you could, when targeting older Yosys, always provide a $divfloor cell as a part of nmigen.back.verilog, and then immediately flattening it, so that it never actually appears in output Verilog. But it's not clear that the effort is justified.

whitequark avatar Aug 17 '20 08:08 whitequark

Probably not...

pepijndevos avatar Aug 17 '20 08:08 pepijndevos

This is implemented as of b452e0e8 (issue #621).

whitequark avatar Feb 03 '23 04:02 whitequark