OpenCores
URL https://opencores.org/ocsvn/common/common/trunk

Subversion Repositories common

[/] [common/] [trunk/] [crc32_lib.v] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 bbeaver
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// crc_32_lib, consisting of:                                   ////
4
////   crc_32_64_pipelined_2                                      ////
5 11 bbeaver
////   crc_32_32_pipelined_1                                      ////
6
////   crc_32_8_incremental_pipelined_1                           ////
7 10 bbeaver
////                                                              ////
8
//// This file is part of the general opencores effort.           ////
9
//// <http://www.opencores.org/cores/misc/>                       ////
10
////                                                              ////
11
//// Module Description:                                          ////
12
//// Calculate CRC-32 checksums by applying 8, 16, 24, 32, or     ////
13
////   64 bits of new data per clock.                             ////
14
////  CRC-32 needs to start out with a value of all F's.          ////
15
////  When CRC-32 is applied to a block which ends with the       ////
16
////    CRC-32 of the previous data in the block, the resulting   ////
17
////    CRC-32 checksum is always 32'hCBF43926.                   ////
18
////                                                              ////
19
//// The verilog these routines is started from scratch.  A new   ////
20
////   user might want to look at a wonderful paper by Ross       ////
21
////   Williams, which seems to be at                             ////
22
////     ftp.adelaide.edu.au:/pub/rocksoft/crc_v3.txt             ////
23
//// Also see http://www.easics.be/webtools/crctool               ////
24
////                                                              ////
25
//// To Do:                                                       ////
26
//// None of the flop-to-flop routines have been checked!         ////
27
//// Might make this handle different sizes.                      ////
28
//// Might put some real thought into minimizing things so that   ////
29
////   a poor FPGA can reuse input terms to the max.              ////
30
////                                                              ////
31
//// Author(s):                                                   ////
32
//// - Anonymous                                                  ////
33
////                                                              ////
34
//////////////////////////////////////////////////////////////////////
35
////                                                              ////
36
//// Copyright (C) 2000 Anonymous and OPENCORES.ORG               ////
37
////                                                              ////
38
//// This source file may be used and distributed without         ////
39
//// restriction provided that this copyright statement is not    ////
40
//// removed from the file and that any derivative work contains  ////
41
//// the original copyright notice and the associated disclaimer. ////
42
////                                                              ////
43
//// This source file is free software; you can redistribute it   ////
44
//// and/or modify it under the terms of the GNU Lesser General   ////
45
//// Public License as published by the Free Software Foundation; ////
46
//// either version 2.1 of the License, or (at your option) any   ////
47
//// later version.                                               ////
48
////                                                              ////
49
//// This source is distributed in the hope that it will be       ////
50
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
51
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
52
//// PURPOSE. See the GNU Lesser General Public License for more  ////
53
//// details.                                                     ////
54
////                                                              ////
55
//// You should have received a copy of the GNU Lesser General    ////
56
//// Public License along with this source; if not, download it   ////
57
//// from <http://www.opencores.org/lgpl.shtml>                   ////
58
////                                                              ////
59
//////////////////////////////////////////////////////////////////////
60
//
61 11 bbeaver
// $Id: crc32_lib.v,v 1.2 2001-09-07 11:38:25 bbeaver Exp $
62 10 bbeaver
//
63
// CVS Revision History
64
//
65
// $Log: not supported by cvs2svn $
66 11 bbeaver
// Revision 1.1  2001/09/07 11:32:02  Blue Beaver
67
// no message
68
//
69 10 bbeaver
// Revision 1.24  2001/09/07 11:28:49  Blue Beaver
70
// no message
71
//
72
//
73
 
74
//===========================================================================
75
// NOTE:  I am greatly confused about the order in which the CRC should be
76
//          sent over the wire to a remote machine.  Bit 0 first?  Bit 31 first?
77
//          True or compliment values?  The user has got to figure this out in
78
//          order to interoperate with existing machines.
79
//
80
// NOTE:  Bit order matters in this code, of course.  The existing code on
81
//          the net assumes that when you present a multi-bit word to a parallel
82
//          CRC generator, the MSB corresponds to the earliest data to arrive
83
//          across a serial interface.
84
//
85
// NOTE:  The code also assumes that the data shifts into bit 0 of the shift
86
//          register, and shifts out of bit 31.
87
//
88
// NOTE:  The math for the CRC-32 is beyond me.
89
//
90
// NOTE:  But they are pretty easy to use.
91
//          You initialize a CRC to a special value to keep from missing
92
//            initial 0 bytes.  That is 32'hFFFFFFFF for CRC-32.
93
//          You update a CRC as data comes in.
94
//          You append the calculated CRC to the end of your message.
95
//            You have to agree on logic sense and bit order with the
96
//            receiver, or everything you send will seem wrong.
97
//          The receiver calculates a CRC the same way, but receives a
98
//            message longer than the one you sent, due to the added CRC.
99
//          After the CRC is processed by the receiver, you either compare
100
//            the calculated CRC with the sent one, or look for a magic
101
//            final value which indicates that the message had no errors.
102
//
103
// NOTE:  Looking on the web, one finds a nice tutorial by Cypress entitled
104
//          "Parallel Cyclic Redundancy Check (CRC) for HOTLink(TM)".
105
//        This reminds me of how I learned to do this from a wonderful
106
//          CRC tutorial on the web, done by Ross N. Williams.
107
//
108
// NOTE:  The CRC-32 polynomial is:
109
//            X**0 + X**1 + X**2 + X**4 + X**5 + X**7 + X**8 + X**10
110
//          + X**11 + X**12 + X**16 + X**22 + X**23 + X**26 + X**32
111
//        You initialize it to the value 32'hFFFFFFFF
112
//        You append it to the end of the message.
113
//        The receiver sees the value 32'hC704DD7B when the message is
114
//          received no errors.
115
//
116
//        That means that each clock a new bit comes in, you have to shift
117
//          all the 32 running state bits 1 bit higher and drop the MSB.
118
//          PLUS you have to XOR in (new bit ^ MSB) to locations
119
//          0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, and 26.
120
//
121
//        That is simple but slow.  If you keep track of the bits, you can
122
//          see that it might be possible to apply 1 bit, shift it, apply
123
//          another bit, shift THAT, and end up with a new formula of how
124
//          to update the shift register based on applyig 1 bits at once.
125
//
126
//        That is the general plan.  Figure out how to apply several bits
127
//          at a time.  Write out the big formula, then simplify it if possible.
128
//          Apply the bits, shift several bit locations at once, run faster.
129
//
130
//        But what are the formulas?  Good question.  Use a computer to figure
131
//          this out for you.  And Williams wrote a program!
132
//
133
// NOTE:  The idea is simple, so I may include a program to print out
134
//          formulas at the end of this code.  The module SHOULD be improved
135
//          to group the terms into an XOR tree, with parantheses.  That can
136
//          be left for a new person.
137
//
138
// NOTE:  ALL input data is latched in flops immediately.
139
//        All outputs are already latched.  So everything is flop-to-flop.
140
//        This lets the module be synthesized and layed out independently
141
//          of all other modules when trying to meet timing.
142
//        This also lets the modules which calculate with more than 32
143
//          input bits per clock have an internal pipeline stage where
144
//          the Data component of the new CRC is calculate.  But be
145
//          careful!  An extra layer of pipelining changes when data
146
//          becomes available.
147
//        Might also make versions which let a non-F CRC be loaded.  This
148
//          would be useful if a CRC needed to be calculated incrementally,
149
//          which is the case when calculating AAL-5 checksums, for instance.
150
//
151
// This code was developed using VeriLogger Pro, by Synapticad.
152
// Their support is greatly appreciated.
153
//
154
//===========================================================================
155
 
156
`timescale 1ns/1ps
157
 
158
// Look up the CRC-32 polynomial on the web.
159
// The LSB corresponds to bit 0, the new input bit.
160
`define CRC           32'b0000_0100_1100_0001_0001_1101_1011_0111
161
`define CHECK_VALUE   32'b1100_1011_1111_0100_0011_1001_0010_0110
162
`define NUMBER_OF_BITS_IN_CRC_32   32
163
 
164
// Given a 64-bit aligned data stream, calculate the CRC-32 8 bytes at a time.
165
// Input data and the use_F indication are latched on input at clock 0.
166
// The CRC result is available after clock 2 (!) after the last data item is consumed.
167
// The indication that the CRC is correct is available after clock 3 (!) clocks after
168
//   the last data item is consumed.
169
// If the data stream is not an exact multiple of 8 bytes long, the checksum
170
//   calculated here must be incrementally updated for each byte beyond the
171
//   multiple of 8.  Use another module to do that.
172
 
173
module crc_32_64_pipelined_2 (
174
  use_F_for_CRC,
175
  data_in_64,
176
  running_crc_2,
177
  crc_correct_3,
178
  clk
179
);
180
  parameter NUMBER_OF_BITS_APPLIED = 64;  // do NOT override
181
  input   use_F_for_CRC;
182
  input  [NUMBER_OF_BITS_APPLIED - 1 : 0] data_in_64;
183
  output [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] running_crc_2;
184
  output  crc_correct_3;
185
  input   clk;
186
 
187
// A pipelined version of the CRC_32 working on 64-bit operands.
188
// Latch all operands at Clock 0.
189
// Calculate the Data Dependency during Clock 1.
190
// Update the CRC during Clock 2.
191
// The CRC Correct signal comes out after Clock 3.
192
 
193
// Latch all operands at Clock 0.
194
  reg     use_F_for_CRC_latched_0;
195
  reg    [NUMBER_OF_BITS_APPLIED - 1 : 0] data_in_64_latched_0;
196
 
197
  always @(posedge clk)
198
  begin
199
    use_F_for_CRC_latched_0 <= use_F_for_CRC;
200
    data_in_64_latched_0[NUMBER_OF_BITS_APPLIED - 1 : 0] <=
201
                  data_in_64[NUMBER_OF_BITS_APPLIED - 1 : 0];
202
  end
203
 
204
// Instantiate the Data part of the dependency.
205
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] data_part_1_out_0;
206
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] data_part_2_out_0;
207
 
208
crc_32_64_data_private crc_32_64_data_part (
209
  .data_in_64                 (data_in_64_latched_0[NUMBER_OF_BITS_APPLIED - 1 : 0]),
210
  .data_part_1_out            (data_part_1_out_0[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]),
211
  .data_part_2_out            (data_part_2_out_0[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0])
212
);
213
 
214
// Calculate the Data Dependency during Clock 1.
215
  reg     use_F_for_CRC_prev_1;
216
  reg    [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] data_part_1_latched_1;
217
  reg    [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] data_part_2_latched_1;
218
 
219
  always @(posedge clk)
220
  begin
221
    use_F_for_CRC_prev_1 <= use_F_for_CRC_latched_0;
222
    data_part_1_latched_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] <=
223
                  data_part_1_out_0[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
224
    data_part_2_latched_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] <=
225
                  data_part_2_out_0[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
226
  end
227
 
228
// Update the CRC during Clock 2.
229
  reg    [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] present_crc_2;
230
 
231
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] crc_part_1_out_1;
232
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] crc_part_2_out_1;
233
 
234
crc_32_64_crc_private crc_32_64_crc_part (
235
  .use_F_for_CRC              (use_F_for_CRC_prev_1),
236
  .present_crc                (present_crc_2[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]),
237
  .crc_part_1_out             (crc_part_1_out_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]),
238
  .crc_part_2_out             (crc_part_2_out_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0])
239
);
240
 
241
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] data_depend_part_1 =
242
                    data_part_1_latched_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]
243
                  ^ data_part_2_latched_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];  // source depth 2 gates
244
 
245
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] first_crc_part_1 =
246
                    data_depend_part_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]
247
                  ^ crc_part_1_out_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];  // source depth 4 gates
248
 
249
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] next_crc_1 =
250
                    first_crc_part_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]
251
                  ^ crc_part_2_out_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];  // source depth 5 gates
252
 
253
  always @(posedge clk)
254
  begin
255
    present_crc_2[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] <=
256
                  next_crc_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
257
  end
258
 
259
// Assign separately so that flop outputs can be used in feedback.
260
  assign  running_crc_2[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
261
                  present_crc_2[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
262
 
263
// Watch to detect blocks which end with the correct CRC appended.
264
  reg     crc_correct_3;
265
 
266
  always @(posedge clk)
267
  begin
268
    crc_correct_3 <= (present_crc_2[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] == 32'hCBF43926);
269
  end
270
 
271
// synopsys translate_off
272
// Check the user didn't override anything
273
  initial
274
  begin
275
    if (NUMBER_OF_BITS_APPLIED != 64)
276
    begin
277
      $display ("*** Exiting because %m crc_32_64_pipelined_2 Number of bits %d != 64",
278
                   NUMBER_OF_BITS_APPLIED);
279
      $finish;
280
    end
281
  end
282
// synopsys translate_on
283
endmodule
284
 
285
// Given a 32-bit aligned data stream, calculate the CRC-32 4 bytes at a time.
286
// Inout data and the use_F indication are latched on input at clock 0.
287
// The CRC result is available after clock 1 (!) after the last data item is consumed.
288
// The indication that the CRC is correct is available after clock 2 (!) clocks after
289
//   the last data item is consumed.
290
// If the data stream is not an exact multiple of 4 bytes long, the checksum
291
//   calculated here must be incrementally updated for each byte beyond the
292
//   multiple of 4.  Use another module to do that.
293
 
294
module crc_32_32_pipelined_1 (
295
  use_F_for_CRC,
296
  data_in_32,
297
  running_crc_1,
298
  crc_correct_2,
299
  clk
300
);
301
  parameter NUMBER_OF_BITS_APPLIED = 32;  // do NOT override
302
  input   use_F_for_CRC;
303
  input  [NUMBER_OF_BITS_APPLIED - 1 : 0] data_in_32;
304
  output [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] running_crc_1;
305
  output  crc_correct_2;
306
  input   clk;
307
 
308
// A pipelined version of the CRC_32 working on 32-bit operands.
309
// Latch all operands at Clock 0.
310
// Update the CRC during Clock 1.
311
// The CRC Correct signal comes out after Clock 2.
312
 
313
// Latch all operands at Clock 0.
314
  reg     use_F_for_CRC_latched_0;
315
  reg    [NUMBER_OF_BITS_APPLIED - 1 : 0] data_in_32_latched_0;
316
 
317
  always @(posedge clk)
318
  begin
319
    use_F_for_CRC_latched_0 <= use_F_for_CRC;
320
    data_in_32_latched_0[NUMBER_OF_BITS_APPLIED - 1 : 0] <=
321
                  data_in_32[NUMBER_OF_BITS_APPLIED - 1 : 0];
322
  end
323
 
324
// Update the CRC during Clock 1.
325
  reg    [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] present_crc_1;
326
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] next_crc_0;
327
 
328
crc_32_32_private crc_32_32_crc (
329
  .use_F_for_CRC              (use_F_for_CRC_prev_1),
330
  .present_crc                (present_crc_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]),
331
  .data_in_32                 (data_in_32_latched_0[NUMBER_OF_BITS_APPLIED - 1 : 0]),
332
  .next_crc                   (next_crc_0[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0])
333
);
334
 
335
  always @(posedge clk)
336
  begin
337
    present_crc_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] <=
338
                  next_crc_0[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
339
  end
340
 
341
// Assign separately so that flop outputs can be used in feedback.
342
  assign  running_crc_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
343
                  present_crc_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
344
 
345
// Watch to detect blocks which end with the correct CRC appended.
346
  reg     crc_correct_2;
347
 
348
  always @(posedge clk)
349
  begin
350
    crc_correct_2 <= (present_crc_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] == 32'hCBF43926);
351
  end
352
 
353
// synopsys translate_off
354
// Check the user didn't override anything
355
  initial
356
  begin
357
    if (NUMBER_OF_BITS_APPLIED != 32)
358
    begin
359
      $display ("*** Exiting because %m crc_32_32_pipelined_1 Number of bits %d != 32",
360
                   NUMBER_OF_BITS_APPLIED);
361
      $finish;
362
    end
363
  end
364
// synopsys translate_on
365
endmodule
366
 
367
// Given an 8-bit aligned data stream, calculate the CRC-32 1 byte at a time.
368
// Input data and the use_F indication are latched on input at clock 0.
369
// The CRC result is available after clock 1 (!) after the last data item is consumed.
370
// The indication that the CRC is correct is available after clock 2 (!) clocks after
371
//   the last data item is consumed.
372
// This module can be given a starting CRC, and can incrementally calculate
373
//   a new CRC-32 by applying 1 new data byte at a time.
374
 
375
module crc_32_8_incremental_pipelined_1 (
376
  use_old_CRC,
377
  old_crc,
378
  use_F_for_CRC,
379
  data_in_8,
380
  running_crc_1,
381
  crc_correct_2,
382
  clk
383
);
384
  parameter NUMBER_OF_BITS_APPLIED = 8;  // do NOT override
385
  input   use_old_CRC;
386
  input [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] old_crc;
387
  input   use_F_for_CRC;
388
  input  [NUMBER_OF_BITS_APPLIED - 1 : 0] data_in_8;
389
  output [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] running_crc_1;
390
  output  crc_correct_2;
391
  input   clk;
392
 
393
// A pipelined version of the CRC_32 working on 32-bit operands.
394
// Latch all operands at Clock 0.
395
// Update the CRC during Clock 1.
396
// The CRC Correct signal comes out after Clock 2.
397
 
398
// Latch all operands at Clock 0.
399
  reg     use_old_crc_latched_0;
400
  reg    [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] old_crc_latched_0;
401
  reg     use_F_for_CRC_latched_0;
402
  reg    [NUMBER_OF_BITS_APPLIED - 1 : 0] data_in_8_latched_0;
403
 
404
  always @(posedge clk)
405
  begin
406
    use_old_crc_latched_0 <= use_old_CRC;
407
    old_crc_latched_0[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] <=
408
                  old_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
409
    use_F_for_CRC_latched_0 <= use_F_for_CRC;
410
    data_in_8_latched_0[NUMBER_OF_BITS_APPLIED - 1 : 0] <=
411
                  data_in_8[NUMBER_OF_BITS_APPLIED - 1 : 0];
412
  end
413
 
414
// Update the CRC during Clock 1.
415
  reg    [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] present_crc_1;
416
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] present_crc_0 = use_old_crc_latched_0
417
                  ? old_crc_latched_0[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]
418
                  : present_crc_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
419
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] next_crc_0;
420
 
421
crc_32_8_private crc_32_8_crc (
422
  .use_F_for_CRC              (use_F_for_CRC_prev_1),
423
  .present_crc                (present_crc_0[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]),
424
  .data_in_8                  (data_in_8_latched_0[NUMBER_OF_BITS_APPLIED - 1 : 0]),
425
  .next_crc                   (next_crc_0[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0])
426
);
427
 
428
  always @(posedge clk)
429
  begin
430
    present_crc_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] <=
431
                  next_crc_0[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
432
  end
433
 
434
// Assign separately so that flop outputs can be used in feedback.
435
  assign  running_crc_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
436
                  present_crc_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
437
 
438
// Watch to detect blocks which end with the correct CRC appended.
439
  reg     crc_correct_2;
440
 
441
  always @(posedge clk)
442
  begin
443
    crc_correct_2 <= (present_crc_1[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] == 32'hCBF43926);
444
  end
445
 
446
// synopsys translate_off
447
// Check the user didn't override anything
448
  initial
449
  begin
450
    if (NUMBER_OF_BITS_APPLIED != 8)
451
    begin
452
      $display ("*** Exiting because %m crc_32_8_pipelined_1 Number of bits %d != 8",
453
                   NUMBER_OF_BITS_APPLIED);
454
      $finish;
455
    end
456
  end
457
// synopsys translate_on
458
endmodule
459
 
460
// The private modules which have the real formulas in them:
461
 
462
// Given a 32-bit CRC-32 running value, update it using 8 new bits of data.
463
// The way to make this fast is to find common sub-expressions.
464
//
465
// The user needs to supply external flops to make this work.
466
 
467
module crc_32_8_private (
468
  use_F_for_CRC,
469
  present_crc,
470
  data_in_8,
471
  next_crc
472
);
473
  parameter NUMBER_OF_BITS_APPLIED = 8;
474
  input   use_F_for_CRC;
475
  input  [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] present_crc;
476
  input  [NUMBER_OF_BITS_APPLIED - 1 : 0] data_in_8;
477
  output [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] next_crc;
478
 
479
  wire    X7, X6, X5, X4, X3, X2, X1, X0;
480
  assign  {X7, X6, X5, X4, X3, X2, X1, X0} = data_in_8[NUMBER_OF_BITS_APPLIED - 1 : 0]
481
         ^ (   present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : `NUMBER_OF_BITS_IN_CRC_32 - NUMBER_OF_BITS_APPLIED]
482
             | {NUMBER_OF_BITS_APPLIED{use_F_for_CRC}});
483
 
484
  wire    C23, C22, C21, C20, C19, C18, C17, C16;
485
  wire    C15, C14, C13, C12, C11, C10, C9, C8, C7, C6, C5, C4, C3, C2, C1, C0;
486
  assign  {C23, C22, C21, C20, C19, C18, C17, C16, C15, C14, C13, C12,
487
           C11, C10, C9,  C8,  C7,  C6,  C5,  C4,  C3,  C2,  C1,  C0} =
488
           present_crc[`NUMBER_OF_BITS_IN_CRC_32 - NUMBER_OF_BITS_APPLIED - 1 : 0]
489
         | {(`NUMBER_OF_BITS_IN_CRC_32 - NUMBER_OF_BITS_APPLIED){use_F_for_CRC}};
490
 
491
  assign  next_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
492
    { C23                          ^ X5          ,
493
      C22                     ^ X4           ^ X7,
494
      C21                ^ X3           ^ X6 ^ X7,
495
      C20           ^ X2           ^ X5 ^ X6     ,
496
      C19      ^ X1           ^ X4 ^ X5      ^ X7,
497
      C18 ^ X0           ^ X3 ^ X4      ^ X6     ,
498
      C17           ^ X2 ^ X3                    ,
499
      C16      ^ X1 ^ X2                     ^ X7,
500
      C15 ^ X0 ^ X1                     ^ X6     ,
501
      C14 ^ X0                                   ,
502
      C13                           ^ X5         ,
503
      C12                     ^ X4               ,
504
      C11                ^ X3                ^ X7,
505
      C10           ^ X2                ^ X6 ^ X7,
506
      C9       ^ X1                ^ X5 ^ X6     ,
507
      C8  ^ X0                ^ X4 ^ X5          ,
508
      C7                 ^ X3 ^ X4 ^ X5      ^ X7,
509
      C6            ^ X2 ^ X3 ^ X4      ^ X6 ^ X7,
510
      C5       ^ X1 ^ X2 ^ X3      ^ X5 ^ X6 ^ X7,
511
      C4  ^ X0 ^ X1 ^ X2      ^ X4 ^ X5 ^ X6     ,
512
      C3  ^ X0 ^ X1      ^ X3 ^ X4               ,
513
      C2  ^ X0      ^ X2 ^ X3      ^ X5          ,
514
      C1       ^ X1 ^ X2      ^ X4 ^ X5          ,
515
      C0  ^ X0 ^ X1      ^ X3 ^ X4               ,
516
            X0      ^ X2 ^ X3      ^ X5      ^ X7,
517
                 X1 ^ X2      ^ X4 ^ X5 ^ X6 ^ X7,
518
            X0 ^ X1      ^ X3 ^ X4 ^ X5 ^ X6 ^ X7,
519
            X0      ^ X2 ^ X3 ^ X4      ^ X6     ,
520
                 X1 ^ X2 ^ X3                ^ X7,
521
            X0 ^ X1 ^ X2                ^ X6 ^ X7,
522
            X0 ^ X1                     ^ X6 ^ X7,
523
            X0                          ^ X6
524
     };
525
endmodule
526
 
527
module crc_32_16_private (
528
  use_F_for_CRC,
529
  present_crc,
530
  data_in_16,
531
  next_crc
532
);
533
  parameter NUMBER_OF_BITS_APPLIED = 16;
534
  input   use_F_for_CRC;
535
  input  [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] present_crc;
536
  input  [NUMBER_OF_BITS_APPLIED - 1 : 0] data_in_16;
537
  output [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] next_crc;
538
 
539
/* State Variables depend on input bit number (bigger is earlier) :
540
{
541
31 : C15                           ^ X5           ^ X8       ^ X9                   ^ X11 ^ X15,
542
30 : C14                      ^ X4           ^ X7 ^ X8                  ^ X10 ^ X14            ,
543
29 : C13                 ^ X3           ^ X6 ^ X7            ^ X9 ^ X13                        ,
544
28 : C12            ^ X2           ^ X5 ^ X6      ^ X8 ^ X12                                   ,
545
27 : C11       ^ X1           ^ X4 ^ X5      ^ X7                                   ^ X11      ,
546
26 : C10  ^ X0           ^ X3 ^ X4      ^ X6                            ^ X10                  ,
547
25 : C9             ^ X2 ^ X3                     ^ X8                              ^ X11 ^ X15,
548
24 : C8        ^ X1 ^ X2                     ^ X7                       ^ X10 ^ X14            ,
549
23 : C7   ^ X0 ^ X1                     ^ X6                 ^ X9 ^ X13                   ^ X15,
550
22 : C6   ^ X0                                         ^ X12 ^ X9             ^ X14 ^ X11      ,
551
21 : C5                            ^ X5                      ^ X9 ^ X13 ^ X10                  ,
552
20 : C4                       ^ X4                ^ X8 ^ X12 ^ X9                              ,
553
19 : C3                  ^ X3                ^ X7 ^ X8                              ^ X11 ^ X15,
554
18 : C2             ^ X2                ^ X6 ^ X7                       ^ X10 ^ X14       ^ X15,
555
17 : C1        ^ X1                ^ X5 ^ X6                 ^ X9 ^ X13       ^ X14            ,
556
16 : C0   ^ X0                ^ X4 ^ X5           ^ X8 ^ X12      ^ X13                        ,
557
15 :  0                  ^ X3 ^ X4 ^ X5      ^ X7 ^ X8 ^ X12 ^ X9                         ^ X15,
558
14 :  0             ^ X2 ^ X3 ^ X4      ^ X6 ^ X7 ^ X8                        ^ X14 ^ X11 ^ X15,
559
13 :  0        ^ X1 ^ X2 ^ X3      ^ X5 ^ X6 ^ X7                 ^ X13 ^ X10 ^ X14            ,
560
12 :  0   ^ X0 ^ X1 ^ X2      ^ X4 ^ X5 ^ X6           ^ X12 ^ X9 ^ X13                   ^ X15,
561
11 :  0   ^ X0 ^ X1      ^ X3 ^ X4                     ^ X12 ^ X9             ^ X14       ^ X15,
562
10 :  0   ^ X0      ^ X2 ^ X3      ^ X5                      ^ X9 ^ X13       ^ X14            ,
563
 9 :  0        ^ X1 ^ X2      ^ X4 ^ X5                ^ X12 ^ X9 ^ X13             ^ X11      ,
564
 8 :  0   ^ X0 ^ X1      ^ X3 ^ X4                ^ X8 ^ X12            ^ X10       ^ X11      ,
565
 7 :  0   ^ X0      ^ X2 ^ X3      ^ X5      ^ X7 ^ X8                  ^ X10             ^ X15,
566
 6 :  0        ^ X1 ^ X2      ^ X4 ^ X5 ^ X6 ^ X7 ^ X8                        ^ X14 ^ X11      ,
567
 5 :  0   ^ X0 ^ X1      ^ X3 ^ X4 ^ X5 ^ X6 ^ X7                 ^ X13 ^ X10                  ,
568
 4 :  0   ^ X0      ^ X2 ^ X3 ^ X4      ^ X6      ^ X8 ^ X12                        ^ X11 ^ X15,
569
 3 :  0        ^ X1 ^ X2 ^ X3                ^ X7 ^ X8       ^ X9       ^ X10 ^ X14       ^ X15,
570
 2 :  0   ^ X0 ^ X1 ^ X2                ^ X6 ^ X7 ^ X8       ^ X9 ^ X13       ^ X14            ,
571
 1 :  0   ^ X0 ^ X1                     ^ X6 ^ X7      ^ X12 ^ X9 ^ X13             ^ X11      ,
572
 
573
}
574
*/
575
// There are 2 obvious ways to implement these functions:
576
// 1) XOR the State bits with the Input bits, then calculate the XOR's
577
// 2) Independently calculate a result for Inputs and State variables,
578
//    then XOR the results together.
579
// The second idea seems to take much more logic, but to have no benefit.
580
 
581
// Single numbered terms are calculated in 1 XOR time.
582
  wire    X15, X14, X13, X12, X11, X10, X9, X8, X7, X6, X5, X4, X3, X2, X1, X0;
583
  assign  {X15, X14, X13, X12, X11, X10, X9, X8, X7, X6, X5, X4, X3, X2, X1, X0} =
584
           data_in_16[NUMBER_OF_BITS_APPLIED - 1 : 0]
585
         ^ (   present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : `NUMBER_OF_BITS_IN_CRC_32 - NUMBER_OF_BITS_APPLIED]
586
             | {NUMBER_OF_BITS_APPLIED{use_F_for_CRC}});
587
 
588
// State Bits are shifted over by the width of the input, then XOR's into the X terms.
589
  wire    C15, C14, C13, C12, C11, C10, C9, C8, C7, C6, C5, C4, C3, C2, C1, C0;
590
  assign  {C15, C14, C13, C12, C11, C10, C9, C8, C7, C6, C5, C4, C3, C2, C1, C0} =
591
           present_crc[`NUMBER_OF_BITS_IN_CRC_32 - NUMBER_OF_BITS_APPLIED - 1 : 0]
592
         | {(`NUMBER_OF_BITS_IN_CRC_32 - NUMBER_OF_BITS_APPLIED){use_F_for_CRC}};
593
 
594
// Calculate higher_order terms, to make parity trees.
595
// 2_numbered terms are calculated in 1 XOR times.
596
// NOTE: In a Xilinx chip, it would be fine to constrain X0 and X0_1 to
597
//       be calculated in the same CLB, and so on for all bits.
598
  wire    X0_1   = X0  ^ X1;     wire    X1_2   = X1  ^ X2;
599
  wire    X2_3   = X2  ^ X3;     wire    X3_4   = X3  ^ X4;
600
  wire    X4_5   = X4  ^ X5;     wire    X5_6   = X5  ^ X6;
601
  wire    X6_7   = X6  ^ X7;     wire    X7_8   = X7  ^ X8;
602
// Use odd-ordered XOR terms because it seems these might be useful
603
  wire    X8_12  = X8  ^ X12;    wire    X12_9  = X12 ^ X9;
604
  wire    X9_13  = X9  ^ X13;    wire    X13_10 = X13 ^ X10;
605
  wire    X10_14 = X10 ^ X14;    wire    X14_11 = X14 ^ X11;
606
  wire    X11_15 = X11 ^ X15;
607
 
608
// Calculate terms which might have a single use.  They are calculated here
609
//   so that the parity trees can be balanced.
610
  wire    C15_5  = C15 ^ X5;     wire    C14_4  = C14 ^ X4;
611
  wire    C13_3  = C13 ^ X3;     wire    C12_2  = C12 ^ X2;
612
  wire    C11_1  = C11 ^ X1;     wire    C10_0  = C10 ^ X0;
613
  wire    C9_8   = C9  ^ X8;     wire    C8_7   = C8  ^ X7;
614
  wire    C7_6   = C7  ^ X6;     wire    C6_0   = C6  ^ X0;
615
  wire    C5_5   = C5  ^ X5;     wire    C4_4   = C4  ^ X4;
616
  wire    C3_3   = C3  ^ X3;     wire    C2_2   = C2  ^ X2;
617
  wire    C1_1   = C1  ^ X1;     wire    C0_0   = C0  ^ X0;
618
// Some of these could be matched with other terms to share 1 input in a CLB.
619
  wire    X0_5   = X0  ^ X5;     wire    X0_6   = X0  ^ X6;
620
  wire    X2_6   = X2  ^ X6;     wire    X2_8   = X2  ^ X8;
621
  wire    X3_7   = X3  ^ X7;     wire    X3_9   = X3  ^ X9;
622
  wire    X4_8   = X4  ^ X8;
623
  wire    X5_15  = X5  ^ X15;
624
  wire    X6_10  = X6  ^ X10;
625
  wire    X7_11  = X7  ^ X11;
626
  wire    X8_9   = X8  ^ X9;
627
  wire    X10_11 = X10 ^ X11;    wire    X10_15 = X10 ^ X15;
628
  wire    X13_11 = X13 ^ X11;    wire    X13_15 = X13 ^ X15;
629
  wire    X14_15 = X14 ^ X15;
630
 
631
// NOTE: 5 terms can be implemented in a CLB, as long as the other Flop
632
//         doesn't use logic.  This would be perfect if the data_in_16
633
//         was registered as an input to the module in that CLB.
634
  assign  next_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
635
    { (C15_5  ^ X8_9)   ^ X11_15,
636
      (C14_4  ^ X7_8)   ^ X10_14,
637
      (C13_3  ^ X6_7)   ^ X9_13,
638
      (C12_2  ^ X5_6)   ^ X8_12,
639
      (C11_1  ^ X4_5)   ^ X7_11,
640
      (C10_0  ^ X3_4)   ^ X6_10,
641
      (C9_8   ^ X2_3)   ^ X11_15,
642
      (C8_7   ^ X1_2)   ^ X10_14,
643
      (C7_6   ^ X0_1)   ^ (X9_13  ^ X15),
644
      (C6_0   ^ X12_9)  ^ X14_11,
645
      (C5_5   ^ X9_13)  ^ X10,
646
      (C4_4   ^ X8_12)  ^ X9,
647
      (C3_3   ^ X7_8)   ^ X11_15,
648
      (C2_2   ^ X6_7)   ^ (X14_15 ^ X10),
649
      (C1_1   ^ X5_6)   ^ (X9_13  ^ X14),
650
      (C0_0   ^ X4_5)   ^ (X8_12  ^ X13),
651
      (X3_4   ^ X5_15)  ^ (X7_8   ^ X12_9),
652
     ((X2_3   ^ X4_8)   ^ (X6_7   ^ X14_15)) ^ X11,
653
     ((X1_2   ^ X3_7)   ^ (X5_6   ^ X13_10)) ^ X14,
654
     ((X0_1   ^ X2_6)   ^ (X4_5   ^ X12_9))  ^ X13_15,
655
      (X0_1   ^ X3_4)   ^ (X12_9  ^ X14_15),
656
      (X0_5   ^ X2_3)   ^ (X9_13  ^ X14),
657
      (X1_2   ^ X4_5)   ^ (X12_9  ^ X13_11),
658
      (X0_1   ^ X3_4)   ^ (X8_12  ^ X10_11),
659
      (X0_5   ^ X2_3)   ^ (X7_8   ^ X10_15),
660
     ((X1_2   ^ X4_5)   ^ (X6_7   ^ X14_11)) ^ X8,
661
     ((X0_1   ^ X3_4)   ^ (X5_6   ^ X13_10)) ^ X7,
662
     ((X0_6   ^ X2_3)   ^ (X8_12  ^ X11_15)) ^ X4,
663
     ((X1_2   ^ X3_9)   ^ (X7_8   ^ X10_14)) ^ X15,
664
     ((X0_1   ^ X2_8)   ^ (X6_7   ^ X9_13))  ^ X14,
665
      (X0_1   ^ X6_7)   ^ (X12_9  ^ X13_11),
666
      (X0_6   ^ X12_9)  ^ X10
667
    };
668
endmodule
669
 
670
module crc_32_24_private (
671
  use_F_for_CRC,
672
  present_crc,
673
  data_in_24,
674
  next_crc
675
);
676
  parameter NUMBER_OF_BITS_APPLIED = 24;
677
  input   use_F_for_CRC;
678
  input  [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] present_crc;
679
  input  [NUMBER_OF_BITS_APPLIED - 1 : 0] data_in_24;
680
  output [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] next_crc;
681
 
682
/* State Variables depend on input bit number (bigger is earlier) :
683
{
684
C7                           ^ X5           ^ X8       ^ X9                   ^ X11 ^ X15                                           ^ X23,
685
C6                      ^ X4           ^ X7 ^ X8                  ^ X10 ^ X14                                                 ^ X22 ^ X23,
686
C5                 ^ X3           ^ X6 ^ X7            ^ X9 ^ X13                                                       ^ X21 ^ X22 ^ X23,
687
C4            ^ X2           ^ X5 ^ X6      ^ X8 ^ X12                                                            ^ X20 ^ X21 ^ X22      ,
688
C3       ^ X1           ^ X4 ^ X5      ^ X7                                   ^ X11                         ^ X19 ^ X20 ^ X21       ^ X23,
689
C2  ^ X0           ^ X3 ^ X4      ^ X6                            ^ X10                               ^ X18 ^ X19 ^ X20       ^ X22 ^ X23,
690
C1            ^ X2 ^ X3                     ^ X8                              ^ X11 ^ X15       ^ X17 ^ X18 ^ X19       ^ X21 ^ X22      ,
691
C0       ^ X1 ^ X2                     ^ X7                       ^ X10 ^ X14             ^ X16 ^ X17 ^ X18       ^ X20 ^ X21            ,
692
 
693
 
694
 
695
 
696
 
697
 
698
 
699
 
700
 
701
 
702
 
703
 
704
 
705
 
706
 
707
 
708
 
709
 
710
 
711
 
712
 
713
 
714
 
715
 
716
}
717
*/
718
// There are 2 obvious ways to implement these functions:
719
// 1) XOR the State bits with the Input bits, then calculate the XOR's
720
// 2) Independently calculate a result for Inputs and State variables,
721
//    then XOR the results together.
722
// The second idea seems to take much more logic, but to have no benefit.
723
 
724
// Single numbered terms are calculated in 1 XOR time.
725
  wire    X23, X22, X21, X20, X19, X18, X17, X16;
726
  wire    X15, X14, X13, X12, X11, X10, X9, X8, X7, X6, X5, X4, X3, X2, X1, X0;
727
  assign  {X23, X22, X21, X20, X19, X18, X17, X16, X15, X14, X13, X12,
728
                        X11, X10, X9, X8, X7, X6, X5, X4, X3, X2, X1, X0} =
729
           data_in_24[NUMBER_OF_BITS_APPLIED - 1 : 0]
730
         ^ (   present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : `NUMBER_OF_BITS_IN_CRC_32 - NUMBER_OF_BITS_APPLIED]
731
             | {NUMBER_OF_BITS_APPLIED{use_F_for_CRC}});
732
 
733
// State Bits are shifted over by the width of the input, then XOR's into the X terms.
734
  wire    C7, C6, C5, C4, C3, C2, C1, C0;
735
  assign  {C7, C6, C5, C4, C3, C2, C1, C0} =
736
           present_crc[`NUMBER_OF_BITS_IN_CRC_32 - NUMBER_OF_BITS_APPLIED - 1 : 0]
737
         | {(`NUMBER_OF_BITS_IN_CRC_32 - NUMBER_OF_BITS_APPLIED){use_F_for_CRC}};
738
 
739
// Calculate higher_order terms, to make parity trees.
740
// 2_numbered terms are calculated in 1 XOR times.
741
// NOTE: In a Xilinx chip, it would be fine to constrain X0 and X0_1 to
742
//       be calculated in the same CLB, and so on for all bits.
743
  wire    X0_1   = X0  ^ X1;     wire    X1_2   = X1  ^ X2;
744
  wire    X2_3   = X2  ^ X3;     wire    X3_4   = X3  ^ X4;
745
  wire    X4_5   = X4  ^ X5;     wire    X5_6   = X5  ^ X6;
746
  wire    X6_7   = X6  ^ X7;     wire    X7_8   = X7  ^ X8;
747
// Use odd-ordered XOR terms because it seems these might be useful
748
  wire    X8_12  = X8  ^ X12;    wire    X12_9  = X12 ^ X9;
749
  wire    X9_13  = X9  ^ X13;    wire    X13_10 = X13 ^ X10;
750
  wire    X10_14 = X10 ^ X14;    wire    X14_11 = X14 ^ X11;
751
  wire    X11_15 = X11 ^ X15;
752
// back to simple ordering
753
                                 wire    X15_16 = X15 ^ X16;
754
  wire    X16_17 = X16 ^ X17;    wire    X17_18 = X17 ^ X18;
755
  wire    X18_19 = X18 ^ X19;    wire    X19_20 = X19 ^ X20;
756
  wire    X20_21 = X20 ^ X21;    wire    X21_22 = X21 ^ X22;
757
  wire    X22_23 = X22 ^ X23;
758
 
759
// Calculate terms which might have a single use.  They are calculated here
760
//   so that the parity trees can be balanced.
761
  wire    C7_5   = C7  ^ X5;     wire    C6_4   = C6  ^ X4;
762
  wire    C5_3   = C5  ^ X3;     wire    C4_2   = C4  ^ X2;
763
  wire    C3_1   = C3  ^ X1;     wire    C2_0   = C2  ^ X0;
764
  wire    C1_8   = C1  ^ X8;     wire    C0_7   = C0  ^ X7;
765
// Some of these could be matched with other terms to share 1 input in a CLB.
766
  wire    X8_9   = X8  ^ X9;     wire    X7_11  = X7  ^ X11;
767
  wire    X6_10  = X6  ^ X10;    wire    X21_23 = X21 ^ X23;
768
  wire    X6_17  = X6  ^ X17;    wire    X0_16  = X0  ^ X16;
769
  wire    X5_10  = X5  ^ X10;    wire    X4_9   = X4  ^ X9;
770
  wire    X3_16  = X3  ^ X16;    wire    X20_22 = X20 ^ X22;
771
  wire    X15_19 = X15 ^ X19;    wire    X1_9   = X1  ^ X9;
772
  wire    X13_14 = X13 ^ X14;    wire    X18_20 = X18 ^ X20;
773
  wire    X0_8   = X0  ^ X8;     wire    X12_13 = X12 ^ X13;
774
  wire    X17_19 = X17 ^ X19;    wire    X5_18  = X5  ^ X18;
775
  wire    X4_8   = X4  ^ X8;     wire    X15_17 = X15 ^ X17;
776
  wire    X3_7   = X3  ^ X7;     wire    X2_6   = X2  ^ X6;
777
  wire    X14_17 = X14 ^ X17;    wire    X0_5   = X0  ^ X5;
778
  wire    X14_16 = X14 ^ X16;    wire    X13_15 = X13 ^ X15;
779
  wire    X0_4   = X0  ^ X4;     wire    X0_6   = X0  ^ X6;
780
  wire    X3_9   = X3  ^ X9;     wire    X2_8   = X2  ^ X8;
781
  wire    X13_11 = X13 ^ X11;    wire    X16_23 = X16 ^ X23;
782
  wire    X10_11 = X10 ^ X11;    wire    X10_15 = X10 ^ X15;
783
  wire    X8_22  = X8  ^ X22;    wire    X14_18 = X14 ^ X18;
784
  wire    X6_20  = X6  ^ X20;    wire    X7_21  = X7  ^ X21;
785
 
786
// NOTE: 5 terms can be implemented in a CLB, as long as the other Flop
787
//         doesn't use logic.  This would be perfect if the data_in_24
788
//         was registered as an input to the module in that CLB.
789
  assign  next_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
790
    { (C7_5  ^ X8_9)  ^ (X11_15 ^ X23),
791
      (C6_4  ^ X7_8)  ^ (X10_14 ^ X22_23),
792
     ((C5_3  ^ X6_7)  ^ (X9_13  ^ X21_22)) ^ X23,
793
     ((C4_2  ^ X5_6)  ^ (X8_12  ^ X20_21)) ^ X22,
794
     ((C3_1  ^ X4_5)  ^ (X7_11  ^ X19_20)) ^ X21_23,
795
     ((C2_0  ^ X3_4)  ^ (X6_10  ^ X18_19)) ^  (X20 ^ X22_23),
796
     ((C1_8  ^ X2_3)  ^ (X11_15 ^ X17_18)) ^  (X19 ^ X21_22),
797
     ((C0_7  ^ X1_2)  ^ (X10_14 ^ X16_17)) ^  (X18 ^ X20_21),
798
     ((X0_1  ^ X6_17) ^ (X9_13  ^ X15_16)) ^ X19_20,
799
     ((X0_16 ^ X12_9) ^ (X14_11 ^ X18_19)) ^ X23,
800
      (X5_10 ^ X9_13) ^ (X17_18 ^ X22),
801
      (X4_9  ^ X8_12) ^ (X16_17 ^ X21_23),
802
      (X3_16 ^ X7_8)  ^ (X11_15 ^ X20_22),
803
     ((X2    ^ X6_7)  ^ (X10_14 ^ X15_19)) ^ X21_23,
804
     ((X1_9  ^ X5_6)  ^ (X13_14 ^ X18_20)) ^ X22_23,
805
     ((X0_8  ^ X4_5)  ^ (X12_13 ^ X17_19)) ^ X21_22,
806
     ((X3_4  ^ X5_18) ^ (X7_8   ^ X12_9))  ^  (X15_16 ^ X20_21),
807
     ((X2_3  ^ X4_8)  ^ (X6_7   ^ X14_11)) ^ ((X15_17 ^ X19_20) ^ X23),
808
     ((X1_2  ^ X3_7)  ^ (X5_6   ^ X13_10)) ^ ((X14_16 ^ X18_19) ^ X22),
809
     ((X0_1  ^ X2_6)  ^ (X4_5   ^ X12_9))  ^ ((X13_15 ^ X17_18) ^ X21),
810
     ((X0_1  ^ X3_4)  ^ (X12_9  ^ X14_17)) ^  (X15_16 ^ X20),
811
     ((X0_5  ^ X2_3)  ^ (X9_13  ^ X14))    ^  (X16    ^ X19),
812
     ((X1_2  ^ X4_5)  ^ (X12_9  ^ X13_11)) ^  (X18    ^ X23),
813
     ((X0_1  ^ X3_4)  ^ (X8_12  ^ X10_11)) ^  (X17    ^ X22_23),
814
     ((X0_5  ^ X2_3)  ^ (X7_8   ^ X10_15)) ^  (X16_23 ^ X21_22),
815
     ((X1_2  ^ X4_5)  ^ (X6_7   ^ X8_22))  ^  (X14_11 ^ X20_21),
816
     ((X0_1  ^ X3_4)  ^ (X5_6   ^ X7_21))  ^  (X13_10 ^ X19_20),
817
     ((X0_4  ^ X2_3)  ^ (X6_20  ^ X8_12))  ^  (X11_15 ^ X18_19),
818
     ((X1_2  ^ X3_9)  ^ (X7_8   ^ X10_14)) ^  (X15_19 ^ X17_18),
819
     ((X0_1  ^ X2_8)  ^ (X6_7   ^ X9_13))  ^  (X14_18 ^ X16_17),
820
     ((X0_1  ^ X6_7)  ^ (X12_9  ^ X13_11)) ^ X16_17,
821
      (X0_6  ^ X12_9) ^ (X10    ^ X16)
822
    };
823
endmodule
824
 
825
module crc_32_32_private (
826
  use_F_for_CRC,
827
  present_crc,
828
  data_in_32,
829
  next_crc
830
);
831
  parameter NUMBER_OF_BITS_APPLIED = 32;
832
  input   use_F_for_CRC;
833
  input  [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] present_crc;
834
  input  [NUMBER_OF_BITS_APPLIED - 1 : 0] data_in_32;
835
  output [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] next_crc;
836
 
837
/* State Variables depend on input bit number (bigger is earlier) :
838
{
839
                  ^ 5         ^ 8 ^ 9      ^ 11                ^ 15                                    ^ 23 ^ 24 ^ 25      ^ 27 ^ 28 ^ 29 ^ 30 ^ 31,
840
              ^ 4         ^ 7 ^ 8     ^ 10                ^ 14                                    ^ 22 ^ 23 ^ 24      ^ 26 ^ 27 ^ 28 ^ 29 ^ 30     ,
841
          ^ 3         ^ 6 ^ 7     ^ 9                ^ 13                                    ^ 21 ^ 22 ^ 23      ^ 25 ^ 26 ^ 27 ^ 28 ^ 29      ^ 31,
842
      ^ 2         ^ 5 ^ 6     ^ 8               ^ 12                                    ^ 20 ^ 21 ^ 22      ^ 24 ^ 25 ^ 26 ^ 27 ^ 28      ^ 30     ,
843
  ^ 1         ^ 4 ^ 5     ^ 7              ^ 11                                    ^ 19 ^ 20 ^ 21      ^ 23 ^ 24 ^ 25 ^ 26 ^ 27      ^ 29          ,
844
 
845
      ^ 2 ^ 3                 ^ 8          ^ 11                ^ 15      ^ 17 ^ 18 ^ 19      ^ 21 ^ 22                          ^ 28 ^ 29      ^ 31,
846
  ^ 1 ^ 2                 ^ 7         ^ 10                ^ 14      ^ 16 ^ 17 ^ 18      ^ 20 ^ 21                          ^ 27 ^ 28      ^ 30     ,
847
 
848
 
849
                  ^ 5             ^ 9 ^ 10           ^ 13                ^ 17 ^ 18                ^ 22      ^ 24      ^ 26 ^ 27      ^ 29      ^ 31,
850
              ^ 4             ^ 8 ^ 9           ^ 12                ^ 16 ^ 17                ^ 21      ^ 23      ^ 25 ^ 26      ^ 28      ^ 30     ,
851
          ^ 3             ^ 7 ^ 8          ^ 11                ^ 15 ^ 16                ^ 20      ^ 22      ^ 24 ^ 25      ^ 27      ^ 29          ,
852
      ^ 2             ^ 6 ^ 7         ^ 10                ^ 14 ^ 15                ^ 19      ^ 21      ^ 23 ^ 24      ^ 26      ^ 28           ^ 31,
853
  ^ 1             ^ 5 ^ 6         ^ 9                ^ 13 ^ 14                ^ 18      ^ 20      ^ 22 ^ 23      ^ 25      ^ 27           ^ 30 ^ 31,
854
 
855
          ^ 3 ^ 4 ^ 5     ^ 7 ^ 8 ^ 9           ^ 12           ^ 15 ^ 16      ^ 18      ^ 20 ^ 21           ^ 24           ^ 27           ^ 30     ,
856
      ^ 2 ^ 3 ^ 4     ^ 6 ^ 7 ^ 8          ^ 11           ^ 14 ^ 15      ^ 17      ^ 19 ^ 20           ^ 23           ^ 26           ^ 29          ,
857
  ^ 1 ^ 2 ^ 3     ^ 5 ^ 6 ^ 7         ^ 10           ^ 13 ^ 14      ^ 16      ^ 18 ^ 19           ^ 22           ^ 25           ^ 28           ^ 31,
858
 
859
 
860
 
861
  ^ 1 ^ 2     ^ 4 ^ 5             ^ 9      ^ 11 ^ 12 ^ 13                     ^ 18                     ^ 23 ^ 24                     ^ 29          ,
862
 
863
 
864
  ^ 1 ^ 2     ^ 4 ^ 5 ^ 6 ^ 7 ^ 8          ^ 11           ^ 14                          ^ 20 ^ 21 ^ 22           ^ 25                ^ 29 ^ 30     ,
865
 
866
 
867
  ^ 1 ^ 2 ^ 3             ^ 7 ^ 8 ^ 9 ^ 10                ^ 14 ^ 15      ^ 17 ^ 18 ^ 19                          ^ 25      ^ 27                ^ 31,
868
 
869
 
870
 
871
}
872
*/
873
// There are 2 obvious ways to implement these functions:
874
// 1) XOR the State bits with the Input bits, then calculate the XOR's
875
// 2) Independently calculate a result for Inputs and State variables,
876
//    then XOR the results together.
877
// The second idea seems to take much more logic, but to have no benefit.
878
 
879
  wire    X31, X30, X29, X28, X27, X26, X25, X24, X23, X22, X21, X20;
880
  wire    X19, X18, X17, X16, X15, X14, X13, X12, X11, X10, X9, X8;
881
  wire    X7, X6, X5, X4, X3, X2, X1, X0;
882
  assign  {X31, X30, X29, X28, X27, X26, X25, X24, X23, X22, X21, X20,
883
           X19, X18, X17, X16, X15, X14, X13, X12, X11, X10, X9, X8,
884
           X7, X6, X5, X4, X3, X2, X1, X0} =
885
           data_in_32[NUMBER_OF_BITS_APPLIED - 1 : 0]
886
         ^ (   present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : `NUMBER_OF_BITS_IN_CRC_32 - NUMBER_OF_BITS_APPLIED]
887
             | {NUMBER_OF_BITS_APPLIED{use_F_for_CRC}});
888
 
889
// Calculate higher_order terms, to make parity trees.
890
// NOTE: In a Xilinx chip, it would be fine to constrain X0 and X0_1 to
891
//       be calculated in the same CLB, and so on for all bits.
892
  wire    X0_1   = X0  ^ X1;     wire    X1_2   = X1  ^ X2;
893
  wire    X2_3   = X2  ^ X3;     wire    X3_4   = X3  ^ X4;
894
  wire    X4_5   = X4  ^ X5;     wire    X5_6   = X5  ^ X6;
895
  wire    X6_7   = X6  ^ X7;     wire    X7_8   = X7  ^ X8;
896
// Use odd-ordered XOR terms because it seems these might be useful
897
  wire    X8_12  = X8  ^ X12;    wire    X12_9  = X12 ^ X9;
898
  wire    X9_13  = X9  ^ X13;    wire    X13_10 = X13 ^ X10;
899
  wire    X10_14 = X10 ^ X14;    wire    X14_11 = X14 ^ X11;
900
  wire    X11_15 = X11 ^ X15;
901
// back to simple ordering
902
                                 wire    X15_16 = X15 ^ X16;
903
  wire    X16_17 = X16 ^ X17;    wire    X17_18 = X17 ^ X18;
904
  wire    X18_19 = X18 ^ X19;    wire    X19_20 = X19 ^ X20;
905
  wire    X20_21 = X20 ^ X21;    wire    X21_22 = X21 ^ X22;
906
  wire    X22_23 = X22 ^ X23;    wire    X23_24 = X23 ^ X24;
907
  wire    X24_25 = X24 ^ X25;    wire    X25_26 = X25 ^ X26;
908
  wire    X26_27 = X26 ^ X27;    wire    X27_28 = X27 ^ X28;
909
  wire    X28_29 = X28 ^ X29;    wire    X29_30 = X29 ^ X30;
910
  wire    X30_31 = X30 ^ X31;
911
 
912
// Calculate terms which might have a single use.  They are calculated here
913
//   so that the parity trees can be balanced.
914
  wire    X8_9   = X8 ^ X9;      wire    X29_31 = X29 ^ X31;
915
  wire    X28_30 = X28 ^ X30;    wire    X28_31 = X28 ^ X31;
916
  wire    X27_29 = X27 ^ X29;    wire    X4_6   = X4 ^ X6;
917
  wire    X7_11  = X7 ^ X11;     wire    X6_10  = X6 ^ X10;
918
  wire    X22_24 = X22 ^ X24;    wire    X21_23 = X21 ^ X23;
919
  wire    X20_22 = X20 ^ X22;    wire    X19_21 = X19 ^ X21;
920
  wire    X18_20 = X18 ^ X20;    wire    X17_19 = X17 ^ X19;
921
  wire    X24_27 = X24 ^ X27;    wire    X23_26 = X23 ^ X26;
922
  wire    X22_25 = X22 ^ X25;    wire    X21_24 = X21 ^ X24;
923
 
924
  wire    X20_26 = X20 ^ X26;    wire    X25_27 = X25 ^ X27;
925
  wire    X24_26 = X24 ^ X26;    wire    X18_30 = X18 ^ X30;
926
  wire    X15_17 = X15 ^ X17;    wire    X14_16 = X14 ^ X16;
927
  wire    X13_15 = X13 ^ X15;    wire    X13_11 = X13 ^ X11;
928
  wire    X10_11 = X10 ^ X11;    wire    X10_15 = X10 ^ X15;
929
  wire    X3_5  = X3 ^ X5;       wire    X2_4   = X2 ^ X4;
930
  wire    X3_9  = X3 ^ X9;       wire    X0_5  = X0 ^ X5;
931
  wire    X17_20 = X17 ^ X20;    wire    X16_19 = X16 ^ X19;
932
  wire    X16_21 = X16 ^ X21;    wire    X15_19 = X15 ^ X19;
933
  wire    X27_31 = X27 ^ X31;    wire    X20_31 = X20 ^ X31;
934
  wire    X2_8   = X2 ^ X8;
935
  wire    X14_18 = X14 ^ X18;
936
  wire    X0_6   = X0 ^ X6;
937
  wire    X10_16 = X10 ^ X16;
938
 
939
  assign  next_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
940
    {((X5   ^ X8_9)  ^ (X11_15 ^ X23_24)) ^ ((X25    ^ X27_28) ^ (X29_30 ^ X31)),
941
     ((X4   ^ X7_8)  ^ (X10_14 ^ X22_23)) ^ ((X24    ^ X26_27) ^ (X28_29 ^ X30)),
942
     ((X3   ^ X6_7)  ^ (X9_13  ^ X21_22)) ^ ((X23    ^ X25_26) ^ (X27_28 ^ X29_31)),
943
     ((X2   ^ X5_6)  ^ (X8_12  ^ X20_21)) ^ ((X22    ^ X24_25) ^ (X26_27 ^ X28_30)),
944
     ((X1   ^ X4_5)  ^ (X7_11  ^ X19_20)) ^ ((X21    ^ X23_24) ^ (X25_26 ^ X27_29)),
945
     ((X0   ^ X3_4)  ^ (X6_10  ^ X18_19)) ^ ((X20_26 ^ X22_23) ^ (X24_25 ^ X28_31)),
946
     ((X2_3 ^ X8)    ^ (X11_15 ^ X17_18)) ^ ((X19    ^ X21_22) ^ (X28_29 ^ X31)),
947
     ((X1_2 ^ X7)    ^ (X10_14 ^ X16_17)) ^ ((X18    ^ X20_21) ^ (X27_28 ^ X30)),
948
     ((X0_1 ^ X6)    ^ (X9_13  ^ X15_16)) ^ ((X17    ^ X19_20) ^ (X26_27 ^ X29_31)),
949
     ((X0   ^ X12_9) ^ (X14_11 ^ X16))    ^ ((X18_19 ^ X23_24) ^ (X26_27 ^ X29_31)),
950
     ((X5   ^ X9_13) ^ (X10    ^ X17_18)) ^ ((X22_24 ^ X26_27) ^ (X29_31)),
951
     ((X4   ^ X8_12) ^ (X9     ^ X16_17)) ^ ((X21_23 ^ X25_26) ^ (X28_30)),
952
     ((X3   ^ X7_8)  ^ (X11_15 ^ X16))    ^ ((X20_22 ^ X24_25) ^ (X27_29)),
953
     ((X2   ^ X6_7)  ^ (X10_14 ^ X15))    ^ ((X19_21 ^ X23_24) ^ (X26    ^ X28_31)),
954
     ((X1   ^ X5_6)  ^ (X9_13  ^ X14))    ^ ((X18_20 ^ X22_23) ^ (X25_27 ^ X30_31)),
955
     ((X0   ^ X4_5)  ^ (X8_12  ^ X13))    ^ ((X17_19 ^ X21_22) ^ (X24_26 ^ X29_30)),
956
     ((X3_4 ^ X5)    ^ (X7_8   ^ X12_9))  ^ ((X15_16 ^ X18_30) ^ (X20_21 ^ X24_27)),
957
     ((X2_3 ^ X4_6)  ^ (X7_8   ^ X14_11)) ^ ((X15_17 ^ X19_20) ^ (X23_26 ^ X29)),
958
     ((X1_2 ^ X3_5)  ^ (X6_7   ^ X13_10)) ^ ((X14_16 ^ X18_19) ^ (X22_25 ^ X28_31)),
959
     ((X0_1 ^ X2_4)  ^ (X5_6   ^ X12_9))  ^ ((X13_15 ^ X17_18) ^ (X21_24 ^ X27))    ^ X30_31,
960
     ((X0_1 ^ X3_4)  ^ (X12_9  ^ X14))    ^ ((X15_16 ^ X17_20) ^ (X24_25 ^ X26_27)) ^ X28_31,
961
     ((X0_5 ^ X2_3)  ^ (X9_13  ^ X14))    ^ ((X16_19 ^ X26)    ^ (X28_29 ^ X31)),
962
     ((X1_2 ^ X4_5)  ^ (X12_9  ^ X13_11)) ^ ((X18    ^ X23_24) ^ (X29)),
963
     ((X0_1 ^ X3_4)  ^ (X8_12  ^ X10_11)) ^ ((X17    ^ X22_23) ^ (X28_31)),
964
     ((X0_5 ^ X2_3)  ^ (X7_8   ^ X10_15)) ^ ((X16_21 ^ X22_23) ^ (X24_25 ^ X28_29)),
965
     ((X1_2 ^ X4_5)  ^ (X6_7   ^ X8))     ^ ((X14_11 ^ X20_21) ^ (X22_25 ^ X29_30)),
966
     ((X0_1 ^ X3_4)  ^ (X5_6   ^ X7))     ^ ((X13_10 ^ X19_20) ^ (X21_24 ^ X28_29)),
967
     ((X0   ^ X2_3)  ^ (X4_6   ^ X8_12))  ^ ((X11_15 ^ X18_19) ^ (X20_31 ^ X24_25)) ^ X29_30,
968
     ((X1_2 ^ X3_9)  ^ (X7_8   ^ X10_14)) ^ ((X15_19 ^ X17_18) ^ (X25    ^ X27_31)),
969
     ((X0_1 ^ X2_8)  ^ (X6_7   ^ X9_13))  ^ ((X14_18 ^ X16_17) ^ (X24_26 ^ X30_31)),
970
     ((X0_1 ^ X6_7)  ^ (X12_9  ^ X13_11)) ^ ((X16_17 ^ X24)    ^ (X27_28)),
971
     ((X0_6 ^ X12_9) ^ (X10_16 ^ X24_25)) ^ ((X26    ^ X28_29) ^ (X30_31))
972
    };
973
endmodule
974
 
975
// Calculate the Data dependent part of the CRC-32 function with 64 inputs here in
976
//   a separate module so that the user can pipeline this one clock earlier.  This
977
//   MIGHT mean that the whole thing can run faster.  If not, use as a function!
978
module crc_32_64_data_private (
979
  data_in_64,
980
  data_part_1_out, data_part_2_out
981
);
982
  parameter NUMBER_OF_BITS_APPLIED = 64;
983
  input  [NUMBER_OF_BITS_APPLIED - 1 : 0] data_in_64;
984
  output [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] data_part_1_out;
985
  output [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] data_part_2_out;
986
 
987
/*
988
// After looking at this, I am getting the feeling that the layout of the circuit would
989
//   be the best if more complicated terms were collected from adjacent simple terms.
990
// For instance, the first line might use a term X5^X8, then another X9^X11
991
//
992
// Data Input dependencies
993
{
994
X5 ^X8^X9 ^X11 ^X15 ^X23^X24^X25 ^X27^X28^X29^X30^X31 ^X33 ^X36 ^X43^X44 ^X46^X47 ^X49 ^X52^X53^X54 ^X57 ^X59^X60 ^X62,
995
X4 ^X7^X8 ^X10 ^X14 ^X22^X23^X24 ^X26^X27^X28^X29^X30 ^X32 ^X35 ^X42^X43 ^X45^X46 ^X48 ^X51^X52^X53 ^X56 ^X58^X59 ^X61 ^X63,
996
X3 ^X6^X7 ^X9 ^X13 ^X21^X22^X23 ^X25^X26^X27^X28^X29 ^X31 ^X34 ^X41^X42 ^X44^X45 ^X47 ^X50^X51^X52 ^X55 ^X57^X58 ^X60 ^X62^X63,
997
X2 ^X5^X6 ^X8 ^X12 ^X20^X21^X22 ^X24^X25^X26^X27^X28 ^X30 ^X33 ^X40^X41 ^X43^X44 ^X46 ^X49^X50^X51 ^X54 ^X56^X57 ^X59 ^X61^X62^X63,
998
X1 ^X4^X5 ^X7 ^X11 ^X19^X20^X21 ^X23^X24^X25^X26^X27 ^X29 ^X32 ^X39^X40 ^X42^X43 ^X45 ^X48^X49^X50 ^X53 ^X55^X56 ^X58 ^X60^X61^X62^X63,
999
X0 ^X3^X4 ^X6 ^X10 ^X18^X19^X20 ^X22^X23^X24^X25^X26 ^X28 ^X31 ^X38^X39 ^X41^X42 ^X44 ^X47^X48^X49 ^X52 ^X54^X55 ^X57 ^X59^X60^X61^X62,
1000
X2^X3 ^X8 ^X11 ^X15 ^X17^X18^X19 ^X21^X22 ^X28^X29 ^X31 ^X33 ^X36^X37^X38 ^X40^X41 ^X44 ^X48^X49 ^X51^X52 ^X56^X57^X58 ^X61^X62,
1001
X1^X2 ^X7 ^X10 ^X14 ^X16^X17^X18 ^X20^X21 ^X27^X28 ^X30 ^X32 ^X35^X36^X37 ^X39^X40 ^X43 ^X47^X48 ^X50^X51 ^X55^X56^X57 ^X60^X61 ^X63,
1002
X0^X1 ^X6 ^X9 ^X13 ^X15^X16^X17 ^X19^X20 ^X26^X27 ^X29 ^X31 ^X34^X35^X36 ^X38^X39 ^X42 ^X46^X47 ^X49^X50 ^X54^X55^X56 ^X59^X60 ^X62,
1003
X0 ^X9 ^X11^X12 ^X14 ^X16 ^X18^X19 ^X23^X24 ^X26^X27 ^X29 ^X31 ^X34^X35^X36^X37^X38 ^X41 ^X43^X44^X45 ^X47^X48 ^X52 ^X55 ^X57^X58 ^X60^X61^X62,
1004
X5 ^X9^X10 ^X13 ^X17^X18 ^X22 ^X24 ^X26^X27 ^X29 ^X31 ^X34^X35 ^X37 ^X40 ^X42 ^X49 ^X51^X52^X53 ^X56 ^X61^X62,
1005
X4 ^X8^X9 ^X12 ^X16^X17 ^X21 ^X23 ^X25^X26 ^X28 ^X30 ^X33^X34 ^X36 ^X39 ^X41 ^X48 ^X50^X51^X52 ^X55 ^X60^X61,
1006
X3 ^X7^X8 ^X11 ^X15^X16 ^X20 ^X22 ^X24^X25 ^X27 ^X29 ^X32^X33 ^X35 ^X38 ^X40 ^X47 ^X49^X50^X51 ^X54 ^X59^X60,
1007
X2 ^X6^X7 ^X10 ^X14^X15 ^X19 ^X21 ^X23^X24 ^X26 ^X28 ^X31^X32 ^X34 ^X37 ^X39 ^X46 ^X48^X49^X50 ^X53 ^X58^X59,
1008
X1 ^X5^X6 ^X9 ^X13^X14 ^X18 ^X20 ^X22^X23 ^X25 ^X27 ^X30^X31 ^X33 ^X36 ^X38 ^X45 ^X47^X48^X49 ^X52 ^X57^X58,
1009
X0 ^X4^X5 ^X8 ^X12^X13 ^X17 ^X19 ^X21^X22 ^X24 ^X26 ^X29^X30 ^X32 ^X35 ^X37 ^X44 ^X46^X47^X48 ^X51 ^X56^X57,
1010
X3^X4^X5 ^X7^X8^X9 ^X12 ^X15^X16 ^X18 ^X20^X21 ^X24 ^X27 ^X30 ^X33^X34 ^X44^X45 ^X49^X50 ^X52^X53^X54^X55^X56^X57 ^X59^X60 ^X62,
1011
X2^X3^X4 ^X6^X7^X8 ^X11 ^X14^X15 ^X17 ^X19^X20 ^X23 ^X26 ^X29 ^X32^X33 ^X43^X44 ^X48^X49 ^X51^X52^X53^X54^X55^X56 ^X58^X59 ^X61 ^X63,
1012
X1^X2^X3 ^X5^X6^X7 ^X10 ^X13^X14 ^X16 ^X18^X19 ^X22 ^X25 ^X28 ^X31^X32 ^X42^X43 ^X47^X48 ^X50^X51^X52^X53^X54^X55 ^X57^X58 ^X60 ^X62,
1013
X0^X1^X2 ^X4^X5^X6 ^X9 ^X12^X13 ^X15 ^X17^X18 ^X21 ^X24 ^X27 ^X30^X31 ^X41^X42 ^X46^X47 ^X49^X50^X51^X52^X53^X54 ^X56^X57 ^X59 ^X61 ^X63,
1014
X0^X1 ^X3^X4 ^X9 ^X12 ^X14^X15^X16^X17 ^X20 ^X24^X25^X26^X27^X28 ^X31 ^X33 ^X36 ^X40^X41 ^X43^X44^X45 ^X47^X48 ^X50^X51 ^X54^X55^X56^X57^X58^X59,
1015
X0 ^X2^X3 ^X5 ^X9 ^X13^X14 ^X16 ^X19 ^X26 ^X28^X29 ^X31^X32^X33 ^X35^X36 ^X39^X40 ^X42 ^X50 ^X52 ^X55^X56 ^X58^X59^X60 ^X62^X63,
1016
X1^X2 ^X4^X5 ^X9 ^X11^X12^X13 ^X18 ^X23^X24 ^X29 ^X32^X33^X34^X35^X36 ^X38^X39 ^X41 ^X43^X44 ^X46^X47 ^X51^X52^X53 ^X55 ^X58 ^X60^X61,
1017
X0^X1 ^X3^X4 ^X8 ^X10^X11^X12 ^X17 ^X22^X23 ^X28 ^X31^X32^X33^X34^X35 ^X37^X38 ^X40 ^X42^X43 ^X45^X46 ^X50^X51^X52 ^X54 ^X57 ^X59^X60 ^X63,
1018
X0 ^X2^X3 ^X5 ^X7^X8 ^X10 ^X15^X16 ^X21^X22^X23^X24^X25 ^X28^X29 ^X32 ^X34 ^X37 ^X39 ^X41^X42^X43 ^X45^X46^X47 ^X50^X51^X52 ^X54 ^X56^X57^X58 ^X60,
1019
X1^X2 ^X4^X5^X6^X7^X8 ^X11 ^X14 ^X20^X21^X22 ^X25 ^X29^X30 ^X38 ^X40^X41^X42^X43 ^X45 ^X47 ^X50^X51^X52 ^X54^X55^X56 ^X60 ^X62,
1020
X0^X1 ^X3^X4^X5^X6^X7 ^X10 ^X13 ^X19^X20^X21 ^X24 ^X28^X29 ^X37 ^X39^X40^X41^X42 ^X44 ^X46 ^X49^X50^X51 ^X53^X54^X55 ^X59 ^X61 ^X63,
1021
X0 ^X2^X3^X4 ^X6 ^X8 ^X11^X12 ^X15 ^X18^X19^X20 ^X24^X25 ^X29^X30^X31 ^X33 ^X38^X39^X40^X41 ^X44^X45^X46^X47^X48 ^X50 ^X57^X58^X59 ^X63,
1022
X1^X2^X3 ^X7^X8^X9^X10 ^X14^X15 ^X17^X18^X19 ^X25 ^X27 ^X31^X32^X33 ^X36^X37^X38^X39^X40 ^X45 ^X52^X53^X54 ^X56 ^X58^X59^X60,
1023
X0^X1^X2 ^X6^X7^X8^X9 ^X13^X14 ^X16^X17^X18 ^X24 ^X26 ^X30^X31^X32 ^X35^X36^X37^X38^X39 ^X44 ^X51^X52^X53 ^X55 ^X57^X58^X59,
1024
X0^X1 ^X6^X7 ^X9 ^X11^X12^X13 ^X16^X17 ^X24 ^X27^X28 ^X33^X34^X35 ^X37^X38 ^X44 ^X46^X47 ^X49^X50^X51 ^X53 ^X56 ^X58^X59^X60 ^X62^X63,
1025
X0 ^X6 ^X9^X10 ^X12 ^X16 ^X24^X25^X26 ^X28^X29^X30^X31^X32 ^X34 ^X37 ^X44^X45 ^X47^X48 ^X50 ^X53^X54^X55 ^X58 ^X60^X61 ^X63
1026
}
1027
*/
1028
// Data terms depend ONLY on data in.
1029
  wire    D63, D62, D61, D60, D59, D58, D57, D56, D55, D54, D53, D52;
1030
  wire    D51, D50, D49, D48, D47, D46, D45, D44, D43, D42, D41, D40;
1031
  wire    D39, D38, D37, D36, D35, D34, D33, D32;
1032
  wire    D31, D30, D29, D28, D27, D26, D25, D24, D23, D22, D21, D20;
1033
  wire    D19, D18, D17, D16, D15, D14, D13, D12, D11, D10, D9, D8;
1034
  wire    D7, D6, D5, D4, D3, D2, D1, D0;
1035
  assign  {D63, D62, D61, D60, D59, D58, D57, D56, D55, D54, D53, D52,
1036
           D51, D50, D49, D48, D47, D46, D45, D44, D43, D42, D41, D40,
1037
           D39, D38, D37, D36, D35, D34, D33, D32,
1038
           D31, D30, D29, D28, D27, D26, D25, D24, D23, D22, D21, D20,
1039
           D19, D18, D17, D16, D15, D14, D13, D12, D11, D10, D9, D8,
1040
           D7, D6, D5, D4, D3, D2, D1, D0} =
1041
           data_in_64[63 : 0];
1042
 
1043
// Calculate higher_order terms, to make parity trees.
1044
// NOTE: In a Xilinx chip, it would be fine to constrain D0 and D0_1 to
1045
//       be calculated in the same CLB, and so on for all bits.
1046
  wire    D0_1   = D0  ^ D1;     wire    D1_2   = D1  ^ D2;
1047
  wire    D2_3   = D2  ^ D3;     wire    D3_4   = D3  ^ D4;
1048
  wire    D4_5   = D4  ^ D5;     wire    D5_6   = D5  ^ D6;
1049
  wire    D6_7   = D6  ^ D7;     wire    D7_8   = D7  ^ D8;
1050
  wire    D8_9   = D8  ^ D9;     wire    D9_10  = D9  ^ D10;
1051
  wire    D10_11 = D10 ^ D11;    wire    D11_12 = D11 ^ D12;
1052
  wire    D12_13 = D12 ^ D13;    wire    D13_14 = D13 ^ D14;
1053
  wire    D14_15 = D14 ^ D15;    wire    D15_16 = D15 ^ D16;
1054
  wire    D16_17 = D16 ^ D17;    wire    D17_18 = D17 ^ D18;
1055
  wire    D18_19 = D18 ^ D19;    wire    D19_20 = D19 ^ D20;
1056
  wire    D20_21 = D20 ^ D21;    wire    D21_22 = D21 ^ D22;
1057
  wire    D22_23 = D22 ^ D23;    wire    D23_24 = D23 ^ D24;
1058
  wire    D24_25 = D24 ^ D25;    wire    D25_26 = D25 ^ D26;
1059
  wire    D26_27 = D26 ^ D27;    wire    D27_28 = D27 ^ D28;
1060
  wire    D28_29 = D28 ^ D29;    wire    D29_30 = D29 ^ D30;
1061
  wire    D30_31 = D30 ^ D31;    wire    D31_32 = D31 ^ D32;
1062
  wire    D32_33 = D32 ^ D33;    wire    D33_34 = D33 ^ D34;
1063
  wire    D34_35 = D34 ^ D35;    wire    D35_36 = D35 ^ D36;
1064
  wire    D36_37 = D36 ^ D37;    wire    D37_38 = D37 ^ D38;
1065
  wire    D38_39 = D38 ^ D39;    wire    D39_40 = D39 ^ D40;
1066
  wire    D40_41 = D40 ^ D41;    wire    D41_42 = D41 ^ D42;
1067
  wire    D42_43 = D42 ^ D43;    wire    D43_44 = D43 ^ D44;
1068
  wire    D44_45 = D44 ^ D45;    wire    D45_46 = D45 ^ D46;
1069
  wire    D46_47 = D46 ^ D47;    wire    D47_48 = D47 ^ D48;
1070
  wire    D48_49 = D48 ^ D49;    wire    D49_50 = D49 ^ D50;
1071
  wire    D50_51 = D50 ^ D51;    wire    D51_52 = D51 ^ D52;
1072
  wire    D52_53 = D52 ^ D53;    wire    D53_54 = D53 ^ D54;
1073
  wire    D54_55 = D54 ^ D55;    wire    D55_56 = D55 ^ D56;
1074
  wire    D56_57 = D56 ^ D57;    wire    D57_58 = D57 ^ D58;
1075
  wire    D58_59 = D58 ^ D59;    wire    D59_60 = D59 ^ D60;
1076
  wire    D60_61 = D60 ^ D61;    wire    D61_62 = D61 ^ D62;
1077
  wire    D62_63 = D62 ^ D63;
1078
 
1079
// Calculate terms which might have a single use.  They are calculated here
1080
//   so that the parity trees can be balanced.
1081
 
1082
  wire    D5_11  = D5  ^ D11;    wire    D15_23 = D15 ^ D23;
1083
  wire    D4_10  = D4  ^ D10;    wire    D14_22 = D14 ^ D22;
1084
  wire    D3_9   = D3  ^ D9;     wire    D13_21 = D13 ^ D21;
1085
  wire    D2_8   = D2  ^ D8;     wire    D12_20 = D12 ^ D20;
1086
  wire    D1_7   = D1  ^ D7;     wire    D11_19 = D11 ^ D19;
1087
  wire    D0_6   = D0  ^ D6;     wire    D10_18 = D10 ^ D18;
1088
  wire    D8_11  = D8  ^ D11;    wire    D15_17 = D15 ^ D17;
1089
  wire    D7_10  = D7  ^ D10;    wire    D14_16 = D14 ^ D16;
1090
  wire    D6_9   = D6  ^ D9;     wire    D13_15 = D13 ^ D15;
1091
  wire    D0_9   = D0  ^ D9;
1092
  wire    D5_13  = D5  ^ D13;    wire    D22_24 = D22 ^ D24;
1093
  wire    D4_12  = D4  ^ D12;    wire    D21_23 = D21 ^ D23;
1094
  wire    D3_11  = D3  ^ D11;    wire    D20_22 = D20 ^ D22;
1095
  wire    D2_10  = D2  ^ D10;    wire    D19_21 = D19 ^ D21;
1096
  wire    D1_9   = D1  ^ D9;     wire    D18_20 = D18 ^ D20;
1097
  wire    D0_8   = D0  ^ D8;     wire    D17_19 = D17 ^ D19;
1098
  wire    D5_7   = D5  ^ D7;     wire    D12_18 = D12 ^ D18;
1099
  wire    D4_6   = D4  ^ D6;     wire    D11_17 = D11 ^ D17;
1100
  wire    D3_5   = D3  ^ D5;     wire    D10_16 = D10 ^ D16;
1101
  wire    D2_4   = D2  ^ D4;     wire    D9_15  = D9  ^ D15;
1102
  wire    D29_31 = D29 ^ D31;    wire    D37_40 = D37 ^ D40;
1103
  wire    D28_30 = D28 ^ D30;    wire    D36_39 = D36 ^ D39;
1104
  wire    D27_29 = D27 ^ D29;    wire    D35_38 = D35 ^ D38;
1105
  wire    D26_28 = D26 ^ D28;    wire    D34_37 = D34 ^ D37;
1106
  wire    D25_27 = D25 ^ D27;    wire    D33_36 = D33 ^ D36;
1107
  wire    D24_26 = D24 ^ D26;    wire    D32_35 = D32 ^ D35;
1108
  wire    D31_33 = D31 ^ D33;    wire    D30_32 = D30 ^ D32;
1109
  wire    D36_49 = D36 ^ D49;    wire    D54_57 = D54 ^ D57;
1110
  wire    D35_48 = D35 ^ D48;    wire    D53_56 = D53 ^ D56;
1111
  wire    D34_47 = D34 ^ D47;    wire    D52_55 = D52 ^ D55;
1112
  wire    D33_46 = D33 ^ D46;    wire    D51_54 = D51 ^ D54;
1113
  wire    D32_45 = D32 ^ D45;    wire    D50_53 = D50 ^ D53;
1114
  wire    D31_44 = D31 ^ D44;    wire    D49_52 = D49 ^ D52;
1115
  wire    D38_44 = D38 ^ D44;    wire    D37_43 = D37 ^ D43;
1116
  wire    D36_42 = D36 ^ D42;    wire    D38_41 = D38 ^ D41;
1117
  wire    D59_61 = D59 ^ D61;    wire    D61_63 = D61 ^ D63;
1118
  wire    D58_60 = D58 ^ D60;    wire    D57_59 = D57 ^ D59;
1119
  wire    D57_63 = D57 ^ D63;    wire    D56_62 = D56 ^ D62;
1120
  wire    D45_52 = D45 ^ D52;    wire    D55_60 = D55 ^ D60;
1121
  wire    D42_49 = D42 ^ D49;    wire    D41_48 = D41 ^ D48;
1122
  wire    D40_47 = D40 ^ D47;    wire    D39_46 = D39 ^ D46;
1123
  wire    D38_45 = D38 ^ D45;
1124
  wire    D37_44 = D37 ^ D44;    wire    D48_51 = D48 ^ D51;
1125
  wire    D24_27 = D24 ^ D27;    wire    D30_52 = D30 ^ D52;
1126
  wire    D23_26 = D23 ^ D26;    wire    D29_51 = D29 ^ D51;
1127
  wire    D22_25 = D22 ^ D25;    wire    D28_50 = D28 ^ D50;
1128
  wire    D21_24 = D21 ^ D24;    wire    D27_49 = D27 ^ D49;
1129
  wire    D57_62 = D57 ^ D62;    wire    D56_61 = D56 ^ D61;
1130
  wire    D54_59 = D54 ^ D59;
1131
  wire    D9_12  = D9  ^ D12;    wire    D20_24 = D20 ^ D24;
1132
  wire    D36_43 = D36 ^ D43;
1133
  wire    D0_5   = D0  ^ D5;     wire    D9_16  = D9  ^ D16;
1134
  wire    D19_26 = D19 ^ D26;    wire    D33_42 = D33 ^ D42;
1135
  wire    D50_52 = D50 ^ D52;
1136
  wire    D9_11  = D9  ^ D11;    wire    D18_29 = D18 ^ D29;
1137
  wire    D36_41 = D36 ^ D41;
1138
  wire    D53_55 = D53 ^ D55;
1139
  wire    D8_10  = D8  ^ D10;    wire    D17_28 = D17 ^ D28;
1140
  wire    D35_40 = D35 ^ D40;    wire    D52_54 = D52 ^ D54;
1141
  wire    D10_21 = D10 ^ D21;    wire    D32_34 = D32 ^ D34;
1142
  wire    D37_39 = D37 ^ D39;    wire    D43_45 = D43 ^ D45;
1143
  wire    D14_20 = D14 ^ D20;    wire    D25_38 = D25 ^ D38;
1144
  wire    D45_47 = D45 ^ D47;    wire    D60_62 = D60 ^ D62;
1145
  wire    D13_19 = D13 ^ D19;
1146
  wire    D24_37 = D24 ^ D37;    wire    D44_46 = D44 ^ D46;
1147
  wire    D51_53 = D51 ^ D53;
1148
  wire    D0_2   = D0  ^ D2;     wire    D6_8   = D6  ^ D8;
1149
  wire    D15_18 = D15 ^ D18;
1150
  wire    D48_50 = D48 ^ D50;    wire    D59_63 = D59 ^ D63;
1151
  wire    D3_17  = D3  ^ D17;    wire    D56_58 = D56 ^ D58;
1152
  wire    D2_16  = D2  ^ D16;    wire    D44_51 = D44 ^ D51;
1153
  wire    D55_57 = D55 ^ D57;
1154
  wire    D24_33 = D24 ^ D33;    wire    D44_49 = D44 ^ D49;
1155
  wire    D12_16 = D12 ^ D16;    wire    D58_63 = D58 ^ D63;
1156
 
1157
 
1158
// Need to distribute this logic so that it can be fast.  The user can
1159
//   use 1 or 2 outputs, just so long as their XOR is the final value.
1160
 
1161
  assign  data_part_1_out[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =  // first half of each formula
1162
   {  (((D5_11 ^ D8_9)   ^ (D15_23 ^D24_25)) ^ ((D27_28 ^D29_30) ^ (D31_33 ^D36_49))),
1163
      (((D4_10 ^ D7_8)   ^ (D14_22 ^D23_24)) ^ ((D26_27 ^D28_29) ^ (D30_32 ^D35_48))),
1164
      (((D3_9  ^ D6_7)   ^ (D13_21 ^D22_23)) ^ ((D25_26 ^D27_28) ^ (D29_31 ^D34_47))),
1165
      (((D2_8  ^ D5_6)   ^ (D12_20 ^D21_22)) ^ ((D24_25 ^D26_27) ^ (D28_30 ^D33_46))),
1166
      (((D1_7  ^ D4_5)   ^ (D11_19 ^D20_21)) ^ ((D23_24 ^D25_26) ^ (D27_29 ^D32_45))),
1167
      (((D0_6  ^ D3_4)   ^ (D10_18 ^D19_20)) ^ ((D22_23 ^D24_25) ^ (D26_28 ^D31_44))),
1168
      (((D2_3  ^ D8_11)  ^ (D15_17 ^D18_19)) ^ ((D21_22 ^D28_29) ^ (D31_33 ^D36_37))),
1169
      (((D1_2  ^ D7_10)  ^ (D14_16 ^D17_18)) ^ ((D20_21 ^D27_28) ^ (D30_32 ^D35_36))),
1170
      (((D0_1  ^ D6_9)   ^ (D13_15 ^D16_17)) ^ ((D19_20 ^D26_27) ^ (D29_31 ^D34_35))),
1171
      (((D0_9  ^ D11_12) ^ (D14_16 ^D18_19)) ^ ((D23_24 ^D26_27) ^ (D29_31 ^D34_35))),
1172
      (((D5_13 ^ D9_10)  ^ (D17_18 ^D22_24)) ^ ((D26_27 ^D29_31) ^ (D34_35 ^D37_40))),
1173
      (((D4_12 ^ D8_9)   ^ (D16_17 ^D21_23)) ^ ((D25_26 ^D28_30) ^ (D33_34 ^D36_39))),
1174
      (((D3_11 ^ D7_8)   ^ (D15_16 ^D20_22)) ^ ((D24_25 ^D27_29) ^ (D32_33 ^D35_38))),
1175
      (((D2_10 ^ D6_7)   ^ (D14_15 ^D19_21)) ^ ((D23_24 ^D26_28) ^ (D31_32 ^D34_37))),
1176
      (((D1_9  ^ D5_6)   ^ (D13_14 ^D18_20)) ^ ((D22_23 ^D25_27) ^ (D30_31 ^D33_36))),
1177
      (((D0_8  ^ D4_5)   ^ (D12_13 ^D17_19)) ^ ((D21_22 ^D24_26) ^ (D29_30 ^D32_35))),
1178
      (((D3_4  ^ D5_7)   ^ (D8_9   ^D12_18)) ^ ((D15_16 ^D20_21) ^ (D24_27 ^D30_52))),
1179
      (((D2_3  ^ D4_6)   ^ (D7_8   ^D11_17)) ^ ((D14_15 ^D19_20) ^ (D23_26 ^D29_51))),
1180
      (((D1_2  ^ D3_5)   ^ (D6_7   ^D10_16)) ^ ((D13_14 ^D18_19) ^ (D22_25 ^D28_50))),
1181
      (((D0_1  ^ D2_4)   ^ (D5_6   ^D9_15))  ^ ((D12_13 ^D17_18) ^ (D21_24 ^D27_49))),
1182
      (((D0_1  ^ D3_4)   ^ (D9_12  ^D14_15)) ^ ((D16_17 ^D20_24) ^ (D25_26 ^D27_28))),
1183
      (((D0_5  ^ D2_3)   ^ (D9_16  ^D13_14)) ^ ((D19_26 ^D28_29) ^ (D31_32 ^D33_42))),
1184
      (((D1_2  ^ D4_5)   ^ (D9_11  ^D12_13)) ^ ((D18_29 ^D23_24) ^ (D32_33 ^D34_35))),
1185
      (((D0_1  ^ D3_4)   ^ (D8_10  ^D11_12)) ^ ((D17_28 ^D22_23) ^ (D31_32 ^D33_34))),
1186
      (((D0_5  ^ D2_3)   ^ (D7_8   ^D10_21)) ^ ((D15_16 ^D22_23) ^ (D24_25 ^D28_29))),
1187
      (((D1_2  ^ D4_5)   ^ (D6_7   ^D8_11))  ^ ((D14_20 ^D21_22) ^ (D25_38 ^D29_30))),
1188
      (((D0_1  ^ D3_4)   ^ (D5_6   ^D7_10))  ^ ((D13_19 ^D20_21) ^ (D24_37 ^D28_29))),
1189
      (((D0_2  ^ D3_4)   ^ (D6_8   ^D11_12)) ^ ((D15_18 ^D19_20) ^ (D24_25 ^D29_30))),
1190
      (((D1_2  ^ D3_17)  ^ (D7_8   ^D9_10))  ^ ((D14_15 ^D18_19) ^ (D25_27 ^D31_32))),
1191
      (((D0_1  ^ D2_16)  ^ (D6_7   ^D8_9))   ^ ((D13_14 ^D17_18) ^ (D24_26 ^D30_31))),
1192
      (((D0_1  ^ D6_7)   ^ (D9_11  ^D12_13)) ^ ((D16_17 ^D24_33) ^ (D27_28 ^D34_35))),
1193
      (((D0_6  ^ D9_10)  ^ (D12_16 ^D24_25)) ^ ((D26_28 ^D29_30) ^ (D31_32 ^D34_37)))
1194
    };
1195
 
1196
  assign  data_part_2_out[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
1197
   {  (((D43_44 ^ D46_47) ^ (D52_53 ^ D54_57)) ^ ((D59_60 ^ D62))),
1198
      (((D42_43 ^ D45_46) ^ (D51_52 ^ D53_56)) ^ ((D58_59 ^ D61_63))),
1199
      (((D41_42 ^ D44_45) ^ (D50_51 ^ D52_55)) ^ ((D57_58 ^ D60)    ^  D62_63)),
1200
      (((D40_41 ^ D43_44) ^ (D49_50 ^ D51_54)) ^ ((D56_57 ^ D59_61) ^  D62_63)),
1201
      (((D39_40 ^ D42_43) ^ (D48_49 ^ D50_53)) ^ ((D55_56 ^ D58_60) ^ (D61_62 ^ D63))),
1202
      (((D38_39 ^ D41_42) ^ (D47_48 ^ D49_52)) ^ ((D54_55 ^ D57_59) ^ (D60_61 ^ D62))),
1203
      (((D38_44 ^ D40_41) ^ (D48_49 ^ D51_52)) ^ ((D56_57 ^ D58)    ^  D61_62)),
1204
      (((D37_43 ^ D39_40) ^ (D47_48 ^ D50_51)) ^ ((D55_56 ^ D57_63) ^  D60_61)),
1205
      (((D36_42 ^ D38_39) ^ (D46_47 ^ D49_50)) ^ ((D54_55 ^ D56_62) ^  D59_60)),
1206
      (((D36_37 ^ D38_41) ^ (D43_44 ^ D45_52)) ^ ((D47_48 ^ D55_60) ^ (D57_58 ^ D61_62))),
1207
      (((D42_49 ^ D51_52) ^ (D53_56 ^ D61_62))),
1208
      (((D41_48 ^ D50_51) ^ (D52_55 ^ D60_61))),
1209
      (((D40_47 ^ D49_50) ^ (D51_54 ^ D59_60))),
1210
      (((D39_46 ^ D48_49) ^ (D50_53 ^ D58_59))),
1211
      (((D38_45 ^ D47_48) ^ (D49_52 ^ D57_58))),
1212
      (((D37_44 ^ D46_47) ^ (D48_51 ^ D56_57))),
1213
      (((D33_34 ^ D44_45) ^ (D49_50 ^ D53_54)) ^ ((D55_56 ^ D57_62) ^  D59_60)),
1214
      (((D32_33 ^ D43_44) ^ (D48_49 ^ D52_53)) ^ ((D54_55 ^ D56_61) ^ (D58_59 ^ D63))),
1215
      (((D31_32 ^ D42_43) ^ (D47_48 ^ D51_52)) ^ ((D53_54 ^ D55_60) ^ (D57_58 ^ D62))),
1216
      (((D30_31 ^ D41_42) ^ (D46_47 ^ D50_51)) ^ ((D52_53 ^ D54_59) ^ (D56_57 ^ D61_63))),
1217
      (((D31_33 ^ D36_43) ^ (D40_41 ^ D44_45)) ^ ((D47_48 ^ D50_51) ^ (D54_55 ^ D56_57))) ^ D58_59,
1218
      (((D35_36 ^ D39_40) ^ (D50_52 ^ D55_56)) ^ ((D58_59 ^ D60)    ^  D62_63)),
1219
      (((D36_41 ^ D38_39) ^ (D43_44 ^ D46_47)) ^ ((D51_52 ^ D53_55) ^ (D58    ^ D60_61))),
1220
      (((D35_40 ^ D37_38) ^ (D42_43 ^ D45_46)) ^ ((D50_51 ^ D52_54) ^ (D57_63 ^ D59_60))),
1221
      (((D32_34 ^ D37_39) ^ (D41_42 ^ D43_45)) ^ ((D46_47 ^ D50_51) ^ (D52_54 ^ D56_57))) ^ D58_60,
1222
      (((D40_41 ^ D42_43) ^ (D45_47 ^ D50_51)) ^ ((D52_54 ^ D55_56) ^  D60_62)),
1223
      (((D39_40 ^ D41_42) ^ (D44_46 ^ D49_50)) ^ ((D51_53 ^ D54_55) ^ (D59    ^ D61_63))),
1224
      (((D31_33 ^ D38_39) ^ (D40_41 ^ D44_45)) ^ ((D46_47 ^ D48_50) ^ (D57_58 ^ D59_63))),
1225
      (((D33_36 ^ D37_38) ^ (D39_40 ^ D45_52)) ^ ((D53_54 ^ D56_58) ^  D59_60)),
1226
      (((D32_35 ^ D36_37) ^ (D38_39 ^ D44_51)) ^ ((D52_53 ^ D55_57) ^  D58_59)),
1227
      (((D37_38 ^ D44_49) ^ (D46_47 ^ D50_51)) ^ ((D53_56 ^ D58_59) ^ (D60    ^ D62_63))),
1228
      (((D44_45 ^ D47_48) ^ (D50_53 ^ D54_55)) ^ ((D58_63 ^ D60_61)))
1229
    };
1230
endmodule
1231
 
1232
module crc_32_64_crc_private (
1233
  use_F_for_CRC,
1234
  present_crc,
1235
  crc_part_1_out, crc_part_2_out
1236
);
1237
  input   use_F_for_CRC;
1238
  input  [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] present_crc;
1239
  output [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] crc_part_1_out;
1240
  output [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] crc_part_2_out;
1241
 
1242
/*
1243
// CRC input dependencies
1244
{
1245
C1 ^C4 ^C11^C12 ^C14^C15 ^C17 ^C20^C21^C22 ^C25 ^C27^C28 ^C30,
1246
C0 ^C3 ^C10^C11 ^C13^C14 ^C16 ^C19^C20^C21 ^C24 ^C26^C27 ^C29 ^C31,
1247
C2 ^C9^C10 ^C12^C13 ^C15 ^C18^C19^C20 ^C23 ^C25^C26 ^C28 ^C30^C31,
1248
C1 ^C8^C9 ^C11^C12 ^C14 ^C17^C18^C19 ^C22 ^C24^C25 ^C27 ^C29^C30^C31,
1249
C0 ^C7^C8 ^C10^C11 ^C13 ^C16^C17^C18 ^C21 ^C23^C24 ^C26 ^C28^C29^C30^C31,
1250
C6^C7 ^C9^C10 ^C12 ^C15^C16^C17 ^C20 ^C22^C23 ^C25 ^C27^C28^C29^C30,
1251
C1 ^C4^C5^C6 ^C8^C9 ^C12 ^C16^C17 ^C19^C20 ^C24^C25^C26 ^C29^C30,
1252
C0 ^C3^C4^C5 ^C7^C8 ^C11 ^C15^C16 ^C18^C19 ^C23^C24^C25 ^C28^C29 ^C31,
1253
C2^C3^C4 ^C6^C7 ^C10 ^C14^C15 ^C17^C18 ^C22^C23^C24 ^C27^C28 ^C30,
1254
C2^C3^C4^C5^C6 ^C9 ^C11^C12^C13 ^C15^C16 ^C20 ^C23 ^C25^C26 ^C28^C29^C30,
1255
C2^C3 ^C5 ^C8 ^C10 ^C17 ^C19^C20^C21 ^C24 ^C29^C30,
1256
C1^C2 ^C4 ^C7 ^C9 ^C16 ^C18^C19^C20 ^C23 ^C28^C29,
1257
C0^C1 ^C3 ^C6 ^C8 ^C15 ^C17^C18^C19 ^C22 ^C27^C28,
1258
C0 ^C2 ^C5 ^C7 ^C14 ^C16^C17^C18 ^C21 ^C26^C27,
1259
C1 ^C4 ^C6 ^C13 ^C15^C16^C17 ^C20 ^C25^C26,
1260
C0 ^C3 ^C5 ^C12 ^C14^C15^C16 ^C19 ^C24^C25,
1261
C1^C2 ^C12^C13 ^C17^C18 ^C20^C21^C22^C23^C24^C25 ^C27^C28 ^C30,
1262
C0^C1 ^C11^C12 ^C16^C17 ^C19^C20^C21^C22^C23^C24 ^C26^C27 ^C29 ^C31,
1263
C0 ^C10^C11 ^C15^C16 ^C18^C19^C20^C21^C22^C23 ^C25^C26 ^C28 ^C30,
1264
C9^C10 ^C14^C15 ^C17^C18^C19^C20^C21^C22 ^C24^C25 ^C27 ^C29 ^C31,
1265
C1 ^C4 ^C8^C9 ^C11^C12^C13 ^C15^C16 ^C18^C19 ^C22^C23^C24^C25^C26^C27,
1266
C0^C1 ^C3^C4 ^C7^C8 ^C10 ^C18 ^C20 ^C23^C24 ^C26^C27^C28 ^C30^C31,
1267
C0^C1^C2^C3^C4 ^C6^C7 ^C9 ^C11^C12 ^C14^C15 ^C19^C20^C21 ^C23 ^C26 ^C28^C29,
1268
C0^C1^C2^C3 ^C5^C6 ^C8 ^C10^C11 ^C13^C14 ^C18^C19^C20 ^C22 ^C25 ^C27^C28 ^C31,
1269
C0 ^C2 ^C5 ^C7 ^C9^C10^C11 ^C13^C14^C15 ^C18^C19^C20 ^C22 ^C24^C25^C26 ^C28,
1270
C6 ^C8^C9^C10^C11 ^C13 ^C15 ^C18^C19^C20 ^C22^C23^C24 ^C28 ^C30,
1271
C5 ^C7^C8^C9^C10 ^C12 ^C14 ^C17^C18^C19 ^C21^C22^C23 ^C27 ^C29 ^C31,
1272
C1 ^C6^C7^C8^C9 ^C12^C13^C14^C15^C16 ^C18 ^C25^C26^C27 ^C31,
1273
C0^C1 ^C4^C5^C6^C7^C8 ^C13 ^C20^C21^C22 ^C24 ^C26^C27^C28,
1274
C0 ^C3^C4^C5^C6^C7 ^C12 ^C19^C20^C21 ^C23 ^C25^C26^C27,
1275
C1^C2^C3 ^C5^C6 ^C12 ^C14^C15 ^C17^C18^C19 ^C21 ^C24 ^C26^C27^C28 ^C30^C31,
1276
C0 ^C2 ^C5 ^C12^C13 ^C15^C16 ^C18 ^C21^C22^C23 ^C26 ^C28^C29 ^C31
1277
}
1278
 */
1279
// CRC terms depend ONLY on CRC data from the previous clock
1280
  wire    C31, C30, C29, C28, C27, C26, C25, C24, C23, C22, C21, C20, C19, C18, C17;
1281
  wire    C16, C15, C14, C13, C12, C11, C10, C9, C8, C7, C6, C5, C4, C3, C2, C1, C0;
1282
  assign  {C31, C30, C29, C28, C27, C26, C25, C24,
1283
           C23, C22, C21, C20, C19, C18, C17, C16, C15, C14, C13, C12,
1284
           C11, C10, C9,  C8,  C7,  C6,  C5,  C4,  C3,  C2,  C1,  C0} =
1285
           present_crc[`NUMBER_OF_BITS_IN_CRC_32- 1 : 0]
1286
         | {`NUMBER_OF_BITS_IN_CRC_32{use_F_for_CRC}};
1287
 
1288
  wire    C0_1   = C0  ^ C1;     wire    C1_2   = C1  ^ C2;
1289
  wire    C2_3   = C2  ^ C3;     wire    C3_4   = C3  ^ C4;
1290
  wire    C4_5   = C4  ^ C5;     wire    C5_6   = C5  ^ C6;
1291
  wire    C6_7   = C6  ^ C7;     wire    C7_8   = C7  ^ C8;
1292
  wire    C8_9   = C8  ^ C9;     wire    C9_10  = C9  ^ C10;
1293
  wire    C10_11 = C10 ^ C11;    wire    C11_12 = C11 ^ C12;
1294
  wire    C12_13 = C12 ^ C13;    wire    C13_14 = C13 ^ C14;
1295
  wire    C14_15 = C14 ^ C15;    wire    C15_16 = C15 ^ C16;
1296
  wire    C16_17 = C16 ^ C17;    wire    C17_18 = C17 ^ C18;
1297
  wire    C18_19 = C18 ^ C19;    wire    C19_20 = C19 ^ C20;
1298
  wire    C20_21 = C20 ^ C21;    wire    C21_22 = C21 ^ C22;
1299
  wire    C22_23 = C22 ^ C23;    wire    C23_24 = C23 ^ C24;
1300
  wire    C24_25 = C24 ^ C25;    wire    C25_26 = C25 ^ C26;
1301
  wire    C26_27 = C26 ^ C27;    wire    C27_28 = C27 ^ C28;
1302
  wire    C28_29 = C28 ^ C29;    wire    C29_30 = C29 ^ C30;
1303
  wire    C30_31 = C30 ^ C31;
1304
 
1305
// Calculate terms which might have a single use.  They are calculated here
1306
//   so that the parity trees can be balanced.
1307
  wire    C1_4 =   C1  ^ C4;     wire    C0_3   = C0  ^ C3;
1308
  wire    C0_2 =   C0  ^ C2;     wire    C5_7   = C5  ^ C7;
1309
  wire    C17_20 = C17 ^ C20;    wire    C25_30 = C25 ^ C30;
1310
  wire    C16_19 = C16 ^ C19;    wire    C24_31 = C24 ^ C31;
1311
  wire    C2_15  = C2  ^ C15;    wire    C18_23 = C18 ^ C23;
1312
  wire    C1_14  = C1  ^ C14;    wire    C17_22 = C17 ^ C22;
1313
  wire    C0_13  = C0  ^ C13;    wire    C16_21 = C16 ^ C21;
1314
  wire    C27_29 = C27 ^ C29;    wire    C12_15 = C12 ^ C15;
1315
  wire    C20_25 = C20 ^ C25;    wire    C12_24 = C12 ^ C24;
1316
  wire    C11_23 = C11 ^ C23;    wire    C4_10  = C4  ^ C10;
1317
  wire    C24_30 = C24 ^ C30;    wire    C6_9   = C6  ^ C9;
1318
  wire    C13_20 = C13 ^ C20;    wire    C23_28 = C23 ^ C28;
1319
  wire    C5_8   = C5  ^ C8;     wire    C10_17 = C10 ^ C17;
1320
  wire    C21_24 = C21 ^ C24;    wire    C4_7   = C4  ^ C7;
1321
  wire    C9_16  = C9  ^ C16;    wire    C20_23 = C20 ^ C23;
1322
  wire    C3_6   = C3  ^ C6;     wire    C8_15  = C8  ^ C15;
1323
  wire    C19_22 = C19 ^ C22;    wire    C14_16 = C14 ^ C16;
1324
  wire    C6_13 =  C6  ^ C13;    wire    C15_20 = C15 ^ C20;
1325
  wire    C5_12 =  C5  ^ C12;    wire    C14_19 = C14 ^ C19;
1326
  wire    C29_31 = C29 ^ C31;    wire    C28_30 = C28 ^ C30;
1327
  wire    C10_18 = C10 ^ C18;    wire    C20_26 = C20 ^ C26;
1328
  wire    C4_9   = C4  ^ C9;     wire    C21_23 = C21 ^ C23;
1329
  wire    C8_18  = C8  ^ C18;    wire    C22_25 = C22 ^ C25;
1330
  wire    C11_13 = C11 ^ C13;    wire    C20_22 = C20 ^ C22;
1331
  wire    C26_28 = C26 ^ C28;    wire    C15_18 = C15 ^ C18;
1332
  wire    C14_17 = C14 ^ C17;    wire    C23_27 = C23 ^ C27;
1333
  wire    C1_12  = C1  ^ C12;    wire    C18_25 = C18 ^ C25;
1334
  wire    C8_13  = C8  ^ C13;    wire    C22_24 = C22 ^ C24;
1335
  wire    C12_19 = C12 ^ C19;    wire    C23_25 = C23 ^ C25;
1336
  wire    C3_12  = C3  ^ C12;    wire    C19_21 = C19 ^ C21;
1337
  wire    C24_26 = C24 ^ C26;    wire    C5_18  = C5  ^ C18;
1338
  wire    C23_26 = C23 ^ C26;
1339
 
1340
  assign  crc_part_1_out[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
1341
    {
1342
     (C1_4  ^ C11_12) ^ (C14_15 ^ C17_20),
1343
     (C0_3  ^ C10_11) ^ (C13_14 ^ C16_19),
1344
     (C2_15 ^ C9_10)  ^ (C12_13 ^ C18_23),
1345
     (C1_14 ^ C8_9)   ^ (C11_12 ^ C17_22),
1346
     (C0_13 ^ C7_8)   ^ (C10_11 ^ C16_21),
1347
     (C6_7  ^ C9_10)  ^ (C12_15 ^ C16_17),
1348
     (C1_4  ^ C5_6)   ^ (C8_9   ^ C12_24),
1349
     (C0_3  ^ C4_5)   ^ (C7_8   ^ C11_23),
1350
     (C2_3  ^ C4_10)  ^ (C6_7   ^ C14_15),
1351
     (C2_3  ^ C4_5)   ^ (C6_9   ^ C11_12),
1352
     (C2_3  ^ C5_8)   ^ (C10_17 ^ C19_20),
1353
     (C1_2  ^ C4_7)   ^ (C9_16  ^ C18_19),
1354
     (C0_1  ^ C3_6)   ^ (C8_15  ^ C17_18),
1355
     (C0_2  ^ C5_7)   ^ (C14_16 ^ C17_18),
1356
     (C1_4  ^ C6_13)  ^ (C15_20 ^ C16_17),
1357
     (C0_3  ^ C5_12)  ^ (C14_19 ^ C15_16),
1358
     (C1_2  ^ C12_13) ^ (C17_18 ^ C20_21),
1359
     (C0_1  ^ C11_12) ^ (C16_17 ^ C19_20),
1360
     (C0    ^ C10_11) ^ (C15_16 ^ C18_19),
1361
     (C9_10 ^ C14_15) ^ (C17_18 ^ C19_20),
1362
     (C1_4  ^ C8_9)   ^ (C11_12 ^ C13),
1363
     (C0_1  ^ C3_4)   ^ (C7_8   ^ C10_18),
1364
     (C0_1  ^ C2_3)   ^ (C4_9   ^ C6_7),
1365
     (C0_1  ^ C2_3)   ^ (C5_6   ^ C8_18),
1366
     (C0_2  ^ C5_7)   ^ (C9_10  ^ C11_13),
1367
     (C6_13 ^ C8_9)   ^ (C10_11 ^ C15_18),
1368
     (C5_12 ^ C7_8)   ^ (C9_10  ^ C14_17),
1369
     (C1_12 ^ C6_7)   ^ (C8_9   ^ C13_14),
1370
     (C0_1  ^ C4_5)   ^ (C6_7   ^ C8_13),
1371
     (C0_3  ^ C4_5)   ^ (C6_7   ^ C12_19),
1372
     (C1_2  ^ C3_12)  ^ (C5_6   ^ C14_15),
1373
     (C0_2  ^ C5_18)  ^ (C12_13 ^ C15_16)
1374
    };
1375
 
1376
  assign  crc_part_2_out[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
1377
    {
1378
     (C21_22 ^ C25_30) ^ (C27_28         ),
1379
     (C20_21 ^ C24_31) ^ (C26_27 ^ C29   ),
1380
     (C19_20 ^ C25_26) ^ (C28    ^ C30_31),
1381
     (C18_19 ^ C24_25) ^ (C27_29 ^ C30_31),
1382
     (C17_18 ^ C23_24) ^ (C26    ^ C28_29) ^ (C30_31),
1383
     (C20_25 ^ C22_23) ^ (C27_28 ^ C29_30),
1384
     (C16_17 ^ C19_20) ^ (C25_26 ^ C29_30),
1385
     (C15_16 ^ C18_19) ^ (C24_25 ^ C28_29) ^ (C31),
1386
     (C17_18 ^ C22_23) ^ (C24_30 ^ C27_28),
1387
     (C13_20 ^ C15_16) ^ (C23_28 ^ C25_26) ^ (C29_30),
1388
     (C21_24 ^ C29_30),
1389
     (C20_23 ^ C28_29),
1390
     (C19_22 ^ C27_28),
1391
     (C21    ^ C26_27),
1392
     (C25_26),
1393
     (C24_25),
1394
     (C22_23 ^ C24_25) ^ (C27_28 ^ C30),
1395
     (C21_22 ^ C23_24) ^ (C26_27 ^ C29_31),
1396
     (C20_21 ^ C22_23) ^ (C25_26 ^ C28_30),
1397
     (C21_22 ^ C24_25) ^ (C27    ^ C29_31),
1398
     (C15_16 ^ C18_19) ^ (C22_23 ^ C24_25) ^ (C26_27),
1399
     (C20_26 ^ C23_24) ^ (C27_28 ^ C30_31),
1400
     (C11_12 ^ C14_15) ^ (C19_20 ^ C21_23) ^ (C26 ^ C28_29),
1401
     (C10_11 ^ C13_14) ^ (C19_20 ^ C22_25) ^ (C27_28 ^ C31),
1402
     (C14_15 ^ C18_19) ^ (C20_22 ^ C24_25) ^ (C26_28),
1403
     (C19_20 ^ C22_23) ^ (C24    ^ C28_30),
1404
     (C18_19 ^ C21_22) ^ (C23_27 ^ C29_31),
1405
     (C15_16 ^ C18_25) ^ (C26_27 ^ C31),
1406
     (C20_21 ^ C22_24) ^ (C26_27 ^ C28),
1407
     (C20_21 ^ C23_25) ^ (C26_27),
1408
     (C17_18 ^ C19_21) ^ (C24_26 ^ C27_28) ^ (C30_31),
1409
     (C21_22 ^ C23_26) ^ (C28_29 ^ C31)
1410
    };
1411
endmodule
1412
 
1413
module crc_32_64_private (
1414
  use_F_for_CRC,
1415
  present_crc,
1416
  data_in_64,
1417
  next_crc
1418
);
1419
  parameter NUMBER_OF_BITS_APPLIED = 64;
1420
  input   use_F_for_CRC;
1421
  input  [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] present_crc;
1422
  input  [NUMBER_OF_BITS_APPLIED - 1 : 0] data_in_64;
1423
  output [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] next_crc;
1424
 
1425
// There are 2 obvious ways to implement these functions:
1426
// 1) XOR the State bits with the Input bits, then calculate the XOR's
1427
// 2) Independently calculate a result for Inputs and State variables,
1428
//    then XOR the results together.
1429
// Once the applied data width > CRC size, it seems best to use the second technique.
1430
// The formulas for each output term are seen to have a large number of
1431
//   terms depending on input data, and a smaller number of terms dependent
1432
//   on the initial value of the CRC.
1433
// Calculate the Data component of the dependency.  This can be done in
1434
//   a pipelined fashion, since it doesn't matter how long it takes.
1435
// Calculate the CRC component of the dependency.  Each clock this must
1436
//   be XOR'd with the correctly time-aligned Data component, and the
1437
//   results must be put back in the running CRC latches.
1438
// It looks like 64 bits per clock may be FASTER than 32 bits per clock,
1439
//   because the Data dependency can be done in several clocks.
1440
 
1441
// Instantiate the Data part of the dependency.
1442
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] data_part_1_out;
1443
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] data_part_2_out;
1444
 
1445
crc_32_64_data_private crc_32_64_data_part (
1446
  .data_in_64                 (data_in_64[NUMBER_OF_BITS_APPLIED - 1 : 0]),
1447
  .data_part_1_out            (data_part_1_out[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]),
1448
  .data_part_2_out            (data_part_2_out[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0])
1449
);
1450
 
1451
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] data_depend_part =
1452
                    data_part_1_out[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]
1453
                  ^ data_part_2_out[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
1454
 
1455
// Instantiate the CRC part of the dependency.
1456
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] crc_part_1_out;
1457
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] crc_part_2_out;
1458
 
1459
crc_32_64_crc_private crc_32_64_crc_part (
1460
  .use_F_for_CRC              (use_F_for_CRC),
1461
  .present_crc                (present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]),
1462
  .crc_part_1_out             (crc_part_1_out[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]),
1463
  .crc_part_2_out             (crc_part_2_out[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0])
1464
);
1465
 
1466
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] first_part =
1467
                    data_depend_part[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]
1468
                  ^ crc_part_1_out[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];  // source depth 4 gates
1469
 
1470
  assign  next_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
1471
                    first_part[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]
1472
                  ^ crc_part_2_out[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];  // source depth 5 gates
1473
endmodule
1474
 
1475
 `define COMPARE_PARALLEL_VERSIONS_AGAINST_SERIAL_VERSION_FOR_DEBUG
1476
`ifdef COMPARE_PARALLEL_VERSIONS_AGAINST_SERIAL_VERSION_FOR_DEBUG
1477
// a slow one to make sure I did things right.
1478
module crc_32_1_bit_at_a_time (
1479
  use_F_for_CRC,
1480
  present_crc,
1481
  data_in_1,
1482
  next_crc
1483
);
1484
  input   use_F_for_CRC;
1485
  input  [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] present_crc;
1486
  input   data_in_1;
1487
  output [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] next_crc;
1488
 
1489
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] resettable_crc;
1490
  assign  resettable_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
1491
                         {`NUMBER_OF_BITS_IN_CRC_32{use_F_for_CRC}}
1492
                       | present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
1493
 
1494
  wire    xor_value = data_in_1 ^ resettable_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1];
1495
 
1496
  assign  next_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] = xor_value
1497
                     ? {resettable_crc[`NUMBER_OF_BITS_IN_CRC_32 - 2 : 0], 1'b0} ^ `CRC
1498
                     : {resettable_crc[`NUMBER_OF_BITS_IN_CRC_32 - 2 : 0], 1'b0};
1499
endmodule
1500
 
1501
module test_crc_1 ();
1502
 
1503
  integer i, j;
1504
  reg    [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] present_crc;
1505
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] next_crc;
1506
  reg     use_F_for_CRC;
1507
  reg    [7:0] data_in_8;
1508
  reg    [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] present_crc_8;
1509
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] next_crc_8;
1510
  reg    [15:0] data_in_16;
1511
  reg    [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] present_crc_16;
1512
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] next_crc_16;
1513
  reg    [23:0] data_in_24;
1514
  reg    [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] present_crc_24;
1515
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] next_crc_24;
1516
  reg    [31:0] data_in_32;
1517
  reg    [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] present_crc_32;
1518
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] next_crc_32;
1519
  reg    [63:0] data_in_64;
1520
  reg    [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] present_crc_64;
1521
  wire   [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] next_crc_64;
1522
 
1523
 
1524
// Assign data_in_8 before invoking.  This consumes data MSB first
1525
task apply_1_8_to_crc;
1526
  integer j;
1527
  begin
1528
    #0 ;
1529
    present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
1530
                            next_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
1531
    for (j = 0; j < 8; j = j + 1)  // apply data bit at a time
1532
    begin
1533
      #0 ;
1534
      present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
1535
                            next_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
1536
      data_in_8[7:0] = {data_in_8[6:0], 1'b0};  // Shift byte out MSB first
1537
      use_F_for_CRC = 1'b0;
1538
    end
1539
  end
1540
endtask
1541
 
1542
task apply_16_to_crc;
1543
  integer j;
1544
  begin
1545
    #0 ;
1546
    present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =  // remember: apply 16 bits
1547
                            next_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
1548
    use_F_for_CRC = 1'b0;
1549
  end
1550
endtask
1551
 
1552
task apply_24_to_crc;
1553
  integer j;
1554
  begin
1555
    #0 ;
1556
    present_crc_24[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =  // remember: apply 24 bits
1557
                            next_crc_24[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
1558
    use_F_for_CRC = 1'b0;
1559
  end
1560
endtask
1561
 
1562
task apply_32_to_crc;
1563
  integer j;
1564
  begin
1565
    #0 ;
1566
    present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =  // remember: apply 32 bits
1567
                            next_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
1568
    use_F_for_CRC = 1'b0;
1569
  end
1570
endtask
1571
 
1572
task apply_64_to_crc;
1573
  integer j;
1574
  begin
1575
    #0 ;
1576
    present_crc_64[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =  // remember: apply 64 bits
1577
                            next_crc_64[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
1578
    use_F_for_CRC = 1'b0;
1579
  end
1580
endtask
1581
 
1582
  initial
1583
  begin
1584
    #10;
1585
    $display ("running serial version of code against parallel versions");
1586
    use_F_for_CRC = 1'b1;
1587
    for (i = 0; i < 43; i = i + 1)
1588
    begin
1589
      data_in_8[7:0] = 8'h00;
1590
      apply_1_8_to_crc;
1591
    end
1592
    data_in_8[7:0] = 8'h28;
1593
    apply_1_8_to_crc;
1594
    if (~present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'h864D7F99)
1595
      $display ("*** 1-bit after 40 bytes of 1'b0, I want 32'h864D7F99, I get 32\`h%x",
1596
                 ~present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1597
    if (~present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'h864D7F99)
1598
      $display ("*** 8-bit after 40 bytes of 1'b0, I want 32'h864D7F99, I get 32\`h%x",
1599
                 ~present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1600
    data_in_8[7:0] = 8'h86;
1601
    apply_1_8_to_crc;
1602
    data_in_8[7:0] = 8'h4D;
1603
    apply_1_8_to_crc;
1604
    data_in_8[7:0] = 8'h7F;
1605
    apply_1_8_to_crc;
1606
    data_in_8[7:0] = 8'h99;
1607
    apply_1_8_to_crc;
1608
//        The receiver sees the value 32'hC704DD7B when the message is
1609
//          received no errors.  Bit reversed, that is 32'hDEBB20E3.
1610
    if (present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1611
      $display ("*** 1-bit 0's after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1612
                  present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1613
    if (present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1614
      $display ("*** 8-bit 0's after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1615
                  present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1616
 
1617
    use_F_for_CRC = 1'b1;
1618
    data_in_16[15:0] = 16'h0000;
1619
    for (i = 0; i < 21; i = i + 1)
1620
    begin
1621
      apply_16_to_crc;
1622
    end
1623
    data_in_16[15:0] = 16'h0028;
1624
    apply_16_to_crc;
1625
    if (~present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'h864D7F99)
1626
      $display ("*** 16-bit after 40 bytes of 1'b0, I want 32'h864D7F99, I get 32\`h%x",
1627
                 ~present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1628
    data_in_16[15:0] = 16'h864D;
1629
    apply_16_to_crc;
1630
    data_in_16[15:0] = 16'h7F99;
1631
    apply_16_to_crc;
1632
    if (present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1633
      $display ("*** 16-bit 0's after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1634
                  present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1635
 
1636
    use_F_for_CRC = 1'b1;
1637
    data_in_24[23:0] = 24'h000000;
1638
    for (i = 0; i < 14; i = i + 1)
1639
    begin
1640
      apply_24_to_crc;
1641
    end
1642
    present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
1643
                                  present_crc_24[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
1644
    data_in_16[15:0] = 16'h0028;
1645
    apply_16_to_crc;
1646
    if (~present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'h864D7F99)
1647
      $display ("*** 24-bit after 40 bytes of 1'b0, I want 32'h864D7F99, I get 32\`h%x",
1648
                 ~present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1649
    data_in_16[15:0] = 16'h864D;
1650
    apply_16_to_crc;
1651
    data_in_16[15:0] = 16'h7F99;
1652
    apply_16_to_crc;
1653
    if (present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1654
      $display ("*** 24-bit 0's after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1655
                  present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1656
 
1657
    use_F_for_CRC = 1'b1;
1658
    data_in_32[31:0] = 32'h00000000;
1659
    for (i = 0; i < 10; i = i + 1)
1660
    begin
1661
      apply_32_to_crc;
1662
    end
1663
    data_in_32[31:0] = 32'h00000028;
1664
    apply_32_to_crc;
1665
    if (~present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'h864D7F99)
1666
      $display ("*** 32-bit after 40 bytes of 1'b0, I want 32'h864D7F99, I get 32\`h%x",
1667
                 ~present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1668
    data_in_32[31:0] = 32'h864D7F99;
1669
    apply_32_to_crc;
1670
    if (present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1671
      $display ("*** 32-bit 0's after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1672
                  present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1673
 
1674
// NOTE:  WORKING:  add 48
1675
 
1676
    use_F_for_CRC = 1'b1;
1677
    data_in_64[63:0] = 64'h00000000_00000000;
1678
    for (i = 0; i < 5; i = i + 1)
1679
    begin
1680
      apply_64_to_crc;
1681
    end
1682
    present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
1683
                                  present_crc_64[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
1684
    data_in_32[31:0] = 32'h00000028;
1685
    apply_32_to_crc;
1686
    if (~present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'h864D7F99)
1687
      $display ("*** 64-bit after 40 bytes of 1'b0, I want 32'h864D7F99, I get 32\`h%x",
1688
                 ~present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1689
    data_in_32[31:0] = 32'h864D7F99;
1690
    apply_32_to_crc;
1691
    if (present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1692
      $display ("*** 64-bit 0's after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1693
                  present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1694
 
1695
 
1696
    use_F_for_CRC = 1'b1;
1697
    for (i = 0; i < 40; i = i + 1)
1698
    begin
1699
      data_in_8[7:0] = 8'hFF;
1700
      apply_1_8_to_crc;
1701
    end
1702
    for (i = 0; i < 3; i = i + 1)
1703
    begin
1704
      data_in_8[7:0] = 8'h00;
1705
      apply_1_8_to_crc;
1706
    end
1707
    data_in_8[7:0] = 8'h28;
1708
    apply_1_8_to_crc;
1709
    if (~present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC55E457A)
1710
      $display ("*** 1-bit after 40 bytes of 1'b1, I want 32'hC55E457A, I get 32\`h%x",
1711
                 ~present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1712
    if (~present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC55E457A)
1713
      $display ("*** 8-bit after 40 bytes of 1'b1, I want 32'hC55E457A, I get 32\`h%x",
1714
                 ~present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1715
    data_in_8[7:0] = 8'hC5;
1716
    apply_1_8_to_crc;
1717
    data_in_8[7:0] = 8'h5E;
1718
    apply_1_8_to_crc;
1719
    data_in_8[7:0] = 8'h45;
1720
    apply_1_8_to_crc;
1721
    data_in_8[7:0] = 8'h7A;
1722
    apply_1_8_to_crc;
1723
    if (present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1724
      $display ("*** 1-bit 1's after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1725
                  present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1726
    if (present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1727
      $display ("*** 8-bit 1's after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1728
                  present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1729
 
1730
    use_F_for_CRC = 1'b1;
1731
    data_in_16[15:0] = 16'hFFFF;
1732
    for (i = 0; i < 20; i = i + 1)
1733
    begin
1734
      apply_16_to_crc;
1735
    end
1736
    data_in_16[15:0] = 16'h0000;
1737
    apply_16_to_crc;
1738
    data_in_16[15:0] = 16'h0028;
1739
    apply_16_to_crc;
1740
    if (~present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC55E457A)
1741
      $display ("*** 16-bit after 40 bytes of 1'b1, I want 32'hC55E457A, I get 32\`h%x",
1742
                 ~present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1743
    data_in_16[15:0] = 16'hC55E;
1744
    apply_16_to_crc;
1745
    data_in_16[15:0] = 16'h457A;
1746
    apply_16_to_crc;
1747
    if (present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1748
      $display ("*** 16-bit 1's after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1749
                  present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1750
 
1751
    use_F_for_CRC = 1'b1;
1752
    data_in_24[23:0] = 24'hFFFFFF;
1753
    for (i = 0; i < 13; i = i + 1)
1754
    begin
1755
      apply_24_to_crc;
1756
    end
1757
    present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
1758
                                  present_crc_24[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
1759
    data_in_8[7:0] = 8'hFF;
1760
    apply_1_8_to_crc;
1761
    present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
1762
                                  present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
1763
    data_in_16[15:0] = 16'h0000;
1764
    apply_16_to_crc;
1765
    data_in_16[15:0] = 16'h0028;
1766
    apply_16_to_crc;
1767
    if (~present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC55E457A)
1768
      $display ("*** 24-bit after 40 bytes of 1'b1, I want 32'hC55E457A, I get 32\`h%x",
1769
                 ~present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1770
    data_in_16[15:0] = 16'hC55E;
1771
    apply_16_to_crc;
1772
    data_in_16[15:0] = 16'h457A;
1773
    apply_16_to_crc;
1774
    if (present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1775
      $display ("*** 24-bit 1's after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1776
                  present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1777
 
1778
    use_F_for_CRC = 1'b1;
1779
    data_in_32[31:0] = 32'hFFFFFFFF;
1780
    for (i = 0; i < 10; i = i + 1)
1781
    begin
1782
      apply_32_to_crc;
1783
    end
1784
    data_in_32[31:0] = 32'h00000028;
1785
    apply_32_to_crc;
1786
    if (~present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC55E457A)
1787
      $display ("*** 32-bit after 40 bytes of 1'b1, I want 32'hC55E457A, I get 32\`h%x",
1788
                 ~present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1789
    data_in_32[31:0] = 32'hC55E457A;
1790
    apply_32_to_crc;
1791
    if (present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1792
      $display ("*** 32-bit 1's after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1793
                  present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1794
 
1795
// NOTE:  WORKING:  add 48
1796
 
1797
    use_F_for_CRC = 1'b1;
1798
    data_in_64[63:0] = 64'hFFFFFFFF_FFFFFFFF;
1799
    for (i = 0; i < 5; i = i + 1)
1800
    begin
1801
      apply_64_to_crc;
1802
    end
1803
    present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
1804
                                  present_crc_64[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
1805
    data_in_32[31:0] = 32'h00000028;
1806
    apply_32_to_crc;
1807
    if (~present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC55E457A)
1808
      $display ("*** 64-bit after 40 bytes of 1'b1, I want 32'hC55E457A, I get 32\`h%x",
1809
                 ~present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1810
    data_in_32[31:0] = 32'hC55E457A;
1811
    apply_32_to_crc;
1812
    if (present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1813
      $display ("*** 64-bit 1's after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1814
                  present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1815
 
1816
 
1817
    use_F_for_CRC = 1'b1;
1818
    for (i = 0; i < 40; i = i + 1)
1819
    begin
1820
      data_in_8[7:0] = i + 1;
1821
      apply_1_8_to_crc;
1822
    end
1823
    for (i = 0; i < 3; i = i + 1)
1824
    begin
1825
      data_in_8[7:0] = 8'h00;
1826
      apply_1_8_to_crc;
1827
    end
1828
    data_in_8[7:0] = 8'h28;
1829
    apply_1_8_to_crc;
1830
    if (~present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hBF671ED0)
1831
      $display ("*** 1-bit after 40 bytes of i+1, I want 32'hBF671ED0, I get 32\`h%x",
1832
                 ~present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1833
    if (~present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hBF671ED0)
1834
      $display ("*** 8-bit after 40 bytes of i+1, I want 32'hBF671ED0, I get 32\`h%x",
1835
                 ~present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1836
    data_in_8[7:0] = 8'hBF;
1837
    apply_1_8_to_crc;
1838
    data_in_8[7:0] = 8'h67;
1839
    apply_1_8_to_crc;
1840
    data_in_8[7:0] = 8'h1E;
1841
    apply_1_8_to_crc;
1842
    data_in_8[7:0] = 8'hD0;
1843
    apply_1_8_to_crc;
1844
    if (present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1845
      $display ("*** 1-bit i+1 after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1846
                  present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1847
    if (present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1848
      $display ("*** 8-bit i+1 after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1849
                  present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1850
 
1851
    use_F_for_CRC = 1'b1;
1852
    for (i = 0; i < 20; i = i + 1)
1853
    begin
1854
      data_in_16[15:0] = (((2 * i) + 1) << 8) | ((2 * i) + 2);
1855
      apply_16_to_crc;
1856
    end
1857
    data_in_16[15:0] = 16'h0000;
1858
    apply_16_to_crc;
1859
    data_in_16[15:0] = 16'h0028;
1860
    apply_16_to_crc;
1861
    if (~present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hBF671ED0)
1862
      $display ("*** 16-bit after 40 bytes of i+1, I want 32'hBF671ED0, I get 32\`h%x",
1863
                 ~present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1864
    data_in_16[15:0] = 16'hBF67;
1865
    apply_16_to_crc;
1866
    data_in_16[15:0] = 16'h1ED0;
1867
    apply_16_to_crc;
1868
    if (present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1869
      $display ("*** 16-bit i+1 after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1870
                  present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1871
 
1872
    use_F_for_CRC = 1'b1;
1873
    for (i = 0; i < 13; i = i + 1)
1874
    begin
1875
      data_in_24[23:0] = (((3 * i) + 1) << 16) | (((3 * i) + 2) << 8) | ((3 * i) + 3);
1876
      apply_24_to_crc;
1877
    end
1878
    present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
1879
                                  present_crc_24[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
1880
    data_in_8[7:0] = 8'h28;
1881
    apply_1_8_to_crc;
1882
    present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
1883
                                  present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
1884
    data_in_16[15:0] = 16'h0000;
1885
    apply_16_to_crc;
1886
    data_in_16[15:0] = 16'h0028;
1887
    apply_16_to_crc;
1888
    if (~present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hBF671ED0)
1889
      $display ("*** 24-bit after 40 bytes of i+1, I want 32'hBF671ED0, I get 32\`h%x",
1890
                 ~present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1891
    data_in_16[15:0] = 16'hBF67;
1892
    apply_16_to_crc;
1893
    data_in_16[15:0] = 16'h1ED0;
1894
    apply_16_to_crc;
1895
    if (present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1896
      $display ("*** 24-bit i+1 after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1897
                  present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1898
 
1899
    use_F_for_CRC = 1'b1;
1900
    for (i = 0; i < 10; i = i + 1)
1901
    begin
1902
      data_in_32[31:0] = (((4 * i) + 1) << 24) | (((4 * i) + 2) << 16)
1903
                       | (((4 * i) + 3) << 8)  |  ((4 * i) + 4);
1904
      apply_32_to_crc;
1905
    end
1906
    data_in_32[31:0] = 32'h00000028;
1907
    apply_32_to_crc;
1908
    if (~present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hBF671ED0)
1909
      $display ("*** 32-bit after 40 bytes of i+1, I want 32'hBF671ED0, I get 32\`h%x",
1910
                 ~present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1911
    data_in_32[31:0] = 32'hBF671ED0;
1912
    apply_32_to_crc;
1913
    if (present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1914
      $display ("*** 32-bit i+1 after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1915
                  present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1916
 
1917
// NOTE:  WORKING:  add 48
1918
 
1919
    use_F_for_CRC = 1'b1;
1920
    for (i = 0; i < 5; i = i + 1)
1921
    begin
1922
      data_in_64[63:0] = (((8 * i) + 1) << 56) | (((8 * i) + 2) << 48)
1923
                       | (((8 * i) + 3) << 40) | (((8 * i) + 4) << 32)
1924
                       | (((8 * i) + 5) << 24) | (((8 * i) + 6) << 16)
1925
                       | (((8 * i) + 7) << 8)  |  ((8 * i) + 8);
1926
      apply_64_to_crc;
1927
    end
1928
    present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] =
1929
                                  present_crc_64[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0];
1930
    data_in_32[31:0] = 32'h00000028;
1931
    apply_32_to_crc;
1932
    if (~present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hBF671ED0)
1933
      $display ("*** 64-bit after 40 bytes of i+1, I want 32'hBF671ED0, I get 32\`h%x",
1934
                 ~present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1935
    data_in_32[31:0] = 32'hBF671ED0;
1936
    apply_32_to_crc;
1937
    if (present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] !== 32'hC704DD7B)
1938
      $display ("*** 64-bit i+1 after running CRC through, I want 32'hC704DD7B, I get 32\`h%x",
1939
                  present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
1940
 
1941
  end
1942
 
1943
crc_32_1_bit_at_a_time test_1_bit (
1944
  .use_F_for_CRC              (use_F_for_CRC),
1945
  .present_crc                (present_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]),
1946
  .data_in_1                  (data_in_8[7]),
1947
  .next_crc                   (next_crc[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0])
1948
);
1949
 
1950
crc_32_8_private test_8_bit (
1951
  .use_F_for_CRC              (use_F_for_CRC),
1952
  .present_crc                (present_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]),
1953
  .data_in_8                  (data_in_8[7:0]),
1954
  .next_crc                   (next_crc_8[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0])
1955
);
1956
 
1957
crc_32_16_private test_16_bit (
1958
  .use_F_for_CRC              (use_F_for_CRC),
1959
  .present_crc                (present_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]),
1960
  .data_in_16                 (data_in_16[15:0]),
1961
  .next_crc                   (next_crc_16[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0])
1962
);
1963
 
1964
crc_32_24_private test_24_bit (
1965
  .use_F_for_CRC              (use_F_for_CRC),
1966
  .present_crc                (present_crc_24[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]),
1967
  .data_in_24                 (data_in_24[23:0]),
1968
  .next_crc                   (next_crc_24[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0])
1969
);
1970
 
1971
crc_32_32_private test_32_bit (
1972
  .use_F_for_CRC              (use_F_for_CRC),
1973
  .present_crc                (present_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]),
1974
  .data_in_32                 (data_in_32[31:0]),
1975
  .next_crc                   (next_crc_32[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0])
1976
);
1977
 
1978
crc_32_64_private test_64_bit (
1979
  .use_F_for_CRC              (use_F_for_CRC),
1980
  .present_crc                (present_crc_64[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]),
1981
  .data_in_64                 (data_in_64[63:0]),
1982
  .next_crc                   (next_crc_64[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0])
1983
);
1984
 
1985
//  Angie Tso's CRC-32 Test Cases
1986
//  tsoa@ttc.com
1987
//  Angie Tso
1988
//  Telecommunications Techniques Corp.     E-mail: tsoa@ttc.com
1989
//  20400 Observation Drive,                Voice : 301-353-1550 ext.4061
1990
//  Germantown, MD 20876-4023               Fax   : 301-353-1536 Mail Stop O
1991
//  
1992
//  Angie posted the following on the cell-relay list Mon, 24 Oct 1994 18:33:11 GMT=20
1993
//  --------------------------------------------------------------------------------
1994
//  
1995
//  Here are the examples of valid AAL-5 CS-PDU in I.363:
1996
//     (There are three examples in I.363)
1997
//  
1998
//  40 Octets filled with "0"
1999
//  CPCS-UU = 0, CPI = 0, Length = 40, CRC-32 = 864d7f99
2000
//  char pkt_data[48]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2001
//                     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2002
//                     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2003
//                     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2004
//                     0x00,0x00,0x00,0x28,0x86,0x4d,0x7f,0x99};
2005
//  
2006
//  40 Octets filled with "1"
2007
//  CPCS-UU = 0, CPI = 0, Length = 40, CRC-32 = c55e457a
2008
//  char pkt_data[48]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2009
//                     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2010
//                     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2011
//                     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2012
//                     0x00,0x00,0x00,0x28,0xc5,0x5e,0x45,0x7a};
2013
//  
2014
//  40 Octets counting: 1 to 40
2015
//  CPCS-UU = 0, CPI = 0, Length = 40, CRC-32 = bf671ed0
2016
//  char pkt_data[48]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,
2017
//                     0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,
2018
//                     0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,
2019
//                     0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,
2020
//                     0x00,0x00,0x00,0x28,0xbf,0x67,0x1e,0xd0};
2021
//  
2022
//  Here is one out of my calculation for your reference:
2023
//  
2024
//  40 Octets counting: 1 to 40
2025
//  CPCS-UU = 11, CPI = 22, CRC-32 = acba602a
2026
//  char pkt_data[48]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,
2027
//                     0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,
2028
//                     0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,
2029
//                     0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,
2030
//                     0x11,0x22,0x00,0x28,0xac,0xba,0x60,0x2a};
2031
 
2032
endmodule
2033
`endif  // COMPARE_PARALLEL_VERSIONS_AGAINST_SERIAL_VERSION_FOR_DEBUG
2034
 
2035
// `define CALCULATE_FUNCTIONAL_DEPENDENCE_ON_INPUT_AND_STATE
2036
`ifdef CALCULATE_FUNCTIONAL_DEPENDENCE_ON_INPUT_AND_STATE
2037
 
2038
// Try to make a program which will generate formulas for how to do CRC-32
2039
//   several bits at a time.
2040
// The idea is to get a single-bit implementation which works.  (!)
2041
// Then apply an initial value for state and an input data stream.
2042
// The initial value will have a single bit set, and the data stream
2043
//   will have a single 1-bit followed by 0 bits.
2044
// Grind the state machine forward the desired number of bits N, and
2045
//   look at the stored state.  Each place in the shift register where
2046
//   there is a 1'b1, that is a bit which is sensitive to the input
2047
//   or state bit in a parallel implementation N bits wide.
2048
 
2049
module print_out_formulas ();
2050
 
2051
  parameter NUM_BITS_TO_DO_IN_PARALLEL = 8'h40;
2052
 
2053
  reg    [`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] running_state;
2054
  reg    [63:0] input_vector;
2055
  reg     xor_value;
2056
  integer i, j, remaining_length;
2057
 
2058
  reg    [2047:0] corner_turner;  // 32 bits * 64 shifts
2059
 
2060
  initial
2061
  begin
2062
    $display ("Calculating functional dependence on input bits, for %d bits.  Rightmost bit is State Bit 0.",
2063
                 NUM_BITS_TO_DO_IN_PARALLEL);
2064
    for (i = 0; i < NUM_BITS_TO_DO_IN_PARALLEL; i = i + 1)
2065
    begin
2066
      running_state = {`NUMBER_OF_BITS_IN_CRC_32{1'b0}};
2067
      input_vector = 64'h80000000_00000000;  // MSB first for this program
2068
      for (j = 0; j < i + 1; j = j + 1)
2069
      begin
2070
        xor_value = input_vector[63] ^ running_state[`NUMBER_OF_BITS_IN_CRC_32 - 1];
2071
        running_state[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0] = xor_value
2072
                  ? {running_state[`NUMBER_OF_BITS_IN_CRC_32 - 2 : 0], 1'b0} ^ `CRC
2073
                  : {running_state[`NUMBER_OF_BITS_IN_CRC_32 - 2 : 0], 1'b0};
2074
        input_vector[63 : 0] =
2075
                    {input_vector[62 : 0], 1'b0};
2076
      end
2077
      $display ("input bit number (bigger is earlier) %d, dependence %b",
2078
                   i, running_state[`NUMBER_OF_BITS_IN_CRC_32 - 1 : 0]);
2079
// First entry, which gets shifted the most in corner_turner, is the last bit loaded                    
2080
      corner_turner[2047:0] = {corner_turner[2047 - `NUMBER_OF_BITS_IN_CRC_32 : 0],
2081
                                      running_state[`NUMBER_OF_BITS_IN_CRC_32 - 1:0]};
2082
    end
2083
 
2084
// Plan: reverse the order bits are reported in
2085
// Add C23 terms to first 24 terms
2086
// Insert ^ X
2087
 
2088
// Count out formulas in the opposite order, write out valid formulas.
2089
    $display ("When the amount of data applied to the CRC is less than the length of the CRC itself,");
2090
    $display ("  the Most Significant CRC_LEN - CRC_WIDTH terms are of the form data_in[N] ^ State[N].");
2091
    $display ("The next CRC_WIDTH terms are NOT dependent on the CRC values, except in so much as");
2092
    $display ("  they depend on CSR bits because of X = D ^ C terms.");
2093
    $display ("State Variables depend on input bit number (bigger is earlier) :");
2094
// try to read out formulas by sweeping a 1-bit through the corner_turner array.
2095
    $display ("{");
2096
    for (i = `NUMBER_OF_BITS_IN_CRC_32 - 1; i >= NUM_BITS_TO_DO_IN_PARALLEL; i = i - 1)
2097
    begin  // Bits which depend on shifted state bits directly
2098
      $write ("%d : C%0d ", i, i - NUM_BITS_TO_DO_IN_PARALLEL);
2099
      for (j = 0; j < NUM_BITS_TO_DO_IN_PARALLEL; j = j + 1)
2100
      begin
2101
        if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2102
                                                                            != 1'b0)
2103
          $write (" ^ X%0d", j[5:0]);
2104
        else if (j >= 10) $write ("      "); else $write ("     ");
2105
      end
2106
      $write (",\n");
2107
    end
2108
 
2109
    if (NUM_BITS_TO_DO_IN_PARALLEL <= `NUMBER_OF_BITS_IN_CRC_32)
2110
    begin
2111
      remaining_length = NUM_BITS_TO_DO_IN_PARALLEL - 1;
2112
    end
2113
    else
2114
    begin
2115
      remaining_length = `NUMBER_OF_BITS_IN_CRC_32 - 1;
2116
    end
2117
    for (i = remaining_length; i >= 0; i = i - 1)
2118
    begin  // bits which only depend on shifted XOR'd bits
2119
      $write ("%d :  0 ", i);
2120
      for (j = 0; j < NUM_BITS_TO_DO_IN_PARALLEL; j = j + 1)
2121
      begin
2122
        if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2123
                                                                            != 1'b0)
2124
          $write (" ^ X%0d", j[5:0]);
2125
        else if (j >= 10) $write ("      "); else $write ("     ");
2126
      end
2127
      if (i != 0) $write (",\n"); else $write ("\n");
2128
    end
2129
    $display ("}");
2130
 
2131
// Write out bits in a different order, to make it easier to group terms.
2132
    if (NUM_BITS_TO_DO_IN_PARALLEL >= 16)
2133
    begin
2134
      $display ("{");
2135
      for (i = `NUMBER_OF_BITS_IN_CRC_32 - 1; i >= NUM_BITS_TO_DO_IN_PARALLEL; i = i - 1)
2136
      begin  // Bits which depend on shifted state bits directly
2137
        $write ("%d : C%0d ", i, i - NUM_BITS_TO_DO_IN_PARALLEL);
2138
        for (j = 0; j <= 8; j = j + 1)
2139
        begin
2140
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2141
                                                                              != 1'b0)
2142
            $write (" ^ X%0d", j[5:0]);
2143
          else if (j >= 10) $write ("      "); else $write ("     ");
2144
        end
2145
        j = 12;
2146
        begin
2147
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2148
                                                                              != 1'b0)
2149
            $write (" ^ X%0d", j[5:0]);
2150
          else if (j >= 10) $write ("      "); else $write ("     ");
2151
        end
2152
        j = 9;
2153
        begin
2154
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2155
                                                                              != 1'b0)
2156
            $write (" ^ X%0d", j[5:0]);
2157
          else if (j >= 10) $write ("      "); else $write ("     ");
2158
        end
2159
        j = 13;
2160
        begin
2161
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2162
                                                                              != 1'b0)
2163
            $write (" ^ X%0d", j[5:0]);
2164
          else if (j >= 10) $write ("      "); else $write ("     ");
2165
        end
2166
        j = 10;
2167
        begin
2168
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2169
                                                                              != 1'b0)
2170
            $write (" ^ X%0d", j[5:0]);
2171
          else if (j >= 10) $write ("      "); else $write ("     ");
2172
        end
2173
        j = 14;
2174
        begin
2175
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2176
                                                                              != 1'b0)
2177
            $write (" ^ X%0d", j[5:0]);
2178
          else if (j >= 10) $write ("      "); else $write ("     ");
2179
        end
2180
        j = 11;
2181
        begin
2182
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2183
                                                                              != 1'b0)
2184
            $write (" ^ X%0d", j[5:0]);
2185
          else if (j >= 10) $write ("      "); else $write ("     ");
2186
        end
2187
        j = 15;
2188
        begin
2189
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2190
                                                                              != 1'b0)
2191
            $write (" ^ X%0d", j[5:0]);
2192
          else if (j >= 10) $write ("      "); else $write ("     ");
2193
        end
2194
        for (j = 16; j < NUM_BITS_TO_DO_IN_PARALLEL; j = j + 1)
2195
        begin
2196
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2197
                                                                            != 1'b0)
2198
            $write (" ^ X%0d", j[5:0]);
2199
          else if (j >= 10) $write ("      "); else $write ("     ");
2200
        end
2201
        $write (",\n");
2202
      end
2203
 
2204
      if (NUM_BITS_TO_DO_IN_PARALLEL <= `NUMBER_OF_BITS_IN_CRC_32)
2205
      begin
2206
        remaining_length = NUM_BITS_TO_DO_IN_PARALLEL - 1;
2207
      end
2208
      else
2209
      begin
2210
        remaining_length = `NUMBER_OF_BITS_IN_CRC_32 - 1;
2211
      end
2212
      for (i = remaining_length; i >= 0; i = i - 1)
2213
      begin  // bits which only depend on shifted XOR'd bits
2214
        $write ("%d :  0 ", i);
2215
        for (j = 0; j <= 8; j = j + 1)
2216
        begin
2217
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2218
                                                                              != 1'b0)
2219
            $write (" ^ X%0d", j[5:0]);
2220
          else if (j >= 10) $write ("      "); else $write ("     ");
2221
        end
2222
        j = 12;
2223
        begin
2224
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2225
                                                                              != 1'b0)
2226
            $write (" ^ X%0d", j[5:0]);
2227
          else if (j >= 10) $write ("      "); else $write ("     ");
2228
        end
2229
        j = 9;
2230
        begin
2231
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2232
                                                                              != 1'b0)
2233
            $write (" ^ X%0d", j[5:0]);
2234
          else if (j >= 10) $write ("      "); else $write ("     ");
2235
        end
2236
        j = 13;
2237
        begin
2238
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2239
                                                                              != 1'b0)
2240
            $write (" ^ X%0d", j[5:0]);
2241
          else if (j >= 10) $write ("      "); else $write ("     ");
2242
        end
2243
        j = 10;
2244
        begin
2245
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2246
                                                                              != 1'b0)
2247
            $write (" ^ X%0d", j[5:0]);
2248
          else if (j >= 10) $write ("      "); else $write ("     ");
2249
        end
2250
        j = 14;
2251
        begin
2252
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2253
                                                                              != 1'b0)
2254
            $write (" ^ X%0d", j[5:0]);
2255
          else if (j >= 10) $write ("      "); else $write ("     ");
2256
        end
2257
        j = 11;
2258
        begin
2259
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2260
                                                                              != 1'b0)
2261
            $write (" ^ X%0d", j[5:0]);
2262
          else if (j >= 10) $write ("      "); else $write ("     ");
2263
        end
2264
        j = 15;
2265
        begin
2266
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2267
                                                                              != 1'b0)
2268
            $write (" ^ X%0d", j[5:0]);
2269
          else if (j >= 10) $write ("      "); else $write ("     ");
2270
        end
2271
        for (j = 16; j < NUM_BITS_TO_DO_IN_PARALLEL; j = j + 1)
2272
        begin
2273
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2274
                                                                            != 1'b0)
2275
            $write (" ^ X%0d", j[5:0]);
2276
          else if (j >= 10) $write ("      "); else $write ("     ");
2277
        end
2278
        if (i != 0) $write (",\n"); else $write ("\n");
2279
      end
2280
      $display ("}");
2281
    end  // if width >= 16
2282
 
2283
    if (NUM_BITS_TO_DO_IN_PARALLEL <= `NUMBER_OF_BITS_IN_CRC_32)
2284
    begin
2285
      $display ("Since the number of data bits applied is <= number of CRC bits, each");
2286
      $display ("  X term in these formulas corresponds to X = Data_In ^ State");
2287
    end
2288
    else
2289
    begin
2290
      $display ("The number of bits being applied to the CRC is greater than the number of");
2291
      $display ("  bits in the CRC.  Each X term in these formulas corersponds to a Data_In bit.");
2292
      $display ("If the shift distance was small, the original CRC bits would be XOR'd with");
2293
      $display ("  the new data.  In this case, the shift distance per clock is large, so the");
2294
      $display ("  dependence on the original CRC bits has to be handled carefully.");
2295
      $display ("Here is the plan: Calculate the contribution due to the incoming data based");
2296
      $display ("  on the formulas produced for a particular shift distance.");
2297
      $display ("Separately, calculate the data dependence due to the present CRC.");
2298
      $display ("This is accomplished by using the HIGH numbered terms discovered when tracking");
2299
      $display ("  data dependencies.  For instance, if the shift distance is");
2300
      $display ("  64 and the CRC is 32 bits wide, the top 32 X terms of each of the formulas");
2301
      $display ("  is re-interpreted as C (state) terms.");
2302
      $display ("The terms depending on X63 : X32 are re-interpred to be terms depending on");
2303
      $display ("  CSR bits 31 : 0 correspondingly");
2304
      $display ("{");
2305
      for (i = `NUMBER_OF_BITS_IN_CRC_32 - 1; i >= 0; i = i - 1)
2306
      begin  // Bits which depend on shifted state bits directly
2307
        $write ("%d : ", i);
2308
        for (j = `NUMBER_OF_BITS_IN_CRC_32;
2309
             j < NUM_BITS_TO_DO_IN_PARALLEL +`NUMBER_OF_BITS_IN_CRC_32;
2310
             j = j + 1)
2311
        begin
2312
          if (corner_turner[(NUM_BITS_TO_DO_IN_PARALLEL-j-1)*`NUMBER_OF_BITS_IN_CRC_32 + i]
2313
                                                                            != 1'b0)
2314
            $write (" ^ C%0d", j[5:0] - `NUMBER_OF_BITS_IN_CRC_32);
2315
          else if (j >= 10) $write ("      "); else $write ("     ");
2316
        end
2317
        if (i != 0) $write (",\n"); else $write ("\n");
2318
      end
2319
      $display ("}");
2320
    end
2321
  end
2322
endmodule
2323
`endif  // CALCULATE_FUNCTIONAL_DEPENDENCE_ON_INPUT_AND_STATE
2324
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.