Home | History | Annotate | Download | only in auxprogs
      1 
      2 #include <stdio.h>
      3 
      4 typedef  unsigned long long int  ULong;
      5 
      6 /* ------------------------ SRADI ------------------------ */
      7 
      8 #define INSN_SRADI(nnn)                                                    \
      9    void do_sradi_##nnn ( ULong arg, /*OUT*/ULong* res, /*OUT*/ULong* xer ) \
     10    {                                                                       \
     11      ULong argW = arg;                                                     \
     12      ULong resW = 0;                                                       \
     13      ULong xerW = 0;                                                       \
     14      __asm__ __volatile__(                                                 \
     15         "sradi %0,%2, " #nnn "\n\t"                                        \
     16         "mfxer %1"                                                         \
     17         : /*out*/ "=b"(resW),  "=b"(xerW)                                  \
     18         : /*in*/  "b"(argW)                                                \
     19         : /*trash*/ "cc"                                                   \
     20      );                                                                    \
     21      *res = resW;                                                          \
     22      *xer = xerW;                                                          \
     23    }
     24 
     25 INSN_SRADI(0)
     26 INSN_SRADI(1)
     27 INSN_SRADI(2)
     28 INSN_SRADI(3)
     29 INSN_SRADI(4)
     30 INSN_SRADI(5)
     31 INSN_SRADI(6)
     32 INSN_SRADI(7)
     33 INSN_SRADI(8)
     34 INSN_SRADI(9)
     35 INSN_SRADI(10)
     36 INSN_SRADI(11)
     37 INSN_SRADI(12)
     38 INSN_SRADI(13)
     39 INSN_SRADI(14)
     40 INSN_SRADI(15)
     41 INSN_SRADI(16)
     42 INSN_SRADI(17)
     43 INSN_SRADI(18)
     44 INSN_SRADI(19)
     45 INSN_SRADI(20)
     46 INSN_SRADI(21)
     47 INSN_SRADI(22)
     48 INSN_SRADI(23)
     49 INSN_SRADI(24)
     50 INSN_SRADI(25)
     51 INSN_SRADI(26)
     52 INSN_SRADI(27)
     53 INSN_SRADI(28)
     54 INSN_SRADI(29)
     55 INSN_SRADI(30)
     56 INSN_SRADI(31)
     57 INSN_SRADI(32)
     58 INSN_SRADI(33)
     59 INSN_SRADI(34)
     60 INSN_SRADI(35)
     61 INSN_SRADI(36)
     62 INSN_SRADI(37)
     63 INSN_SRADI(38)
     64 INSN_SRADI(39)
     65 INSN_SRADI(40)
     66 INSN_SRADI(41)
     67 INSN_SRADI(42)
     68 INSN_SRADI(43)
     69 INSN_SRADI(44)
     70 INSN_SRADI(45)
     71 INSN_SRADI(46)
     72 INSN_SRADI(47)
     73 INSN_SRADI(48)
     74 INSN_SRADI(49)
     75 INSN_SRADI(50)
     76 INSN_SRADI(51)
     77 INSN_SRADI(52)
     78 INSN_SRADI(53)
     79 INSN_SRADI(54)
     80 INSN_SRADI(55)
     81 INSN_SRADI(56)
     82 INSN_SRADI(57)
     83 INSN_SRADI(58)
     84 INSN_SRADI(59)
     85 INSN_SRADI(60)
     86 INSN_SRADI(61)
     87 INSN_SRADI(62)
     88 INSN_SRADI(63)
     89 
     90 static void* all_sradi[64]
     91   = {
     92        (void*)&do_sradi_0,
     93        (void*)&do_sradi_1,
     94        (void*)&do_sradi_2,
     95        (void*)&do_sradi_3,
     96        (void*)&do_sradi_4,
     97        (void*)&do_sradi_5,
     98        (void*)&do_sradi_6,
     99        (void*)&do_sradi_7,
    100        (void*)&do_sradi_8,
    101        (void*)&do_sradi_9,
    102        (void*)&do_sradi_10,
    103        (void*)&do_sradi_11,
    104        (void*)&do_sradi_12,
    105        (void*)&do_sradi_13,
    106        (void*)&do_sradi_14,
    107        (void*)&do_sradi_15,
    108        (void*)&do_sradi_16,
    109        (void*)&do_sradi_17,
    110        (void*)&do_sradi_18,
    111        (void*)&do_sradi_19,
    112        (void*)&do_sradi_20,
    113        (void*)&do_sradi_21,
    114        (void*)&do_sradi_22,
    115        (void*)&do_sradi_23,
    116        (void*)&do_sradi_24,
    117        (void*)&do_sradi_25,
    118        (void*)&do_sradi_26,
    119        (void*)&do_sradi_27,
    120        (void*)&do_sradi_28,
    121        (void*)&do_sradi_29,
    122        (void*)&do_sradi_30,
    123        (void*)&do_sradi_31,
    124        (void*)&do_sradi_32,
    125        (void*)&do_sradi_33,
    126        (void*)&do_sradi_34,
    127        (void*)&do_sradi_35,
    128        (void*)&do_sradi_36,
    129        (void*)&do_sradi_37,
    130        (void*)&do_sradi_38,
    131        (void*)&do_sradi_39,
    132        (void*)&do_sradi_40,
    133        (void*)&do_sradi_41,
    134        (void*)&do_sradi_42,
    135        (void*)&do_sradi_43,
    136        (void*)&do_sradi_44,
    137        (void*)&do_sradi_45,
    138        (void*)&do_sradi_46,
    139        (void*)&do_sradi_47,
    140        (void*)&do_sradi_48,
    141        (void*)&do_sradi_49,
    142        (void*)&do_sradi_50,
    143        (void*)&do_sradi_51,
    144        (void*)&do_sradi_52,
    145        (void*)&do_sradi_53,
    146        (void*)&do_sradi_54,
    147        (void*)&do_sradi_55,
    148        (void*)&do_sradi_56,
    149        (void*)&do_sradi_57,
    150        (void*)&do_sradi_58,
    151        (void*)&do_sradi_59,
    152        (void*)&do_sradi_60,
    153        (void*)&do_sradi_61,
    154        (void*)&do_sradi_62,
    155        (void*)&do_sradi_63
    156    };
    157 
    158 /* ------------------------ SRAWI ------------------------ */
    159 
    160 #define INSN_SRAWI(nnn)                                                    \
    161    void do_srawi_##nnn ( ULong arg, /*OUT*/ULong* res, /*OUT*/ULong* xer ) \
    162    {                                                                       \
    163      ULong argW = arg;                                                     \
    164      ULong resW = 0;                                                       \
    165      ULong xerW = 0;                                                       \
    166      __asm__ __volatile__(                                                 \
    167         "srawi %0,%2, " #nnn "\n\t"                                        \
    168         "mfxer %1"                                                         \
    169         : /*out*/ "=b"(resW),  "=b"(xerW)                                  \
    170         : /*in*/  "b"(argW)                                                \
    171         : /*trash*/ "cc"                                                   \
    172      );                                                                    \
    173      *res = resW;                                                          \
    174      *xer = xerW;                                                          \
    175    }
    176 
    177 INSN_SRAWI(0)
    178 INSN_SRAWI(1)
    179 INSN_SRAWI(2)
    180 INSN_SRAWI(3)
    181 INSN_SRAWI(4)
    182 INSN_SRAWI(5)
    183 INSN_SRAWI(6)
    184 INSN_SRAWI(7)
    185 INSN_SRAWI(8)
    186 INSN_SRAWI(9)
    187 INSN_SRAWI(10)
    188 INSN_SRAWI(11)
    189 INSN_SRAWI(12)
    190 INSN_SRAWI(13)
    191 INSN_SRAWI(14)
    192 INSN_SRAWI(15)
    193 INSN_SRAWI(16)
    194 INSN_SRAWI(17)
    195 INSN_SRAWI(18)
    196 INSN_SRAWI(19)
    197 INSN_SRAWI(20)
    198 INSN_SRAWI(21)
    199 INSN_SRAWI(22)
    200 INSN_SRAWI(23)
    201 INSN_SRAWI(24)
    202 INSN_SRAWI(25)
    203 INSN_SRAWI(26)
    204 INSN_SRAWI(27)
    205 INSN_SRAWI(28)
    206 INSN_SRAWI(29)
    207 INSN_SRAWI(30)
    208 INSN_SRAWI(31)
    209 
    210 static void* all_srawi[32]
    211   = {
    212        (void*)&do_srawi_0,
    213        (void*)&do_srawi_1,
    214        (void*)&do_srawi_2,
    215        (void*)&do_srawi_3,
    216        (void*)&do_srawi_4,
    217        (void*)&do_srawi_5,
    218        (void*)&do_srawi_6,
    219        (void*)&do_srawi_7,
    220        (void*)&do_srawi_8,
    221        (void*)&do_srawi_9,
    222        (void*)&do_srawi_10,
    223        (void*)&do_srawi_11,
    224        (void*)&do_srawi_12,
    225        (void*)&do_srawi_13,
    226        (void*)&do_srawi_14,
    227        (void*)&do_srawi_15,
    228        (void*)&do_srawi_16,
    229        (void*)&do_srawi_17,
    230        (void*)&do_srawi_18,
    231        (void*)&do_srawi_19,
    232        (void*)&do_srawi_20,
    233        (void*)&do_srawi_21,
    234        (void*)&do_srawi_22,
    235        (void*)&do_srawi_23,
    236        (void*)&do_srawi_24,
    237        (void*)&do_srawi_25,
    238        (void*)&do_srawi_26,
    239        (void*)&do_srawi_27,
    240        (void*)&do_srawi_28,
    241        (void*)&do_srawi_29,
    242        (void*)&do_srawi_30,
    243        (void*)&do_srawi_31
    244    };
    245 
    246 /* ------------------------ SRAD ------------------------ */
    247 
    248 void do_srad ( ULong arg1, ULong arg2,
    249                /*OUT*/ULong* res, /*OUT*/ULong* xer )
    250 {
    251    ULong arg1W = arg1;
    252    ULong arg2W = arg2;
    253    ULong resW  = 0;
    254    ULong xerW  = 0;
    255    __asm__ __volatile__(
    256      "srad %0,%2,%3\n\t"
    257      "mfxer %1"
    258      : /*out*/ "=b"(resW),  "=b"(xerW)
    259      : /*in*/  "b"(arg1W), "b"(arg2W)
    260      : /*trash*/ "cc"
    261   );
    262   *res = resW;
    263   *xer = xerW;
    264 }
    265 
    266 
    267 /* ------------------------ SRAW ------------------------ */
    268 
    269 void do_sraw ( ULong arg1, ULong arg2,
    270                /*OUT*/ULong* res, /*OUT*/ULong* xer )
    271 {
    272    ULong arg1W = arg1;
    273    ULong arg2W = arg2;
    274    ULong resW  = 0;
    275    ULong xerW  = 0;
    276    __asm__ __volatile__(
    277      "sraw %0,%2,%3\n\t"
    278      "mfxer %1"
    279      : /*out*/ "=b"(resW),  "=b"(xerW)
    280      : /*in*/  "b"(arg1W), "b"(arg2W)
    281      : /*trash*/ "cc"
    282   );
    283   *res = resW;
    284   *xer = xerW;
    285 }
    286 
    287 /* ------------------------ SRD ------------------------ */
    288 
    289 void do_srd ( ULong arg1, ULong arg2,
    290               /*OUT*/ULong* res, /*OUT*/ULong* xer )
    291 {
    292    ULong arg1W = arg1;
    293    ULong arg2W = arg2;
    294    ULong resW  = 0;
    295    ULong xerW  = 0;
    296    __asm__ __volatile__(
    297      "srd %0,%2,%3\n\t"
    298      "mfxer %1"
    299      : /*out*/ "=b"(resW),  "=b"(xerW)
    300      : /*in*/  "b"(arg1W), "b"(arg2W)
    301      : /*trash*/ "cc"
    302   );
    303   *res = resW;
    304   *xer = xerW;
    305 }
    306 
    307 
    308 /* ------------------------ SRW ------------------------ */
    309 
    310 void do_srw ( ULong arg1, ULong arg2,
    311               /*OUT*/ULong* res, /*OUT*/ULong* xer )
    312 {
    313    ULong arg1W = arg1;
    314    ULong arg2W = arg2;
    315    ULong resW  = 0;
    316    ULong xerW  = 0;
    317    __asm__ __volatile__(
    318      "srw %0,%2,%3\n\t"
    319      "mfxer %1"
    320      : /*out*/ "=b"(resW),  "=b"(xerW)
    321      : /*in*/  "b"(arg1W), "b"(arg2W)
    322      : /*trash*/ "cc"
    323   );
    324   *res = resW;
    325   *xer = xerW;
    326 }
    327 
    328 
    329 /* ------------------------ SLD ------------------------ */
    330 
    331 void do_sld ( ULong arg1, ULong arg2,
    332               /*OUT*/ULong* res, /*OUT*/ULong* xer )
    333 {
    334    ULong arg1W = arg1;
    335    ULong arg2W = arg2;
    336    ULong resW  = 0;
    337    ULong xerW  = 0;
    338    __asm__ __volatile__(
    339      "sld %0,%2,%3\n\t"
    340      "mfxer %1"
    341      : /*out*/ "=b"(resW),  "=b"(xerW)
    342      : /*in*/  "b"(arg1W), "b"(arg2W)
    343      : /*trash*/ "cc"
    344   );
    345   *res = resW;
    346   *xer = xerW;
    347 }
    348 
    349 
    350 /* ------------------------ SLW ------------------------ */
    351 
    352 void do_slw ( ULong arg1, ULong arg2,
    353               /*OUT*/ULong* res, /*OUT*/ULong* xer )
    354 {
    355    ULong arg1W = arg1;
    356    ULong arg2W = arg2;
    357    ULong resW  = 0;
    358    ULong xerW  = 0;
    359    __asm__ __volatile__(
    360      "slw %0,%2,%3\n\t"
    361      "mfxer %1"
    362      : /*out*/ "=b"(resW),  "=b"(xerW)
    363      : /*in*/  "b"(arg1W), "b"(arg2W)
    364      : /*trash*/ "cc"
    365   );
    366   *res = resW;
    367   *xer = xerW;
    368 }
    369 
    370 
    371 /* ------------------------  ------------------------ */
    372 /* ------------------------  ------------------------ */
    373 /* ------------------------  ------------------------ */
    374 
    375 #define N_ARGS64 41
    376 
    377 ULong args64[N_ARGS64] = {
    378   0x0000000000000000ULL,
    379 
    380   0x0000000000000001ULL,
    381   0x0000000031415927ULL,
    382   0x000000007FFFFFFFULL,
    383   0x0000000080000000ULL,
    384   0x00000000FFFFFFFFULL,
    385 
    386   0x0000000100000000ULL,
    387   0x3141592700000000ULL,
    388   0x7FFFFFFF00000000ULL,
    389   0x8000000000000000ULL,
    390   0xFFFFFFFF00000000ULL,
    391 
    392   0x7FFFFFFF00000001ULL,
    393   0x7FFFFFFF31415927ULL,
    394   0x7FFFFFFF7FFFFFFFULL,
    395   0x7FFFFFFF80000000ULL,
    396   0x7FFFFFFFFFFFFFFFULL,
    397 
    398   0x000000017FFFFFFFULL,
    399   0x314159277FFFFFFFULL,
    400   0x7FFFFFFF7FFFFFFFULL,
    401   0x800000007FFFFFFFULL,
    402   0xFFFFFFFF7FFFFFFFULL,
    403 
    404   0x8000000000000001ULL,
    405   0x8000000031415927ULL,
    406   0x800000007FFFFFFFULL,
    407   0x8000000080000000ULL,
    408   0x80000000FFFFFFFFULL,
    409 
    410   0x0000000180000000ULL,
    411   0x3141592780000000ULL,
    412   0x7FFFFFFF80000000ULL,
    413   0x8000000080000000ULL,
    414   0xFFFFFFFF80000000ULL,
    415 
    416   0xFFFFFFFF00000001ULL,
    417   0xFFFFFFFF31415927ULL,
    418   0xFFFFFFFF7FFFFFFFULL,
    419   0xFFFFFFFF80000000ULL,
    420   0xFFFFFFFFFFFFFFFFULL,
    421 
    422   0x00000001FFFFFFFFULL,
    423   0x31415927FFFFFFFFULL,
    424   0x7FFFFFFFFFFFFFFFULL,
    425   0x80000000FFFFFFFFULL,
    426   0xFFFFFFFFFFFFFFFFULL
    427 };
    428 
    429 void do_unary ( char* name, void** fns, int n_fns )
    430 {
    431    int i, j;
    432    ULong arg, res, xer;
    433    void(*fn)(ULong,ULong*,ULong*);
    434    for (i = 0; i < n_fns; i++) { /* shift */
    435       for (j = 0; j < N_ARGS64; j++) { /* arg */
    436          arg = args64[j];
    437          res = xer = 0;
    438          fn = fns[i];
    439          fn( arg, &res, &xer );
    440          printf("%5s(0x%016llx, %2d) = 0x%016llx, %d\n",
    441                 name, arg, (int)i, res, (int)((xer >> 29 & 1)));
    442       }
    443    }
    444 }
    445 
    446 void do_binary ( char* name, void* fnV )
    447 {
    448    int i, j;
    449    ULong arg1, arg2, res, xer;
    450    void(*fn)(ULong,ULong,ULong*,ULong*);
    451    for (i = 0; i < 64+10; i++) { /* shift */
    452       for (j = 0; j < N_ARGS64; j++) { /* arg */
    453          arg1 = args64[j];
    454          arg2 = i;
    455          res = xer = 0;
    456          fn = fnV;
    457          fn( arg1, arg2, &res, &xer );
    458          printf("%5s(0x%016llx, %2d) = 0x%016llx, %d\n",
    459                 name, arg1, (int)arg2, res, (int)((xer >> 29 & 1)));
    460       }
    461    }
    462 }
    463 
    464 int main ( void )
    465 {
    466    do_unary("sradi", all_sradi, 64);
    467    do_unary("srawi", all_srawi, 32);
    468    do_binary("srad", do_srad);
    469    do_binary("sraw", do_sraw);
    470    do_binary("srd",  do_srd);
    471    do_binary("srw",  do_srw);
    472    do_binary("sld",  do_sld);
    473    do_binary("slw",  do_slw);
    474    return 0;
    475 }
    476 
    477 /*
    478 0
    479 1
    480 2
    481 3
    482 4
    483 5
    484 6
    485 7
    486 8
    487 9
    488 10
    489 11
    490 12
    491 13
    492 14
    493 15
    494 16
    495 17
    496 18
    497 19
    498 20
    499 21
    500 22
    501 23
    502 24
    503 25
    504 26
    505 27
    506 28
    507 29
    508 30
    509 31
    510 32
    511 33
    512 34
    513 35
    514 36
    515 37
    516 38
    517 39
    518 40
    519 41
    520 42
    521 43
    522 44
    523 45
    524 46
    525 47
    526 48
    527 49
    528 50
    529 51
    530 52
    531 53
    532 54
    533 55
    534 56
    535 57
    536 58
    537 59
    538 60
    539 61
    540 62
    541 63
    542 */
    543 
    544