- BlackBox:
    name: Clash.Sized.Vector.head
    kind: Expression
    type: 'head :: Vec (n + 1) a -> a'
    template: '~FROMBV[~VAR[vec][0][\~SIZE[~TYP[0]]-1 -: ~SIZE[~TYPO]\]][~TYPO]'
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.tail
    kind: Expression
    type: 'tail :: Vec (n + 1) a -> Vec n a'
    template: '~VAR[vec][0][~SIZE[~TYPO]-1 : 0]'
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.last
    kind: Expression
    type: Vec (n + 1) a -> a
    template: ~FROMBV[~VAR[vec][0][\~SIZE[~TYPO]-1:0\]][~TYPO]
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.init
    kind: Expression
    type: Vec (n + 1) a -> Vec n a
    template: '~VAR[vec][0][~SIZE[~TYP[0]]-1 : ~SIZE[~TYPEL[~TYP[0]]]]'
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.select
    kind: Declaration
    type: |-
      select :: (CmpNat (i + s) (s * n) ~ GT) -- ARG[0]
              => SNat f                        -- ARG[1]
              -> SNat s                        -- ARG[2]
              -> SNat n                        -- ARG[3]
              -> Vec i a                       -- ARG[4]
              -> Vec n a
    template: |-
      // select begin
      wire ~TYPEL[~TYPO] ~SYM[1] [0:~LENGTH[~TYP[4]]-1];
      genvar ~GENSYM[i][2];
      ~GENERATE
      for (~SYM[2]=0; ~SYM[2] < ~LENGTH[~TYP[4]]; ~SYM[2]=~SYM[2]+1) begin : ~GENSYM[mk_array][3]
        assign ~SYM[1][(~LENGTH[~TYP[4]]-1)-~SYM[2]] = ~VAR[vec][4][~SYM[2]*~SIZE[~TYPEL[~TYPO]]+:~SIZE[~TYPEL[~TYPO]]];
      end
      ~ENDGENERATE

      genvar ~GENSYM[i][4];
      ~GENERATE
      for (~SYM[4]=0; ~SYM[4] < ~LIT[3]; ~SYM[4] = ~SYM[4] + 1) begin : ~GENSYM[select][5]
        assign ~RESULT[(~LIT[3]-1-~SYM[4])*~SIZE[~TYPEL[~TYPO]]+:~SIZE[~TYPEL[~TYPO]]] = ~SYM[1][~LIT[1] + (~LIT[2] * ~SYM[4])];
      end
      ~ENDGENERATE
      // select end
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.++
    kind: Expression
    type: '(++) :: Vec n a -> Vec m a -> Vec (n + m) a'
    template: '{~ARG[0],~ARG[1]}'
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.concat
    kind: Expression
    type: 'concat :: Vec n (Vec m a) -> Vec (n * m) a'
    template: ~ARG[0]
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.splitAt
    kind: Expression
    type: 'splitAt :: SNat m -> Vec (m + n) a -> (Vec m a, Vec n a)'
    template: ~ARG[1]
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.unconcat
    kind: Expression
    type: |-
      unconcat :: KnownNat n     -- ARG[0]
                 => SNat m         -- ARG[1]
                 -> Vec (n * m) a  -- ARG[2]
                 -> Vec n (Vec m a)
    template: ~ARG[2]~DEVNULL[~ARG[0]]~DEVNULL[~ARG[1]]
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.map
    kind: Declaration
    type: 'map :: (a -> b) -> Vec n a -> Vec n b'
    template: |-
      // map begin
      genvar ~GENSYM[i][1];
      ~GENERATE
      for (~SYM[1]=0; ~SYM[1] < ~LENGTH[~TYPO]; ~SYM[1] = ~SYM[1] + 1) begin : ~GENSYM[map][2]~IF~SIZE[~TYP[1]]~THEN
        wire ~TYPEL[~TYP[1]] ~GENSYM[map_in][3];
        assign ~SYM[3] = ~VAR[vec][1][~SYM[1]*~SIZE[~TYPEL[~TYP[1]]]+:~SIZE[~TYPEL[~TYP[1]]]];~ELSE ~FI
        ~OUTPUTUSAGE[0] ~TYPEL[~TYPO] ~GENSYM[map_out][4];
        ~INST 0
          ~OUTPUT <= ~SYM[4]~ ~TYPEL[~TYPO]~
          ~INPUT  <= ~SYM[3]~ ~TYPEL[~TYP[1]]~
        ~INST
        assign ~RESULT[~SYM[1]*~SIZE[~TYPEL[~TYPO]]+:~SIZE[~TYPEL[~TYPO]]] = ~SYM[4];
      end
      ~ENDGENERATE
      // map end
    workInfo: Identity 1 [0]
- BlackBox:
    name: Clash.Sized.Vector.imap
    kind: Declaration
    type: 'imap :: KnownNat n => (Index n -> a -> b) -> Vec n a -> Vec n b'
    template: |-
      // imap begin
      genvar ~GENSYM[i][1];
      ~GENERATE
      for (~SYM[1]=0; ~SYM[1] < ~LENGTH[~TYPO]; ~SYM[1] = ~SYM[1] + 1) begin : ~GENSYM[imap][2]
        wire [~SIZE[~INDEXTYPE[~LIT[0]]]-1:0] ~GENSYM[map_index][3];~IF~SIZE[~TYP[2]]~THEN
        wire ~TYPEL[~TYP[2]] ~GENSYM[map_in][4];
        assign ~SYM[4] = ~VAR[vec][2][~SYM[1]*~SIZE[~TYPEL[~TYP[2]]]+:~SIZE[~TYPEL[~TYP[2]]]];~ELSE ~FI
        ~OUTPUTUSAGE[1] ~TYPEL[~TYPO] ~GENSYM[map_out][5];

        assign ~SYM[3] = ~SIZE[~INDEXTYPE[~LIT[0]]]'d~MAXINDEX[~TYPO] - ~SYM[1][0+:~SIZE[~INDEXTYPE[~LIT[0]]]];
        ~INST 1
          ~OUTPUT <= ~SYM[5]~ ~TYPEL[~TYPO]~
          ~INPUT  <= ~SYM[3]~ ~INDEXTYPE[~LIT[0]]~
          ~INPUT  <= ~SYM[4]~ ~TYPEL[~TYP[2]]~
        ~INST
        assign ~RESULT[~SYM[1]*~SIZE[~TYPEL[~TYPO]]+:~SIZE[~TYPEL[~TYPO]]] = ~SYM[5];
      end
      ~ENDGENERATE
      // imap end
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.imap_go
    kind: Declaration
    type: 'imap_go :: (Index n -> a -> b) -> Vec m a -> Index n -> Vec m b'
    template: |-
      // imap begin
      genvar ~GENSYM[i][1];
      ~GENERATE
      for (~SYM[1]=0; ~SYM[1] < ~LENGTH[~TYPO]; ~SYM[1] = ~SYM[1] + 1) begin : ~GENSYM[imap][2]
        wire ~TYP[2] ~GENSYM[map_index][3];~IF~SIZE[~TYP[1]]~THEN
        wire ~TYPEL[~TYP[1]] ~GENSYM[map_in][4];
        assign ~SYM[4] = ~VAR[vec][1][~SYM[1]*~SIZE[~TYPEL[~TYP[1]]]+:~SIZE[~TYPEL[~TYP[1]]]];~ELSE ~FI
        ~OUTPUTUSAGE[0] ~TYPEL[~TYPO] ~GENSYM[map_out][5];

        assign ~SYM[3] = ~SIZE[~TYP[2]]'d~MAXINDEX[~TYPO] - ~SYM[1][0+:~SIZE[~TYP[2]]] + ~ARG[2];
        ~INST 0
          ~OUTPUT <= ~SYM[5]~ ~TYPEL[~TYPO]~
          ~INPUT  <= ~SYM[3]~ ~TYP[2]~
          ~INPUT  <= ~SYM[4]~ ~TYPEL[~TYP[1]]~
        ~INST
        assign ~RESULT[~SYM[1]*~SIZE[~TYPEL[~TYPO]]+:~SIZE[~TYPEL[~TYPO]]] = ~SYM[5];
      end
      ~ENDGENERATE
      // imap end
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.zipWith
    kind: Declaration
    type: 'zipWith :: (a -> b -> c) -> Vec n a -> Vec n b -> Vec n c'
    template: |-
      // zipWith start
      genvar ~GENSYM[i][2];
      ~GENERATE
      for (~SYM[2] = 0; ~SYM[2] < ~LENGTH[~TYPO]; ~SYM[2] = ~SYM[2] + 1) begin : ~GENSYM[zipWith][6]~IF~SIZE[~TYP[1]]~THEN
        wire ~TYPEL[~TYP[1]] ~GENSYM[zipWith_in1][3];
        assign ~SYM[3] = ~VAR[vec1][1][~SYM[2]*~SIZE[~TYPEL[~TYP[1]]]+:~SIZE[~TYPEL[~TYP[1]]]];~ELSE ~FI~IF~SIZE[~TYP[2]]~THEN
        wire ~TYPEL[~TYP[2]] ~GENSYM[zipWith_in2][4];
        assign ~SYM[4] = ~VAR[vec2][2][~SYM[2]*~SIZE[~TYPEL[~TYP[2]]]+:~SIZE[~TYPEL[~TYP[2]]]];~ELSE ~FI
        ~OUTPUTUSAGE[0] ~TYPEL[~TYPO] ~SYM[5];
        ~INST 0
          ~OUTPUT <= ~SYM[5]~ ~TYPEL[~TYPO]~
          ~INPUT  <= ~SYM[3]~ ~TYPEL[~TYP[1]]~
          ~INPUT  <= ~SYM[4]~ ~TYPEL[~TYP[2]]~
        ~INST
        assign ~RESULT[~SYM[2]*~SIZE[~TYPEL[~TYPO]]+:~SIZE[~TYPEL[~TYPO]]] = ~SYM[5];
      end
      ~ENDGENERATE
      // zipWith end
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.foldr
    kind: Declaration
    type: 'foldr :: (a -> b -> b) -> b -> Vec n a -> b'
    template: |-
      // foldr start~IF ~LENGTH[~TYP[2]] ~THEN
      wire ~TYPO ~GENSYM[intermediate][0] [0:~LENGTH[~TYP[2]]];
      assign ~SYM[0][~LENGTH[~TYP[2]]] = ~ARG[1];

      genvar ~GENSYM[i][3];
      ~GENERATE
      for (~SYM[3]=0; ~SYM[3] < ~LENGTH[~TYP[2]]; ~SYM[3]=~SYM[3]+1) begin : ~GENSYM[foldr][4]~IF~SIZE[~TYP[2]]~THEN
        wire ~TYPEL[~TYP[2]] ~GENSYM[foldr_in1][5];
        assign ~SYM[5] = ~VAR[xs][2][(~LENGTH[~TYP[2]]-1-~SYM[3])*~SIZE[~TYPEL[~TYP[2]]]+:~SIZE[~TYPEL[~TYP[2]]]];~ELSE ~FI
        wire ~TYPO ~GENSYM[foldr_in2][6];
        ~OUTPUTUSAGE[0] ~TYPO ~GENSYM[foldr_out][7];

        assign ~SYM[6] = ~SYM[0][~SYM[3]+1];
        ~INST 0
          ~OUTPUT <= ~SYM[7]~ ~TYP[1]~
          ~INPUT  <= ~SYM[5]~ ~TYPEL[~TYP[2]]~
          ~INPUT  <= ~SYM[6]~ ~TYP[1]~
        ~INST
        assign ~SYM[0][~SYM[3]] = ~SYM[7];
      end
      ~ENDGENERATE

      assign ~RESULT = ~SYM[0][0];
      ~ELSE
      assign ~RESULT = ~ARG[1];
      ~FI// foldr end
    workInfo: Never
- BlackBoxHaskell:
    name: Clash.Sized.Vector.index_int
    templateFunction: Clash.Primitives.Sized.Vector.indexIntVerilog
- BlackBox:
    name: Clash.Sized.Vector.replace_int
    kind: Declaration
    type: 'replace_int :: KnownNat n => Vec n a -> Int -> a -> Vec n a'
    template: |-
      // vector replace begin
      genvar ~GENSYM[i][0];
      ~GENERATE
      for (~SYM[0]=0;~SYM[0]<~LENGTH[~TYPO];~SYM[0]=~SYM[0]+1) begin : ~GENSYM[vector_replace][1]
        assign ~RESULT[(~MAXINDEX[~TYPO]-~SYM[0])*~SIZE[~TYP[3]]+:~SIZE[~TYP[3]]] = ~ARG[2] == ~SYM[0] ? ~ARG[3] : ~VAR[vec][1][(~MAXINDEX[~TYPO]-~SYM[0])*~SIZE[~TYP[3]]+:~SIZE[~TYP[3]]];
      end
      ~ENDGENERATE
      // vector replace end
- BlackBox:
    name: Clash.Sized.Vector.maxIndex
    kind: Expression
    type: 'maxIndex :: KnownNat n => Vec n a -> Int'
    template: ~SIZE[~TYPO]'sd~LIT[0] - ~SIZE[~TYPO]'d1
    workInfo: Constant
- BlackBox:
    name: Clash.Sized.Vector.length
    kind: Expression
    type: 'length :: KnownNat n => Vec n a -> Int'
    template: ~SIZE[~TYPO]'sd~LIT[0]
    workInfo: Constant
- BlackBox:
    name: Clash.Sized.Vector.replicate
    kind: Expression
    type: 'replicate :: SNat n -> a -> Vec n a'
    template: '{~LIT[0] {~ARG[1]}}'
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.transpose
    kind: Declaration
    type: 'transpose :: KnownNat n => Vec m (Vec n a) -> Vec n (Vec m a)'
    template: |-
      // transpose begin
      genvar ~GENSYM[row_index][1];
      genvar ~GENSYM[col_index][2];
      ~GENERATE
      for (~SYM[1] = 0; ~SYM[1] < ~LENGTH[~TYP[1]]; ~SYM[1] = ~SYM[1] + 1) begin : ~GENSYM[transpose_outer][3]
        for (~SYM[2] = 0; ~SYM[2] < ~LENGTH[~TYPO]; ~SYM[2] = ~SYM[2] + 1) begin : ~GENSYM[transpose_inner][4]
          assign ~RESULT[((~SYM[2]*~SIZE[~TYPEL[~TYPO]])+(~SYM[1]*~SIZE[~TYPEL[~TYPEL[~TYPO]]]))+:~SIZE[~TYPEL[~TYPEL[~TYPO]]]] = ~VAR[matrix][1][((~SYM[1]*~SIZE[~TYPEL[~TYP[1]]])+(~SYM[2]*~SIZE[~TYPEL[~TYPEL[~TYPO]]]))+:~SIZE[~TYPEL[~TYPEL[~TYPO]]]];
        end
      end
      ~ENDGENERATE
      // transpose end
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.reverse
    kind: Declaration
    type: 'reverse :: Vec n a -> Vec n a'
    template: |-
      // reverse begin
      genvar ~GENSYM[i][1];
      ~GENERATE
      for (~SYM[1] = 0; ~SYM[1] < ~LENGTH[~TYPO]; ~SYM[1] = ~SYM[1] + 1) begin : ~GENSYM[reverse][2]
        assign ~RESULT[(~LENGTH[~TYPO] - 1 - ~SYM[1])*~SIZE[~TYPEL[~TYPO]]+:~SIZE[~TYPEL[~TYPO]]] = ~VAR[vec][0][~SYM[1]*~SIZE[~TYPEL[~TYPO]]+:~SIZE[~TYPEL[~TYPO]]];
      end
      ~ENDGENERATE
      // reverse end
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.concatBitVector#
    kind: Expression
    type: |-
      concatBitVector# :: (KnownNat n, KnownNat m) -- (ARG[0],ARG[1])
                        => Vec n (BitVector m)      -- ARG[2]
                        -> BitVector (n * m)
    template: ~ARG[2]
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.unconcatBitVector#
    kind: Expression
    type: |-
      unconcatBitVector# :: (KnownNat n, KnownNat m) -- (ARG[0],ARG[1])
                          => BitVector (n * m)        -- ARG[2]
                          -> Vec n (BitVector m)
    template: ~ARG[2]
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.rotateLeftS
    kind: Declaration
    type: 'rotateLeftS :: KnownNat n => Vec n a -> SNat d -> Vec n a'
    template: |-
      // rotateLeftS begin
      localparam ~GENSYM[shift_amount][2] = ~LIT[2] % ~LIT[0];

      ~GENERATE
      if (~SYM[2] == 0) begin : ~GENSYM[no_shift][3]
        assign ~RESULT = ~VAR[vec][1];
      end else begin : ~GENSYM[do_shift][4]
        assign ~RESULT = {~VAR[vec][1][((~LIT[0]-~SYM[2])*~SIZE[~TYPEL[~TYPO]])-1 : 0]
                         ,~VAR[vec][1][~SIZE[~TYPO]-1 : (~LIT[0]-~SYM[2])*~SIZE[~TYPEL[~TYPO]]]
                         };
      end
      ~ENDGENERATE
      // rotateLeftS end
    workInfo: Never
- BlackBox:
    name: Clash.Sized.Vector.rotateRightS
    kind: Declaration
    type: 'rotateRightS :: KnownNat n => Vec n a -> SNat d -> Vec n a'
    template: |-
      // rotateRightS begin
      localparam ~GENSYM[shift_amount][2] = ~LIT[2] % ~LIT[0];

      ~GENERATE
      if (~SYM[2] == 0) begin : ~GENSYM[no_shift][3]
        assign ~RESULT = ~VAR[vec][1];
      end else begin : ~GENSYM[do_shift][4]
        assign ~RESULT = {~VAR[vec][1][(~SYM[2]*~SIZE[~TYPEL[~TYPO]])-1 : 0]
                         ,~VAR[vec][1][~SIZE[~TYPO]-1 : ~SYM[2]*~SIZE[~TYPEL[~TYPO]]]
                         };
      end
      ~ENDGENERATE
      // rotateRightS end
    workInfo: Never
