prims.v 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. * prims.v
  3. *
  4. * vim: ts=4 sw=4
  5. *
  6. * Copyright (C) 2019 Sylvain Munaut <tnt@246tNt.com>
  7. * All rights reserved.
  8. *
  9. * BSD 3-clause, see LICENSE.bsd
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. * * Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * * Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * * Neither the name of the <organization> nor the
  19. * names of its contributors may be used to endorse or promote products
  20. * derived from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  26. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  27. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  29. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. `default_nettype none
  34. module lut4_n #(
  35. parameter [15:0] LUT_INIT = 0,
  36. parameter integer WIDTH = 16,
  37. parameter integer RBEL_X = 0,
  38. parameter integer RBEL_Y = 0,
  39. parameter integer RBEL_Z = 0,
  40. parameter RBEL_GROUP = ""
  41. )(
  42. input wire [WIDTH-1:0] i0,
  43. input wire [WIDTH-1:0] i1,
  44. input wire [WIDTH-1:0] i2,
  45. input wire [WIDTH-1:0] i3,
  46. output wire [WIDTH-1:0] o
  47. );
  48. genvar i;
  49. generate
  50. for (i=0; i<WIDTH; i=i+1)
  51. begin : bit
  52. (* RBEL_X=RBEL_X *)
  53. (* RBEL_Y=RBEL_Y+(RBEL_Z+i)>>3 *)
  54. (* RBEL_Z=(RBEL_Z+i)&7 *)
  55. (* RBEL_GROUP=RBEL_GROUP *)
  56. SB_LUT4 #(
  57. .LUT_INIT(LUT_INIT)
  58. ) lut_I (
  59. .I0(i0[i]),
  60. .I1(i1[i]),
  61. .I2(i2[i]),
  62. .I3(i3[i]),
  63. .O(o[i])
  64. );
  65. end
  66. endgenerate
  67. endmodule // lut4_n
  68. module lut4_carry_n #(
  69. parameter [15:0] LUT_INIT = 0,
  70. parameter integer WIDTH = 16,
  71. parameter integer RBEL_X = 0,
  72. parameter integer RBEL_Y = 0,
  73. parameter integer RBEL_Z = 0,
  74. parameter RBEL_GROUP = ""
  75. )(
  76. input wire [WIDTH-1:0] i0,
  77. input wire [WIDTH-1:0] i1,
  78. input wire [WIDTH-1:0] i2,
  79. input wire cin,
  80. output wire [WIDTH-1:0] o,
  81. output wire cout
  82. );
  83. wire [WIDTH:0] carry;
  84. assign cout = carry[WIDTH];
  85. assign carry[0] = cin;
  86. genvar i;
  87. generate
  88. for (i=0; i<WIDTH; i=i+1)
  89. begin : bit
  90. (* RBEL_X=RBEL_X *)
  91. (* RBEL_Y=RBEL_Y+(RBEL_Z+i)>>3 *)
  92. (* RBEL_Z=(RBEL_Z+i)&7 *)
  93. (* RBEL_GROUP=RBEL_GROUP *)
  94. SB_LUT4 #(
  95. .LUT_INIT(LUT_INIT)
  96. ) lut_I (
  97. .I0(i0[i]),
  98. .I1(i1[i]),
  99. .I2(i2[i]),
  100. .I3(carry[i]),
  101. .O(o[i])
  102. );
  103. SB_CARRY carry_I (
  104. .CO(carry[i+1]),
  105. .I0(i0[i]),
  106. .I1(i1[i]),
  107. .CI(carry[i])
  108. );
  109. end
  110. endgenerate
  111. endmodule // lut4_carry_n
  112. module dff_n #(
  113. parameter integer WIDTH = 16,
  114. parameter integer RBEL_X = 0,
  115. parameter integer RBEL_Y = 0,
  116. parameter integer RBEL_Z = 0,
  117. parameter RBEL_GROUP = ""
  118. )(
  119. input wire [WIDTH-1:0] d,
  120. output wire [WIDTH-1:0] q,
  121. input wire clk
  122. );
  123. genvar i;
  124. generate
  125. for (i=0; i<WIDTH; i=i+1)
  126. begin : bit
  127. (* RBEL_X=RBEL_X *)
  128. (* RBEL_Y=RBEL_Y+(RBEL_Z+i)>>3 *)
  129. (* RBEL_Z=(RBEL_Z+i)&7 *)
  130. (* RBEL_GROUP=RBEL_GROUP *)
  131. (* dont_touch="true" *)
  132. SB_DFF dff_I (
  133. .D(d[i]),
  134. .Q(q[i]),
  135. .C(clk)
  136. );
  137. end
  138. endgenerate
  139. endmodule // dff_n
  140. module dffe_n #(
  141. parameter integer WIDTH = 16,
  142. parameter integer RBEL_X = 0,
  143. parameter integer RBEL_Y = 0,
  144. parameter integer RBEL_Z = 0,
  145. parameter RBEL_GROUP = ""
  146. )(
  147. input wire [WIDTH-1:0] d,
  148. output wire [WIDTH-1:0] q,
  149. input wire ce,
  150. input wire clk
  151. );
  152. genvar i;
  153. generate
  154. for (i=0; i<WIDTH; i=i+1)
  155. begin : bit
  156. (* RBEL_X=RBEL_X *)
  157. (* RBEL_Y=RBEL_Y+((RBEL_Z+i)>>3) *)
  158. (* RBEL_Z=(RBEL_Z+i)&7 *)
  159. (* RBEL_GROUP=RBEL_GROUP *)
  160. (* dont_touch="true" *)
  161. SB_DFFE dff_I (
  162. .D(d[i]),
  163. .Q(q[i]),
  164. .E(ce),
  165. .C(clk)
  166. );
  167. end
  168. endgenerate
  169. endmodule // dffe_n
  170. module dffer_n #(
  171. parameter RSTVAL = 16'h0000,
  172. parameter integer WIDTH = 16,
  173. parameter integer RBEL_X = 0,
  174. parameter integer RBEL_Y = 0,
  175. parameter integer RBEL_Z = 0,
  176. parameter RBEL_GROUP = ""
  177. )(
  178. input wire [WIDTH-1:0] d,
  179. output wire [WIDTH-1:0] q,
  180. input wire ce,
  181. input wire clk,
  182. input wire rst
  183. );
  184. genvar i;
  185. generate
  186. for (i=0; i<WIDTH; i=i+1)
  187. begin : bit
  188. if (RSTVAL[i] == 1'b1)
  189. (* RBEL_X=RBEL_X *)
  190. (* RBEL_Y=RBEL_Y+((RBEL_Z+i)>>3) *)
  191. (* RBEL_Z=(RBEL_Z+i)&7 *)
  192. (* RBEL_GROUP=RBEL_GROUP *)
  193. (* dont_touch="true" *)
  194. SB_DFFES dff_I (
  195. .D(d[i]),
  196. .Q(q[i]),
  197. .E(ce),
  198. .S(rst),
  199. .C(clk)
  200. );
  201. else
  202. (* RBEL_X=RBEL_X *)
  203. (* RBEL_Y=RBEL_Y+((RBEL_Z+i)>>3) *)
  204. (* RBEL_Z=(RBEL_Z+i)&7 *)
  205. (* RBEL_GROUP=RBEL_GROUP *)
  206. (* dont_touch="true" *)
  207. SB_DFFER dff_I (
  208. .D(d[i]),
  209. .Q(q[i]),
  210. .E(ce),
  211. .R(rst),
  212. .C(clk)
  213. );
  214. end
  215. endgenerate
  216. endmodule // dffer_n
  217. module dffesr_n #(
  218. parameter RSTVAL = 16'h0000,
  219. parameter integer WIDTH = 16,
  220. parameter integer RBEL_X = 0,
  221. parameter integer RBEL_Y = 0,
  222. parameter integer RBEL_Z = 0,
  223. parameter RBEL_GROUP = ""
  224. )(
  225. input wire [WIDTH-1:0] d,
  226. output wire [WIDTH-1:0] q,
  227. input wire ce,
  228. input wire clk,
  229. input wire rst
  230. );
  231. genvar i;
  232. generate
  233. for (i=0; i<WIDTH; i=i+1)
  234. begin : bit
  235. if (RSTVAL[i] == 1'b1)
  236. (* RBEL_X=RBEL_X *)
  237. (* RBEL_Y=RBEL_Y+((RBEL_Z+i)>>3) *)
  238. (* RBEL_Z=(RBEL_Z+i)&7 *)
  239. (* RBEL_GROUP=RBEL_GROUP *)
  240. (* dont_touch="true" *)
  241. SB_DFFESS dff_I (
  242. .D(d[i]),
  243. .Q(q[i]),
  244. .E(ce),
  245. .S(rst),
  246. .C(clk)
  247. );
  248. else
  249. (* RBEL_X=RBEL_X *)
  250. (* RBEL_Y=RBEL_Y+((RBEL_Z+i)>>3) *)
  251. (* RBEL_Z=(RBEL_Z+i)&7 *)
  252. (* RBEL_GROUP=RBEL_GROUP *)
  253. (* dont_touch="true" *)
  254. SB_DFFESR dff_I (
  255. .D(d[i]),
  256. .Q(q[i]),
  257. .E(ce),
  258. .R(rst),
  259. .C(clk)
  260. );
  261. end
  262. endgenerate
  263. endmodule // dffesr_n