1#include <stdio.h>
2
3#define branch(mask,_v1,_v2)                           \
4  ({                                                   \
5        unsigned char taken;                           \
6        unsigned b1 = _v1, b2 = _v2;                   \
7        asm volatile("     or   %[b1],%[b2]\n\t"       \
8                     "     brc  " #mask " ,1f\n\t"     \
9                     "     mvi  %[taken],0\n\t"        \
10                     "     j    0f\n\t"                \
11                     "1:   mvi  %[taken],1\n\t"        \
12                     "0:   bcr  0,0 /* nop */\n\t"     \
13             : [taken] "=Q" (taken), [b1] "+d"(b1)     \
14             : [b2] "d"(b2)                            \
15             : "cc");                                  \
16        taken;                                         \
17   })
18
19void
20or_1(void)
21{
22   int wrong, ok, v1, v2;
23
24   printf("Test #1  result = 0\n");
25
26   v1 = v2 = 0;
27   wrong = ok = 0;
28   if (branch(0,  v1, v2)) ++wrong; else ++ok;
29   if (branch(1,  v1, v2)) ++wrong; else ++ok;
30   if (branch(2,  v1, v2)) ++wrong; else ++ok;
31   if (branch(3,  v1, v2)) ++wrong; else ++ok;
32   if (branch(4,  v1, v2)) ++wrong; else ++ok;
33   if (branch(5,  v1, v2)) ++wrong; else ++ok;
34   if (branch(6,  v1, v2)) ++wrong; else ++ok;
35   if (branch(7,  v1, v2)) ++wrong; else ++ok;
36   if (branch(8,  v1, v2)) ++ok; else ++wrong;
37   if (branch(9,  v1, v2)) ++ok; else ++wrong;
38   if (branch(10, v1, v2)) ++ok; else ++wrong;
39   if (branch(11, v1, v2)) ++ok; else ++wrong;
40   if (branch(12, v1, v2)) ++ok; else ++wrong;
41   if (branch(13, v1, v2)) ++ok; else ++wrong;
42   if (branch(14, v1, v2)) ++ok; else ++wrong;
43   if (branch(15, v1, v2)) ++ok; else ++wrong;
44
45   if (wrong != 0 || ok != 16)
46      printf("FAILED\n");
47   else
48      printf("OK\n");
49}
50
51void
52or_2(void)
53{
54   int wrong, ok, v1, v2;
55
56   printf("Test #2  result = 0xffffffff\n");
57   v1 = 0;
58   v2 = ~0;
59   wrong = ok = 0;
60   if (branch(0,  v1, v2)) ++wrong; else ++ok;
61   if (branch(1,  v1, v2)) ++wrong; else ++ok;
62   if (branch(2,  v1, v2)) ++wrong; else ++ok;
63   if (branch(3,  v1, v2)) ++wrong; else ++ok;
64   if (branch(4,  v1, v2)) ++ok; else ++wrong;
65   if (branch(5,  v1, v2)) ++ok; else ++wrong;
66   if (branch(6,  v1, v2)) ++ok; else ++wrong;
67   if (branch(7,  v1, v2)) ++ok; else ++wrong;
68   if (branch(8,  v1, v2)) ++wrong; else ++ok;
69   if (branch(9,  v1, v2)) ++wrong; else ++ok;
70   if (branch(10, v1, v2)) ++wrong; else ++ok;
71   if (branch(11, v1, v2)) ++wrong; else ++ok;
72   if (branch(12, v1, v2)) ++ok; else ++wrong;
73   if (branch(13, v1, v2)) ++ok; else ++wrong;
74   if (branch(14, v1, v2)) ++ok; else ++wrong;
75   if (branch(15, v1, v2)) ++ok; else ++wrong;
76
77   if (wrong != 0 || ok != 16)
78      printf("FAILED\n");
79   else
80      printf("OK\n");
81}
82
83int main()
84{
85   or_1();
86   or_2();
87   return 0;
88}
89