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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [ken/] [modconst.go] - Blame information for rev 858

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// $G $D/$F.go && $L $F.$A && ./$A.out
2
 
3
// Copyright 2009 The Go Authors. All rights reserved.
4
// Use of this source code is governed by a BSD-style
5
// license that can be found in the LICENSE file.
6
 
7
package main
8
 
9
import "math/rand"
10
 
11
const Count = 1e5
12
 
13
func i64rand() int64 {
14
        for {
15
                a := int64(rand.Uint32())
16
                a = (a << 32) | int64(rand.Uint32())
17
                a >>= uint(rand.Intn(64))
18
                if -a != a {
19
                        return a
20
                }
21
        }
22
        return 0 // impossible
23
}
24
 
25
func i64test(a, b, c int64) {
26
        d := a % c
27
        if d != b {
28
                println("i64", a, b, c, d)
29
                panic("fail")
30
        }
31
}
32
 
33
func i64run() {
34
        var a, b int64
35
 
36
        for i := 0; i < Count; i++ {
37
                a = i64rand()
38
 
39
                b = a % 1
40
                i64test(a, b, 1)
41
                b = a % 2
42
                i64test(a, b, 2)
43
                b = a % 3
44
                i64test(a, b, 3)
45
                b = a % 4
46
                i64test(a, b, 4)
47
                b = a % 5
48
                i64test(a, b, 5)
49
                b = a % 6
50
                i64test(a, b, 6)
51
                b = a % 7
52
                i64test(a, b, 7)
53
                b = a % 8
54
                i64test(a, b, 8)
55
                b = a % 10
56
                i64test(a, b, 10)
57
                b = a % 16
58
                i64test(a, b, 16)
59
                b = a % 20
60
                i64test(a, b, 20)
61
                b = a % 32
62
                i64test(a, b, 32)
63
                b = a % 60
64
                i64test(a, b, 60)
65
                b = a % 64
66
                i64test(a, b, 64)
67
                b = a % 128
68
                i64test(a, b, 128)
69
                b = a % 256
70
                i64test(a, b, 256)
71
                b = a % 16384
72
                i64test(a, b, 16384)
73
 
74
                b = a % -1
75
                i64test(a, b, -1)
76
                b = a % -2
77
                i64test(a, b, -2)
78
                b = a % -3
79
                i64test(a, b, -3)
80
                b = a % -4
81
                i64test(a, b, -4)
82
                b = a % -5
83
                i64test(a, b, -5)
84
                b = a % -6
85
                i64test(a, b, -6)
86
                b = a % -7
87
                i64test(a, b, -7)
88
                b = a % -8
89
                i64test(a, b, -8)
90
                b = a % -10
91
                i64test(a, b, -10)
92
                b = a % -16
93
                i64test(a, b, -16)
94
                b = a % -20
95
                i64test(a, b, -20)
96
                b = a % -32
97
                i64test(a, b, -32)
98
                b = a % -60
99
                i64test(a, b, -60)
100
                b = a % -64
101
                i64test(a, b, -64)
102
                b = a % -128
103
                i64test(a, b, -128)
104
                b = a % -256
105
                i64test(a, b, -256)
106
                b = a % -16384
107
                i64test(a, b, -16384)
108
        }
109
}
110
 
111
func u64rand() uint64 {
112
        a := uint64(rand.Uint32())
113
        a = (a << 32) | uint64(rand.Uint32())
114
        a >>= uint(rand.Intn(64))
115
        return a
116
}
117
 
118
func u64test(a, b, c uint64) {
119
        d := a % c
120
        if d != b {
121
                println("u64", a, b, c, d)
122
                panic("fail")
123
        }
124
}
125
 
126
func u64run() {
127
        var a, b uint64
128
 
129
        for i := 0; i < Count; i++ {
130
                a = u64rand()
131
 
132
                b = a % 1
133
                u64test(a, b, 1)
134
                b = a % 2
135
                u64test(a, b, 2)
136
                b = a % 3
137
                u64test(a, b, 3)
138
                b = a % 4
139
                u64test(a, b, 4)
140
                b = a % 5
141
                u64test(a, b, 5)
142
                b = a % 6
143
                u64test(a, b, 6)
144
                b = a % 7
145
                u64test(a, b, 7)
146
                b = a % 8
147
                u64test(a, b, 8)
148
                b = a % 10
149
                u64test(a, b, 10)
150
                b = a % 16
151
                u64test(a, b, 16)
152
                b = a % 20
153
                u64test(a, b, 20)
154
                b = a % 32
155
                u64test(a, b, 32)
156
                b = a % 60
157
                u64test(a, b, 60)
158
                b = a % 64
159
                u64test(a, b, 64)
160
                b = a % 128
161
                u64test(a, b, 128)
162
                b = a % 256
163
                u64test(a, b, 256)
164
                b = a % 16384
165
                u64test(a, b, 16384)
166
        }
167
}
168
 
169
func i32rand() int32 {
170
        for {
171
                a := int32(rand.Uint32())
172
                a >>= uint(rand.Intn(32))
173
                if -a != a {
174
                        return a
175
                }
176
        }
177
        return 0 // impossible
178
}
179
 
180
func i32test(a, b, c int32) {
181
        d := a % c
182
        if d != b {
183
                println("i32", a, b, c, d)
184
                panic("fail")
185
        }
186
}
187
 
188
func i32run() {
189
        var a, b int32
190
 
191
        for i := 0; i < Count; i++ {
192
                a = i32rand()
193
 
194
                b = a % 1
195
                i32test(a, b, 1)
196
                b = a % 2
197
                i32test(a, b, 2)
198
                b = a % 3
199
                i32test(a, b, 3)
200
                b = a % 4
201
                i32test(a, b, 4)
202
                b = a % 5
203
                i32test(a, b, 5)
204
                b = a % 6
205
                i32test(a, b, 6)
206
                b = a % 7
207
                i32test(a, b, 7)
208
                b = a % 8
209
                i32test(a, b, 8)
210
                b = a % 10
211
                i32test(a, b, 10)
212
                b = a % 16
213
                i32test(a, b, 16)
214
                b = a % 20
215
                i32test(a, b, 20)
216
                b = a % 32
217
                i32test(a, b, 32)
218
                b = a % 60
219
                i32test(a, b, 60)
220
                b = a % 64
221
                i32test(a, b, 64)
222
                b = a % 128
223
                i32test(a, b, 128)
224
                b = a % 256
225
                i32test(a, b, 256)
226
                b = a % 16384
227
                i32test(a, b, 16384)
228
 
229
                b = a % -1
230
                i32test(a, b, -1)
231
                b = a % -2
232
                i32test(a, b, -2)
233
                b = a % -3
234
                i32test(a, b, -3)
235
                b = a % -4
236
                i32test(a, b, -4)
237
                b = a % -5
238
                i32test(a, b, -5)
239
                b = a % -6
240
                i32test(a, b, -6)
241
                b = a % -7
242
                i32test(a, b, -7)
243
                b = a % -8
244
                i32test(a, b, -8)
245
                b = a % -10
246
                i32test(a, b, -10)
247
                b = a % -16
248
                i32test(a, b, -16)
249
                b = a % -20
250
                i32test(a, b, -20)
251
                b = a % -32
252
                i32test(a, b, -32)
253
                b = a % -60
254
                i32test(a, b, -60)
255
                b = a % -64
256
                i32test(a, b, -64)
257
                b = a % -128
258
                i32test(a, b, -128)
259
                b = a % -256
260
                i32test(a, b, -256)
261
        }
262
}
263
 
264
func u32rand() uint32 {
265
        a := uint32(rand.Uint32())
266
        a >>= uint(rand.Intn(32))
267
        return a
268
}
269
 
270
func u32test(a, b, c uint32) {
271
        d := a % c
272
        if d != b {
273
                println("u32", a, b, c, d)
274
                panic("fail")
275
        }
276
}
277
 
278
func u32run() {
279
        var a, b uint32
280
 
281
        for i := 0; i < Count; i++ {
282
                a = u32rand()
283
 
284
                b = a % 1
285
                u32test(a, b, 1)
286
                b = a % 2
287
                u32test(a, b, 2)
288
                b = a % 3
289
                u32test(a, b, 3)
290
                b = a % 4
291
                u32test(a, b, 4)
292
                b = a % 5
293
                u32test(a, b, 5)
294
                b = a % 6
295
                u32test(a, b, 6)
296
                b = a % 7
297
                u32test(a, b, 7)
298
                b = a % 8
299
                u32test(a, b, 8)
300
                b = a % 10
301
                u32test(a, b, 10)
302
                b = a % 16
303
                u32test(a, b, 16)
304
                b = a % 20
305
                u32test(a, b, 20)
306
                b = a % 32
307
                u32test(a, b, 32)
308
                b = a % 60
309
                u32test(a, b, 60)
310
                b = a % 64
311
                u32test(a, b, 64)
312
                b = a % 128
313
                u32test(a, b, 128)
314
                b = a % 256
315
                u32test(a, b, 256)
316
                b = a % 16384
317
                u32test(a, b, 16384)
318
        }
319
}
320
 
321
func i16rand() int16 {
322
        for {
323
                a := int16(rand.Uint32())
324
                a >>= uint(rand.Intn(16))
325
                if -a != a {
326
                        return a
327
                }
328
        }
329
        return 0 // impossible
330
}
331
 
332
func i16test(a, b, c int16) {
333
        d := a % c
334
        if d != b {
335
                println("i16", a, b, c, d)
336
                panic("fail")
337
        }
338
}
339
 
340
func i16run() {
341
        var a, b int16
342
 
343
        for i := 0; i < Count; i++ {
344
                a = i16rand()
345
 
346
                b = a % 1
347
                i16test(a, b, 1)
348
                b = a % 2
349
                i16test(a, b, 2)
350
                b = a % 3
351
                i16test(a, b, 3)
352
                b = a % 4
353
                i16test(a, b, 4)
354
                b = a % 5
355
                i16test(a, b, 5)
356
                b = a % 6
357
                i16test(a, b, 6)
358
                b = a % 7
359
                i16test(a, b, 7)
360
                b = a % 8
361
                i16test(a, b, 8)
362
                b = a % 10
363
                i16test(a, b, 10)
364
                b = a % 16
365
                i16test(a, b, 16)
366
                b = a % 20
367
                i16test(a, b, 20)
368
                b = a % 32
369
                i16test(a, b, 32)
370
                b = a % 60
371
                i16test(a, b, 60)
372
                b = a % 64
373
                i16test(a, b, 64)
374
                b = a % 128
375
                i16test(a, b, 128)
376
                b = a % 256
377
                i16test(a, b, 256)
378
                b = a % 16384
379
                i16test(a, b, 16384)
380
 
381
                b = a % -1
382
                i16test(a, b, -1)
383
                b = a % -2
384
                i16test(a, b, -2)
385
                b = a % -3
386
                i16test(a, b, -3)
387
                b = a % -4
388
                i16test(a, b, -4)
389
                b = a % -5
390
                i16test(a, b, -5)
391
                b = a % -6
392
                i16test(a, b, -6)
393
                b = a % -7
394
                i16test(a, b, -7)
395
                b = a % -8
396
                i16test(a, b, -8)
397
                b = a % -10
398
                i16test(a, b, -10)
399
                b = a % -16
400
                i16test(a, b, -16)
401
                b = a % -20
402
                i16test(a, b, -20)
403
                b = a % -32
404
                i16test(a, b, -32)
405
                b = a % -60
406
                i16test(a, b, -60)
407
                b = a % -64
408
                i16test(a, b, -64)
409
                b = a % -128
410
                i16test(a, b, -128)
411
                b = a % -256
412
                i16test(a, b, -256)
413
                b = a % -16384
414
                i16test(a, b, -16384)
415
        }
416
}
417
 
418
func u16rand() uint16 {
419
        a := uint16(rand.Uint32())
420
        a >>= uint(rand.Intn(16))
421
        return a
422
}
423
 
424
func u16test(a, b, c uint16) {
425
        d := a % c
426
        if d != b {
427
                println("u16", a, b, c, d)
428
                panic("fail")
429
        }
430
}
431
 
432
func u16run() {
433
        var a, b uint16
434
 
435
        for i := 0; i < Count; i++ {
436
                a = u16rand()
437
 
438
                b = a % 1
439
                u16test(a, b, 1)
440
                b = a % 2
441
                u16test(a, b, 2)
442
                b = a % 3
443
                u16test(a, b, 3)
444
                b = a % 4
445
                u16test(a, b, 4)
446
                b = a % 5
447
                u16test(a, b, 5)
448
                b = a % 6
449
                u16test(a, b, 6)
450
                b = a % 7
451
                u16test(a, b, 7)
452
                b = a % 8
453
                u16test(a, b, 8)
454
                b = a % 10
455
                u16test(a, b, 10)
456
                b = a % 16
457
                u16test(a, b, 16)
458
                b = a % 20
459
                u16test(a, b, 20)
460
                b = a % 32
461
                u16test(a, b, 32)
462
                b = a % 60
463
                u16test(a, b, 60)
464
                b = a % 64
465
                u16test(a, b, 64)
466
                b = a % 128
467
                u16test(a, b, 128)
468
                b = a % 256
469
                u16test(a, b, 256)
470
                b = a % 16384
471
                u16test(a, b, 16384)
472
        }
473
}
474
 
475
func i8rand() int8 {
476
        for {
477
                a := int8(rand.Uint32())
478
                a >>= uint(rand.Intn(8))
479
                if -a != a {
480
                        return a
481
                }
482
        }
483
        return 0 // impossible
484
}
485
 
486
func i8test(a, b, c int8) {
487
        d := a % c
488
        if d != b {
489
                println("i8", a, b, c, d)
490
                panic("fail")
491
        }
492
}
493
 
494
func i8run() {
495
        var a, b int8
496
 
497
        for i := 0; i < Count; i++ {
498
                a = i8rand()
499
 
500
                b = a % 1
501
                i8test(a, b, 1)
502
                b = a % 2
503
                i8test(a, b, 2)
504
                b = a % 3
505
                i8test(a, b, 3)
506
                b = a % 4
507
                i8test(a, b, 4)
508
                b = a % 5
509
                i8test(a, b, 5)
510
                b = a % 6
511
                i8test(a, b, 6)
512
                b = a % 7
513
                i8test(a, b, 7)
514
                b = a % 8
515
                i8test(a, b, 8)
516
                b = a % 10
517
                i8test(a, b, 10)
518
                b = a % 8
519
                i8test(a, b, 8)
520
                b = a % 20
521
                i8test(a, b, 20)
522
                b = a % 32
523
                i8test(a, b, 32)
524
                b = a % 60
525
                i8test(a, b, 60)
526
                b = a % 64
527
                i8test(a, b, 64)
528
                b = a % 127
529
                i8test(a, b, 127)
530
 
531
                b = a % -1
532
                i8test(a, b, -1)
533
                b = a % -2
534
                i8test(a, b, -2)
535
                b = a % -3
536
                i8test(a, b, -3)
537
                b = a % -4
538
                i8test(a, b, -4)
539
                b = a % -5
540
                i8test(a, b, -5)
541
                b = a % -6
542
                i8test(a, b, -6)
543
                b = a % -7
544
                i8test(a, b, -7)
545
                b = a % -8
546
                i8test(a, b, -8)
547
                b = a % -10
548
                i8test(a, b, -10)
549
                b = a % -8
550
                i8test(a, b, -8)
551
                b = a % -20
552
                i8test(a, b, -20)
553
                b = a % -32
554
                i8test(a, b, -32)
555
                b = a % -60
556
                i8test(a, b, -60)
557
                b = a % -64
558
                i8test(a, b, -64)
559
                b = a % -128
560
                i8test(a, b, -128)
561
                b = a % -101
562
                i8test(a, b, -101)
563
        }
564
}
565
 
566
func u8rand() uint8 {
567
        a := uint8(rand.Uint32())
568
        a >>= uint(rand.Intn(8))
569
        return a
570
}
571
 
572
func u8test(a, b, c uint8) {
573
        d := a % c
574
        if d != b {
575
                println("u8", a, b, c, d)
576
                panic("fail")
577
        }
578
}
579
 
580
func u8run() {
581
        var a, b uint8
582
 
583
        for i := 0; i < Count; i++ {
584
                a = u8rand()
585
 
586
                b = a % 1
587
                u8test(a, b, 1)
588
                b = a % 2
589
                u8test(a, b, 2)
590
                b = a % 3
591
                u8test(a, b, 3)
592
                b = a % 4
593
                u8test(a, b, 4)
594
                b = a % 5
595
                u8test(a, b, 5)
596
                b = a % 6
597
                u8test(a, b, 6)
598
                b = a % 7
599
                u8test(a, b, 7)
600
                b = a % 8
601
                u8test(a, b, 8)
602
                b = a % 10
603
                u8test(a, b, 10)
604
                b = a % 8
605
                u8test(a, b, 8)
606
                b = a % 20
607
                u8test(a, b, 20)
608
                b = a % 32
609
                u8test(a, b, 32)
610
                b = a % 60
611
                u8test(a, b, 60)
612
                b = a % 64
613
                u8test(a, b, 64)
614
                b = a % 127
615
                u8test(a, b, 127)
616
        }
617
}
618
 
619
func main() {
620
        xtest()
621
        i64run()
622
        u64run()
623
        i32run()
624
        u32run()
625
        i16run()
626
        u16run()
627
        i8run()
628
        u8run()
629
}
630
 
631
func xtest() {
632
}

powered by: WebSVN 2.1.0

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