clash-lib-1.8.1: Clash: a functional hardware description language - As a library
Copyright(C) 2015-2016 University of Twente
2021-2024 QBayLogic B.V.
2022 LumiGuide Fietsdetectie B.V.
LicenseBSD2 (see the file LICENSE)
MaintainerQBayLogic B.V. <devops@qbaylogic.com>
Safe HaskellNone
LanguageHaskell2010

Clash.Normalize.Transformations.DEC

Description

The disjointExpressionConsolidation transformation lifts applications of global binders out of alternatives of case-statements.

e.g. It converts:

case x of
  A -> f 3 y
  B -> f x x
  C -> h x

into:

let f_arg0 = case x of {A -> 3; B -> x}
    f_arg1 = case x of {A -> y; B -> x}
    f_out  = f f_arg0 f_arg1
in  case x of
      A -> f_out
      B -> f_out
      C -> h x
Synopsis

Documentation

disjointExpressionConsolidation :: HasCallStack => NormRewrite Source #

This transformation lifts applications of global binders out of alternatives of case-statements.

e.g. It converts:

case x of
  A -> f 3 y
  B -> f x x
  C -> h x

into:

let f_arg0 = case x of {A -> 3; B -> x}
    f_arg1 = case x of {A -> y; B -> x}
    f_out  = f f_arg0 f_arg1
in  case x of
      A -> f_out
      B -> f_out
      C -> h x

Though that's a lie. It actually converts it into:

let f_tupIn = case x of {A -> (3,y); B -> (x,x)}
    f_arg0  = case f_tupIn of (l,_) -> l
    f_arg1  = case f_tupIn of (_,r) -> r
    f_out   = f f_arg0 f_arg1
in  case x of
      A -> f_out
      B -> f_out
      C -> h x

In order to share the expression that's in the subject of the case expression, and to share the decoder circuit that logic synthesis will create to map the bits of the subject expression to the bits needed to make the selection in the multiplexer.