1
0

test-i386-shift.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. #ifndef OP_SHIFTD
  7. #ifdef OP_NOBYTE
  8. #define EXECSHIFT(size, rsize, res, s1, s2, flags) \
  9. asm ("push %4\n\t"\
  10. "popf\n\t"\
  11. stringify(OP) size " %" rsize "2, %" rsize "0\n\t" \
  12. "pushf\n\t"\
  13. "pop %1\n\t"\
  14. : "=g" (res), "=g" (flags)\
  15. : "r" (s1), "0" (res), "1" (flags));
  16. #else
  17. #define EXECSHIFT(size, rsize, res, s1, s2, flags) \
  18. asm ("push %4\n\t"\
  19. "popf\n\t"\
  20. stringify(OP) size " %%cl, %" rsize "0\n\t" \
  21. "pushf\n\t"\
  22. "pop %1\n\t"\
  23. : "=q" (res), "=g" (flags)\
  24. : "c" (s1), "0" (res), "1" (flags));
  25. #endif
  26. #if defined(__x86_64__)
  27. void exec_opq(long s2, long s0, long s1, long iflags)
  28. {
  29. long res, flags;
  30. res = s0;
  31. flags = iflags;
  32. EXECSHIFT("q", "", res, s1, s2, flags);
  33. /* overflow is undefined if count != 1 */
  34. if (s1 != 1)
  35. flags &= ~CC_O;
  36. printf("%-10s A=" FMTLX " B=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n",
  37. stringify(OP) "q", s0, s1, res, iflags, flags & CC_MASK);
  38. }
  39. #endif
  40. void exec_opl(long s2, long s0, long s1, long iflags)
  41. {
  42. long res, flags;
  43. res = s0;
  44. flags = iflags;
  45. EXECSHIFT("l", "k", res, s1, s2, flags);
  46. /* overflow is undefined if count != 1 */
  47. if (s1 != 1)
  48. flags &= ~CC_O;
  49. printf("%-10s A=" FMTLX " B=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n",
  50. stringify(OP) "l", s0, s1, res, iflags, flags & CC_MASK);
  51. }
  52. void exec_opw(long s2, long s0, long s1, long iflags)
  53. {
  54. long res, flags;
  55. res = s0;
  56. flags = iflags;
  57. EXECSHIFT("w", "w", res, s1, s2, flags);
  58. /* overflow is undefined if count != 1 */
  59. if (s1 != 1)
  60. flags &= ~CC_O;
  61. printf("%-10s A=" FMTLX " B=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n",
  62. stringify(OP) "w", s0, s1, res, iflags, flags & CC_MASK);
  63. }
  64. #else
  65. #define EXECSHIFT(size, rsize, res, s1, s2, flags) \
  66. asm ("push %4\n\t"\
  67. "popf\n\t"\
  68. stringify(OP) size " %%cl, %" rsize "5, %" rsize "0\n\t" \
  69. "pushf\n\t"\
  70. "pop %1\n\t"\
  71. : "=g" (res), "=g" (flags)\
  72. : "c" (s1), "0" (res), "1" (flags), "r" (s2));
  73. #if defined(__x86_64__)
  74. void exec_opq(long s2, long s0, long s1, long iflags)
  75. {
  76. long res, flags;
  77. res = s0;
  78. flags = iflags;
  79. EXECSHIFT("q", "", res, s1, s2, flags);
  80. /* overflow is undefined if count != 1 */
  81. if (s1 != 1)
  82. flags &= ~CC_O;
  83. printf("%-10s A=" FMTLX " B=" FMTLX " C=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n",
  84. stringify(OP) "q", s0, s2, s1, res, iflags, flags & CC_MASK);
  85. }
  86. #endif
  87. void exec_opl(long s2, long s0, long s1, long iflags)
  88. {
  89. long res, flags;
  90. res = s0;
  91. flags = iflags;
  92. EXECSHIFT("l", "k", res, s1, s2, flags);
  93. /* overflow is undefined if count != 1 */
  94. if (s1 != 1)
  95. flags &= ~CC_O;
  96. printf("%-10s A=" FMTLX " B=" FMTLX " C=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n",
  97. stringify(OP) "l", s0, s2, s1, res, iflags, flags & CC_MASK);
  98. }
  99. void exec_opw(long s2, long s0, long s1, long iflags)
  100. {
  101. long res, flags;
  102. res = s0;
  103. flags = iflags;
  104. EXECSHIFT("w", "w", res, s1, s2, flags);
  105. /* overflow is undefined if count != 1 */
  106. if (s1 != 1)
  107. flags &= ~CC_O;
  108. printf("%-10s A=" FMTLX " B=" FMTLX " C=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n",
  109. stringify(OP) "w", s0, s2, s1, res, iflags, flags & CC_MASK);
  110. }
  111. #endif
  112. #ifndef OP_NOBYTE
  113. void exec_opb(long s0, long s1, long iflags)
  114. {
  115. long res, flags;
  116. res = s0;
  117. flags = iflags;
  118. EXECSHIFT("b", "b", res, s1, 0, flags);
  119. /* overflow is undefined if count != 1 */
  120. if (s1 != 1)
  121. flags &= ~CC_O;
  122. printf("%-10s A=" FMTLX " B=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n",
  123. stringify(OP) "b", s0, s1, res, iflags, flags & CC_MASK);
  124. }
  125. #endif
  126. void exec_op(long s2, long s0, long s1)
  127. {
  128. s2 = i2l(s2);
  129. s0 = i2l(s0);
  130. #if defined(__x86_64__)
  131. exec_opq(s2, s0, s1, 0);
  132. #endif
  133. exec_opl(s2, s0, s1, 0);
  134. #ifdef OP_SHIFTD
  135. exec_opw(s2, s0, s1, 0);
  136. #else
  137. exec_opw(s2, s0, s1, 0);
  138. #endif
  139. #ifndef OP_NOBYTE
  140. exec_opb(s0, s1, 0);
  141. #endif
  142. #ifdef OP_CC
  143. #if defined(__x86_64__)
  144. exec_opq(s2, s0, s1, CC_C);
  145. #endif
  146. exec_opl(s2, s0, s1, CC_C);
  147. exec_opw(s2, s0, s1, CC_C);
  148. exec_opb(s0, s1, CC_C);
  149. #endif
  150. }
  151. void glue(test_, OP)(void)
  152. {
  153. int i, n;
  154. #if defined(__x86_64__)
  155. n = 64;
  156. #else
  157. n = 32;
  158. #endif
  159. for(i = 0; i < n; i++)
  160. exec_op(0x21ad3d34, 0x12345678, i);
  161. for(i = 0; i < n; i++)
  162. exec_op(0x813f3421, 0x82345679, i);
  163. for(i = 0; i < n; i++)
  164. exec_op(0x21ad3d34, 0x82345679, i);
  165. for(i = 0; i < n; i++)
  166. exec_op(0x813f3421, 0x12345678, i);
  167. for(i = 0; i < n; i++)
  168. exec_op(0x80008481, 0x80008688, i);
  169. for(i = 0; i < n; i++)
  170. exec_op(0xffffffff, 0xffffffff, i);
  171. for(i = 0; i < n; i++)
  172. exec_op(0xfffe0080, 0xfffe0080, i);
  173. }
  174. void *glue(_test_, OP) __init_call = glue(test_, OP);
  175. #undef OP
  176. #undef OP_CC
  177. #undef OP_SHIFTD
  178. #undef OP_NOBYTE
  179. #undef EXECSHIFT