test-i386.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #define exec_op glue(exec_, OP)
  2. #define exec_opq glue(glue(exec_, OP), q)
  3. #define exec_opl glue(glue(exec_, OP), l)
  4. #define exec_opw glue(glue(exec_, OP), w)
  5. #define exec_opb glue(glue(exec_, OP), b)
  6. #define EXECOP2(size, rsize, res, s1, flags) \
  7. asm ("push %4\n\t"\
  8. "popf\n\t"\
  9. stringify(OP) size " %" rsize "2, %" rsize "0\n\t" \
  10. "pushf\n\t"\
  11. "pop %1\n\t"\
  12. : "=q" (res), "=g" (flags)\
  13. : "q" (s1), "0" (res), "1" (flags)); \
  14. printf("%-10s A=" FMTLX " B=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n", \
  15. stringify(OP) size, s0, s1, res, iflags, flags & CC_MASK);
  16. #define EXECOP1(size, rsize, res, flags) \
  17. asm ("push %3\n\t"\
  18. "popf\n\t"\
  19. stringify(OP) size " %" rsize "0\n\t" \
  20. "pushf\n\t"\
  21. "pop %1\n\t"\
  22. : "=q" (res), "=g" (flags)\
  23. : "0" (res), "1" (flags)); \
  24. printf("%-10s A=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n", \
  25. stringify(OP) size, s0, res, iflags, flags & CC_MASK);
  26. #ifdef OP1
  27. #if defined(__x86_64__)
  28. void exec_opq(long s0, long s1, long iflags)
  29. {
  30. long res, flags;
  31. res = s0;
  32. flags = iflags;
  33. EXECOP1("q", "", res, flags);
  34. }
  35. #endif
  36. void exec_opl(long s0, long s1, long iflags)
  37. {
  38. long res, flags;
  39. res = s0;
  40. flags = iflags;
  41. EXECOP1("l", "k", res, flags);
  42. }
  43. void exec_opw(long s0, long s1, long iflags)
  44. {
  45. long res, flags;
  46. res = s0;
  47. flags = iflags;
  48. EXECOP1("w", "w", res, flags);
  49. }
  50. void exec_opb(long s0, long s1, long iflags)
  51. {
  52. long res, flags;
  53. res = s0;
  54. flags = iflags;
  55. EXECOP1("b", "b", res, flags);
  56. }
  57. #else
  58. #if defined(__x86_64__)
  59. void exec_opq(long s0, long s1, long iflags)
  60. {
  61. long res, flags;
  62. res = s0;
  63. flags = iflags;
  64. EXECOP2("q", "", res, s1, flags);
  65. }
  66. #endif
  67. void exec_opl(long s0, long s1, long iflags)
  68. {
  69. long res, flags;
  70. res = s0;
  71. flags = iflags;
  72. EXECOP2("l", "k", res, s1, flags);
  73. }
  74. void exec_opw(long s0, long s1, long iflags)
  75. {
  76. long res, flags;
  77. res = s0;
  78. flags = iflags;
  79. EXECOP2("w", "w", res, s1, flags);
  80. }
  81. void exec_opb(long s0, long s1, long iflags)
  82. {
  83. long res, flags;
  84. res = s0;
  85. flags = iflags;
  86. EXECOP2("b", "b", res, s1, flags);
  87. }
  88. #endif
  89. void exec_op(long s0, long s1)
  90. {
  91. s0 = i2l(s0);
  92. s1 = i2l(s1);
  93. #if defined(__x86_64__)
  94. exec_opq(s0, s1, 0);
  95. #endif
  96. exec_opl(s0, s1, 0);
  97. exec_opw(s0, s1, 0);
  98. exec_opb(s0, s1, 0);
  99. #ifdef OP_CC
  100. #if defined(__x86_64__)
  101. exec_opq(s0, s1, CC_C);
  102. #endif
  103. exec_opl(s0, s1, CC_C);
  104. exec_opw(s0, s1, CC_C);
  105. exec_opb(s0, s1, CC_C);
  106. #endif
  107. }
  108. void glue(test_, OP)(void)
  109. {
  110. exec_op(0x12345678, 0x812FADA);
  111. exec_op(0x12341, 0x12341);
  112. exec_op(0x12341, -0x12341);
  113. exec_op(0xffffffff, 0);
  114. exec_op(0xffffffff, -1);
  115. exec_op(0xffffffff, 1);
  116. exec_op(0xffffffff, 2);
  117. exec_op(0x7fffffff, 0);
  118. exec_op(0x7fffffff, 1);
  119. exec_op(0x7fffffff, -1);
  120. exec_op(0x80000000, -1);
  121. exec_op(0x80000000, 1);
  122. exec_op(0x80000000, -2);
  123. exec_op(0x12347fff, 0);
  124. exec_op(0x12347fff, 1);
  125. exec_op(0x12347fff, -1);
  126. exec_op(0x12348000, -1);
  127. exec_op(0x12348000, 1);
  128. exec_op(0x12348000, -2);
  129. exec_op(0x12347f7f, 0);
  130. exec_op(0x12347f7f, 1);
  131. exec_op(0x12347f7f, -1);
  132. exec_op(0x12348080, -1);
  133. exec_op(0x12348080, 1);
  134. exec_op(0x12348080, -2);
  135. exec_op(0xfffe0080, -1);
  136. exec_op(0xfffe0080, 1);
  137. exec_op(0xfffe0080, 0);
  138. exec_op(0xfffe0080, 0xfffe0080);
  139. exec_op(0xfffe0080, 0x80);
  140. exec_op(0xfffe0080, 0x81);
  141. exec_op(0xfffe0080, 0x10000);
  142. exec_op(0xfffe0080, 0x20000);
  143. exec_op(0xfffe0080, 0x1ff7f);
  144. exec_op(0xfffe0080, 0x1ff80);
  145. exec_op(0xfffe0080, 0x1ff81);
  146. exec_op(0xfffe0080, 0x1ffff);
  147. exec_op(0, 0);
  148. }
  149. void *glue(_test_, OP) __init_call = glue(test_, OP);
  150. #undef OP
  151. #undef OP_CC