Home | History | Annotate | Download | only in s390x
      1 #include <stdio.h>
      2 
      3 #define branch(mask,_v1,_v2)                           \
      4   ({                                                   \
      5         unsigned char taken;                           \
      6         unsigned long b1 = _v1;                        \
      7         unsigned long b2 = _v2;                        \
      8         asm volatile(   "       algr %[b1],%[b2]\n\t"  \
      9                  	"	brc " #mask " ,1f\n\t" \
     10                         "       mvi %[taken],0\n\t"    \
     11 			"	j   0f\n\t"            \
     12 			"1:	mvi %[taken],1\n\t"    \
     13 			"0:	bcr 0,0 /* nop */\n\t" \
     14              : [taken] "=Q" (taken), [b1] "+d"(b1)     \
     15              : [b2] "d"(b2)                            \
     16              : "cc");                                  \
     17         taken;                                         \
     18    })
     19 
     20 
     21 void
     22 algr_cc_0(void)
     23 {
     24   unsigned long v1, v2;
     25   int wrong, ok;
     26 
     27   printf("Test #1  cc == 0\n");
     28 
     29   v1 = v2 = 0;
     30   wrong = ok = 0;
     31   if (branch(0,  v1, v2)) ++wrong; else ++ok;
     32   if (branch(1,  v1, v2)) ++wrong; else ++ok;
     33   if (branch(2,  v1, v2)) ++wrong; else ++ok;
     34   if (branch(3,  v1, v2)) ++wrong; else ++ok;
     35   if (branch(4,  v1, v2)) ++wrong; else ++ok;
     36   if (branch(5,  v1, v2)) ++wrong; else ++ok;
     37   if (branch(6,  v1, v2)) ++wrong; else ++ok;
     38   if (branch(7,  v1, v2)) ++wrong; else ++ok;
     39   if (branch(8,  v1, v2)) ++ok; else ++wrong;
     40   if (branch(9,  v1, v2)) ++ok; else ++wrong;
     41   if (branch(10, v1, v2)) ++ok; else ++wrong;
     42   if (branch(11, v1, v2)) ++ok; else ++wrong;
     43   if (branch(12, v1, v2)) ++ok; else ++wrong;
     44   if (branch(13, v1, v2)) ++ok; else ++wrong;
     45   if (branch(14, v1, v2)) ++ok; else ++wrong;
     46   if (branch(15, v1, v2)) ++ok; else ++wrong;
     47 
     48   if (wrong != 0 || ok != 16)
     49     printf("FAILED\n");
     50   else
     51     printf("OK\n");
     52 }
     53 
     54 void
     55 algr_cc_1(void)
     56 {
     57   unsigned long v1, v2;
     58   int wrong, ok;
     59 
     60   printf("Test #2  cc == 1\n");
     61 
     62   v1 = v2 = 42;
     63   wrong = ok = 0;
     64 
     65   if (branch(0,  v1, v2)) ++wrong; else ++ok;
     66   if (branch(1,  v1, v2)) ++wrong; else ++ok;
     67   if (branch(2,  v1, v2)) ++wrong; else ++ok;
     68   if (branch(3,  v1, v2)) ++wrong; else ++ok;
     69   if (branch(4,  v1, v2)) ++ok; else ++wrong;
     70   if (branch(5,  v1, v2)) ++ok; else ++wrong;
     71   if (branch(6,  v1, v2)) ++ok; else ++wrong;
     72   if (branch(7,  v1, v2)) ++ok; else ++wrong;
     73   if (branch(8,  v1, v2)) ++wrong; else ++ok;
     74   if (branch(9,  v1, v2)) ++wrong; else ++ok;
     75   if (branch(10, v1, v2)) ++wrong; else ++ok;
     76   if (branch(11, v1, v2)) ++wrong; else ++ok;
     77   if (branch(12, v1, v2)) ++ok; else ++wrong;
     78   if (branch(13, v1, v2)) ++ok; else ++wrong;
     79   if (branch(14, v1, v2)) ++ok; else ++wrong;
     80   if (branch(15, v1, v2)) ++ok; else ++wrong;
     81 
     82   if (wrong != 0 || ok != 16)
     83     printf("FAILED\n");
     84   else
     85     printf("OK\n");
     86 }
     87 
     88 void
     89 algr_cc_2(void)
     90 {
     91   unsigned long v1, v2;
     92   int wrong, ok;
     93 
     94   printf("Test #3  cc == 2\n");
     95 
     96   v1 = ~0ULL;
     97   v2 = 1;
     98 
     99   wrong = ok = 0;
    100 
    101   if (branch(0,  v1, v2)) ++wrong; else ++ok;
    102   if (branch(1,  v1, v2)) ++wrong; else ++ok;
    103   if (branch(2,  v1, v2)) ++ok; else ++wrong;
    104   if (branch(3,  v1, v2)) ++ok; else ++wrong;
    105   if (branch(4,  v1, v2)) ++wrong; else ++ok;
    106   if (branch(5,  v1, v2)) ++wrong; else ++ok;
    107   if (branch(6,  v1, v2)) ++ok; else ++wrong;
    108   if (branch(7,  v1, v2)) ++ok; else ++wrong;
    109   if (branch(8,  v1, v2)) ++wrong; else ++ok;
    110   if (branch(9,  v1, v2)) ++wrong; else ++ok;
    111   if (branch(10, v1, v2)) ++ok; else ++wrong;
    112   if (branch(11, v1, v2)) ++ok; else ++wrong;
    113   if (branch(12, v1, v2)) ++wrong; else ++ok;
    114   if (branch(13, v1, v2)) ++wrong; else ++ok;
    115   if (branch(14, v1, v2)) ++ok; else ++wrong;
    116   if (branch(15, v1, v2)) ++ok; else ++wrong;
    117 
    118   if (wrong != 0 /* || ok != 16 */)
    119     printf("FAILED\n");
    120   else
    121     printf("OK\n");
    122 }
    123 
    124 void
    125 algr_cc_3(void)
    126 {
    127   unsigned long v1, v2;
    128   int wrong, ok;
    129 
    130   printf("Test #4  cc == 3\n");
    131 
    132   v1 = ~0ULL;
    133   v2 = 100;
    134 
    135   wrong = ok = 0;
    136 
    137   if (branch(0,  v1, v2)) ++wrong; else ++ok;
    138   if (branch(1,  v1, v2)) ++ok; else ++wrong;
    139   if (branch(2,  v1, v2)) ++wrong; else ++ok;
    140   if (branch(3,  v1, v2)) ++ok; else ++wrong;
    141   if (branch(4,  v1, v2)) ++wrong; else ++ok;
    142   if (branch(5,  v1, v2)) ++ok; else ++wrong;
    143   if (branch(6,  v1, v2)) ++wrong; else ++ok;
    144   if (branch(7,  v1, v2)) ++ok; else ++wrong;
    145   if (branch(8,  v1, v2)) ++wrong; else ++ok;
    146   if (branch(9,  v1, v2)) ++ok; else ++wrong;
    147   if (branch(10, v1, v2)) ++wrong; else ++ok;
    148   if (branch(11, v1, v2)) ++ok; else ++wrong;
    149   if (branch(12, v1, v2)) ++wrong; else ++ok;
    150   if (branch(13, v1, v2)) ++ok; else ++wrong;
    151   if (branch(14, v1, v2)) ++wrong; else ++ok;
    152   if (branch(15, v1, v2)) ++ok; else ++wrong;
    153 
    154   if (wrong != 0 || ok != 16)
    155     printf("FAILED\n");
    156   else
    157     printf("OK\n");
    158 }
    159 
    160 int main()
    161 {
    162   algr_cc_0();
    163   algr_cc_1();
    164   algr_cc_2();
    165   algr_cc_3();
    166 
    167   return 0;
    168 }
    169