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 value)
     29 {
     30    register uint32_t val asm("r7") = value;
     31 
     32    asm volatile(
     33                 "aghi  15,-160\n\t"
     34                 CLIJ(7,NEVER,8,2a) "\n\t"    /* 0x2a == 42 */
     35                 "brasl 14,if_not_taken\n\t"
     36                 "j     0f\n\t"
     37                 "brasl 14,if_taken\n\t"
     38                 "0: aghi 15,160\n\t" : : "d"(val) : "15", BRASLCLOBBER);
     39    return;
     40 }
     41 
     42 void compare_always(uint32_t value)
     43 {
     44    register uint32_t val asm("r7") = value;
     45 
     46    asm volatile(
     47                 "aghi  15,-160\n\t"
     48                 CLIJ(7,ALWAYS,8,2a) "\n\t"    /* 0x2a == 42 */
     49                 "brasl 14,if_not_taken\n\t"
     50                 "j     0f\n\t"
     51                 "brasl 14,if_taken\n\t"
     52                 "0: aghi 15,160\n\t" : : "d"(val) : "15", BRASLCLOBBER);
     53    return;
     54 }
     55 
     56 void compare_le42(uint32_t value)
     57 {
     58    register uint32_t val asm("r7") = value;
     59 
     60    asm volatile(
     61                 "aghi  15,-160\n\t"
     62                 CLIJ(7,LE,8,2a) "\n\t"    /* 0x2a == 42 */
     63                 "brasl 14,if_gt\n\t"
     64                 "j     0f\n\t"
     65                 "brasl 14,if_le\n\t"
     66                 "0: aghi 15,160\n\t" : : "d"(val) : "15", BRASLCLOBBER);
     67    return;
     68 }
     69 
     70 void compare_ge42(uint32_t value)
     71 {
     72    register uint32_t val asm("r7") = value;
     73 
     74    asm volatile(
     75                 "aghi  15,-160\n\t"
     76                 CLIJ(7,GE,8,2a) "\n\t"    /* 0x2a == 42 */
     77                 "brasl 14,if_lt\n\t"
     78                 "j     0f\n\t"
     79                 "brasl 14,if_ge\n\t"
     80                 "0: aghi 15,160\n\t" : : "d"(val) : "15", BRASLCLOBBER);
     81    return;
     82 }
     83 
     84 void compare_gt42(uint32_t value)
     85 {
     86    register uint32_t val asm("r7") = value;
     87 
     88    asm volatile(
     89                 "aghi  15,-160\n\t"
     90                 CLIJ(7,GT,8,2a) "\n\t"    /* 0x2a == 42 */
     91                 "brasl 14,if_le\n\t"
     92                 "j     0f\n\t"
     93                 "brasl 14,if_gt\n\t"
     94                 "0: aghi 15,160\n\t" : : "d"(val) : "15", BRASLCLOBBER);
     95    return;
     96 }
     97 
     98 void compare_lt42(uint32_t value)
     99 {
    100    register uint32_t val asm("r7") = value;
    101 
    102    asm volatile(
    103                 "aghi  15,-160\n\t"
    104                 CLIJ(7,LT,8,2a) "\n\t"    /* 0x2a == 42 */
    105                 "brasl 14,if_ge\n\t"
    106                 "j     0f\n\t"
    107                 "brasl 14,if_lt\n\t"
    108                 "0: aghi 15,160\n\t" : : "d"(val) : "15", BRASLCLOBBER);
    109    return;
    110 }
    111 
    112 void compare_eq42(uint32_t value)
    113 {
    114    register uint32_t val asm("r7") = value;
    115 
    116    asm volatile(
    117                 "aghi  15,-160\n\t"
    118                 CLIJ(7,EQ,8,2a) "\n\t"    /* 0x2a == 42 */
    119                 "brasl 14,if_ne\n\t"
    120                 "j     0f\n\t"
    121                 "brasl 14,if_eq\n\t"
    122                 "0: aghi 15,160\n\t" : : "d"(val) : "15", BRASLCLOBBER);
    123    return;
    124 }
    125 
    126 void compare_ne42(uint32_t value)
    127 {
    128    register uint32_t val asm("r7") = value;
    129 
    130    asm volatile(
    131                 "aghi  15,-160\n\t"
    132                 CLIJ(7,NE,8,2a) "\n\t"    /* 0x2a == 42 */
    133                 "brasl 14,if_eq\n\t"
    134                 "j     0f\n\t"
    135                 "brasl 14,if_ne\n\t"
    136                 "0: aghi 15,160\n\t" : : "d"(val) : "15", BRASLCLOBBER);
    137    return;
    138 }
    139 
    140 int main()
    141 {
    142    compare_eq42(12);
    143    compare_eq42(42);
    144    compare_eq42(100);
    145 
    146    compare_ne42(12);
    147    compare_ne42(42);
    148    compare_ne42(100);
    149 
    150    compare_gt42(12);
    151    compare_gt42(42);
    152    compare_gt42(100);
    153 
    154    compare_lt42(12);
    155    compare_lt42(42);
    156    compare_lt42(100);
    157 
    158    compare_le42(12);
    159    compare_le42(42);
    160    compare_le42(100);
    161 
    162    compare_ge42(12);
    163    compare_ge42(42);
    164    compare_ge42(100);
    165 
    166    compare_never(12);
    167    compare_never(42);
    168    compare_never(100);
    169 
    170    compare_always(12);
    171    compare_always(42);
    172    compare_always(100);
    173 
    174    return 0;
    175 }
    176