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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [mp3/] [lib/] [xilinx/] [coregen/] [XilinxCoreLib/] [C_COMPARE_V3_0.v] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 266 lampret
/* $Id: C_COMPARE_V3_0.v,v 1.1.1.1 2001-11-04 19:00:05 lampret Exp $
2
--
3
-- Filename - C_COMPARE_V3_0.v
4
-- Author - Xilinx
5
-- Creation - 28 Jan 1999
6
--
7
-- Description - This file contains the Verilog behavior for the Baseblocks C_COMPARE_V3_0 module
8
*/
9
 
10
`ifdef C_COMPARE_V3_0_DEF
11
`else
12
`define C_COMPARE_V3_0_DEF
13
 
14
`ifdef C_REG_FD_V3_0_DEF
15
`else
16
`include "XilinxCoreLib/C_REG_FD_V3_0.v"
17
`endif
18
 
19
`define c_set 0
20
`define c_clear 1
21
`define c_override 0
22
`define c_no_override 1
23
`define c_signed 0
24
`define c_unsigned 1
25
 
26
module C_COMPARE_V3_0 (A, B, CLK, CE, ACLR, ASET, SCLR, SSET,
27
                                  A_EQ_B, A_NE_B, A_LT_B, A_GT_B, A_LE_B, A_GE_B,
28
                                  QA_EQ_B, QA_NE_B, QA_LT_B, QA_GT_B, QA_LE_B, QA_GE_B);
29
 
30
        parameter C_AINIT_VAL           = "";
31
        parameter C_B_CONSTANT          = 0;
32
        parameter C_B_VALUE             = "";
33
        parameter C_DATA_TYPE           = `c_unsigned;
34
        parameter C_ENABLE_RLOCS        = 1;
35
        parameter C_HAS_ACLR            = 0;
36
        parameter C_HAS_ASET            = 0;
37
        parameter C_HAS_A_EQ_B          = 1;
38
        parameter C_HAS_A_GE_B          = 0;
39
        parameter C_HAS_A_GT_B          = 0;
40
        parameter C_HAS_A_LE_B          = 0;
41
        parameter C_HAS_A_LT_B          = 0;
42
        parameter C_HAS_A_NE_B          = 0;
43
        parameter C_HAS_CE                      = 0;
44
        parameter C_HAS_QA_EQ_B         = 0;
45
        parameter C_HAS_QA_GE_B         = 0;
46
        parameter C_HAS_QA_GT_B         = 0;
47
        parameter C_HAS_QA_LE_B         = 0;
48
        parameter C_HAS_QA_LT_B         = 0;
49
        parameter C_HAS_QA_NE_B         = 0;
50
        parameter C_HAS_SCLR            = 0;
51
        parameter C_HAS_SSET            = 0;
52
        parameter C_PIPE_STAGES         = 1;
53
        parameter C_SYNC_ENABLE         = `c_override;
54
        parameter C_SYNC_PRIORITY       = `c_clear;
55
        parameter C_WIDTH                       = 16;
56
 
57
 
58
        input [C_WIDTH-1 : 0] A;
59
        input [C_WIDTH-1 : 0] B;
60
        input CLK;
61
        input CE;
62
        input ACLR;
63
        input ASET;
64
        input SCLR;
65
        input SSET;
66
        output A_EQ_B;
67
        output A_NE_B;
68
        output A_LT_B;
69
        output A_GT_B;
70
        output A_LE_B;
71
        output A_GE_B;
72
        output QA_EQ_B;
73
        output QA_NE_B;
74
        output QA_LT_B;
75
        output QA_GT_B;
76
        output QA_LE_B;
77
        output QA_GE_B;
78
 
79
        // Internal values to drive signals when input is missing
80
        reg [C_WIDTH-1 : 0] intB;
81
        reg intCE;
82
        reg intACLR;
83
        reg intASET;
84
        reg intSCLR;
85
        reg intSSET;
86
        reg intA_EQ_B;
87
        reg intA_NE_B;
88
        reg intA_LT_B;
89
        reg intA_GT_B;
90
        reg intA_LE_B;
91
        reg intA_GE_B;
92
        wire intQA_EQ_B;
93
        wire intQA_NE_B;
94
        wire intQA_LT_B;
95
        wire intQA_GT_B;
96
        wire intQA_LE_B;
97
        wire intQA_GE_B;
98
        reg lastCLK;
99
 
100
        reg [C_PIPE_STAGES+2 : 0] intQA_EQ_Bpipe;
101
        reg intQA_EQ_Bpipeend;
102
        reg [C_PIPE_STAGES+2 : 0] intQA_NE_Bpipe;
103
        reg intQA_NE_Bpipeend;
104
        reg [C_PIPE_STAGES+2 : 0] intQA_LT_Bpipe;
105
        reg intQA_LT_Bpipeend;
106
        reg [C_PIPE_STAGES+2 : 0] intQA_GT_Bpipe;
107
        reg intQA_GT_Bpipeend;
108
        reg [C_PIPE_STAGES+2 : 0] intQA_LE_Bpipe;
109
        reg intQA_LE_Bpipeend;
110
        reg [C_PIPE_STAGES+2 : 0] intQA_GE_Bpipe;
111
        reg intQA_GE_Bpipeend;
112
 
113
        wire AINIT;
114
        wire SINIT;
115
 
116
        wire A_EQ_B = (C_HAS_A_EQ_B == 1 ? intA_EQ_B : 1'bx);
117
        wire A_NE_B = (C_HAS_A_NE_B == 1 ? intA_NE_B : 1'bx);
118
        wire A_LT_B = (C_HAS_A_LT_B == 1 ? intA_LT_B : 1'bx);
119
        wire A_GT_B = (C_HAS_A_GT_B == 1 ? intA_GT_B : 1'bx);
120
        wire A_LE_B = (C_HAS_A_LE_B == 1 ? intA_LE_B : 1'bx);
121
        wire A_GE_B = (C_HAS_A_GE_B == 1 ? intA_GE_B : 1'bx);
122
        wire QA_EQ_B = (C_HAS_QA_EQ_B == 1 ? intQA_EQ_B : 1'bx);
123
        wire QA_NE_B = (C_HAS_QA_NE_B == 1 ? intQA_NE_B : 1'bx);
124
        wire QA_LT_B = (C_HAS_QA_LT_B == 1 ? intQA_LT_B : 1'bx);
125
        wire QA_GT_B = (C_HAS_QA_GT_B == 1 ? intQA_GT_B : 1'bx);
126
        wire QA_LE_B = (C_HAS_QA_LE_B == 1 ? intQA_LE_B : 1'bx);
127
        wire QA_GE_B = (C_HAS_QA_GE_B == 1 ? intQA_GE_B : 1'bx);
128
 
129
        integer pipe, notdone, i;
130
 
131
        reg aeqb, aneb, altb, agtb, aleb, ageb;
132
        reg [C_WIDTH-1:0] a_low;
133
        reg [C_WIDTH-1:0] a_high;
134
        reg [C_WIDTH-1:0] b_low;
135
        reg [C_WIDTH-1:0] b_high;
136
 
137
        // Instance the required output regs
138
                C_REG_FD_V3_0 #(C_AINIT_VAL, C_ENABLE_RLOCS, C_HAS_ACLR, 0, C_HAS_ASET,
139
                                   C_HAS_CE, C_HAS_SCLR, 0, C_HAS_SSET,
140
                                   "0", C_SYNC_ENABLE, C_SYNC_PRIORITY, 1)
141
                        regaeqb (.D(intQA_EQ_Bpipeend), .CLK(CLK), .CE(CE), .ACLR(ACLR), .ASET(ASET),
142
                                  .AINIT(AINIT), .SCLR(SCLR), .SSET(SSET), .SINIT(SINIT),
143
                                  .Q(intQA_EQ_B));
144
 
145
                C_REG_FD_V3_0 #(C_AINIT_VAL, C_ENABLE_RLOCS, C_HAS_ACLR, 0, C_HAS_ASET,
146
                                   C_HAS_CE, C_HAS_SCLR, 0, C_HAS_SSET,
147
                                   "0", C_SYNC_ENABLE, C_SYNC_PRIORITY, 1)
148
                        reganeb (.D(intQA_NE_Bpipeend), .CLK(CLK), .CE(CE), .ACLR(ACLR), .ASET(ASET),
149
                                  .AINIT(AINIT), .SCLR(SCLR), .SSET(SSET), .SINIT(SINIT),
150
                                  .Q(intQA_NE_B));
151
 
152
                C_REG_FD_V3_0 #(C_AINIT_VAL, C_ENABLE_RLOCS, C_HAS_ACLR, 0, C_HAS_ASET,
153
                                   C_HAS_CE, C_HAS_SCLR, 0, C_HAS_SSET,
154
                                   "0", C_SYNC_ENABLE, C_SYNC_PRIORITY, 1)
155
                        regaltb (.D(intQA_LT_Bpipeend), .CLK(CLK), .CE(CE), .ACLR(ACLR), .ASET(ASET),
156
                                  .AINIT(AINIT), .SCLR(SCLR), .SSET(SSET), .SINIT(SINIT),
157
                                  .Q(intQA_LT_B));
158
 
159
                C_REG_FD_V3_0 #(C_AINIT_VAL, C_ENABLE_RLOCS, C_HAS_ACLR, 0, C_HAS_ASET,
160
                                   C_HAS_CE, C_HAS_SCLR, 0, C_HAS_SSET,
161
                                   "0", C_SYNC_ENABLE, C_SYNC_PRIORITY, 1)
162
                        regagtb (.D(intQA_GT_Bpipeend), .CLK(CLK), .CE(CE), .ACLR(ACLR), .ASET(ASET),
163
                                  .AINIT(AINIT), .SCLR(SCLR), .SSET(SSET), .SINIT(SINIT),
164
                                  .Q(intQA_GT_B));
165
 
166
                C_REG_FD_V3_0 #(C_AINIT_VAL, C_ENABLE_RLOCS, C_HAS_ACLR, 0, C_HAS_ASET,
167
                                   C_HAS_CE, C_HAS_SCLR, 0, C_HAS_SSET,
168
                                   "0", C_SYNC_ENABLE, C_SYNC_PRIORITY, 1)
169
                        regaleb (.D(intQA_LE_Bpipeend), .CLK(CLK), .CE(CE), .ACLR(ACLR), .ASET(ASET),
170
                                  .AINIT(AINIT), .SCLR(SCLR), .SSET(SSET), .SINIT(SINIT),
171
                                  .Q(intQA_LE_B));
172
 
173
                C_REG_FD_V3_0 #(C_AINIT_VAL, C_ENABLE_RLOCS, C_HAS_ACLR, 0, C_HAS_ASET,
174
                                   C_HAS_CE, C_HAS_SCLR, 0, C_HAS_SSET,
175
                                   "0", C_SYNC_ENABLE, C_SYNC_PRIORITY, 1)
176
                        regageb (.D(intQA_GE_Bpipeend), .CLK(CLK), .CE(CE), .ACLR(ACLR), .ASET(ASET),
177
                                  .AINIT(AINIT), .SCLR(SCLR), .SSET(SSET), .SINIT(SINIT),
178
                                  .Q(intQA_GE_B));
179
 
180
        initial
181
        begin
182
                #1;
183
                intCE = defval(CE, C_HAS_CE, 1);
184
                intB = defvecval(B, (C_B_CONSTANT == 1) ? 0 : 1, to_bits(C_B_VALUE));
185
 
186
                intQA_EQ_Bpipe = 'b0;
187
                intQA_NE_Bpipe = 'b0;
188
                intQA_LT_Bpipe = 'b0;
189
                intQA_GT_Bpipe = 'b0;
190
                intQA_LE_Bpipe = 'b0;
191
                intQA_GE_Bpipe = 'b0;
192
 
193
                if(is_X(A) == 1 || is_X(intB) == 1)
194
                begin
195
                        notdone = 1;
196
                        if((is_X(A) && A === {C_WIDTH{1'bx}}) && (is_X(intB) && intB === {C_WIDTH{1'bx}}))
197
                        begin
198
                                aeqb <= 1'bx;
199
                                aneb <= 1'bx;
200
                                altb <= 1'bx;
201
                                agtb <= 1'bx;
202
                                aleb <= 1'bx;
203
                                ageb <= 1'bx;
204
                                notdone = 0;
205
                        end
206
                        else if(C_DATA_TYPE == `c_signed)
207
                        begin
208
/*                              if(A[C_WIDTH-1] === 1'bx && intB[C_WIDTH-1] === 1'bx)
209
                                // Don't know the sign of EITHER data => ALL X's
210
                                begin
211
                                        aeqb <= 1'bx;
212
                                        aneb <= 1'bx;
213
                                        altb <= 1'bx;
214
                                        agtb <= 1'bx;
215
                                        aleb <= 1'bx;
216
                                        ageb <= 1'bx;
217
                                        notdone = 0;
218
                                end
219
                                else if (A[C_WIDTH-1] !== 1'bx && intB[C_WIDTH-1] !== 1'bx)
220
*/                              if (A[C_WIDTH-1] !== 1'bx && intB[C_WIDTH-1] !== 1'bx)
221
                                begin
222
                                // The sign bits are both known
223
                                        if (A[C_WIDTH-1] !== intB[C_WIDTH-1])
224
                                        begin
225
                                        // different signs!
226
                                                if (A[C_WIDTH-1] === 1'b1)
227
                                                begin
228
                                                // A is negative and B is positive
229
                                                        aeqb <= 0;
230
                                                        aneb <= 1;
231
                                                        altb <= 1;
232
                                                        agtb <= 0;
233
                                                        aleb <= 1;
234
                                                        ageb <= 0;
235
                                                        notdone = 0;
236
                                                end
237
                                                else // A is +ve and B is -ve
238
                                                begin
239
                                                        aeqb <= 0;
240
                                                        aneb <= 1;
241
                                                        altb <= 0;
242
                                                        agtb <= 1;
243
                                                        aleb <= 0;
244
                                                        ageb <= 1;
245
                                                        notdone = 0;
246
                                                end
247
                                        end
248
                                end
249
                        end
250
                    if (notdone == 1) // check further  
251
                        begin
252
                        // Make copies of A and B with all X's substituted with 0's and 1's
253
                                a_low = A;
254
                                a_high = A;
255
                                b_low = intB;
256
                                b_high = intB;
257
                                for (i=C_WIDTH-2; i >= 0; i = i - 1)
258
                                begin
259
                                        if (a_low[i] === 1'bx)
260
                                        begin
261
                                                a_low[i] = 0;
262
                                                a_high[i] = 1;
263
                                        end
264
                                        if (b_low[i] === 1'bx)
265
                                        begin
266
                                                b_low[i] = 0;
267
                                                b_high[i] = 1;
268
                                        end
269
                                end
270
                                // we now (almost - need to check possible sign bits) have worst-case values which must agree on the comparison result 
271
                                // if that result is not to be unknown...
272
                                if (C_DATA_TYPE == `c_signed)
273
                                begin
274
                                        // Set the sign bits of the range values to 0 since
275
                                        // the sign of the values will be treated separately
276
                                        a_low[C_WIDTH-1] = 0;
277
                                        a_high[C_WIDTH-1] = 0;
278
                                        b_low[C_WIDTH-1] = 0;
279
                                        b_high[C_WIDTH-1] = 0;
280
 
281
                                        if((A[C_WIDTH-1] === 1'b1 && intB[C_WIDTH-1] === 1'bx)
282
                                                        || (intB[C_WIDTH-1] === 1'b0 && A[C_WIDTH-1] === 1'bx))
283
                                        begin // Sign of A is -ve and sign of B is unknown OR
284
                                                  // sign of B is +ve and sign of A is unknown
285
                                                // Is A always < B?
286
                                                if (a_high < b_low)
287
                                                begin
288
                                                // A is definitely < than B
289
                                                        aeqb <= 0;
290
                                                        aneb <= 1;
291
                                                        altb <= 1;
292
                                                        agtb <= 0;
293
                                                        aleb <= 1;
294
                                                        ageb <= 0;
295
                                                end
296
                                                else if (a_high == b_low)
297
                                                begin
298
                                                // A is <= than B
299
                                                        aeqb <= 1'bx;
300
                                                        aneb <= 1'bx;
301
                                                        altb <= 1'bx;
302
                                                        agtb <= 0;
303
                                                        aleb <= 1;
304
                                                        ageb <= 1'bx;
305
                                                end
306
                                                else if (a_low != b_low && a_low !== b_high && a_high !== b_low && a_high !== b_high && !(intB === {C_WIDTH{1'bx}} || A === {C_WIDTH{1'bx}}))
307
                                                begin // Definitely not equal!
308
                                                        aeqb <= 1'b0;
309
                                                        aneb <= 1'b1;
310
                                                        altb <= 1'bx;
311
                                                        agtb <= 1'bx;
312
                                                        aleb <= 1'bx;
313
                                                        ageb <= 1'bx;
314
                                                end
315
                                                else // There is > 1 overlap between the ranges so all X's
316
                                                begin
317
                                                        aeqb <= 1'bx;
318
                                                        aneb <= 1'bx;
319
                                                        altb <= 1'bx;
320
                                                        agtb <= 1'bx;
321
                                                        aleb <= 1'bx;
322
                                                        ageb <= 1'bx;
323
                                                end
324
                                        end
325
                                        else if((A[C_WIDTH-1] === 1'b0 && intB[C_WIDTH-1] === 1'bx)
326
                                                        || (intB[C_WIDTH-1] === 1'b1 && A[C_WIDTH-1] === 1'bx))
327
                                        begin // Sign of A is +ve and sign of B is unknown OR
328
                                                  // sign of B is -ve and sign of A is unknown
329
                                                // Is B always < A?
330
                                                if (b_high < a_low)
331
                                                begin
332
                                                // B is definitely < than A
333
                                                        aeqb <= 0;
334
                                                        aneb <= 1;
335
                                                        altb <= 0;
336
                                                        agtb <= 1;
337
                                                        aleb <= 0;
338
                                                        ageb <= 1;
339
                                                end
340
                                                else if (b_high == a_low)
341
                                                begin
342
                                                // B is <= than A
343
                                                        aeqb <= 1'bx;
344
                                                        aneb <= 1'bx;
345
                                                        altb <= 0;
346
                                                        agtb <= 1'bx;
347
                                                        aleb <= 1'bx;
348
                                                        ageb <= 1;
349
                                                end
350
                                                else if (a_low != b_low && a_low !== b_high && a_high !== b_low && a_high !== b_high && !(intB === {C_WIDTH{1'bx}} || A === {C_WIDTH{1'bx}}))
351
                                                begin // Definitely not equal!
352
                                                        aeqb <= 1'b0;
353
                                                        aneb <= 1'b1;
354
                                                        altb <= 1'bx;
355
                                                        agtb <= 1'bx;
356
                                                        aleb <= 1'bx;
357
                                                        ageb <= 1'bx;
358
                                                end
359
                                                else // There is > 1 overlap between the ranges so all X's
360
                                                begin
361
                                                        aeqb <= 1'bx;
362
                                                        aneb <= 1'bx;
363
                                                        altb <= 1'bx;
364
                                                        agtb <= 1'bx;
365
                                                        aleb <= 1'bx;
366
                                                        ageb <= 1'bx;
367
                                                end
368
                                        end
369
                                        else // Sign bits on A and B are identical and both are known
370
                                        begin
371
                                                if (a_high < b_low)
372
                                                begin
373
                                                // A is definitely < than B
374
                                                        aeqb <= 0;
375
                                                        aneb <= 1;
376
                                                        altb <= 1;
377
                                                        agtb <= 0;
378
                                                        aleb <= 1;
379
                                                        ageb <= 0;
380
                                                end
381
                                                else if (a_low > b_high)
382
                                                begin
383
                                                // A is definitely > than B
384
                                                        aeqb <= 0;
385
                                                        aneb <= 1;
386
                                                        altb <= 0;
387
                                                        agtb <= 1;
388
                                                        aleb <= 0;
389
                                                        ageb <= 1;
390
                                                end
391
                                                else if (a_high == b_low)
392
                                                begin
393
                                                // A is <= than B
394
                                                        aeqb <= 1'bx;
395
                                                        aneb <= 1'bx;
396
                                                        altb <= 1'bx;
397
                                                        agtb <= 0;
398
                                                        aleb <= 1;
399
                                                        ageb <= 1'bx;
400
                                                end
401
                                                else if (a_low == b_high)
402
                                                begin
403
                                                // A is >= than B
404
                                                        aeqb <= 1'bx;
405
                                                        aneb <= 1'bx;
406
                                                        altb <= 0;
407
                                                        agtb <= 1'bx;
408
                                                        aleb <= 1'bx;
409
                                                        ageb <= 1;
410
                                                end
411
                                                else if (a_low != b_low && a_low !== b_high && a_high !== b_low && a_high !== b_high && !(intB === {C_WIDTH{1'bx}} || A === {C_WIDTH{1'bx}}))
412
                                                begin // Definitely not equal!
413
                                                        aeqb <= 1'b0;
414
                                                        aneb <= 1'b1;
415
                                                        altb <= 1'bx;
416
                                                        agtb <= 1'bx;
417
                                                        aleb <= 1'bx;
418
                                                        ageb <= 1'bx;
419
                                                end
420
                                                else // There is > 1 overlap between the ranges so all X's
421
                                                begin
422
                                                        aeqb <= 1'bx;
423
                                                        aneb <= 1'bx;
424
                                                        altb <= 1'bx;
425
                                                        agtb <= 1'bx;
426
                                                        aleb <= 1'bx;
427
                                                        ageb <= 1'bx;
428
                                                end
429
                                        end
430
                                end
431
                                else // unsigned data
432
                                begin
433
                                        if (a_low[C_WIDTH-1] === 1'bx)
434
                                        begin
435
                                                a_low[C_WIDTH-1] = 0;
436
                                                a_high[C_WIDTH-1] = 1;
437
                                        end
438
                                        if (b_low[C_WIDTH-1] === 1'bx)
439
                                        begin
440
                                                b_low[C_WIDTH-1] = 0;
441
                                                b_high[C_WIDTH-1] = 1;
442
                                        end
443
                                        if (a_high < b_low)
444
                                        begin
445
                                        // A is definitely < than B
446
                                                aeqb <= 0;
447
                                                aneb <= 1;
448
                                                altb <= 1;
449
                                                agtb <= 0;
450
                                                aleb <= 1;
451
                                                ageb <= 0;
452
                                        end
453
                                        else if (a_low > b_high)
454
                                        begin
455
                                        // A is definitely > than B     
456
                                                aeqb <= 0;
457
                                                aneb <= 1;
458
                                                altb <= 0;
459
                                                agtb <= 1;
460
                                                aleb <= 0;
461
                                                ageb <= 1;
462
                                        end
463
                                        else if (a_high == b_low)
464
                                        begin
465
                                        // A is <= B
466
                                                aeqb <= 1'bx;
467
                                                aneb <= 1'bx;
468
                                                altb <= 1'bx;
469
                                                agtb <= 0;
470
                                                aleb <= 1;
471
                                                ageb <= 1'bx;
472
                                        end
473
                                        else if (a_low == b_high)
474
                                        begin
475
                                        // A is >= B
476
                                                aeqb <= 1'bx;
477
                                                aneb <= 1'bx;
478
                                                altb <= 0;
479
                                                agtb <= 1'bx;
480
                                                aleb <= 1'bx;
481
                                                ageb <= 1;
482
                                        end
483
                                                else if (a_low != b_low && a_low !== b_high && a_high !== b_low && a_high !== b_high && !(intB === {C_WIDTH{1'bx}} || A === {C_WIDTH{1'bx}}))
484
                                                begin // Definitely not equal!
485
                                                        aeqb <= 1'b0;
486
                                                        aneb <= 1'b1;
487
                                                        altb <= 1'bx;
488
                                                        agtb <= 1'bx;
489
                                                        aleb <= 1'bx;
490
                                                        ageb <= 1'bx;
491
                                                end
492
                                        else // There is > 1 overlap between the ranges so all X's
493
                                        begin
494
                                                aeqb <= 1'bx;
495
                                                aneb <= 1'bx;
496
                                                altb <= 1'bx;
497
                                                agtb <= 1'bx;
498
                                                aleb <= 1'bx;
499
                                                ageb <= 1'bx;
500
                                        end
501
                                end
502
                        end
503
                end
504
                else if (C_DATA_TYPE == `c_signed)
505
                begin
506
                        // Signed data so examine MSB and rest separately in some cases
507
                        if(A == intB)
508
                        begin
509
                                aeqb <= 1;
510
                                aneb <= 0;
511
                                altb <= 0;
512
                                agtb <= 0;
513
                        end
514
                        else if(A[C_WIDTH-1] == intB[C_WIDTH-1]) // Both numbers are -ve or both are +ve
515
                        begin
516
                                if(A < intB)
517
                                begin
518
                                        aeqb <= 0;
519
                                        aneb <= 1;
520
                                        altb <= 1;
521
                                        agtb <= 0;
522
                                end
523
                                if(A > intB)
524
                                begin
525
                                        aeqb <= 0;
526
                                        aneb <= 1;
527
                                        altb <= 0;
528
                                        agtb <= 1;
529
                                end
530
                        end
531
                        else if(A[C_WIDTH-1] == 1 && intB[C_WIDTH-1] == 0) // A is -ve, B is +ve
532
                        begin
533
                                aeqb <= 0;
534
                                aneb <= 1;
535
                                altb <= 1;
536
                                agtb <= 0;
537
                        end
538
                        else if(A[C_WIDTH-1] == 0 && intB[C_WIDTH-1] == 1) // A is +ve, B is -ve
539
                        begin
540
                                aeqb <= 0;
541
                                aneb <= 1;
542
                                altb <= 0;
543
                                agtb <= 1;
544
                        end
545
                        if(aeqb == 1 || altb == 1)
546
                                aleb <= 1;
547
                        else
548
                                aleb <= 0;
549
                        if(aeqb == 1 || agtb == 1)
550
                                ageb <= 1;
551
                        else
552
                                ageb <= 0;
553
                end
554
                else // Data is unsigned
555
                begin
556
                        if(A == intB)
557
                        begin
558
                                aeqb <= 1;
559
                                aneb <= 0;
560
                                altb <= 0;
561
                                agtb <= 0;
562
                        end
563
                        if(A < intB)
564
                        begin
565
                                aeqb <= 0;
566
                                aneb <= 1;
567
                                altb <= 1;
568
                                agtb <= 0;
569
                        end
570
                        if(A > intB)
571
                        begin
572
                                aeqb <= 0;
573
                                aneb <= 1;
574
                                altb <= 0;
575
                                agtb <= 1;
576
                        end
577
                        if(aeqb == 1 || altb == 1)
578
                                aleb <= 1;
579
                        else
580
                                aleb <= 0;
581
                        if(aeqb == 1 || agtb == 1)
582
                                ageb <= 1;
583
                        else
584
                                ageb <= 0;
585
                end
586
 
587
                intA_EQ_B <= #1 aeqb;
588
                intA_NE_B <= #1 aneb;
589
                intA_LT_B <= #1 altb;
590
                intA_GT_B <= #1 agtb;
591
                intA_LE_B <= #1 aleb;
592
                intA_GE_B <= #1 ageb;
593
 
594
        end
595
 
596
        always @(CLK)
597
                lastCLK <= CLK;
598
 
599
        always @(A or B or CE or ACLR or ASET or SCLR or SSET)
600
        begin
601
                intCE = defval(CE, C_HAS_CE, 1);
602
                intB = defvecval(B, (C_B_CONSTANT == 1) ? 0 : 1, to_bits(C_B_VALUE));
603
 
604
                if(is_X(A) == 1 || is_X(intB) == 1)
605
                begin
606
                        notdone = 1;
607
                        if((is_X(A) && A === {C_WIDTH{1'bx}}) && (is_X(intB) && intB === {C_WIDTH{1'bx}}))
608
                        begin
609
                                aeqb = 1'bx;
610
                                aneb = 1'bx;
611
                                altb = 1'bx;
612
                                agtb = 1'bx;
613
                                aleb = 1'bx;
614
                                ageb = 1'bx;
615
                                notdone = 0;
616
                        end
617
                        else if(C_DATA_TYPE == `c_signed)
618
                        begin
619
/*                              if(A[C_WIDTH-1] === 1'bx && intB[C_WIDTH-1] === 1'bx)
620
                                // Don't know the sign of EITHER data => ALL X's
621
                                begin
622
                                        aeqb = 1'bx;
623
                                        aneb = 1'bx;
624
                                        altb = 1'bx;
625
                                        agtb = 1'bx;
626
                                        aleb = 1'bx;
627
                                        ageb = 1'bx;
628
                                        notdone = 0;
629
                                end
630
                                else if (A[C_WIDTH-1] !== 1'bx && intB[C_WIDTH-1] !== 1'bx)
631
*/                              if (A[C_WIDTH-1] !== 1'bx && intB[C_WIDTH-1] !== 1'bx)
632
                                begin
633
                                // The sign bits are both known
634
                                        if (A[C_WIDTH-1] !== intB[C_WIDTH-1])
635
                                        begin
636
                                        // different signs!
637
                                                if (A[C_WIDTH-1] === 1'b1)
638
                                                begin
639
                                                // A is negative and B is positive
640
                                                        aeqb = 0;
641
                                                        aneb = 1;
642
                                                        altb = 1;
643
                                                        agtb = 0;
644
                                                        aleb = 1;
645
                                                        ageb = 0;
646
                                                        notdone = 0;
647
                                                end
648
                                                else // A is +ve and B is -ve
649
                                                begin
650
                                                        aeqb = 0;
651
                                                        aneb = 1;
652
                                                        altb = 0;
653
                                                        agtb = 1;
654
                                                        aleb = 0;
655
                                                        ageb = 1;
656
                                                        notdone = 0;
657
                                                end
658
                                        end
659
                                end
660
                        end
661
                    if (notdone == 1) // check further  
662
                        begin
663
                        // Make copies of A and B with all X's substituted with 0's and 1's
664
                                a_low = A;
665
                                a_high = A;
666
                                b_low = intB;
667
                                b_high = intB;
668
                                for (i=C_WIDTH-2; i >= 0; i = i - 1)
669
                                begin
670
                                        if (a_low[i] === 1'bx)
671
                                        begin
672
                                                a_low[i] = 0;
673
                                                a_high[i] = 1;
674
                                        end
675
                                        if (b_low[i] === 1'bx)
676
                                        begin
677
                                                b_low[i] = 0;
678
                                                b_high[i] = 1;
679
                                        end
680
                                end
681
                                // we now (almost - need to check possible sign bits) have worst-case values which must agree on the comparison result 
682
                                // if that result is not to be unknown...
683
                                if (C_DATA_TYPE == `c_signed)
684
                                begin
685
                                        // Set the sign bits of the range values to 0 since
686
                                        // the sign of the values will be treated separately
687
                                        a_low[C_WIDTH-1] = 0;
688
                                        a_high[C_WIDTH-1] = 0;
689
                                        b_low[C_WIDTH-1] = 0;
690
                                        b_high[C_WIDTH-1] = 0;
691
 
692
                                        if((A[C_WIDTH-1] === 1'b1 && intB[C_WIDTH-1] === 1'bx)
693
                                                        || (intB[C_WIDTH-1] === 1'b0 && A[C_WIDTH-1] === 1'bx))
694
                                        begin // Sign of A is -ve and sign of B is unknown OR
695
                                                  // sign of B is +ve and sign of A is unknown
696
                                                // Is A always < B?
697
                                                if (a_high < b_low)
698
                                                begin
699
                                                // A is definitely < than B
700
                                                        aeqb = 0;
701
                                                        aneb = 1;
702
                                                        altb = 1;
703
                                                        agtb = 0;
704
                                                        aleb = 1;
705
                                                        ageb = 0;
706
                                                end
707
                                                else if (a_high == b_low)
708
                                                begin
709
                                                // A is <= than B
710
                                                        aeqb = 1'bx;
711
                                                        aneb = 1'bx;
712
                                                        altb = 1'bx;
713
                                                        agtb = 0;
714
                                                        aleb = 1;
715
                                                        ageb = 1'bx;
716
                                                end
717
                                                else if (a_low != b_low && a_low !== b_high && a_high !== b_low && a_high !== b_high && !(intB === {C_WIDTH{1'bx}} || A === {C_WIDTH{1'bx}}))
718
                                                begin // Definitely not equal!
719
                                                        aeqb = 1'b0;
720
                                                        aneb = 1'b1;
721
                                                        altb = 1'bx;
722
                                                        agtb = 1'bx;
723
                                                        aleb = 1'bx;
724
                                                        ageb = 1'bx;
725
                                                end
726
                                                else // There is > 1 overlap between the ranges so all X's
727
                                                begin
728
                                                        aeqb = 1'bx;
729
                                                        aneb = 1'bx;
730
                                                        altb = 1'bx;
731
                                                        agtb = 1'bx;
732
                                                        aleb = 1'bx;
733
                                                        ageb = 1'bx;
734
                                                end
735
                                        end
736
                                        else if((A[C_WIDTH-1] === 1'b0 && intB[C_WIDTH-1] === 1'bx)
737
                                                        || (intB[C_WIDTH-1] === 1'b1 && A[C_WIDTH-1] === 1'bx))
738
                                        begin // Sign of A is +ve and sign of B is unknown OR
739
                                                  // sign of B is -ve and sign of A is unknown
740
                                                // Is B always < A?
741
                                                if (b_high < a_low)
742
                                                begin
743
                                                // B is definitely < than A
744
                                                        aeqb = 0;
745
                                                        aneb = 1;
746
                                                        altb = 0;
747
                                                        agtb = 1;
748
                                                        aleb = 0;
749
                                                        ageb = 1;
750
                                                end
751
                                                else if (b_high == a_low)
752
                                                begin
753
                                                // B is <= than A
754
                                                        aeqb = 1'bx;
755
                                                        aneb = 1'bx;
756
                                                        altb = 0;
757
                                                        agtb = 1'bx;
758
                                                        aleb = 1'bx;
759
                                                        ageb = 1;
760
                                                end
761
                                                else if (a_low != b_low && a_low !== b_high && a_high !== b_low && a_high !== b_high && !(intB === {C_WIDTH{1'bx}} || A === {C_WIDTH{1'bx}}))
762
                                                begin // Definitely not equal!
763
                                                        aeqb = 1'b0;
764
                                                        aneb = 1'b1;
765
                                                        altb = 1'bx;
766
                                                        agtb = 1'bx;
767
                                                        aleb = 1'bx;
768
                                                        ageb = 1'bx;
769
                                                end
770
                                                else // There is > 1 overlap between the ranges so all X's
771
                                                begin
772
                                                        aeqb = 1'bx;
773
                                                        aneb = 1'bx;
774
                                                        altb = 1'bx;
775
                                                        agtb = 1'bx;
776
                                                        aleb = 1'bx;
777
                                                        ageb = 1'bx;
778
                                                end
779
                                        end
780
                                        else // Sign bits on A and B are identical and both are known
781
                                        begin
782
                                                if (a_high < b_low)
783
                                                begin
784
                                                // A is definitely < than B
785
                                                        aeqb = 0;
786
                                                        aneb = 1;
787
                                                        altb = 1;
788
                                                        agtb = 0;
789
                                                        aleb = 1;
790
                                                        ageb = 0;
791
                                                end
792
                                                else if (a_low > b_high)
793
                                                begin
794
                                                // A is definitely > than B
795
                                                        aeqb = 0;
796
                                                        aneb = 1;
797
                                                        altb = 0;
798
                                                        agtb = 1;
799
                                                        aleb = 0;
800
                                                        ageb = 1;
801
                                                end
802
                                                else if (a_high == b_low)
803
                                                begin
804
                                                // A is <= than B
805
                                                        aeqb = 1'bx;
806
                                                        aneb = 1'bx;
807
                                                        altb = 1'bx;
808
                                                        agtb = 0;
809
                                                        aleb = 1;
810
                                                        ageb = 1'bx;
811
                                                end
812
                                                else if (a_low == b_high)
813
                                                begin
814
                                                // A is >= than B
815
                                                        aeqb = 1'bx;
816
                                                        aneb = 1'bx;
817
                                                        altb = 0;
818
                                                        agtb = 1'bx;
819
                                                        aleb = 1'bx;
820
                                                        ageb = 1;
821
                                                end
822
                                                else if (a_low != b_low && a_low !== b_high && a_high !== b_low && a_high !== b_high && !(intB === {C_WIDTH{1'bx}} || A === {C_WIDTH{1'bx}}))
823
                                                begin // Definitely not equal!
824
                                                        aeqb = 1'b0;
825
                                                        aneb = 1'b1;
826
                                                        altb = 1'bx;
827
                                                        agtb = 1'bx;
828
                                                        aleb = 1'bx;
829
                                                        ageb = 1'bx;
830
                                                end
831
                                                else // There is > 1 overlap between the ranges so all X's
832
                                                begin
833
                                                        aeqb = 1'bx;
834
                                                        aneb = 1'bx;
835
                                                        altb = 1'bx;
836
                                                        agtb = 1'bx;
837
                                                        aleb = 1'bx;
838
                                                        ageb = 1'bx;
839
                                                end
840
                                        end
841
                                end
842
                                else // unsigned data
843
                                begin
844
                                        if (a_low[C_WIDTH-1] === 1'bx)
845
                                        begin
846
                                                a_low[C_WIDTH-1] = 0;
847
                                                a_high[C_WIDTH-1] = 1;
848
                                        end
849
                                        if (b_low[C_WIDTH-1] === 1'bx)
850
                                        begin
851
                                                b_low[C_WIDTH-1] = 0;
852
                                                b_high[C_WIDTH-1] = 1;
853
                                        end
854
                                        if (a_high < b_low)
855
                                        begin
856
                                        // A is definitely < than B
857
                                                aeqb = 0;
858
                                                aneb = 1;
859
                                                altb = 1;
860
                                                agtb = 0;
861
                                                aleb = 1;
862
                                                ageb = 0;
863
                                        end
864
                                        else if (a_low > b_high)
865
                                        begin
866
                                        // A is definitely > than B     
867
                                                aeqb = 0;
868
                                                aneb = 1;
869
                                                altb = 0;
870
                                                agtb = 1;
871
                                                aleb = 0;
872
                                                ageb = 1;
873
                                        end
874
                                        else if (a_high == b_low)
875
                                        begin
876
                                        // A is <= B
877
                                                aeqb = 1'bx;
878
                                                aneb = 1'bx;
879
                                                altb = 1'bx;
880
                                                agtb = 0;
881
                                                aleb = 1;
882
                                                ageb = 1'bx;
883
                                        end
884
                                        else if (a_low == b_high)
885
                                        begin
886
                                        // A is >= B
887
                                                aeqb = 1'bx;
888
                                                aneb = 1'bx;
889
                                                altb = 0;
890
                                                agtb = 1'bx;
891
                                                aleb = 1'bx;
892
                                                ageb = 1;
893
                                        end
894
                                                else if (a_low != b_low && a_low !== b_high && a_high !== b_low && a_high !== b_high && !(intB === {C_WIDTH{1'bx}} || A === {C_WIDTH{1'bx}}))
895
                                                begin // Definitely not equal!
896
                                                        aeqb = 1'b0;
897
                                                        aneb = 1'b1;
898
                                                        altb = 1'bx;
899
                                                        agtb = 1'bx;
900
                                                        aleb = 1'bx;
901
                                                        ageb = 1'bx;
902
                                                end
903
                                        else // There is > 1 overlap between the ranges so all X's
904
                                        begin
905
                                                aeqb = 1'bx;
906
                                                aneb = 1'bx;
907
                                                altb = 1'bx;
908
                                                agtb = 1'bx;
909
                                                aleb = 1'bx;
910
                                                ageb = 1'bx;
911
                                        end
912
                                end
913
                        end
914
                end
915
                else if (C_DATA_TYPE == `c_signed)
916
                begin
917
                        // Signed data so examine MSB and rest separately in some cases
918
                        if(A == intB)
919
                        begin
920
                                aeqb = 1;
921
                                aneb = 0;
922
                                altb = 0;
923
                                agtb = 0;
924
                        end
925
                        else if(A[C_WIDTH-1] == intB[C_WIDTH-1]) // Both numbers are -ve or both are +ve
926
                        begin
927
                                if(A < intB)
928
                                begin
929
                                        aeqb = 0;
930
                                        aneb = 1;
931
                                        altb = 1;
932
                                        agtb = 0;
933
                                end
934
                                if(A > intB)
935
                                begin
936
                                        aeqb = 0;
937
                                        aneb = 1;
938
                                        altb = 0;
939
                                        agtb = 1;
940
                                end
941
                        end
942
                        else if(A[C_WIDTH-1] == 1 && intB[C_WIDTH-1] == 0) // A is -ve, B is +ve
943
                        begin
944
                                aeqb = 0;
945
                                aneb = 1;
946
                                altb = 1;
947
                                agtb = 0;
948
                        end
949
                        else if(A[C_WIDTH-1] == 0 && intB[C_WIDTH-1] == 1) // A is +ve, B is -ve
950
                        begin
951
                                aeqb = 0;
952
                                aneb = 1;
953
                                altb = 0;
954
                                agtb = 1;
955
                        end
956
                        if(aeqb == 1 || altb == 1)
957
                                aleb = 1;
958
                        else
959
                                aleb = 0;
960
                        if(aeqb == 1 || agtb == 1)
961
                                ageb = 1;
962
                        else
963
                                ageb = 0;
964
                end
965
                else // Data is unsigned
966
                begin
967
                        if(A == intB)
968
                        begin
969
                                aeqb = 1;
970
                                aneb = 0;
971
                                altb = 0;
972
                                agtb = 0;
973
                        end
974
                        if(A < intB)
975
                        begin
976
                                aeqb = 0;
977
                                aneb = 1;
978
                                altb = 1;
979
                                agtb = 0;
980
                        end
981
                        if(A > intB)
982
                        begin
983
                                aeqb = 0;
984
                                aneb = 1;
985
                                altb = 0;
986
                                agtb = 1;
987
                        end
988
                        if(aeqb == 1 || altb == 1)
989
                                aleb = 1;
990
                        else
991
                                aleb = 0;
992
                        if(aeqb == 1 || agtb == 1)
993
                                ageb = 1;
994
                        else
995
                                ageb = 0;
996
                end
997
 
998
                intA_EQ_B <= #1 aeqb;
999
                intA_NE_B <= #1 aneb;
1000
                intA_LT_B <= #1 altb;
1001
                intA_GT_B <= #1 agtb;
1002
                intA_LE_B <= #1 aleb;
1003
                intA_GE_B <= #1 ageb;
1004
        end
1005
 
1006
        always@(posedge CLK)
1007
        begin
1008
                if(CLK === 1'b1 && lastCLK === 1'b0 && intCE === 1'b1) // OK! Update pipelines!
1009
                begin
1010
                        for(pipe = 2; pipe <= C_PIPE_STAGES-1; pipe = pipe + 1)
1011
                        begin
1012
                                intQA_EQ_Bpipe[pipe] <= intQA_EQ_Bpipe[pipe+1];
1013
                                intQA_NE_Bpipe[pipe] <= intQA_NE_Bpipe[pipe+1];
1014
                                intQA_LT_Bpipe[pipe] <= intQA_LT_Bpipe[pipe+1];
1015
                                intQA_GT_Bpipe[pipe] <= intQA_GT_Bpipe[pipe+1];
1016
                                intQA_LE_Bpipe[pipe] <= intQA_LE_Bpipe[pipe+1];
1017
                                intQA_GE_Bpipe[pipe] <= intQA_GE_Bpipe[pipe+1];
1018
                        end
1019
                        intQA_EQ_Bpipe[C_PIPE_STAGES] <= intA_EQ_B;
1020
                        intQA_NE_Bpipe[C_PIPE_STAGES] <= intA_NE_B;
1021
                        intQA_LT_Bpipe[C_PIPE_STAGES] <= intA_LT_B;
1022
                        intQA_GT_Bpipe[C_PIPE_STAGES] <= intA_GT_B;
1023
                        intQA_LE_Bpipe[C_PIPE_STAGES] <= intA_LE_B;
1024
                        intQA_GE_Bpipe[C_PIPE_STAGES] <= intA_GE_B;
1025
                end
1026
                else if((CLK === 1'bx && lastCLK === 1'b0) || (CLK === 1'b1 && lastCLK === 1'bx) || intCE === 1'bx) // POSSIBLY Update pipelines!
1027
                begin
1028
                        for(pipe = 2; pipe <= C_PIPE_STAGES-1; pipe = pipe + 1)
1029
                        begin
1030
                                if(intQA_EQ_Bpipe[pipe] !== intQA_EQ_Bpipe[pipe+1])
1031
                                        intQA_EQ_Bpipe[pipe] <= 1'bx;
1032
                                if(intQA_NE_Bpipe[pipe] !== intQA_NE_Bpipe[pipe+1])
1033
                                        intQA_NE_Bpipe[pipe] <= 1'bx;
1034
                                if(intQA_LT_Bpipe[pipe] !== intQA_LT_Bpipe[pipe+1])
1035
                                        intQA_LT_Bpipe[pipe] <= 1'bx;
1036
                                if(intQA_GT_Bpipe[pipe] !== intQA_GT_Bpipe[pipe+1])
1037
                                        intQA_GT_Bpipe[pipe] <= 1'bx;
1038
                                if(intQA_LE_Bpipe[pipe] !== intQA_LE_Bpipe[pipe+1])
1039
                                        intQA_LE_Bpipe[pipe] <= 1'bx;
1040
                                if(intQA_GE_Bpipe[pipe] !== intQA_GE_Bpipe[pipe+1])
1041
                                        intQA_GE_Bpipe[pipe] <= 1'bx;
1042
                        end
1043
                        if(intQA_EQ_Bpipe[C_PIPE_STAGES] !== intA_EQ_B)
1044
                                intQA_EQ_Bpipe[C_PIPE_STAGES] <= 1'bx;
1045
                        if(intQA_NE_Bpipe[C_PIPE_STAGES] !== intA_NE_B)
1046
                                intQA_NE_Bpipe[C_PIPE_STAGES] <= 1'bx;
1047
                        if(intQA_LT_Bpipe[C_PIPE_STAGES] !== intA_LT_B)
1048
                                intQA_LT_Bpipe[C_PIPE_STAGES] <= 1'bx;
1049
                        if(intQA_GT_Bpipe[C_PIPE_STAGES] !== intA_GT_B)
1050
                                intQA_GT_Bpipe[C_PIPE_STAGES] <= 1'bx;
1051
                        if(intQA_LE_Bpipe[C_PIPE_STAGES] !== intA_LE_B)
1052
                                intQA_LE_Bpipe[C_PIPE_STAGES] <= 1'bx;
1053
                        if(intQA_GE_Bpipe[C_PIPE_STAGES] !== intA_GE_B)
1054
                                intQA_GE_Bpipe[C_PIPE_STAGES] <= 1'bx;
1055
                end
1056
        end
1057
 
1058
        always@(intA_EQ_B or intQA_EQ_Bpipe[2])
1059
        begin
1060
                if(C_PIPE_STAGES < 2) // No pipeline
1061
                        intQA_EQ_Bpipeend <= intA_EQ_B;
1062
                else // Pipeline stages required
1063
                begin
1064
                        intQA_EQ_Bpipeend <= intQA_EQ_Bpipe[2];
1065
                end
1066
        end
1067
        always@(intA_NE_B or intQA_NE_Bpipe[2])
1068
        begin
1069
                if(C_PIPE_STAGES < 2) // No pipeline
1070
                        intQA_NE_Bpipeend <= intA_NE_B;
1071
                else // Pipeline stages required
1072
                begin
1073
                        intQA_NE_Bpipeend <= intQA_NE_Bpipe[2];
1074
                end
1075
        end
1076
        always@(intA_LT_B or intQA_LT_Bpipe[2])
1077
        begin
1078
                if(C_PIPE_STAGES < 2) // No pipeline
1079
                        intQA_LT_Bpipeend <= intA_LT_B;
1080
                else // Pipeline stages required
1081
                begin
1082
                        intQA_LT_Bpipeend <= intQA_LT_Bpipe[2];
1083
                end
1084
        end
1085
        always@(intA_GT_B or intQA_GT_Bpipe[2])
1086
        begin
1087
                if(C_PIPE_STAGES < 2) // No pipeline
1088
                        intQA_GT_Bpipeend <= intA_GT_B;
1089
                else // Pipeline stages required
1090
                begin
1091
                        intQA_GT_Bpipeend <= intQA_GT_Bpipe[2];
1092
                end
1093
        end
1094
        always@(intA_LE_B or intQA_LE_Bpipe[2])
1095
        begin
1096
                if(C_PIPE_STAGES < 2) // No pipeline
1097
                        intQA_LE_Bpipeend <= intA_LE_B;
1098
                else // Pipeline stages required
1099
                begin
1100
                        intQA_LE_Bpipeend <= intQA_LE_Bpipe[2];
1101
                end
1102
        end
1103
        always@(intA_GE_B or intQA_GE_Bpipe[2])
1104
        begin
1105
                if(C_PIPE_STAGES < 2) // No pipeline
1106
                        intQA_GE_Bpipeend <= intA_GE_B;
1107
                else // Pipeline stages required
1108
                begin
1109
                        intQA_GE_Bpipeend <= intQA_GE_Bpipe[2];
1110
                end
1111
        end
1112
 
1113
        function is_X;
1114
        input [C_WIDTH-1 : 0] i;
1115
        integer j;
1116
                begin
1117
                        is_X = 0;
1118
                        for(j = 0; j < C_WIDTH; j = j + 1)
1119
                                if(i[j] === 1'bx)
1120
                                        is_X = 1;
1121
                end
1122
        endfunction
1123
 
1124
        function defval;
1125
        input i;
1126
        input hassig;
1127
        input val;
1128
                begin
1129
                        if(hassig == 1)
1130
                                defval = i;
1131
                        else
1132
                                defval = val;
1133
                end
1134
        endfunction
1135
 
1136
        function [C_WIDTH - 1 : 0] defvecval;
1137
        input [C_WIDTH-1 : 0] i;
1138
        input hassig;
1139
        input [C_WIDTH-1 : 0] val;
1140
                begin
1141
                        if(hassig == 1)
1142
                                defvecval = i;
1143
                        else
1144
                                defvecval = val;
1145
                end
1146
        endfunction
1147
 
1148
        function [C_WIDTH - 1 : 0] to_bits;
1149
        input [C_WIDTH*8 : 1] instring;
1150
        integer i;
1151
        integer non_null_string;
1152
        begin
1153
                non_null_string = 0;
1154
                for(i = C_WIDTH; i > 0; i = i - 1)
1155
                begin // Is the string empty?
1156
                        if(instring[(i*8)] == 0 &&
1157
                                instring[(i*8)-1] == 0 &&
1158
                                instring[(i*8)-2] == 0 &&
1159
                                instring[(i*8)-3] == 0 &&
1160
                                instring[(i*8)-4] == 0 &&
1161
                                instring[(i*8)-5] == 0 &&
1162
                                instring[(i*8)-6] == 0 &&
1163
                                instring[(i*8)-7] == 0 &&
1164
                                non_null_string == 0)
1165
                                        non_null_string = 0; // Use the return value to flag a non-empty string
1166
                        else
1167
                                        non_null_string = 1; // Non-null character!
1168
                end
1169
                if(non_null_string == 0) // String IS empty! Just return the value to be all '0's
1170
                begin
1171
                        for(i = C_WIDTH; i > 0; i = i - 1)
1172
                                to_bits[i-1] = 0;
1173
                end
1174
                else
1175
                begin
1176
                        for(i = C_WIDTH; i > 0; i = i - 1)
1177
                        begin // Is this character a '0'? (ASCII = 48 = 00110000)
1178
                                if(instring[(i*8)] == 0 &&
1179
                                        instring[(i*8)-1] == 0 &&
1180
                                        instring[(i*8)-2] == 1 &&
1181
                                        instring[(i*8)-3] == 1 &&
1182
                                        instring[(i*8)-4] == 0 &&
1183
                                        instring[(i*8)-5] == 0 &&
1184
                                        instring[(i*8)-6] == 0 &&
1185
                                        instring[(i*8)-7] == 0)
1186
                                                to_bits[i-1] = 0;
1187
                                  // Or is it a '1'? 
1188
                                else if(instring[(i*8)] == 0 &&
1189
                                        instring[(i*8)-1] == 0 &&
1190
                                        instring[(i*8)-2] == 1 &&
1191
                                        instring[(i*8)-3] == 1 &&
1192
                                        instring[(i*8)-4] == 0 &&
1193
                                        instring[(i*8)-5] == 0 &&
1194
                                        instring[(i*8)-6] == 0 &&
1195
                                        instring[(i*8)-7] == 1)
1196
                                                to_bits[i-1] = 1;
1197
                                  // Or is it a ' '? (a null char - in which case insert a '0')
1198
                                else if(instring[(i*8)] == 0 &&
1199
                                        instring[(i*8)-1] == 0 &&
1200
                                        instring[(i*8)-2] == 0 &&
1201
                                        instring[(i*8)-3] == 0 &&
1202
                                        instring[(i*8)-4] == 0 &&
1203
                                        instring[(i*8)-5] == 0 &&
1204
                                        instring[(i*8)-6] == 0 &&
1205
                                        instring[(i*8)-7] == 0)
1206
                                                to_bits[i-1] = 0;
1207
                                else
1208
                                begin
1209
                                        $display("Error: non-binary digit in string \"%s\"\nExiting simulation...", instring);
1210
                                        $finish;
1211
                                end
1212
                        end
1213
                end
1214
        end
1215
        endfunction
1216
 
1217
endmodule
1218
 
1219
`undef c_set
1220
`undef c_clear
1221
`undef c_override
1222
`undef c_no_override
1223
`undef c_signed
1224
`undef c_unsigned
1225
 
1226
`endif
1227
 

powered by: WebSVN 2.1.0

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