rules.386 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. # Rules to optimize BCC assembler output for 386
  2. # Many of these rules are very broken, ho hum.
  3. # Rules for loading a long constant
  4. xor ax,ax
  5. xor %[bx|si|di]1,%[bx|si|di]1
  6. =
  7. xor eax,eax
  8. xor eax,eax
  9. mov %[ebx|ecx|edx]1,eax
  10. =
  11. xor %1,%1
  12. xor ax,ax
  13. mov %[bx|si|di]*,%[*|#]0%1
  14. =
  15. mov eax,%0%1<<16
  16. mov ax,%[*|#]0%1
  17. xor %[bx|si|di]2,%[bx|si|di]2
  18. =
  19. mov eax,%0%1 & $0000FFFF
  20. mov ax,%0[%1]
  21. xor %[bx|si|di]2,%[bx|si|di]2
  22. =
  23. movzx eax,word ptr %0[%1]
  24. mov ax,%[si|di]1
  25. xor bx,bx
  26. =
  27. movzx eax,%1
  28. %[movzx|movsx]5 eax,%1
  29. mov %[ebx|ecx|edx]2,eax
  30. =
  31. %5 %2,%1
  32. %[movzx|movsx]5 %[ebx|ecx|edx]1,%2
  33. mov eax,%[#|*]0%3
  34. %[add|and|xor|or]4 eax,%[ebx|ecx|edx]1
  35. =
  36. %5 eax,%2
  37. %4 eax,%0%3
  38. mov ax,%0[%1]
  39. cwde
  40. =
  41. movsx eax,word ptr %0[%1]
  42. mov ax,%[si|di]1
  43. cwde
  44. =
  45. movsx eax,%1
  46. mov ax,%[#|*]3%1
  47. mov %[bx|si|di]*,%[#|*]4%2
  48. =
  49. mov eax,%4%2<<16 + %1
  50. # Rules for pushing variables and constants onto the stack
  51. push %![dword ptr]%1[%[bx|si|di|bp]3]
  52. push %![dword ptr]%(%1-2)[%[bx|si|di|bp]3]
  53. =
  54. push dword ptr %(%1-2)[%3]
  55. push [%1+2]
  56. push [%1]
  57. =
  58. push dword ptr [%1]
  59. push %[bx|si|di]*
  60. push ax
  61. =
  62. push eax
  63. mov eax,%[#|*]0%1
  64. push eax
  65. =
  66. push dword %0%1
  67. mov %1,%[eax|ebx|ecx|edx]2
  68. push dword ptr %1
  69. =
  70. mov %1,%2
  71. push %2
  72. # Rules for loading long variables
  73. mov ax,[%1]
  74. mov %[bx|si|di]*,[%1+2]
  75. =
  76. mov eax,[%1]
  77. mov ax,%1[%[bx|si|di|bp]3]
  78. mov %[bx|si|di]*,%(%1+2)[%[bx|si|di|bp]3]
  79. =
  80. mov eax,%1[%3]
  81. mov ax,#%1[bx]
  82. mov %[bx|si|di]*,#%1+2[bx]
  83. =
  84. mov eax,#%1[bx]
  85. mov [%1],ax
  86. mov [%1+2],%[bx|si|di]*
  87. =
  88. mov [%1],eax
  89. mov [%1+%3],ax
  90. mov [%1+%(%3+2)],%[bx|si|di]*
  91. =
  92. mov [%1+%3],eax
  93. mov %1[%[si|di|bp]3],ax
  94. mov %(%1+2)[%[si|di|bp]3],%[bx|si|di]*
  95. =
  96. mov %1[%3],eax
  97. mov #%1[bx],ax
  98. mov #%1+2[bx],%[bx|si|di]*
  99. =
  100. mov #%1[bx],eax
  101. mov eax,%[#|*]0%1
  102. mov %![dword ptr]%3[%2],eax
  103. =
  104. mov dword ptr %3[%2],%0%1
  105. xor ax,ax
  106. xor %[bx|si|di]3,%[bx|si|di]3
  107. mov %1[%[bx|bp]4],ax
  108. mov %(%1+2)[%[bx|bp]4],%[bx|si|di]3
  109. =
  110. mov dword ptr %1[%4],#0
  111. mov ax,%1
  112. mov %[bx|si|di]5,%2
  113. mov %3[%[bx|bp]6],ax
  114. mov %(%3+2)[%[bx|bp]6],%[bx|si|di]5
  115. =
  116. mov eax,dword ptr %1
  117. mov dword ptr %3[%6],eax
  118. # Long return values are in EAX, so we can skip dx
  119. mov dx,bx
  120. add sp,*%1
  121. =
  122. add sp,*%1
  123. # Rules for manipulating long values
  124. call %1
  125. mov bx,dx
  126. =
  127. call %1
  128. call l%[tstu|tst]*l
  129. =
  130. test eax,eax
  131. call l%[comu|com]*l
  132. =
  133. not eax
  134. mov eax,eax
  135. %1
  136. =
  137. %1
  138. mov %2,%[eax|ebx|ecx|edx]1
  139. mov %[eax|ebx|ecx|edx]1,%2
  140. =
  141. mov %2,%1
  142. cwd
  143. mov bx,dx
  144. =
  145. cwde
  146. mov %[ebx|ecx|edx]0,%1
  147. mov eax,%2
  148. %3 eax,%[ebc|ecx|edx]0
  149. =
  150. mov eax,%2
  151. %3 eax,%1
  152. %[movzx|movsx|mov]0 %[eax|ebx|ecx|edx]2,%4
  153. %[add|and|xor|sub|or]1 %[eax|ebx|ecx|edx]2,%6
  154. mov %6,%[eax|ebx|ecx|edx]2
  155. =
  156. %0 %2,%4
  157. %1 %6,%2
  158. mov eax,%[#|*]0%1
  159. cmp eax,%2
  160. %[jbe |jae |jne |jge |jle ]3 %4
  161. =
  162. cmp dword ptr %2,%0%1
  163. %=[jbe |jae |jne |jge |jle ][jae |jbe |jne |jle |jge ]3 %4
  164. mov eax,%[#|*]0%1
  165. cmp eax,%2
  166. %[jb |ja |je |jg |jl ]3 %4
  167. =
  168. cmp dword ptr %2,%0%1
  169. %=[jb |ja |je |jg |jl ][ja |jb |je |jl |jg ]3 %4
  170. mov eax,%1[%3]
  171. cmp eax,dword %[#|*]0%2
  172. =
  173. cmp dword ptr %1[%3],%0%2
  174. # Rules for calling the bcc library routines.
  175. push %1
  176. push %2
  177. mov eax,%3[bp]
  178. %4 eax,%(%3-4)[bp]
  179. add sp,*8
  180. =
  181. mov edx,%2
  182. mov eax,%1
  183. %4 eax,edx
  184. push %1
  185. mov eax,%2
  186. push eax
  187. mov eax,%3[bp]
  188. %4 eax,%(%3-4)[bp]
  189. add sp,*8
  190. =
  191. mov edx,%2
  192. mov eax,%1
  193. %4 eax,edx
  194. push %1
  195. xor eax,eax
  196. push eax
  197. mov eax,%2[bp]
  198. %3 eax,%(%2-4)[bp]
  199. add sp,*8
  200. =
  201. mov eax,%1
  202. %3 eax,#0
  203. push %1
  204. mov eax,%2
  205. %3 eax,%4[bp]
  206. add sp,*4
  207. =
  208. mov edx,%1
  209. mov eax,%2
  210. %3 eax,edx
  211. push %1
  212. mov eax,%2
  213. %3 eax,%4[bp]
  214. mov %2,eax
  215. add sp,*4
  216. =
  217. mov edx,%1
  218. %3 %2,edx
  219. push %1
  220. push %2
  221. mov eax,%3[bp]
  222. %4 eax,%(%3-4)[bp]
  223. lea sp,%(%3+4)[bp]
  224. =
  225. mov edx,%2
  226. mov eax,%1
  227. %4 eax,edx
  228. push %1
  229. mov eax,%2
  230. push eax
  231. mov eax,%3[bp]
  232. %4 eax,%(%3-4)[bp]
  233. lea sp,%(%3+4)[bp]
  234. =
  235. mov edx,%2
  236. mov eax,%1
  237. %4 eax,edx
  238. push %1
  239. xor eax,eax
  240. push eax
  241. mov eax,%2[bp]
  242. %3 eax,%(%2-4)[bp]
  243. lea sp,%(%2+4)[bp]
  244. =
  245. mov eax,%1
  246. %3 eax,#0
  247. push %1
  248. mov eax,%2
  249. %3 eax,%4[bp]
  250. lea sp,%(%4+4)[bp]
  251. =
  252. mov edx,%1
  253. mov eax,%2
  254. %3 eax,edx
  255. # Rules for calling the basic bcc library routines.
  256. mov di,#%2
  257. call l%3%[ul|l]*
  258. =
  259. %3 eax,[%2]
  260. mov di,*%2
  261. call lsll
  262. =
  263. lsl eax,*%2
  264. lea di,%2
  265. call l%3%[ul|l]*
  266. =
  267. %3 eax,%2
  268. mov di,%[si|di]1
  269. call l%3%[ul|l]*
  270. =
  271. %3 eax,[%1]
  272. mov di,%[ax|bx|cx|dx]1
  273. call l%3%[ul|l]*
  274. =
  275. mov di,%[ax|bx|cx|dx]1
  276. %3 eax,[di]
  277. # Rules for pushing short values
  278. mov %[ax|bx|cx|dx|si|di]2,%0[%1]
  279. push %[ax|bx|cx|dx|si|di]2
  280. =
  281. push word ptr %0[%1]
  282. mov %[ax|bx|cx|dx|si|di]2,%[#|*]0%1
  283. push %[ax|bx|cx|dx|si|di]2
  284. =
  285. push %0%1
  286. # Shifting rules
  287. %[shl|shr]2 %1,*1
  288. %[shl|shr]2 %1,*1
  289. =
  290. %2 %1,*2
  291. mov cl,*%1
  292. %[shl|shr]2 %3,cl
  293. =
  294. %2 %3,*%1
  295. mov dx,ax
  296. shl ax,*%1
  297. add ax,dx
  298. shl ax,*%2
  299. =
  300. mov dx,ax
  301. imul ax,*%(1<%1+1<%2)
  302. mov dx,ax
  303. imul ax,*%1
  304. add ax,dx
  305. =
  306. mov dx,ax
  307. imul ax,*%(%1+1)
  308. mov dx,ax
  309. imul ax,*%1
  310. shl ax,*%2
  311. =
  312. mov dx,ax
  313. imul ax,*%(%1<%2)
  314. mov ax,%![#|*]%4
  315. mov dx,ax
  316. imul ax,*%1
  317. %[add|and|xor|sub|or]2 ax,%![dx]%3
  318. =
  319. imul ax,%4,*%1
  320. %2 ax,%3
  321. mov ax,%![#|*]%4
  322. mov dx,ax
  323. imul ax,*%1
  324. push ax
  325. =
  326. imul ax,%4,*%1
  327. push ax
  328. imul ax,%2,%[#|*]0%1
  329. add ax,%3
  330. mov bx,ax
  331. =
  332. imul bx,%2,%0%1
  333. add bx,%3
  334. # Different rules
  335. %1 dword ptr %[eax|ebx|ecx|edx]3,*%2
  336. =
  337. %1 %3,*%2
  338. %1 dword ptr %[eax|ebx|ecx|edx]3,#%2
  339. =
  340. %1 %3,#%2
  341. eor %1,%2
  342. =
  343. xor %1,%2
  344. com %1
  345. =
  346. not %1
  347. xor bx,bx
  348. =
  349. and eax,#$0000FFFF