Home | History | Annotate | Download | only in test
      1 
      2 #define FULLTXT 1
      3 
      4 #define exec_op glue(exec_, OP)
      5 #define exec_opl glue(glue(exec_, OP), l)
      6 #define exec_opw glue(glue(exec_, OP), w)
      7 #define exec_opb glue(glue(exec_, OP), b)
      8 
      9 #define EXECOP2(size, res, s1, flags) \
     10     asm ("push %4\n\t"\
     11          "popf\n\t"\
     12          stringify(OP) size " %" size "2, %" size "0\n\t" \
     13          "pushf\n\t"\
     14          "popl %1\n\t"\
     15          : "=q" (res), "=g" (flags)\
     16          : "q" (s1), "0" (res), "1" (flags));
     17 
     18 #define EXECOP1(size, res, flags) \
     19     asm ("push %3\n\t"\
     20          "popf\n\t"\
     21          stringify(OP) size " %" size "0\n\t" \
     22          "pushf\n\t"\
     23          "popl %1\n\t"\
     24          : "=q" (res), "=g" (flags)\
     25          : "0" (res), "1" (flags));
     26 
     27 #ifdef OP1
     28 inline void exec_opl(int s0, int s1, int iflags)
     29 {
     30     int res, flags;
     31     res = s0;
     32     flags = iflags;
     33     EXECOP1("", res, flags);
     34     if (FULLTXT)
     35        printf("%-6s A=%08x R=%08x CCIN=%04x CC=%04x\n",
     36               stringify(OP) "l", s0, res, iflags, flags & CC_MASK);
     37     else
     38        printf("%08x %04x %04x\n",
     39                res, iflags, flags & CC_MASK);
     40 
     41 }
     42 inline void exec_opw(int s0, int s1, int iflags)
     43 {
     44     int res, flags;
     45     res = s0;
     46     flags = iflags;
     47     EXECOP1("w", res, flags);
     48     if (FULLTXT)
     49        printf("%-6s A=%08x R=%08x CCIN=%04x CC=%04x\n",
     50               stringify(OP) "w", s0, res, iflags, flags & CC_MASK);
     51     else
     52        printf("%08x %04x %04x\n",
     53               res, iflags, flags & CC_MASK);
     54 
     55 }
     56 inline void exec_opb(int s0, int s1, int iflags)
     57 {
     58     int res, flags;
     59     res = s0;
     60     flags = iflags;
     61     EXECOP1("b", res, flags);
     62     if (FULLTXT)
     63        printf("%-6s A=%08x R=%08x CCIN=%04x CC=%04x\n",
     64               stringify(OP) "b", s0, res, iflags, flags & CC_MASK);
     65     else
     66        printf("%08x %04x %04x\n",
     67               res, iflags, flags & CC_MASK);
     68 
     69 }
     70 #else
     71 inline void exec_opl(int s0, int s1, int iflags)
     72 {
     73     int res, flags;
     74     res = s0;
     75     flags = iflags;
     76     EXECOP2("", res, s1, flags);
     77     if (FULLTXT)
     78        printf("%-6s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
     79               stringify(OP) "l", s0, s1, res, iflags, flags & CC_MASK);
     80     else
     81        printf("%08x %04x %04x\n",
     82               res, iflags, flags & CC_MASK);
     83 }
     84 
     85 inline void exec_opw(int s0, int s1, int iflags)
     86 {
     87     int res, flags;
     88     res = s0;
     89     flags = iflags;
     90     EXECOP2("w", res, s1, flags);
     91     if (FULLTXT)
     92        printf("%-6s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
     93               stringify(OP) "w", s0, s1, res, iflags, flags & CC_MASK);
     94     else
     95        printf("%08x %04x %04x\n",
     96               res, iflags, flags & CC_MASK);
     97 }
     98 
     99 inline void exec_opb(int s0, int s1, int iflags)
    100 {
    101     int res, flags;
    102     res = s0;
    103     flags = iflags;
    104     EXECOP2("b", res, s1, flags);
    105     if (FULLTXT)
    106        printf("%-6s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
    107               stringify(OP) "b", s0, s1, res, iflags, flags & CC_MASK);
    108     else
    109        printf("%08x %04x %04x\n",
    110               res, iflags, flags & CC_MASK);
    111 }
    112 #endif
    113 
    114 void exec_op(int s0, int s1)
    115 {
    116 #if 1
    117   int o,s,z,a,c,p,flags_in;
    118   for (o = 0; o < 2; o++) {
    119   for (s = 0; s < 2; s++) {
    120   for (z = 0; z < 2; z++) {
    121   for (a = 0; a < 2; a++) {
    122   for (c = 0; c < 2; c++) {
    123   for (p = 0; p < 2; p++) {
    124 
    125     flags_in = (o ? CC_O : 0)
    126              | (s ? CC_S : 0)
    127              | (z ? CC_Z : 0)
    128              | (a ? CC_A : 0)
    129              | (c ? CC_C : 0)
    130              | (p ? CC_P : 0);
    131     exec_opl(s0, s1, flags_in);
    132     exec_opw(s0, s1, flags_in);
    133     exec_opb(s0, s1, flags_in);
    134   }}}}}}
    135 #else
    136     exec_opl(s0, s1, 0);
    137     exec_opw(s0, s1, 0);
    138     exec_opb(s0, s1, 0);
    139     exec_opl(s0, s1, CC_C);
    140     exec_opw(s0, s1, CC_C);
    141     exec_opb(s0, s1, CC_C);
    142 #endif
    143 }
    144 
    145 void glue(test_, OP)(void)
    146 {
    147 #define NVALS 57
    148    int i, j;
    149    static unsigned int val[NVALS]
    150     = { 0x00, 0x01, 0x02, 0x03,
    151         0x3F, 0x40, 0x41,
    152         0x7E, 0x7F, 0x80, 0x81, 0x82,
    153         0xBF, 0xC0, 0xC1,
    154         0xFC, 0xFD, 0xFE, 0xFF,
    155 
    156         0xFF00, 0xFF01, 0xFF02, 0xFF03,
    157         0xFF3F, 0xFF40, 0xFF41,
    158         0xFF7E, 0xFF7F, 0xFF80, 0xFF81, 0xFF82,
    159         0xFFBF, 0xFFC0, 0xFFC1,
    160         0xFFFC, 0xFFFD, 0xFFFE, 0xFFFF,
    161 
    162         0xFFFFFF00, 0xFFFFFF01, 0xFFFFFF02, 0xFFFFFF03,
    163         0xFFFFFF3F, 0xFFFFFF40, 0xFFFFFF41,
    164         0xFFFFFF7E, 0xFFFFFF7F, 0xFFFFFF80, 0xFFFFFF81, 0xFFFFFF82,
    165         0xFFFFFFBF, 0xFFFFFFC0, 0xFFFFFFC1,
    166         0xFFFFFFFC, 0xFFFFFFFD, 0xFFFFFFFE, 0xFFFFFFFF
    167       };
    168 
    169     exec_op(0x12345678, 0x812FADA);
    170     exec_op(0x12341, 0x12341);
    171     exec_op(0x12341, -0x12341);
    172     exec_op(0xffffffff, 0);
    173     exec_op(0xffffffff, -1);
    174     exec_op(0xffffffff, 1);
    175     exec_op(0xffffffff, 2);
    176     exec_op(0x7fffffff, 0);
    177     exec_op(0x7fffffff, 1);
    178     exec_op(0x7fffffff, -1);
    179     exec_op(0x80000000, -1);
    180     exec_op(0x80000000, 1);
    181     exec_op(0x80000000, -2);
    182     exec_op(0x12347fff, 0);
    183     exec_op(0x12347fff, 1);
    184     exec_op(0x12347fff, -1);
    185     exec_op(0x12348000, -1);
    186     exec_op(0x12348000, 1);
    187     exec_op(0x12348000, -2);
    188     exec_op(0x12347f7f, 0);
    189     exec_op(0x12347f7f, 1);
    190     exec_op(0x12347f7f, -1);
    191     exec_op(0x12348080, -1);
    192     exec_op(0x12348080, 1);
    193     exec_op(0x12348080, -2);
    194 
    195 #if TEST_INTEGER_VERBOSE
    196     if (1)
    197     for (i = 0; i < NVALS; i++)
    198       for (j = 0; j < NVALS; j++)
    199 	exec_op(val[i], val[j]);
    200 #endif
    201 
    202 #undef NVALS
    203 }
    204 
    205 void *glue(_test_, OP) __init_call = glue(test_, OP);
    206 
    207 #undef OP
    208 #undef OP_CC
    209 
    210 #undef FULLTXT
    211