summaryrefslogtreecommitdiffstats
path: root/spec/compiler/unit/builtins.yml
blob: cad01f41eb754881c8c22c1f44991799867a7741 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
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
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
copyrights:
- Copyright (C) 2023 embedded brains GmbH & Co. KG
enabled-by: true
links:
- role: validation
  uid: /req/unit-test-compiler-builtins
test-actions:
- action-brief: |
    Check the return value of __builtin_clz() for a sample set of inputs.
  action-code: |
    volatile unsigned int n;

    n = 1U;
    T_eq_int( __builtin_clz( n ), 31 );

    n = 1U << 31;
    T_eq_int( __builtin_clz( n ), 0 );

    n = ~0U;
    T_eq_int( __builtin_clz( n ), 0 );
  checks: []
  links:
  - name: __builtin_clz
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check the return value of __builtin_clzll() for a sample set of inputs.
  action-code: |
    volatile unsigned long long n;

    n = 1ULL;
    T_eq_int( __builtin_clzll( n ), 63 );

    n = 1ULL << 31;
    T_eq_int( __builtin_clzll( n ), 32 );

    n = 1ULL << 32;
    T_eq_int( __builtin_clzll( n ), 31 );

    n = 1ULL << 63;
    T_eq_int( __builtin_clzll( n ), 0 );

    n = ~0ULL;
    T_eq_int( __builtin_clzll( n ), 0 );
  checks: []
  links:
  - name: __builtin_clzll
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check the return value of __builtin_ctz() for a sample set of inputs.
  action-code: |
    volatile unsigned int n;

    n = 1U;
    T_eq_int( __builtin_ctz( n ), 0 );

    n = 1U << 31;
    T_eq_int( __builtin_ctz( n ), 31 );

    n = ~0U;
    T_eq_int( __builtin_ctz( n ), 0 );
  checks: []
  links:
  - name: __builtin_ctz
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check the return value of __builtin_ctzll() for a sample set of inputs.
  action-code: |
    volatile unsigned long long n;

    n = 1ULL;
    T_eq_int( __builtin_ctzll( n ), 0 );

    n = 1ULL << 31;
    T_eq_int( __builtin_ctzll( n ), 31 );

    n = 1ULL << 32;
    T_eq_int( __builtin_ctzll( n ), 32 );

    n = 1ULL << 63;
    T_eq_int( __builtin_ctzll( n ), 63 );

    n = ~0ULL;
    T_eq_int( __builtin_ctzll( n ), 0 );
  checks: []
  links:
  - name: __builtin_ctzll
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check the return value of __builtin_ffs() for a sample set of inputs.
  action-code: |
    volatile unsigned int n;

    n = 1U;
    T_eq_int( __builtin_ffs( n ), 1 );

    n = 1U << 31;
    T_eq_int( __builtin_ffs( n ), 32 );

    n = 0U;
    T_eq_int( __builtin_ffs( n ), 0 );
  checks: []
  links:
  - name: __builtin_ffs
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check the return value of __builtin_ffsll() for a sample set of inputs.
  action-code: |
    volatile unsigned long long n;

    n = 1ULL;
    T_eq_int( __builtin_ffsll( n ), 1 );

    n = 1ULL << 31;
    T_eq_int( __builtin_ffsll( n ), 32 );

    n = 1ULL << 32;
    T_eq_int( __builtin_ffsll( n ), 33 );

    n = 1ULL << 63;
    T_eq_int( __builtin_ffsll( n ), 64 );

    n = 0ULL;
    T_eq_int( __builtin_ffsll( n ), 0 );
  checks: []
  links:
  - name: __builtin_ffsll
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check the return value of __builtin_parity() for a sample set of inputs.
  action-code: |
    volatile unsigned int n;

    n = 1U;
    T_eq_int( __builtin_parity( n ), 1 );

    n = ~0U;
    T_eq_int( __builtin_parity( n ), 0 );
  checks: []
  links:
  - name: __builtin_parity
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check the return value of __builtin_parityll() for a sample set of inputs.
  action-code: |
    volatile unsigned long long n;

    n = 1ULL;
    T_eq_int( __builtin_parityll( n ), 1 );

    n = ~0ULL;
    T_eq_int( __builtin_parityll( n ), 0 );
  checks: []
  links:
  - name: __builtin_parityll
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check the return value of __builtin_popcount() for a sample set of inputs.
  action-code: |
    volatile unsigned int n;

    n = 0U;
    T_eq_int( __builtin_popcount( n ), 0 );

    n = 1U;
    T_eq_int( __builtin_popcount( n ), 1 );

    n = ~0U;
    T_eq_int( __builtin_popcount( n ), 32 );
  checks: []
  links:
  - name: __builtin_popcount
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check the return value of __builtin_popcountll() for a sample set of inputs.
  action-code: |
    volatile unsigned long long n;

    n = 0ULL;
    T_eq_int( __builtin_popcountll( n ), 0 );

    n = 1ULL;
    T_eq_int( __builtin_popcountll( n ), 1 );

    n = ~0ULL;
    T_eq_int( __builtin_popcountll( n ), 64 );
  checks: []
  links:
  - name: __builtin_popcountll
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check the return value of __builtin_bswap32() for a sample set of inputs.
  action-code: |
    volatile uint32_t n;

    n = UINT32_C( 0 );
    T_eq_u32( __builtin_bswap32( n ), n );

    n = UINT32_C( 1 );
    T_eq_u32( __builtin_bswap32( n ), n << 24 );

    n = UINT32_C( 0x12345678 );
    T_eq_u32( __builtin_bswap32( n ), UINT32_C( 0x78563412 ) );

    n = ~UINT32_C( 0 );
    T_eq_u32( __builtin_bswap32( n ), n );
  checks: []
  links:
  - name: __builtin_bswap32
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check the return value of __builtin_bswap64() for a sample set of inputs.
  action-code: |
    volatile uint64_t n;

    n = UINT64_C( 0 );
    T_eq_u64( __builtin_bswap64( n ), n );

    n = UINT64_C( 1 );
    T_eq_u64( __builtin_bswap64( n ), n << 56 );

    n = UINT64_C( 0x123456789abcdef0 );
    T_eq_u64( __builtin_bswap64( n ), UINT64_C( 0xf0debc9a78563412 ) );

    n = ~UINT64_C( 0 );
    T_eq_u64( __builtin_bswap64( n ), n );
  checks: []
  links:
  - name: __builtin_popcount64
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check signed 64-bit comparisons for a sample set of values.
  action-code: |
    volatile int64_t a;
    volatile int64_t b;

    a = INT64_C( 0 );
    b = INT64_C( 0 );
    T_false( a < b );

    a = INT64_C( 0 );
    b = INT64_C( 1 );
    T_true( a < b );

    a = INT64_C( 0x123456789abcdef0 );
    b = INT64_C( 0xf0debc9a78563412 );
    T_false( a < b );

    a = INT64_C( 0xf0debc9a78563412 );
    b = INT64_C( 0x123456789abcdef0 );
    T_true( a < b );
  checks: []
  links:
  - name: __cmpdi2
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check unsigned 64-bit comparisons for a sample set of values.
  action-code: |
    volatile uint64_t a;
    volatile uint64_t b;

    a = UINT64_C( 0 );
    b = UINT64_C( 0 );
    T_false( a < b );

    a = UINT64_C( 0 );
    b = UINT64_C( 1 );
    T_true( a < b );

    a = UINT64_C( 0x123456789abcdef0 );
    b = UINT64_C( 0xf0debc9a78563412 );
    T_true( a < b );

    a = UINT64_C( 0xf0debc9a78563412 );
    b = UINT64_C( 0x123456789abcdef0 );
    T_false( a < b );
  checks: []
  links:
  - name: __ucmpdi2
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check signed 64-bit arithmetic left shift for a sample set of values.
  action-code: |
    volatile int64_t i;
    volatile int s;

    i = INT64_C( 1 );
    s = 0;
    T_eq_i64( i << s, INT64_C( 1 ) );

    i = -INT64_C( 1 );
    s = 0;
    T_eq_i64( i << s, -INT64_C( 1 ) );

    i = INT64_C( 1 );
    s = 1;
    T_eq_i64( i << s, INT64_C( 2 ) );

    i = -INT64_C( 1 );
    s = 1;
    T_eq_i64( i << s, -INT64_C( 2 ) );
  checks: []
  links:
  - name: __ashldi2
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check signed 64-bit arithmetic right shift for a sample set of values.
  action-code: |
    volatile int64_t i;
    volatile int s;

    i = INT64_C( 1 );
    s = 0;
    T_eq_i64( i >> s, INT64_C( 1 ) );

    i = -INT64_C( 1 );
    s = 0;
    T_eq_i64( i >> s, -INT64_C( 1 ) );

    i = INT64_C( 2 );
    s = 1;
    T_eq_i64( i >> s, INT64_C( 1 ) );

    i = -INT64_C( 2 );
    s = 1;
    T_eq_i64( i >> s, -INT64_C( 1 ) );
  checks: []
  links:
  - name: __ashrdi2
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check unsigned 64-bit logical right shift for a sample set of values.
  action-code: |
    volatile uint64_t i;
    volatile int s;

    i = UINT64_C( 1 );
    s = 0;
    T_eq_u64( i >> s, UINT64_C( 1 ) );

    i = -UINT64_C( 1 );
    s = 0;
    T_eq_u64( i >> s, UINT64_C( 0xffffffffffffffff ) );

    i = UINT64_C( 2 );
    s = 1;
    T_eq_u64( i >> s, UINT64_C( 1 ) );

    i = -UINT64_C( 2 );
    s = 1;
    T_eq_u64( i >> s, UINT64_C( 0x7fffffffffffffff ) );
  checks: []
  links:
  - name: __lshrdi2
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check signed 64-bit multiplication for a sample set of values.
  action-code: |
    volatile int64_t a;
    volatile int64_t b;

    a = INT64_C( 1 );
    b = INT64_C( 1 );
    T_eq_i64( a * b, INT64_C( 1 ) );

    a = INT64_C( 1 );
    b = INT64_C( 0 );
    T_eq_i64( a * b, INT64_C( 0 ) );

    a = INT64_C( 0 );
    b = INT64_C( 1 );
    T_eq_i64( a * b, INT64_C( 0 ) );
  checks: []
  links:
  - name: __negdi2
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check signed 64-bit negation for a sample set of values.
  action-code: |
    volatile int64_t i;

    i = INT64_C( 1 );
    T_eq_i64( -i, -INT64_C( 1 ) );

    i = -INT64_C( 1 );
    T_eq_i64( -i, INT64_C( 1 ) );
  checks: []
  links:
  - name: __negdi2
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check signed 64-bit divisions for a sample set of values.
  action-code: |
    volatile int64_t n;
    volatile int64_t d;

    n = INT64_C( 0 );
    d = INT64_C( 0 );
    do_longjmp = true;

    if ( setjmp( exception_return_context ) == 0 ) {
      n = n / d;
    }

    n = INT64_C( 1 );
    d = INT64_C( 0 );
    do_longjmp = true;

    if ( setjmp( exception_return_context ) == 0 ) {
      n = n / d;
    }

    n = INT64_C( 0x7fffffffffffffff );
    d = INT64_C( 0 );
    do_longjmp = true;

    if ( setjmp( exception_return_context ) == 0 ) {
      n = n / d;
    }

    n = INT64_C( 0x7fffffff00000000 );
    d = INT64_C( 0 );
    do_longjmp = true;

    if ( setjmp( exception_return_context ) == 0 ) {
      n = n / d;
    }

    n = INT64_C( 0 );
    d = INT64_C( 1 );
    T_eq_i64( n / d, INT64_C( 0 ) );

    n = INT64_C( 1 );
    d = INT64_C( 1 );
    T_eq_i64( n / d, INT64_C( 1 ) );

    n = INT64_C( 0x7fffffffffffffff );
    d = INT64_C( 1 );
    T_eq_i64( n / d, INT64_C( 9223372036854775807 ) );

    n = INT64_C( 2 );
    d = INT64_C( 1 );
    T_eq_i64( n / d, INT64_C( 2 ) );

    n = INT64_C( 2 );
    d = INT64_C( 1 );
    T_eq_i64( n / d, INT64_C( 2 ) );

    n = INT64_C( 1 );
    d = INT64_C( 0x7fffffffffffffff );
    T_eq_i64( n / d, INT64_C( 0 ) );

    n = INT64_C( 0x7fffffffffffffff );
    d = INT64_C( 0x7fffffffffffffff );
    T_eq_i64( n / d, INT64_C( 1 ) );

    n = INT64_C( 1 );
    d = INT64_C( 0x7fffffff00000000 );
    T_eq_i64( n / d, INT64_C( 0 ) );

    n = INT64_C( 0x7fffffff00000000 );
    d = INT64_C( 0x7fffffff00000000 );
    T_eq_i64( n / d, INT64_C( 1 ) );

    n = INT64_C( 0x7fffffffffffffff );
    d = INT64_C( 0x7fffffff00000000 );
    T_eq_i64( n / d, INT64_C( 1 ) );

    n = INT64_C( 0x7fffffffffffffff );
    d = INT64_C( 0x8000000000000000 );
    T_eq_i64( n / d, INT64_C( 0 ) );

    n = INT64_C( 0x7fffffffffffffff );
    d = INT64_C( 0x0000000080000000 );
    T_eq_i64( n / d, INT64_C( 0xffffffff ) );

    n = INT64_C( 0x7fffffffffffffff );
    d = INT64_C( 0x00000000f0000000 );
    T_eq_i64( n / d, INT64_C( 2290649224 ) );

    n = INT64_C( 0x00000001ffffffff );
    d = INT64_C( 0x00000000f0000000 );
    T_eq_i64( n / d, INT64_C( 2 ) );

    n = INT64_C( 0x0000000fffffffff );
    d = INT64_C( 0x000000000000000f );
    T_eq_i64( n / d, INT64_C( 4581298449 ) );

    n = INT64_C( 0x0000000100000001 );
    d = INT64_C( 0x0000000f00000000 );
    T_eq_i64( n / d, INT64_C( 0 ) );

    n = INT64_C( 0x0000000f0000000f );
    d = INT64_C( 0x000000ff0000000f );
    T_eq_i64( n / d, INT64_C( 0 ) );
  checks: []
  links:
  - name: __divdi3
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check unsigned 64-bit divisions for a sample set of values.
  action-code: |
    volatile uint64_t n;
    volatile uint64_t d;

    n = UINT64_C( 0 );
    d = UINT64_C( 0 );
    do_longjmp = true;

    if ( setjmp( exception_return_context ) == 0 ) {
      n = n / d;
    }

    n = UINT64_C( 1 );
    d = UINT64_C( 0 );
    do_longjmp = true;

    if ( setjmp( exception_return_context ) == 0 ) {
      n = n / d;
    }

    n = UINT64_C( 0x7fffffffffffffff );
    d = UINT64_C( 0 );
    do_longjmp = true;

    if ( setjmp( exception_return_context ) == 0 ) {
      n = n / d;
    }

    n = UINT64_C( 0x7fffffff00000000 );
    d = UINT64_C( 0 );
    do_longjmp = true;

    if ( setjmp( exception_return_context ) == 0 ) {
      n = n / d;
    }

    n = UINT64_C( 0 );
    d = UINT64_C( 1 );
    T_eq_u64( n / d, UINT64_C( 0 ) );

    n = UINT64_C( 1 );
    d = UINT64_C( 1 );
    T_eq_u64( n / d, UINT64_C( 1 ) );

    n = UINT64_C( 0xffffffffffffffff );
    d = UINT64_C( 1 );
    T_eq_u64( n / d, UINT64_C( 0xffffffffffffffff ) );

    n = UINT64_C( 2 );
    d = UINT64_C( 1 );
    T_eq_u64( n / d, UINT64_C( 2 ) );

    n = UINT64_C( 1 );
    d = UINT64_C( 0xffffffffffffffff );
    T_eq_u64( n / d, UINT64_C( 0 ) );

    n = UINT64_C( 0xffffffffffffffff );
    d = UINT64_C( 0xffffffffffffffff );
    T_eq_u64( n / d, UINT64_C( 1 ) );

    n = UINT64_C( 0xffffffffffffffff );
    d = UINT64_C( 0x8000000000000000 );
    T_eq_u64( n / d, UINT64_C( 1 ) );

    n = UINT64_C( 0x0000000100000001 );
    d = UINT64_C( 0x0000000f00000000 );
    T_eq_u64( n / d, UINT64_C( 0 ) );

    n = UINT64_C( 0xffffffff0000000f );
    d = UINT64_C( 0x000000010000000f );
    T_eq_u64( n / d, UINT64_C( 4294967280 ) );
  checks: []
  links:
  - name: __udivdi3
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check signed 64-bit modulo operations for a sample set of values.
  action-code: |
    volatile int64_t n;
    volatile int64_t d;

    n = INT64_C( 0 );
    d = INT64_C( 0 );
    do_longjmp = true;

    if ( setjmp( exception_return_context ) == 0 ) {
      n = n % d;
    }

    n = INT64_C( 1 );
    d = INT64_C( 0 );
    do_longjmp = true;

    if ( setjmp( exception_return_context ) == 0 ) {
      n = n % d;
    }

    n = INT64_C( 0x7fffffffffffffff );
    d = INT64_C( 0 );
    do_longjmp = true;

    if ( setjmp( exception_return_context ) == 0 ) {
      n = n % d;
    }

    n = INT64_C( 0x7fffffff00000000 );
    d = INT64_C( 0 );
    do_longjmp = true;

    if ( setjmp( exception_return_context ) == 0 ) {
      n = n % d;
    }

    n = INT64_C( 0 );
    d = INT64_C( 1 );
    T_eq_i64( n % d, INT64_C( 0 ) );

    n = INT64_C( 1 );
    d = INT64_C( 1 );
    T_eq_i64( n % d, INT64_C( 0 ) );

    n = INT64_C( 0x7fffffffffffffff );
    d = INT64_C( 1 );
    T_eq_i64( n % d, INT64_C( 0 ) );

    n = INT64_C( 2 );
    d = INT64_C( 1 );
    T_eq_i64( n % d, INT64_C( 0 ) );

    n = INT64_C( 2 );
    d = INT64_C( 1 );
    T_eq_i64( n % d, INT64_C( 0 ) );

    n = INT64_C( 1 );
    d = INT64_C( 0x7fffffffffffffff );
    T_eq_i64( n % d, INT64_C( 1 ) );

    n = INT64_C( 0x7fffffffffffffff );
    d = INT64_C( 0x7fffffffffffffff );
    T_eq_i64( n % d, INT64_C( 0 ) );

    n = INT64_C( 1 );
    d = INT64_C( 0x7fffffff00000000 );
    T_eq_i64( n % d, INT64_C( 1 ) );

    n = INT64_C( 0x7fffffff00000000 );
    d = INT64_C( 0x7fffffff00000000 );
    T_eq_i64( n % d, INT64_C( 0 ) );

    n = INT64_C( 0x7fffffffffffffff );
    d = INT64_C( 0x7fffffff00000000 );
    T_eq_i64( n % d, INT64_C( 0xffffffff ) );

    n = INT64_C( 0x7fffffffffffffff );
    d = INT64_C( 0x8000000000000000 );
    T_eq_i64( n % d, INT64_C( 0x7fffffffffffffff ) );

    n = INT64_C( 0x7fffffffffffffff );
    d = INT64_C( 0x0000000080000000 );
    T_eq_i64( n % d, INT64_C( 2147483647 ) );

    n = INT64_C( 0x7fffffffffffffff );
    d = INT64_C( 0x00000000f0000000 );
    T_eq_i64( n % d, INT64_C( 2147483647 ) );

    n = INT64_C( 0x00000001ffffffff );
    d = INT64_C( 0x00000000f0000000 );
    T_eq_i64( n % d, INT64_C( 536870911 ) );

    n = INT64_C( 0x0000000fffffffff );
    d = INT64_C( 0x000000000000000f );
    T_eq_i64( n % d, INT64_C( 0 ) );

    n = INT64_C( 0x0000000100000001 );
    d = INT64_C( 0x0000000f00000000 );
    T_eq_i64( n % d, INT64_C( 4294967297 ) );

    n = INT64_C( 0x0000000f0000000f );
    d = INT64_C( 0x000000ff0000000f );
    T_eq_i64( n % d, INT64_C( 64424509455 ) );

    #if defined(TEST_UDIVMODDI4)
    /*
     * The above test cases may use __udivmoddi4().  However, the below
     * parameter values for __udivmoddi4() cannot be obtained through the
     * signed modulo or division operations.  On some targets, calls to
     * __udivmoddi4() may result from complex optimizations.
     */
    n = INT64_C( 0xffffffff0000000f );
    d = INT64_C( 0x000000010000000f );
    T_eq_u64( __udivmoddi4( n, d, NULL ), INT64_C( 4294967280 ) );
    #endif
  checks: []
  links:
  - name: __moddi3
    role: unit-test
    uid: ../../if/domain
- action-brief: |
    Check unsigned 64-bit modulo operations for a sample set of values.
  action-code: |
    volatile uint64_t n;
    volatile uint64_t d;

    n = UINT64_C( 0 );
    d = UINT64_C( 0 );
    do_longjmp = true;

    if ( setjmp( exception_return_context ) == 0 ) {
      n = n % d;
    }

    n = UINT64_C( 1 );
    d = UINT64_C( 0 );
    do_longjmp = true;

    if ( setjmp( exception_return_context ) == 0 ) {
      n = n % d;
    }

    n = UINT64_C( 0 );
    d = UINT64_C( 1 );
    T_eq_u64( n % d, UINT64_C( 0 ) );

    n = UINT64_C( 1 );
    d = UINT64_C( 1 );
    T_eq_u64( n % d, UINT64_C( 0 ) );

    n = UINT64_C( 0xffffffffffffffff );
    d = UINT64_C( 1 );
    T_eq_u64( n % d, UINT64_C( 0 ) );

    n = UINT64_C( 2 );
    d = UINT64_C( 1 );
    T_eq_u64( n % d, UINT64_C( 0 ) );

    n = UINT64_C( 1 );
    d = UINT64_C( 0xffffffffffffffff );
    T_eq_u64( n % d, UINT64_C( 1 ) );

    n = UINT64_C( 0xffffffffffffffff );
    d = UINT64_C( 0xffffffffffffffff );
    T_eq_u64( n % d, UINT64_C( 0 ) );
  checks: []
  links:
  - name: __umoddi3
    role: unit-test
    uid: ../../if/domain
test-brief: |
  These unit tests check compiler builtins.
test-context: []
test-context-support: null
test-description: |
  Explicitly test the 64-bit integer division and modulo operations.  They are
  essential for the timekeeping services.  On most 32-bit targets, they need a
  software implementation.
test-header: null
test-includes:
- stdint.h
- setjmp.h
test-local-includes:
- ../validation/tx-support.h
test-setup:
  brief: null
  code: |
    SetFatalHandler( Fatal, exception_return_context );
  description: null
test-stop: null
test-support: |
  #if __LONG_MAX__ == 0x7fffffffL && !defined(__aarch64__)
  #define TEST_UDIVMODDI4
  #endif

  #if defined(TEST_UDIVMODDI4)
  uint64_t __udivmoddi4( uint64_t n, uint64_t d, uint64_t *r );
  #endif

  static bool do_longjmp;

  static jmp_buf exception_return_context;

  static void Fatal(
    rtems_fatal_source source,
    rtems_fatal_code   code,
    void              *arg
  )
  {
    (void) code;

    if ( source == RTEMS_FATAL_SOURCE_EXCEPTION && do_longjmp ) {
      do_longjmp = false;
      _ISR_Set_level( 0 );
      longjmp( arg, 1 );
    }
  }
test-target: testsuites/unit/tc-compiler-builtins.c
test-teardown:
  brief: null
  code: |
    SetFatalHandler( NULL, NULL );
  description: null
type: test-case