# DpgenNand2mask
Keywords: dpgen

- Name : DpgenNand2mask - Programmable Mask Macro-Generator
- Synopsys :

      Generate ( 'DpgenNand2mask', modelname
               , param = { 'nbit'       : n
                         , 'const'      : constVal
                         , 'physical'   : True
                         , 'behavioral' : True
                         }
               )

- Description : Generates a `n` bits conditionnal NAND mask named `modelname`.
- Terminal Names :
  - cmd : mask control ( 1 bit )
  - i0 : input ( `n` bits )
  - nq : output ( `n` bits )
  - vdd : power
  - vss : ground
- Parameters : Parameters are given in the map `param`.
  - nbit (mandatory) : Defines the size of the generator
  - const (mandatory) : Defines the constant (string beginning with 0b, 0x or 0o functions of the basis)
  - physical (optional, default value : False) : In order to generate a layout
  - behavioral (optional, default value : False) : In order to generate a behavior
- How it works :
  - If the `cmd` signal is set to `zero`, the mask is NOT applied, so the whole operator behaves like an inverter.
  - If the `cmd` signal is set to `one`, the mask is applied, the output is the complemented result of the input value ANDed with the mask (suplied by `constVal`).
  - The constant `constVal` is given to the macro-generator call, therefore the value cannot be changed afterward : it's hard wired in the operator.
  - A common error is to give a real constant for the `constVal` argument. Be aware that it is a character string.
- Behavior :

      nq <= WITH cmd SELECT not(i0)              WHEN '0',
                            not(i0 and constVal) WHEN '1';

- Example :

      from stratus import *

      class inst_nand2mask ( Model ) :

        def Interface ( self ) :
          self.i   = SignalIn  (   "i", 32 )
          self.cmd = SignalIn  ( "cmd",  1 )
          self.o   = SignalOut (   "o", 32 )

          self.vdd = VddIn ( "vdd" )
          self.vss = VssIn ( "vss" )

        def Netlist ( self ) :
          Generate ( 'DpgenNand2mask', 'nand2mask_0x0000ffff'
                   , param = { 'nbit'     : 32
                             , 'const'    : "0x0000FFFF"
                             , 'physical' : True
                             }
                   )
          self.I = Inst ( 'nand2mask_0x0000ffff', 'inst'
                        , map = { 'i0'  : self.i
                                , 'cmd' : self.cmd
                                , 'nq'  : self.o
                                , 'vdd' : self.vdd
                                , 'vss' : self.vss
                                }
                        )

        def Layout ( self ) :
          Place ( self.I, NOSYM, Ref(0, 0) )