Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow primitives to assign to multiple results #1560

Merged
merged 5 commits into from
Nov 3, 2020

Conversation

martijnbastiaan
Copy link
Member

@martijnbastiaan martijnbastiaan commented Oct 29, 2020

Approach:

-- A multi result primitive assigns its results to multiple result variables
-- instead of one. Besides producing nicer HDL it works around issues with
-- synthesis tooling described in:
--
--   https://github.com/clash-lang/clash-compiler/issues/1555
--
-- This transformation rewrites primitives indicating they can assign their
-- results to multiple signals, such that netlist can easily render it.
--
-- Example:
--
-- @
-- prim :: forall a. a -> (a, a)
-- @
--
-- will be rewritten to:
--
-- @
--   \a0 -> let
--            r  = prim a0 r0 r1     -- With 'Clash.Core.Term.MultiPrim'
--            r0 = multiPrimSelect r0 r
--            r1 = multiPrimSelect r1 r
--          in
--            (r0, r1)
-- @
--
-- Netlist will not render any @multiPrimSelect@ primitives. Similar to
-- primitives having a /void/ return type, /r/ is not rendered either.
--
-- This transformation is currently hardcoded to recognize tuples as return
-- types, not any product type. It will error if it sees a multi result primitive
-- with a non-tuple return type.
--

@martijnbastiaan martijnbastiaan force-pushed the multiresult-prims branch 2 times, most recently from 6a935a2 to f325ea0 Compare October 29, 2020 12:26
@martijnbastiaan martijnbastiaan force-pushed the multiresult-prims branch 2 times, most recently from 0898267 to fec6fbd Compare October 30, 2020 20:20
@martijnbastiaan martijnbastiaan marked this pull request as ready for review October 30, 2020 20:20
@martijnbastiaan martijnbastiaan force-pushed the multiresult-prims branch 4 times, most recently from 37b701c to 806b84b Compare November 2, 2020 19:49
A multi result primitive assigns its results to multiple result variables
instead of one. Besides producing nicer HDL it works around issues with
synthesis tooling described in:

  #1555

This transformation rewrites primitives indicating they can assign their
results to multiple signals, such that netlist can easily render it.

Example:

@
prim :: forall a. a -> (a, a)
@

will be rewritten to:

@
  \a0 -> let
           r  = prim @t0 a0 r0 r1     -- With 'Clash.Core.Term.MultiPrim'
           r0 = multiPrimSelect r0 r
           r1 = multiPrimSelect r1 r
         in
           (x, y)
@

Netlist will not render any @multiPrimSelect@ primitives. Similar to
primitives having a /void/ return type, /r/ is not rendered either.

This transformation is currently hardcoded to recognize tuples as return
types, not any product type. It will error if it sees a multi result primitive
with a non-tuple return type.

Closes #1555
@martijnbastiaan martijnbastiaan merged commit eaed9ba into master Nov 3, 2020
@martijnbastiaan martijnbastiaan deleted the multiresult-prims branch November 3, 2020 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants