15484c149fffefd9f41b7dec32900b28e81da5254sewardj
208497723f6857432b200545e0a796be0cc92f4ffsewardj#define FULLTXT 1
308497723f6857432b200545e0a796be0cc92f4ffsewardj
45484c149fffefd9f41b7dec32900b28e81da5254sewardj#define exec_op glue(exec_, OP)
55484c149fffefd9f41b7dec32900b28e81da5254sewardj#define exec_opl glue(glue(exec_, OP), l)
65484c149fffefd9f41b7dec32900b28e81da5254sewardj#define exec_opw glue(glue(exec_, OP), w)
75484c149fffefd9f41b7dec32900b28e81da5254sewardj#define exec_opb glue(glue(exec_, OP), b)
85484c149fffefd9f41b7dec32900b28e81da5254sewardj
95484c149fffefd9f41b7dec32900b28e81da5254sewardj#define EXECOP2(size, res, s1, flags) \
105484c149fffefd9f41b7dec32900b28e81da5254sewardj    asm ("push %4\n\t"\
115484c149fffefd9f41b7dec32900b28e81da5254sewardj         "popf\n\t"\
125484c149fffefd9f41b7dec32900b28e81da5254sewardj         stringify(OP) size " %" size "2, %" size "0\n\t" \
135484c149fffefd9f41b7dec32900b28e81da5254sewardj         "pushf\n\t"\
145484c149fffefd9f41b7dec32900b28e81da5254sewardj         "popl %1\n\t"\
155484c149fffefd9f41b7dec32900b28e81da5254sewardj         : "=q" (res), "=g" (flags)\
165484c149fffefd9f41b7dec32900b28e81da5254sewardj         : "q" (s1), "0" (res), "1" (flags));
175484c149fffefd9f41b7dec32900b28e81da5254sewardj
185484c149fffefd9f41b7dec32900b28e81da5254sewardj#define EXECOP1(size, res, flags) \
195484c149fffefd9f41b7dec32900b28e81da5254sewardj    asm ("push %3\n\t"\
205484c149fffefd9f41b7dec32900b28e81da5254sewardj         "popf\n\t"\
215484c149fffefd9f41b7dec32900b28e81da5254sewardj         stringify(OP) size " %" size "0\n\t" \
225484c149fffefd9f41b7dec32900b28e81da5254sewardj         "pushf\n\t"\
235484c149fffefd9f41b7dec32900b28e81da5254sewardj         "popl %1\n\t"\
245484c149fffefd9f41b7dec32900b28e81da5254sewardj         : "=q" (res), "=g" (flags)\
255484c149fffefd9f41b7dec32900b28e81da5254sewardj         : "0" (res), "1" (flags));
265484c149fffefd9f41b7dec32900b28e81da5254sewardj
275484c149fffefd9f41b7dec32900b28e81da5254sewardj#ifdef OP1
285484c149fffefd9f41b7dec32900b28e81da5254sewardjinline void exec_opl(int s0, int s1, int iflags)
295484c149fffefd9f41b7dec32900b28e81da5254sewardj{
305484c149fffefd9f41b7dec32900b28e81da5254sewardj    int res, flags;
315484c149fffefd9f41b7dec32900b28e81da5254sewardj    res = s0;
325484c149fffefd9f41b7dec32900b28e81da5254sewardj    flags = iflags;
335484c149fffefd9f41b7dec32900b28e81da5254sewardj    EXECOP1("", res, flags);
3408497723f6857432b200545e0a796be0cc92f4ffsewardj    if (FULLTXT)
3508497723f6857432b200545e0a796be0cc92f4ffsewardj       printf("%-6s A=%08x R=%08x CCIN=%04x CC=%04x\n",
3608497723f6857432b200545e0a796be0cc92f4ffsewardj              stringify(OP) "l", s0, res, iflags, flags & CC_MASK);
3708497723f6857432b200545e0a796be0cc92f4ffsewardj    else
3808497723f6857432b200545e0a796be0cc92f4ffsewardj       printf("%08x %04x %04x\n",
3908497723f6857432b200545e0a796be0cc92f4ffsewardj               res, iflags, flags & CC_MASK);
4008497723f6857432b200545e0a796be0cc92f4ffsewardj
415484c149fffefd9f41b7dec32900b28e81da5254sewardj}
425484c149fffefd9f41b7dec32900b28e81da5254sewardjinline void exec_opw(int s0, int s1, int iflags)
435484c149fffefd9f41b7dec32900b28e81da5254sewardj{
445484c149fffefd9f41b7dec32900b28e81da5254sewardj    int res, flags;
455484c149fffefd9f41b7dec32900b28e81da5254sewardj    res = s0;
465484c149fffefd9f41b7dec32900b28e81da5254sewardj    flags = iflags;
475484c149fffefd9f41b7dec32900b28e81da5254sewardj    EXECOP1("w", res, flags);
4808497723f6857432b200545e0a796be0cc92f4ffsewardj    if (FULLTXT)
4908497723f6857432b200545e0a796be0cc92f4ffsewardj       printf("%-6s A=%08x R=%08x CCIN=%04x CC=%04x\n",
5008497723f6857432b200545e0a796be0cc92f4ffsewardj              stringify(OP) "w", s0, res, iflags, flags & CC_MASK);
5108497723f6857432b200545e0a796be0cc92f4ffsewardj    else
5208497723f6857432b200545e0a796be0cc92f4ffsewardj       printf("%08x %04x %04x\n",
5308497723f6857432b200545e0a796be0cc92f4ffsewardj              res, iflags, flags & CC_MASK);
5408497723f6857432b200545e0a796be0cc92f4ffsewardj
555484c149fffefd9f41b7dec32900b28e81da5254sewardj}
565484c149fffefd9f41b7dec32900b28e81da5254sewardjinline void exec_opb(int s0, int s1, int iflags)
575484c149fffefd9f41b7dec32900b28e81da5254sewardj{
585484c149fffefd9f41b7dec32900b28e81da5254sewardj    int res, flags;
595484c149fffefd9f41b7dec32900b28e81da5254sewardj    res = s0;
605484c149fffefd9f41b7dec32900b28e81da5254sewardj    flags = iflags;
615484c149fffefd9f41b7dec32900b28e81da5254sewardj    EXECOP1("b", res, flags);
6208497723f6857432b200545e0a796be0cc92f4ffsewardj    if (FULLTXT)
6308497723f6857432b200545e0a796be0cc92f4ffsewardj       printf("%-6s A=%08x R=%08x CCIN=%04x CC=%04x\n",
6408497723f6857432b200545e0a796be0cc92f4ffsewardj              stringify(OP) "b", s0, res, iflags, flags & CC_MASK);
6508497723f6857432b200545e0a796be0cc92f4ffsewardj    else
6608497723f6857432b200545e0a796be0cc92f4ffsewardj       printf("%08x %04x %04x\n",
6708497723f6857432b200545e0a796be0cc92f4ffsewardj              res, iflags, flags & CC_MASK);
6808497723f6857432b200545e0a796be0cc92f4ffsewardj
695484c149fffefd9f41b7dec32900b28e81da5254sewardj}
705484c149fffefd9f41b7dec32900b28e81da5254sewardj#else
715484c149fffefd9f41b7dec32900b28e81da5254sewardjinline void exec_opl(int s0, int s1, int iflags)
725484c149fffefd9f41b7dec32900b28e81da5254sewardj{
735484c149fffefd9f41b7dec32900b28e81da5254sewardj    int res, flags;
745484c149fffefd9f41b7dec32900b28e81da5254sewardj    res = s0;
755484c149fffefd9f41b7dec32900b28e81da5254sewardj    flags = iflags;
765484c149fffefd9f41b7dec32900b28e81da5254sewardj    EXECOP2("", res, s1, flags);
7708497723f6857432b200545e0a796be0cc92f4ffsewardj    if (FULLTXT)
7808497723f6857432b200545e0a796be0cc92f4ffsewardj       printf("%-6s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
7908497723f6857432b200545e0a796be0cc92f4ffsewardj              stringify(OP) "l", s0, s1, res, iflags, flags & CC_MASK);
8008497723f6857432b200545e0a796be0cc92f4ffsewardj    else
8108497723f6857432b200545e0a796be0cc92f4ffsewardj       printf("%08x %04x %04x\n",
8208497723f6857432b200545e0a796be0cc92f4ffsewardj              res, iflags, flags & CC_MASK);
835484c149fffefd9f41b7dec32900b28e81da5254sewardj}
845484c149fffefd9f41b7dec32900b28e81da5254sewardj
855484c149fffefd9f41b7dec32900b28e81da5254sewardjinline void exec_opw(int s0, int s1, int iflags)
865484c149fffefd9f41b7dec32900b28e81da5254sewardj{
875484c149fffefd9f41b7dec32900b28e81da5254sewardj    int res, flags;
885484c149fffefd9f41b7dec32900b28e81da5254sewardj    res = s0;
895484c149fffefd9f41b7dec32900b28e81da5254sewardj    flags = iflags;
905484c149fffefd9f41b7dec32900b28e81da5254sewardj    EXECOP2("w", res, s1, flags);
9108497723f6857432b200545e0a796be0cc92f4ffsewardj    if (FULLTXT)
9208497723f6857432b200545e0a796be0cc92f4ffsewardj       printf("%-6s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
9308497723f6857432b200545e0a796be0cc92f4ffsewardj              stringify(OP) "w", s0, s1, res, iflags, flags & CC_MASK);
9408497723f6857432b200545e0a796be0cc92f4ffsewardj    else
9508497723f6857432b200545e0a796be0cc92f4ffsewardj       printf("%08x %04x %04x\n",
9608497723f6857432b200545e0a796be0cc92f4ffsewardj              res, iflags, flags & CC_MASK);
975484c149fffefd9f41b7dec32900b28e81da5254sewardj}
985484c149fffefd9f41b7dec32900b28e81da5254sewardj
995484c149fffefd9f41b7dec32900b28e81da5254sewardjinline void exec_opb(int s0, int s1, int iflags)
1005484c149fffefd9f41b7dec32900b28e81da5254sewardj{
1015484c149fffefd9f41b7dec32900b28e81da5254sewardj    int res, flags;
1025484c149fffefd9f41b7dec32900b28e81da5254sewardj    res = s0;
1035484c149fffefd9f41b7dec32900b28e81da5254sewardj    flags = iflags;
1045484c149fffefd9f41b7dec32900b28e81da5254sewardj    EXECOP2("b", res, s1, flags);
10508497723f6857432b200545e0a796be0cc92f4ffsewardj    if (FULLTXT)
10608497723f6857432b200545e0a796be0cc92f4ffsewardj       printf("%-6s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
10708497723f6857432b200545e0a796be0cc92f4ffsewardj              stringify(OP) "b", s0, s1, res, iflags, flags & CC_MASK);
10808497723f6857432b200545e0a796be0cc92f4ffsewardj    else
10908497723f6857432b200545e0a796be0cc92f4ffsewardj       printf("%08x %04x %04x\n",
11008497723f6857432b200545e0a796be0cc92f4ffsewardj              res, iflags, flags & CC_MASK);
1115484c149fffefd9f41b7dec32900b28e81da5254sewardj}
1125484c149fffefd9f41b7dec32900b28e81da5254sewardj#endif
1135484c149fffefd9f41b7dec32900b28e81da5254sewardj
1145484c149fffefd9f41b7dec32900b28e81da5254sewardjvoid exec_op(int s0, int s1)
1155484c149fffefd9f41b7dec32900b28e81da5254sewardj{
1165484c149fffefd9f41b7dec32900b28e81da5254sewardj#if 1
1175484c149fffefd9f41b7dec32900b28e81da5254sewardj  int o,s,z,a,c,p,flags_in;
1185484c149fffefd9f41b7dec32900b28e81da5254sewardj  for (o = 0; o < 2; o++) {
1195484c149fffefd9f41b7dec32900b28e81da5254sewardj  for (s = 0; s < 2; s++) {
1205484c149fffefd9f41b7dec32900b28e81da5254sewardj  for (z = 0; z < 2; z++) {
1215484c149fffefd9f41b7dec32900b28e81da5254sewardj  for (a = 0; a < 2; a++) {
1225484c149fffefd9f41b7dec32900b28e81da5254sewardj  for (c = 0; c < 2; c++) {
1235484c149fffefd9f41b7dec32900b28e81da5254sewardj  for (p = 0; p < 2; p++) {
1245484c149fffefd9f41b7dec32900b28e81da5254sewardj
1255484c149fffefd9f41b7dec32900b28e81da5254sewardj    flags_in = (o ? CC_O : 0)
1265484c149fffefd9f41b7dec32900b28e81da5254sewardj             | (s ? CC_S : 0)
1275484c149fffefd9f41b7dec32900b28e81da5254sewardj             | (z ? CC_Z : 0)
1285484c149fffefd9f41b7dec32900b28e81da5254sewardj             | (a ? CC_A : 0)
1295484c149fffefd9f41b7dec32900b28e81da5254sewardj             | (c ? CC_C : 0)
1305484c149fffefd9f41b7dec32900b28e81da5254sewardj             | (p ? CC_P : 0);
1315484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_opl(s0, s1, flags_in);
1325484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_opw(s0, s1, flags_in);
1335484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_opb(s0, s1, flags_in);
1345484c149fffefd9f41b7dec32900b28e81da5254sewardj  }}}}}}
1355484c149fffefd9f41b7dec32900b28e81da5254sewardj#else
1365484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_opl(s0, s1, 0);
1375484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_opw(s0, s1, 0);
1385484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_opb(s0, s1, 0);
1395484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_opl(s0, s1, CC_C);
1405484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_opw(s0, s1, CC_C);
1415484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_opb(s0, s1, CC_C);
1425484c149fffefd9f41b7dec32900b28e81da5254sewardj#endif
1435484c149fffefd9f41b7dec32900b28e81da5254sewardj}
1445484c149fffefd9f41b7dec32900b28e81da5254sewardj
1455484c149fffefd9f41b7dec32900b28e81da5254sewardjvoid glue(test_, OP)(void)
1465484c149fffefd9f41b7dec32900b28e81da5254sewardj{
1475484c149fffefd9f41b7dec32900b28e81da5254sewardj#define NVALS 57
1485484c149fffefd9f41b7dec32900b28e81da5254sewardj   int i, j;
1495484c149fffefd9f41b7dec32900b28e81da5254sewardj   static unsigned int val[NVALS]
1505484c149fffefd9f41b7dec32900b28e81da5254sewardj    = { 0x00, 0x01, 0x02, 0x03,
1515484c149fffefd9f41b7dec32900b28e81da5254sewardj        0x3F, 0x40, 0x41,
1525484c149fffefd9f41b7dec32900b28e81da5254sewardj        0x7E, 0x7F, 0x80, 0x81, 0x82,
1535484c149fffefd9f41b7dec32900b28e81da5254sewardj        0xBF, 0xC0, 0xC1,
1545484c149fffefd9f41b7dec32900b28e81da5254sewardj        0xFC, 0xFD, 0xFE, 0xFF,
1555484c149fffefd9f41b7dec32900b28e81da5254sewardj
1565484c149fffefd9f41b7dec32900b28e81da5254sewardj        0xFF00, 0xFF01, 0xFF02, 0xFF03,
1575484c149fffefd9f41b7dec32900b28e81da5254sewardj        0xFF3F, 0xFF40, 0xFF41,
1585484c149fffefd9f41b7dec32900b28e81da5254sewardj        0xFF7E, 0xFF7F, 0xFF80, 0xFF81, 0xFF82,
1595484c149fffefd9f41b7dec32900b28e81da5254sewardj        0xFFBF, 0xFFC0, 0xFFC1,
1605484c149fffefd9f41b7dec32900b28e81da5254sewardj        0xFFFC, 0xFFFD, 0xFFFE, 0xFFFF,
1615484c149fffefd9f41b7dec32900b28e81da5254sewardj
1625484c149fffefd9f41b7dec32900b28e81da5254sewardj        0xFFFFFF00, 0xFFFFFF01, 0xFFFFFF02, 0xFFFFFF03,
1635484c149fffefd9f41b7dec32900b28e81da5254sewardj        0xFFFFFF3F, 0xFFFFFF40, 0xFFFFFF41,
1645484c149fffefd9f41b7dec32900b28e81da5254sewardj        0xFFFFFF7E, 0xFFFFFF7F, 0xFFFFFF80, 0xFFFFFF81, 0xFFFFFF82,
1655484c149fffefd9f41b7dec32900b28e81da5254sewardj        0xFFFFFFBF, 0xFFFFFFC0, 0xFFFFFFC1,
1665484c149fffefd9f41b7dec32900b28e81da5254sewardj        0xFFFFFFFC, 0xFFFFFFFD, 0xFFFFFFFE, 0xFFFFFFFF
1675484c149fffefd9f41b7dec32900b28e81da5254sewardj      };
1685484c149fffefd9f41b7dec32900b28e81da5254sewardj
1695484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x12345678, 0x812FADA);
1705484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x12341, 0x12341);
1715484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x12341, -0x12341);
1725484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0xffffffff, 0);
1735484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0xffffffff, -1);
1745484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0xffffffff, 1);
1755484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0xffffffff, 2);
1765484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x7fffffff, 0);
1775484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x7fffffff, 1);
1785484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x7fffffff, -1);
1795484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x80000000, -1);
1805484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x80000000, 1);
1815484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x80000000, -2);
1825484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x12347fff, 0);
1835484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x12347fff, 1);
1845484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x12347fff, -1);
1855484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x12348000, -1);
1865484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x12348000, 1);
1875484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x12348000, -2);
1885484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x12347f7f, 0);
1895484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x12347f7f, 1);
1905484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x12347f7f, -1);
1915484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x12348080, -1);
1925484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x12348080, 1);
1935484c149fffefd9f41b7dec32900b28e81da5254sewardj    exec_op(0x12348080, -2);
1945484c149fffefd9f41b7dec32900b28e81da5254sewardj
195686edb9fee8361f7411216c9b90045888c21468fsewardj#if TEST_INTEGER_VERBOSE
1962b5b75151063e2d150760ea826e3d4152149ee14sewardj    if (1)
1975484c149fffefd9f41b7dec32900b28e81da5254sewardj    for (i = 0; i < NVALS; i++)
1985484c149fffefd9f41b7dec32900b28e81da5254sewardj      for (j = 0; j < NVALS; j++)
1995484c149fffefd9f41b7dec32900b28e81da5254sewardj	exec_op(val[i], val[j]);
200686edb9fee8361f7411216c9b90045888c21468fsewardj#endif
201686edb9fee8361f7411216c9b90045888c21468fsewardj
2025484c149fffefd9f41b7dec32900b28e81da5254sewardj#undef NVALS
2035484c149fffefd9f41b7dec32900b28e81da5254sewardj}
2045484c149fffefd9f41b7dec32900b28e81da5254sewardj
2055484c149fffefd9f41b7dec32900b28e81da5254sewardjvoid *glue(_test_, OP) __init_call = glue(test_, OP);
2065484c149fffefd9f41b7dec32900b28e81da5254sewardj
2075484c149fffefd9f41b7dec32900b28e81da5254sewardj#undef OP
2085484c149fffefd9f41b7dec32900b28e81da5254sewardj#undef OP_CC
20908497723f6857432b200545e0a796be0cc92f4ffsewardj
21008497723f6857432b200545e0a796be0cc92f4ffsewardj#undef FULLTXT
211