- BlackBox:
    name: Clash.Sized.Internal.Signed.size#
    kind: Expression
    type: 'size# :: KnownNat
      n => Signed n -> Int'
    template: to_signed(~LIT[0],~SIZE[~TYPO])
    workInfo: Constant
- BlackBox:
    name: Clash.Sized.Internal.Signed.pack#
    kind: Expression
    type: 'pack# :: KnownNat
      n => Signed n -> BitVector n'
    template: std_logic_vector(~ARG[1])
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Internal.Signed.unpack#
    kind: Expression
    type: 'unpack# :: KnownNat
      n => BitVector n -> Signed n'
    template: signed(~ARG[1])
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Internal.Signed.eq#
    kind: Expression
    type: 'eq# :: Signed n
      -> Signed n -> Bool'
    template: ~IF~SIZE[~TYP[0]]~THEN~ARG[0] = ~ARG[1]~ELSEtrue~FI
- BlackBox:
    name: Clash.Sized.Internal.Signed.neq#
    kind: Expression
    type: 'neq# :: Signed
      n -> Signed n -> Bool'
    template: ~IF~SIZE[~TYP[0]]~THEN~ARG[0] /= ~ARG[1]~ELSEfalse~FI
- BlackBox:
    name: Clash.Sized.Internal.Signed.lt#
    kind: Expression
    type: 'lt# :: Signed n
      -> Signed n -> Bool'
    template: ~IF~SIZE[~TYP[0]]~THEN~ARG[0] < ~ARG[1]~ELSEfalse~FI
- BlackBox:
    name: Clash.Sized.Internal.Signed.ge#
    kind: Expression
    type: 'ge# :: Signed n
      -> Signed n -> Bool'
    template: ~IF~SIZE[~TYP[0]]~THEN~ARG[0] >= ~ARG[1]~ELSEtrue~FI
- BlackBox:
    name: Clash.Sized.Internal.Signed.gt#
    kind: Expression
    type: 'gt# :: Signed n
      -> Signed n -> Bool'
    template: ~IF~SIZE[~TYP[0]]~THEN~ARG[0] > ~ARG[1]~ELSEfalse~FI
- BlackBox:
    name: Clash.Sized.Internal.Signed.le#
    kind: Expression
    type: 'le# :: Signed n
      -> Signed n -> Bool'
    template: ~IF~SIZE[~TYP[0]]~THEN~ARG[0] <= ~ARG[1]~ELSEtrue~FI
- BlackBox:
    name: Clash.Sized.Internal.Signed.minBound#
    comment: the quantification with signed gives the array an ascending index
    kind: Expression
    type: 'minBound# :: KnownNat
      n => Signed n'
    template: ~IF~SIZE[~TYPO]~THENsigned'(0 => '1', 1 to ~LIT[0]-1 => '0')~ELSEsigned'(1
      downto 0 => '0')~FI
    workInfo: Constant
- BlackBox:
    name: Clash.Sized.Internal.Signed.maxBound#
    comment: the quantification with signed gives the array an ascending index
    kind: Expression
    type: 'maxBound# :: KnownNat
      n => Signed n'
    template: ~IF~SIZE[~TYPO]~THENsigned'(0 => '0', 1 to ~LIT[0]-1  => '1')~ELSEsigned'(1
      downto 0 => '0')~FI
    workInfo: Constant
- BlackBox:
    name: Clash.Sized.Internal.Signed.*#
    kind: Expression
    type: '(*#) :: KnownNat
      n => Signed n -> Signed n -> Signed n'
    template: resize(~ARG[1] * ~ARG[2], ~LIT[0])
- BlackBox:
    name: Clash.Sized.Internal.Signed.negate#
    kind: Expression
    type: 'negate# :: KnownNat
      n => Signed n -> Signed n'
    template: -~ARG[1]
- BlackBox:
    name: Clash.Sized.Internal.Signed.abs#
    kind: Expression
    type: 'abs# :: KnownNat
      n => Signed n -> Signed n'
    template: abs ~ARG[1]
- BlackBox:
    name: Clash.Sized.Internal.Signed.fromInteger#
    format: Haskell
    kind: Expression
    type: 'fromInteger# ::
      KnownNat n => Integer -> Signed (n :: Nat)'
    templateFunction: Clash.Primitives.Sized.Signed.fromIntegerTF
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Internal.Signed.toEnum#
    kind: Expression
    type: 'toEnum# :: KnownNat
      n => Int -> Signed n'
    template: resize(signed(std_logic_vector(~ARG[1])),~SIZE[~TYPO])
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Internal.Signed.fromEnum#
    kind: Expression
    type: 'fromEnum# :: KnownNat
      n => Signed n -> Int'
    template: ~IF~SIZE[~TYP[1]]~THENresize(~ARG[1],~SIZE[~TYPO])~ELSEto_signed(0,~SIZE[~TYPO])~FI
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Internal.Signed.plus#
    kind: Expression
    type: 'plus# :: Signed
      m -> Signed n -> Signed (1 + Max m n)'
    template: ~IF~AND[~SIZE[~TYP[0]],~SIZE[~TYP[1]]]~THENresize(~ARG[0],~SIZE[~TYPO])
      + resize(~ARG[1],~SIZE[~TYPO])~ELSE~IF~SIZE[~TYP[0]]~THENresize(~ARG[0],~SIZE[~TYPO])~ELSEresize(~ARG[1],~SIZE[~TYPO])~FI~FI
- BlackBox:
    name: Clash.Sized.Internal.Signed.minus#
    kind: Expression
    type: 'minus# :: Signed
      m -> Signed n -> Signed (1 + Max m n)'
    template: ~IF~AND[~SIZE[~TYP[0]],~SIZE[~TYP[1]]]~THENresize(~ARG[0],~SIZE[~TYPO])
      - resize(~ARG[1],~SIZE[~TYPO])~ELSE~IF~SIZE[~TYP[0]]~THENresize(~ARG[0],~SIZE[~TYPO])~ELSEresize(-
      ~ARG[1],~SIZE[~TYPO])~FI~FI
- BlackBox:
    name: Clash.Sized.Internal.Signed.times#
    kind: Expression
    type: 'times# :: Signed
      m -> Signed n -> Signed (m + n)'
    template: ~IF~AND[~SIZE[~TYP[0]],~SIZE[~TYP[1]]]~THEN~ARG[0] * ~ARG[1]~ELSEsigned'(~SIZE[~TYPO]-1
      downto 0 => '0')~FI
- BlackBox:
    name: Clash.Sized.Internal.Signed.rem#
    kind: Declaration
    type: 'rem# :: Signed
      n -> Signed n -> Signed n'
    template: |-
      ~RESULT <= ~ARG[0] rem ~ARG[1]
          -- pragma translate_off
          when (~ARG[1] /= 0) else (others => 'X')
          -- pragma translate_on
          ;
- BlackBox:
    name: Clash.Sized.Internal.Signed.div#
    kind: Declaration
    type: 'div# :: KnownNat
      n => Signed n -> Signed n -> Signed n'
    template: |-
      -- divSigned begin
      ~GENSYM[divSigned][0] : block
        signal ~GENSYM[resultPos][1] : boolean;
        signal ~GENSYM[dividerNeg][2] : boolean;
        signal ~GENSYM[dividend2][3] : signed(~SIZE[~TYPO] downto 0);
        signal ~GENSYM[quot_res][4] : signed(~SIZE[~TYPO] downto 0);
      begin
        ~SYM[1] <= ~VAR[dividend][1](~VAR[dividend][1]'high) = ~VAR[divider][2](~VAR[divider][2]'high);
        ~SYM[2] <= ~VAR[divider][2](~VAR[divider][2]'high) = '1';
        ~SYM[3] <= resize(~VAR[dividend][1],~SIZE[~TYPO]+1)   when ~SYM[1] else
                   (resize(~VAR[dividend][1],~SIZE[~TYPO]+1) - resize(~VAR[divider][2],~SIZE[~TYPO]+1) - 1)   when ~SYM[2] else
                   (resize(~VAR[dividend][1],~SIZE[~TYPO]+1) - resize(~VAR[divider][2],~SIZE[~TYPO]+1) + 1);
        ~SYM[4] <= ~SYM[3] / ~VAR[divider][2]
            -- pragma translate_off
            when (~VAR[divider][2] /= 0) else (others => 'X')
            -- pragma translate_on
            ;
        ~RESULT <= signed(~SYM[4](~SIZE[~TYPO]-1 downto 0));
      end block;
      -- divSigned end
- BlackBox:
    name: Clash.Sized.Internal.Signed.mod#
    kind: Declaration
    type: 'mod# :: Signed
      n -> Signed n -> Signed n'
    template: |-
      ~RESULT <= ~ARG[0] mod ~ARG[1]
          -- pragma translate_off
          when (~ARG[1] /= 0) else (others => 'X')
          -- pragma translate_on
          ;
- BlackBoxHaskell:
    name: Clash.Sized.Internal.Signed.toInteger#
    templateFunction: Clash.Primitives.Sized.ToInteger.signedToIntegerVHDL
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Internal.Signed.and#
    kind: Expression
    type: 'and# :: KnownNat
      n => Signed n -> Signed n -> Signed n'
    template: ~ARG[1] and ~ARG[2]
- BlackBox:
    name: Clash.Sized.Internal.Signed.or#
    kind: Expression
    type: 'or# :: KnownNat
      n => Signed n -> Signed n -> Signed n'
    template: ~ARG[1] or ~ARG[2]
- BlackBox:
    name: Clash.Sized.Internal.Signed.xor#
    kind: Expression
    type: 'xor# :: KnownNat
      n => Signed n -> Signed n -> Signed n'
    template: ~ARG[1] xor ~ARG[2]
- BlackBox:
    name: Clash.Sized.Internal.Signed.complement#
    kind: Expression
    type: 'complement# ::
      KnownNat n => Signed n -> Signed n'
    template: not ~ARG[1]
- BlackBox:
    name: Clash.Sized.Internal.Signed.shiftL#
    kind: Declaration
    type: 'shiftL# :: KnownNat
      n => Signed n -> Int -> Signed n'
    template: |-
      ~GENSYM[~RESULT_shiftL][0] : block
        signal ~GENSYM[sh][1] : natural;
      begin
        ~SYM[1] <=
            -- pragma translate_off
            natural'high when (~VAR[shI][2](~SIZE[~TYP[2]]-1 downto 31) /= 0) else
            -- pragma translate_on
            to_integer(~VAR[shI][2]
            -- pragma translate_off
            (30 downto 0)
            -- pragma translate_on
            );
        ~RESULT <= shift_left(~ARG[1],~SYM[1])
            -- pragma translate_off
            when (~ARG[2] >= 0) else (others => 'X')
            -- pragma translate_on
            ;
      end block;
- BlackBox:
    name: Clash.Sized.Internal.Signed.shiftR#
    kind: Declaration
    type: 'shiftR# :: KnownNat
      n => Signed n -> Int -> Signed n'
    template: |-
      ~GENSYM[~RESULT_shiftR][0] : block
        signal ~GENSYM[sh][1] : natural;
      begin
        ~SYM[1] <=
            -- pragma translate_off
            natural'high when (~VAR[shI][2](~SIZE[~TYP[2]]-1 downto 31) /= 0) else
            -- pragma translate_on
            to_integer(~VAR[shI][2]
            -- pragma translate_off
            (30 downto 0)
            -- pragma translate_on
            );
        ~RESULT <= shift_right(~ARG[1],~SYM[1])
            -- pragma translate_off
            when (~ARG[2] >= 0) else (others => 'X')
            -- pragma translate_on
            ;
      end block;
- BlackBox:
    name: Clash.Sized.Internal.Signed.rotateL#
    kind: Declaration
    type: 'rotateL# :: KnownNat
      n => Signed n -> Int -> Signed n'
    template: |-
      ~RESULT <= rotate_left(~ARG[1],to_integer((~ARG[2])
          -- pragma translate_off
          mod ~SIZE[~TYP[1]]
          -- pragma translate_on
          ))
          -- pragma translate_off
          when (~ARG[2] >= 0) else (others => 'X')
          -- pragma translate_on
          ;
- BlackBox:
    name: Clash.Sized.Internal.Signed.rotateR#
    kind: Declaration
    type: 'rotateR# :: KnownNat
      n => Signed n -> Int -> Signed n'
    template: |-
      ~RESULT <= rotate_right(~ARG[1],to_integer((~ARG[2])
          -- pragma translate_off
          mod ~SIZE[~TYP[1]]
          -- pragma translate_on
          ))
          -- pragma translate_off
          when (~ARG[2] >= 0) else (others => 'X')
          -- pragma translate_on
          ;
- BlackBox:
    name: Clash.Sized.Internal.Signed.resize#
    kind: Expression
    type: 'resize# :: (KnownNat
      n, KnownNat m) => Signed n -> Signed m'
    template: ~IF~SIZE[~TYP[2]]~THENresize(~ARG[2],~LIT[1])~ELSEsigned'(~SIZE[~TYPO]-1
      downto 0 => '0')~FI
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Internal.Signed.truncateB#
    kind: Expression
    type: 'truncateB# :: KnownNat
      m => Signed (n + m) -> Signed m'
    template: ~IF~SIZE[~TYPO]~THEN~VAR[s][1](~LIT[0]-1 downto 0)~ELSEsigned'(0 downto
      1 => '0')~FI
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Internal.Signed.quot#
    kind: Declaration
    type: 'quot# :: KnownNat
      n => Signed n -> Signed n -> Signed n'
    template: |-
      ~RESULT <= ~ARG[1] / ~ARG[2]
          -- pragma translate_off
          when (~ARG[2] /= 0) else (others => 'X')
          -- pragma translate_on
          ;
