Home | History | Annotate | Download | only in s390x
      1 #include <stdio.h>
      2 #include <stdint.h>
      3 #include "opcodes.h"
      4 
      5 #define BRASLCLOBBER "0","1","2","3","4","5","14", \
      6 		     "f0","f1","f2","f3","f4","f5","f6","f7"
      7 
      8 void if_eq(void)        { printf("equal\n");   }
      9 void if_ne(void)        { printf("not equal\n");   }
     10 void if_gt(void)        { printf("greater than\n");   }
     11 void if_le(void)        { printf("less or equal\n");   }
     12 void if_lt(void)        { printf("less than\n");   }
     13 void if_ge(void)        { printf("greater or equal\n");   }
     14 void if_taken(void)     { printf("taken\n");   }
     15 void if_not_taken(void) { printf("not taken\n");   }
     16 
     17 #undef LT
     18 #define NEVER 0
     19 #define GT 2
     20 #define LT 4
     21 #define NE 6
     22 #define EQ 8
     23 #define LE C
     24 #define GE A
     25 #define ALWAYS E
     26 
     27 
     28 void compare_never(uint32_t value1, uint32_t value2)
     29 {
     30    register uint32_t val1 asm("r7") = value1;
     31    register uint32_t val2 asm("r8") = value2;
     32 
     33    asm volatile(
     34                 "aghi  15,-160\n\t"
     35                 CLRJ(7,8,8,NEVER) "\n\t"
     36                 "brasl 14,if_not_taken\n\t"
     37                 "j     0f\n\t"
     38                 "brasl 14,if_taken\n\t"
     39                 "0: aghi 15,160\n\t"
     40                 : : "d"(val1), "d"(val2) : "15", BRASLCLOBBER);
     41    return;
     42 }
     43 
     44 void compare_always(uint32_t value1, uint32_t value2)
     45 {
     46    register uint32_t val1 asm("r7") = value1;
     47    register uint32_t val2 asm("r8") = value2;
     48 
     49    asm volatile(
     50                 "aghi  15,-160\n\t"
     51                 CLRJ(7,8,8,ALWAYS) "\n\t"
     52                 "brasl 14,if_not_taken\n\t"
     53                 "j     0f\n\t"
     54                 "brasl 14,if_taken\n\t"
     55                 "0: aghi 15,160\n\t"
     56                 : : "d"(val1), "d"(val2) : "15", BRASLCLOBBER);
     57    return;
     58 }
     59 
     60 void compare_le(uint32_t value1, uint32_t value2)
     61 {
     62    register uint32_t val1 asm("r7") = value1;
     63    register uint32_t val2 asm("r8") = value2;
     64 
     65    asm volatile(
     66                 "aghi  15,-160\n\t"
     67                 CLRJ(7,8,8,LE) "\n\t"
     68                 "brasl 14,if_gt\n\t"
     69                 "j     0f\n\t"
     70                 "brasl 14,if_le\n\t"
     71                 "0: aghi 15,160\n\t"
     72                 : : "d"(val1), "d"(val2) : "15", BRASLCLOBBER);
     73    return;
     74 }
     75 
     76 void compare_ge(uint32_t value1, uint32_t value2)
     77 {
     78    register uint32_t val1 asm("r7") = value1;
     79    register uint32_t val2 asm("r8") = value2;
     80 
     81    asm volatile(
     82                 "aghi  15,-160\n\t"
     83                 CLRJ(7,8,8,GE) "\n\t"
     84                 "brasl 14,if_lt\n\t"
     85                 "j     0f\n\t"
     86                 "brasl 14,if_ge\n\t"
     87                 "0: aghi 15,160\n\t"
     88                 : : "d"(val1), "d"(val2) : "15", BRASLCLOBBER);
     89    return;
     90 }
     91 
     92 void compare_gt(uint32_t value1, uint32_t value2)
     93 {
     94    register uint32_t val1 asm("r7") = value1;
     95    register uint32_t val2 asm("r8") = value2;
     96 
     97    asm volatile(
     98                 "aghi  15,-160\n\t"
     99                 CLRJ(7,8,8,GT) "\n\t"
    100                 "brasl 14,if_le\n\t"
    101                 "j     0f\n\t"
    102                 "brasl 14,if_gt\n\t"
    103                 "0: aghi 15,160\n\t"
    104                 : : "d"(val1), "d"(val2) : "15", BRASLCLOBBER);
    105    return;
    106 }
    107 
    108 void compare_lt(uint32_t value1, uint32_t value2)
    109 {
    110    register uint32_t val1 asm("r7") = value1;
    111    register uint32_t val2 asm("r8") = value2;
    112 
    113    asm volatile(
    114                 "aghi  15,-160\n\t"
    115                 CLRJ(7,8,8,LT) "\n\t"
    116                 "brasl 14,if_ge\n\t"
    117                 "j     0f\n\t"
    118                 "brasl 14,if_lt\n\t"
    119                 "0: aghi 15,160\n\t"
    120                 : : "d"(val1), "d"(val2) : "15", BRASLCLOBBER);
    121    return;
    122 }
    123 
    124 void compare_eq(uint32_t value1, uint32_t value2)
    125 {
    126    register uint32_t val1 asm("r7") = value1;
    127    register uint32_t val2 asm("r8") = value2;
    128 
    129    asm volatile(
    130                 "aghi  15,-160\n\t"
    131                 CLRJ(7,8,8,EQ) "\n\t"
    132                 "brasl 14,if_ne\n\t"
    133                 "j     0f\n\t"
    134                 "brasl 14,if_eq\n\t"
    135                 "0: aghi 15,160\n\t"
    136                 : : "d"(val1), "d"(val2) : "15", BRASLCLOBBER);
    137    return;
    138 }
    139 
    140 void compare_ne(uint32_t value1, uint32_t value2)
    141 {
    142    register uint32_t val1 asm("r7") = value1;
    143    register uint32_t val2 asm("r8") = value2;
    144 
    145    asm volatile(
    146                 "aghi  15,-160\n\t"
    147                 CLRJ(7,8,8,NE) "\n\t"
    148                 "brasl 14,if_eq\n\t"
    149                 "j     0f\n\t"
    150                 "brasl 14,if_ne\n\t"
    151                 "0: aghi 15,160\n\t"
    152                 : : "d"(val1), "d"(val2) : "15", BRASLCLOBBER);
    153    return;
    154 }
    155 
    156 int main()
    157 {
    158    compare_eq(12, 42);
    159    compare_eq(42, 42);
    160    compare_eq(100, 42);
    161 
    162    compare_ne(12, 42);
    163    compare_ne(42, 42);
    164    compare_ne(100, 42);
    165 
    166    compare_gt(12, 42);
    167    compare_gt(42, 42);
    168    compare_gt(100, 42);
    169 
    170    compare_lt(12, 42);
    171    compare_lt(42, 42);
    172    compare_lt(100, 42);
    173 
    174    compare_le(12, 42);
    175    compare_le(42, 42);
    176    compare_le(100, 42);
    177 
    178    compare_ge(12, 42);
    179    compare_ge(42, 42);
    180    compare_ge(100, 42);
    181 
    182    compare_never(12, 42);
    183    compare_never(42, 42);
    184    compare_never(100, 42);
    185 
    186    compare_always(12, 42);
    187    compare_always(42, 42);
    188    compare_always(100, 42);
    189 
    190    return 0;
    191 }
    192