Guest User

Untitled

a guest
Feb 16th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.35 KB | None | 0 0
  1. diff -r -u -x '*.o' -x '*.cmi' -x '*.cmo' -x '*.cmt' -x '*.cmti' -x '*.cmx' ocaml-4.00.1/asmcomp/amd64/emit.mlp ocaml-4.00.1.orig/asmcomp/amd64/emit.mlp
  2. --- ocaml-4.00.1/asmcomp/amd64/emit.mlp 2013-06-19 12:38:18.296035977 -0400
  3. +++ ocaml-4.00.1.orig/asmcomp/amd64/emit.mlp 2013-06-19 12:48:27.742037078 -0400
  4. @@ -512,124 +512,21 @@
  5. ` incq {emit_reg i.res.(0)}\n`
  6. | Lop(Iintop_imm(Iadd, -1) | Iintop_imm(Isub, 1)) ->
  7. ` decq {emit_reg i.res.(0)}\n`
  8. - | Lop(Iintop_nonpow2div(n, m, s)) ->
  9. - (* Note: i.arg.(0) = i.res.(0) = rdx (cf. selection.ml) *)
  10. - ` movq {emit_reg i.res.(0)}, %rax\n`;
  11. - begin match Int64.one = (Int64.shift_right_logical m 63), n < 0 with
  12. - | false, false ->
  13. - ` movq {emit_reg i.res.(0)}, %rcx\n`;
  14. - ` movabsq ${emit_string (Int64.to_string m)}, {emit_reg i.res.(0)}\n`;
  15. - ` imulq {emit_reg i.res.(0)}\n`;
  16. - ` sarq ${emit_int s}, {emit_reg i.res.(0)}\n`;
  17. - ` shrq $63, %rcx\n`;
  18. - ` addq %rcx, {emit_reg i.res.(0)}\n`
  19. - | true, false ->
  20. - ` movq {emit_reg i.res.(0)}, %rcx\n`;
  21. - ` movabsq ${emit_string (Int64.to_string m)}, {emit_reg i.res.(0)}\n`;
  22. - ` imulq {emit_reg i.res.(0)}\n`;
  23. - ` addq %rcx, {emit_reg i.res.(0)}\n`;
  24. - ` sarq ${emit_int s}, {emit_reg i.res.(0)}\n`;
  25. - ` shrq $63, %rcx\n`;
  26. - ` addq %rcx, {emit_reg i.res.(0)}\n`
  27. - | false, true ->
  28. - ` movabsq ${emit_string (Int64.to_string m)}, {emit_reg i.res.(0)}\n`;
  29. - ` imulq {emit_reg i.res.(0)}\n`;
  30. - ` sarq ${emit_int s}, {emit_reg i.res.(0)}\n`;
  31. - ` movq {emit_reg i.res.(0)}, %rax\n`;
  32. - ` shrq $63, %rax\n`;
  33. - ` addq %rax, {emit_reg i.res.(0)}\n`;
  34. - ` negq {emit_reg i.res.(0)}\n`
  35. - | true, true ->
  36. - ` movq {emit_reg i.res.(0)}, %rcx\n`;
  37. - ` movabsq ${emit_string (Int64.to_string m)}, {emit_reg i.res.(0)}\n`;
  38. - ` imulq {emit_reg i.res.(0)}\n`;
  39. - ` addq %rcx, {emit_reg i.res.(0)}\n`;
  40. - ` sarq ${emit_int s}, {emit_reg i.res.(0)}\n`;
  41. - ` movq {emit_reg i.res.(0)}, %rax\n`;
  42. - ` shrq $63, %rax\n`;
  43. - ` addq %rax, {emit_reg i.res.(0)}\n`;
  44. - ` negq {emit_reg i.res.(0)}\n`
  45. - end
  46. - | Lop(Iintop_nonpow2mod(n, m, s)) ->
  47. - (* Note: i.arg.(0) = i.res.(0) = rdx (cf. selection.ml) *)
  48. - let l = (Misc.log2 n) + Misc.log2 ((-1) * n) in
  49. - ` movq {emit_reg i.res.(0)}, %rax\n`;
  50. - if n = (1 lsl l) || n = (-1) * (1 lsl l)
  51. - then begin
  52. - ` sarq $63, %rax\n`;
  53. - ` shrq ${emit_int(64-l)}, %rax\n`;
  54. - ` leaq (%rax, {emit_reg i.res.(0)}), {emit_reg i.res.(0)}\n`;
  55. - ` movabsq ${emit_int ((1 lsl l) - 1)}, %rcx\n`;
  56. - ` andq %rcx, {emit_reg i.res.(0)}\n`;
  57. - ` subq %rax, {emit_reg i.res.(0)}\n`
  58. - end
  59. - else begin
  60. - ` movq {emit_reg i.res.(0)}, %rcx\n`;
  61. - (match Int64.one = (Int64.shift_right_logical m 63), n < 0 with
  62. - | false, false ->
  63. - ` movabsq ${emit_string (Int64.to_string m)}, {emit_reg i.res.(0)}\n`;
  64. - ` imulq {emit_reg i.res.(0)}\n`;
  65. - ` sarq ${emit_int s}, {emit_reg i.res.(0)}\n`;
  66. - ` movq %rcx, %rax\n`;
  67. - ` shrq $63, %rax\n`;
  68. - ` addq %rax, {emit_reg i.res.(0)}\n`
  69. - | true, false ->
  70. - ` movabsq ${emit_string (Int64.to_string m)}, {emit_reg i.res.(0)}\n`;
  71. - ` imulq {emit_reg i.res.(0)}\n`;
  72. - ` addq %rcx, {emit_reg i.res.(0)}\n`;
  73. - ` sarq ${emit_int s}, {emit_reg i.res.(0)}\n`;
  74. - ` movq %rcx, %rax\n`;
  75. - ` shrq $63, %rax\n`;
  76. - ` addq %rax, {emit_reg i.res.(0)}\n`
  77. - | false, true ->
  78. - ` movabsq ${emit_string (Int64.to_string m)}, {emit_reg i.res.(0)}\n`;
  79. - ` imulq {emit_reg i.res.(0)}\n`;
  80. - ` sarq ${emit_int s}, {emit_reg i.res.(0)}\n`;
  81. - ` movq {emit_reg i.res.(0)}, %rax\n`;
  82. - ` shrq $63, %rax\n`;
  83. - ` addq %rax, {emit_reg i.res.(0)}\n`;
  84. - ` negq {emit_reg i.res.(0)}\n`
  85. - | true, true ->
  86. - ` movabsq ${emit_string (Int64.to_string m)}, {emit_reg i.res.(0)}\n`;
  87. - ` imulq {emit_reg i.res.(0)}\n`;
  88. - ` addq %rcx, {emit_reg i.res.(0)}\n`;
  89. - ` sarq ${emit_int s}, {emit_reg i.res.(0)}\n`;
  90. - ` movq {emit_reg i.res.(0)}, %rax\n`;
  91. - ` shrq $63, %rax\n`;
  92. - ` addq %rax, {emit_reg i.res.(0)}\n`;
  93. - ` negq {emit_reg i.res.(0)}\n`);
  94. - ` movabsq ${emit_int n}, %rax\n`;
  95. - ` imulq {emit_reg i.res.(0)}\n`;
  96. - ` movq %rcx, {emit_reg i.res.(0)}\n`;
  97. - ` subq %rax, {emit_reg i.res.(0)}\n`
  98. - end
  99. | Lop(Iintop_imm(Idiv, n)) ->
  100. (* Note: i.arg.(0) = i.res.(0) = rdx (cf. selection.ml) *)
  101. let l = Misc.log2 n in
  102. - let n_l = Misc.log2 ((-1) * n) in
  103. ` movq {emit_reg i.arg.(0)}, %rax\n`;
  104. - if n = (1 lsl l)
  105. - then begin
  106. - ` sarq ${emit_int(l-1)}, %rax\n`;
  107. - ` shrq ${emit_int(64-l)}, %rax\n`;
  108. - ` addq %rax, {emit_reg i.arg.(0)}\n`;
  109. - ` sarq ${emit_int l}, {emit_reg i.res.(0)}\n`
  110. - end
  111. - else begin
  112. - ` sarq ${emit_int(n_l-1)}, %rax\n`;
  113. - ` shrq ${emit_int(64-n_l)}, %rax\n`;
  114. - ` addq %rax, {emit_reg i.arg.(0)}\n`;
  115. - ` sarq ${emit_int n_l}, {emit_reg i.res.(0)}\n`;
  116. - ` negq {emit_reg i.res.(0)}\n`;
  117. - end
  118. + ` addq ${emit_int(n-1)}, {emit_reg i.arg.(0)}\n`;
  119. + ` testq %rax, %rax\n`;
  120. + ` cmovns %rax, {emit_reg i.arg.(0)}\n`;
  121. + ` sarq ${emit_int l}, {emit_reg i.res.(0)}\n`
  122. | Lop(Iintop_imm(Imod, n)) ->
  123. (* Note: i.arg.(0) = i.res.(0) = rdx (cf. selection.ml) *)
  124. - let l = (Misc.log2 n) + Misc.log2 ((-1) * n) in
  125. ` movq {emit_reg i.arg.(0)}, %rax\n`;
  126. - ` sarq $63, %rax\n`;
  127. - ` shrq ${emit_int(64-l)}, %rax\n`;
  128. - ` leaq (%rax, {emit_reg i.res.(0)}), {emit_reg i.res.(0)}\n`;
  129. - ` andq ${emit_int ((1 lsl l) - 1)}, {emit_reg i.res.(0)}\n`;
  130. + ` testq %rax, %rax\n`;
  131. + ` leaq {emit_int(n-1)}(%rax), %rax\n`;
  132. + ` cmovns {emit_reg i.arg.(0)}, %rax\n`;
  133. + ` andq ${emit_int (-n)}, %rax\n`;
  134. ` subq %rax, {emit_reg i.res.(0)}\n`
  135. | Lop(Iintop_imm(op, n)) ->
  136. (* We have i.arg.(0) = i.res.(0) *)
  137. diff -r -u -x '*.o' -x '*.cmi' -x '*.cmo' -x '*.cmt' -x '*.cmti' -x '*.cmx' ocaml-4.00.1/asmcomp/amd64/proc.ml ocaml-4.00.1.orig/asmcomp/amd64/proc.ml
  138. --- ocaml-4.00.1/asmcomp/amd64/proc.ml 2013-06-19 12:17:11.826037442 -0400
  139. +++ ocaml-4.00.1.orig/asmcomp/amd64/proc.ml 2013-06-19 12:48:27.745037020 -0400
  140. @@ -259,8 +259,6 @@
  141. | Iop(Iextcall(_, false)) -> destroyed_at_c_call
  142. | Iop(Iintop(Idiv | Imod)) -> [| rax; rdx |]
  143. | Iop(Istore(Single, _)) -> [| rxmm15 |]
  144. - | Iop(Iintop_nonpow2div( _, _, _)) -> [| rax; rcx |]
  145. - | Iop(Iintop_nonpow2mod( _, _, _)) -> [| rax; rcx |]
  146. | Iop(Ialloc _ | Iintop(Icomp _) | Iintop_imm((Idiv|Imod|Icomp _), _))
  147. -> [| rax |]
  148. | Iswitch(_, _) -> [| rax; rdx |]
  149. diff -r -u -x '*.o' -x '*.cmi' -x '*.cmo' -x '*.cmt' -x '*.cmti' -x '*.cmx' ocaml-4.00.1/asmcomp/amd64/reload.ml ocaml-4.00.1.orig/asmcomp/amd64/reload.ml
  150. --- ocaml-4.00.1/asmcomp/amd64/reload.ml 2013-06-19 12:17:11.826037442 -0400
  151. +++ ocaml-4.00.1.orig/asmcomp/amd64/reload.ml 2013-06-19 12:48:27.760037083 -0400
  152. @@ -74,8 +74,6 @@
  153. in registers *)
  154. super#reload_operation op arg res
  155. | Iintop(Idiv | Imod | Ilsl | Ilsr | Iasr)
  156. - | Iintop_nonpow2div(_, _, _)
  157. - | Iintop_nonpow2mod(_, _, _)
  158. | Iintop_imm(_, _) ->
  159. (* The argument(s) and results can be either in register or on stack *)
  160. (* Note: Idiv, Imod: arg(0) and res(0) already forced in regs
  161. diff -r -u -x '*.o' -x '*.cmi' -x '*.cmo' -x '*.cmt' -x '*.cmti' -x '*.cmx' ocaml-4.00.1/asmcomp/amd64/selection.ml ocaml-4.00.1.orig/asmcomp/amd64/selection.ml
  162. --- ocaml-4.00.1/asmcomp/amd64/selection.ml 2013-06-19 12:17:11.826037442 -0400
  163. +++ ocaml-4.00.1.orig/asmcomp/amd64/selection.ml 2013-06-19 12:48:27.756037143 -0400
  164. @@ -20,7 +20,6 @@
  165. open Cmm
  166. open Reg
  167. open Mach
  168. -open Selectgen
  169.  
  170. (* Auxiliary for recognizing addressing modes *)
  171.  
  172. @@ -107,8 +106,6 @@
  173. ([| rax; rcx |], [| rdx |])
  174. (* For div and mod with immediate operand, arg must not be in rax.
  175. Keep it simple, force it in rdx. *)
  176. - | Iintop_nonpow2mod(_, _, _)
  177. - | Iintop_nonpow2div(_, _, _)
  178. | Iintop_imm((Idiv|Imod), _) ->
  179. ([| rdx |], [| rdx |])
  180. (* Other instructions are regular *)
  181. @@ -168,25 +165,18 @@
  182. (* Recognize (x / cst) and (x % cst) only if cst is a power of 2. *)
  183. | Cdivi ->
  184. begin match args with
  185. - [arg1; Cconst_int n] when n = 1 lsl (Misc.log2 n)
  186. - || n = (-1) * (1 lsl (Misc.log2 ((-1) *n))) ->
  187. - (Iintop_imm(Idiv, n), [arg1])
  188. - | [arg1; Cconst_int n] ->
  189. - let m, s = div_opt_number n in
  190. - (Iintop_nonpow2div(n, m, s), [arg1])
  191. + [arg1; Cconst_int n] when self#is_immediate n
  192. + && n = 1 lsl (Misc.log2 n) ->
  193. + (Iintop_imm(Idiv, n), [arg1])
  194. | _ -> (Iintop Idiv, args)
  195. end
  196. | Cmodi ->
  197. - begin match args with
  198. + begin match args with
  199. [arg1; Cconst_int n] when self#is_immediate n
  200. - && (n = 1 lsl (Misc.log2 n)
  201. - || n = (-1) * (1 lsl (Misc.log2 ((-1) *n)))) ->
  202. - (Iintop_imm(Imod, n), [arg1])
  203. - | [arg1; Cconst_int n] ->
  204. - let m, s = div_opt_number n in
  205. - (Iintop_nonpow2mod(n, m, s), [arg1])
  206. + && n = 1 lsl (Misc.log2 n) ->
  207. + (Iintop_imm(Imod, n), [arg1])
  208. | _ -> (Iintop Imod, args)
  209. - end
  210. + end
  211. (* Recognize float arithmetic with memory. *)
  212. | Caddf ->
  213. self#select_floatarith true Iaddf Ifloatadd args
  214. diff -r -u -x '*.o' -x '*.cmi' -x '*.cmo' -x '*.cmt' -x '*.cmti' -x '*.cmx' ocaml-4.00.1/asmcomp/emit.ml ocaml-4.00.1.orig/asmcomp/emit.ml
  215. --- ocaml-4.00.1/asmcomp/emit.ml 2013-06-19 12:38:53.653036711 -0400
  216. +++ ocaml-4.00.1.orig/asmcomp/emit.ml 2013-06-19 12:48:27.982037112 -0400
  217. @@ -512,124 +512,21 @@
  218. (emit_string " incq "; emit_reg i.res.(0); emit_char '\n')
  219. | Lop(Iintop_imm(Iadd, -1) | Iintop_imm(Isub, 1)) ->
  220. (emit_string " decq "; emit_reg i.res.(0); emit_char '\n')
  221. - | Lop(Iintop_nonpow2div(n, m, s)) ->
  222. - (* Note: i.arg.(0) = i.res.(0) = rdx (cf. selection.ml) *)
  223. - (emit_string " movq "; emit_reg i.res.(0); emit_string ", %rax\n");
  224. - begin match Int64.one = (Int64.shift_right_logical m 63), n < 0 with
  225. - | false, false ->
  226. - (emit_string " movq "; emit_reg i.res.(0); emit_string ", %rcx\n");
  227. - (emit_string " movabsq $"; emit_string (Int64.to_string m); emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  228. - (emit_string " imulq "; emit_reg i.res.(0); emit_char '\n');
  229. - (emit_string " sarq $"; emit_int s; emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  230. - (emit_string " shrq $63, %rcx\n");
  231. - (emit_string " addq %rcx, "; emit_reg i.res.(0); emit_char '\n')
  232. - | true, false ->
  233. - (emit_string " movq "; emit_reg i.res.(0); emit_string ", %rcx\n");
  234. - (emit_string " movabsq $"; emit_string (Int64.to_string m); emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  235. - (emit_string " imulq "; emit_reg i.res.(0); emit_char '\n');
  236. - (emit_string " addq %rcx, "; emit_reg i.res.(0); emit_char '\n');
  237. - (emit_string " sarq $"; emit_int s; emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  238. - (emit_string " shrq $63, %rcx\n");
  239. - (emit_string " addq %rcx, "; emit_reg i.res.(0); emit_char '\n')
  240. - | false, true ->
  241. - (emit_string " movabsq $"; emit_string (Int64.to_string m); emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  242. - (emit_string " imulq "; emit_reg i.res.(0); emit_char '\n');
  243. - (emit_string " sarq $"; emit_int s; emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  244. - (emit_string " movq "; emit_reg i.res.(0); emit_string ", %rax\n");
  245. - (emit_string " shrq $63, %rax\n");
  246. - (emit_string " addq %rax, "; emit_reg i.res.(0); emit_char '\n');
  247. - (emit_string " negq "; emit_reg i.res.(0); emit_char '\n')
  248. - | true, true ->
  249. - (emit_string " movq "; emit_reg i.res.(0); emit_string ", %rcx\n");
  250. - (emit_string " movabsq $"; emit_string (Int64.to_string m); emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  251. - (emit_string " imulq "; emit_reg i.res.(0); emit_char '\n');
  252. - (emit_string " addq %rcx, "; emit_reg i.res.(0); emit_char '\n');
  253. - (emit_string " sarq $"; emit_int s; emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  254. - (emit_string " movq "; emit_reg i.res.(0); emit_string ", %rax\n");
  255. - (emit_string " shrq $63, %rax\n");
  256. - (emit_string " addq %rax, "; emit_reg i.res.(0); emit_char '\n');
  257. - (emit_string " negq "; emit_reg i.res.(0); emit_char '\n')
  258. - end
  259. - | Lop(Iintop_nonpow2mod(n, m, s)) ->
  260. - (* Note: i.arg.(0) = i.res.(0) = rdx (cf. selection.ml) *)
  261. - let l = (Misc.log2 n) + Misc.log2 ((-1) * n) in
  262. - (emit_string " movq "; emit_reg i.res.(0); emit_string ", %rax\n");
  263. - if n = (1 lsl l) || n = (-1) * (1 lsl l)
  264. - then begin
  265. - (emit_string " sarq $63, %rax\n");
  266. - (emit_string " shrq $"; emit_int(64-l); emit_string ", %rax\n");
  267. - (emit_string " leaq (%rax, "; emit_reg i.res.(0); emit_string "), "; emit_reg i.res.(0); emit_char '\n');
  268. - (emit_string " movabsq $"; emit_int ((1 lsl l) - 1); emit_string ", %rcx\n");
  269. - (emit_string " andq %rcx, "; emit_reg i.res.(0); emit_char '\n');
  270. - (emit_string " subq %rax, "; emit_reg i.res.(0); emit_char '\n')
  271. - end
  272. - else begin
  273. - (emit_string " movq "; emit_reg i.res.(0); emit_string ", %rcx\n");
  274. - (match Int64.one = (Int64.shift_right_logical m 63), n < 0 with
  275. - | false, false ->
  276. - (emit_string " movabsq $"; emit_string (Int64.to_string m); emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  277. - (emit_string " imulq "; emit_reg i.res.(0); emit_char '\n');
  278. - (emit_string " sarq $"; emit_int s; emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  279. - (emit_string " movq %rcx, %rax\n");
  280. - (emit_string " shrq $63, %rax\n");
  281. - (emit_string " addq %rax, "; emit_reg i.res.(0); emit_char '\n')
  282. - | true, false ->
  283. - (emit_string " movabsq $"; emit_string (Int64.to_string m); emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  284. - (emit_string " imulq "; emit_reg i.res.(0); emit_char '\n');
  285. - (emit_string " addq %rcx, "; emit_reg i.res.(0); emit_char '\n');
  286. - (emit_string " sarq $"; emit_int s; emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  287. - (emit_string " movq %rcx, %rax\n");
  288. - (emit_string " shrq $63, %rax\n");
  289. - (emit_string " addq %rax, "; emit_reg i.res.(0); emit_char '\n')
  290. - | false, true ->
  291. - (emit_string " movabsq $"; emit_string (Int64.to_string m); emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  292. - (emit_string " imulq "; emit_reg i.res.(0); emit_char '\n');
  293. - (emit_string " sarq $"; emit_int s; emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  294. - (emit_string " movq "; emit_reg i.res.(0); emit_string ", %rax\n");
  295. - (emit_string " shrq $63, %rax\n");
  296. - (emit_string " addq %rax, "; emit_reg i.res.(0); emit_char '\n');
  297. - (emit_string " negq "; emit_reg i.res.(0); emit_char '\n')
  298. - | true, true ->
  299. - (emit_string " movabsq $"; emit_string (Int64.to_string m); emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  300. - (emit_string " imulq "; emit_reg i.res.(0); emit_char '\n');
  301. - (emit_string " addq %rcx, "; emit_reg i.res.(0); emit_char '\n');
  302. - (emit_string " sarq $"; emit_int s; emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  303. - (emit_string " movq "; emit_reg i.res.(0); emit_string ", %rax\n");
  304. - (emit_string " shrq $63, %rax\n");
  305. - (emit_string " addq %rax, "; emit_reg i.res.(0); emit_char '\n');
  306. - (emit_string " negq "; emit_reg i.res.(0); emit_char '\n'));
  307. - (emit_string " movabsq $"; emit_int n; emit_string ", %rax\n");
  308. - (emit_string " imulq "; emit_reg i.res.(0); emit_char '\n');
  309. - (emit_string " movq %rcx, "; emit_reg i.res.(0); emit_char '\n');
  310. - (emit_string " subq %rax, "; emit_reg i.res.(0); emit_char '\n')
  311. - end
  312. | Lop(Iintop_imm(Idiv, n)) ->
  313. (* Note: i.arg.(0) = i.res.(0) = rdx (cf. selection.ml) *)
  314. let l = Misc.log2 n in
  315. - let n_l = Misc.log2 ((-1) * n) in
  316. (emit_string " movq "; emit_reg i.arg.(0); emit_string ", %rax\n");
  317. - if n = (1 lsl l)
  318. - then begin
  319. - (emit_string " sarq $"; emit_int(l-1); emit_string ", %rax\n");
  320. - (emit_string " shrq $"; emit_int(64-l); emit_string ", %rax\n");
  321. - (emit_string " addq %rax, "; emit_reg i.arg.(0); emit_char '\n');
  322. - (emit_string " sarq $"; emit_int l; emit_string ", "; emit_reg i.res.(0); emit_char '\n')
  323. - end
  324. - else begin
  325. - (emit_string " sarq $"; emit_int(n_l-1); emit_string ", %rax\n");
  326. - (emit_string " shrq $"; emit_int(64-n_l); emit_string ", %rax\n");
  327. - (emit_string " addq %rax, "; emit_reg i.arg.(0); emit_char '\n');
  328. - (emit_string " sarq $"; emit_int n_l; emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  329. - (emit_string " negq "; emit_reg i.res.(0); emit_char '\n');
  330. - end
  331. + (emit_string " addq $"; emit_int(n-1); emit_string ", "; emit_reg i.arg.(0); emit_char '\n');
  332. + (emit_string " testq %rax, %rax\n");
  333. + (emit_string " cmovns %rax, "; emit_reg i.arg.(0); emit_char '\n');
  334. + (emit_string " sarq $"; emit_int l; emit_string ", "; emit_reg i.res.(0); emit_char '\n')
  335. | Lop(Iintop_imm(Imod, n)) ->
  336. (* Note: i.arg.(0) = i.res.(0) = rdx (cf. selection.ml) *)
  337. - let l = (Misc.log2 n) + Misc.log2 ((-1) * n) in
  338. (emit_string " movq "; emit_reg i.arg.(0); emit_string ", %rax\n");
  339. - (emit_string " sarq $63, %rax\n");
  340. - (emit_string " shrq $"; emit_int(64-l); emit_string ", %rax\n");
  341. - (emit_string " leaq (%rax, "; emit_reg i.res.(0); emit_string "), "; emit_reg i.res.(0); emit_char '\n');
  342. - (emit_string " andq $"; emit_int ((1 lsl l) - 1); emit_string ", "; emit_reg i.res.(0); emit_char '\n');
  343. + (emit_string " testq %rax, %rax\n");
  344. + (emit_string " leaq "; emit_int(n-1); emit_string "(%rax), %rax\n");
  345. + (emit_string " cmovns "; emit_reg i.arg.(0); emit_string ", %rax\n");
  346. + (emit_string " andq $"; emit_int (-n); emit_string ", %rax\n");
  347. (emit_string " subq %rax, "; emit_reg i.res.(0); emit_char '\n')
  348. | Lop(Iintop_imm(op, n)) ->
  349. (* We have i.arg.(0) = i.res.(0) *)
  350. diff -r -u -x '*.o' -x '*.cmi' -x '*.cmo' -x '*.cmt' -x '*.cmti' -x '*.cmx' ocaml-4.00.1/asmcomp/mach.ml ocaml-4.00.1.orig/asmcomp/mach.ml
  351. --- ocaml-4.00.1/asmcomp/mach.ml 2013-06-19 12:17:11.822037796 -0400
  352. +++ ocaml-4.00.1.orig/asmcomp/mach.ml 2013-06-19 12:48:27.968037126 -0400
  353. @@ -51,8 +51,6 @@
  354. | Ialloc of int
  355. | Iintop of integer_operation
  356. | Iintop_imm of integer_operation * int
  357. - | Iintop_nonpow2div of int * int64 * int
  358. - | Iintop_nonpow2mod of int * int64 * int
  359. | Inegf | Iabsf | Iaddf | Isubf | Imulf | Idivf
  360. | Ifloatofint | Iintoffloat
  361. | Ispecific of Arch.specific_operation
  362. diff -r -u -x '*.o' -x '*.cmi' -x '*.cmo' -x '*.cmt' -x '*.cmti' -x '*.cmx' ocaml-4.00.1/asmcomp/mach.mli ocaml-4.00.1.orig/asmcomp/mach.mli
  363. --- ocaml-4.00.1/asmcomp/mach.mli 2013-06-19 12:17:11.818037213 -0400
  364. +++ ocaml-4.00.1.orig/asmcomp/mach.mli 2013-06-19 12:48:28.104037844 -0400
  365. @@ -51,8 +51,6 @@
  366. | Ialloc of int
  367. | Iintop of integer_operation
  368. | Iintop_imm of integer_operation * int
  369. - | Iintop_nonpow2div of int * int64 * int
  370. - | Iintop_nonpow2mod of int * int64 * int
  371. | Inegf | Iabsf | Iaddf | Isubf | Imulf | Idivf
  372. | Ifloatofint | Iintoffloat
  373. | Ispecific of Arch.specific_operation
  374. diff -r -u -x '*.o' -x '*.cmi' -x '*.cmo' -x '*.cmt' -x '*.cmti' -x '*.cmx' ocaml-4.00.1/asmcomp/printmach.ml ocaml-4.00.1.orig/asmcomp/printmach.ml
  375. --- ocaml-4.00.1/asmcomp/printmach.ml 2013-06-19 12:17:11.817037391 -0400
  376. +++ ocaml-4.00.1.orig/asmcomp/printmach.ml 2013-06-19 12:48:27.567037039 -0400
  377. @@ -127,8 +127,6 @@
  378. reg arg.(0)
  379. | Ialloc n -> fprintf ppf "alloc %i" n
  380. | Iintop(op) -> fprintf ppf "%a%s%a" reg arg.(0) (intop op) reg arg.(1)
  381. - | Iintop_nonpow2div(n, _, _) -> fprintf ppf "%a%s%i" reg arg.(0) (intop Idiv) n
  382. - | Iintop_nonpow2mod(n, _, _) -> fprintf ppf "%a%s%i" reg arg.(0) (intop Imod) n
  383. | Iintop_imm(op, n) -> fprintf ppf "%a%s%i" reg arg.(0) (intop op) n
  384. | Inegf -> fprintf ppf "-f %a" reg arg.(0)
  385. | Iabsf -> fprintf ppf "absf %a" reg arg.(0)
  386. diff -r -u -x '*.o' -x '*.cmi' -x '*.cmo' -x '*.cmt' -x '*.cmti' -x '*.cmx' ocaml-4.00.1/asmcomp/proc.ml ocaml-4.00.1.orig/asmcomp/proc.ml
  387. --- ocaml-4.00.1/asmcomp/proc.ml 2013-06-19 12:17:11.826037442 -0400
  388. +++ ocaml-4.00.1.orig/asmcomp/proc.ml 2013-06-19 12:48:27.745037020 -0400
  389. @@ -259,8 +259,6 @@
  390. | Iop(Iextcall(_, false)) -> destroyed_at_c_call
  391. | Iop(Iintop(Idiv | Imod)) -> [| rax; rdx |]
  392. | Iop(Istore(Single, _)) -> [| rxmm15 |]
  393. - | Iop(Iintop_nonpow2div( _, _, _)) -> [| rax; rcx |]
  394. - | Iop(Iintop_nonpow2mod( _, _, _)) -> [| rax; rcx |]
  395. | Iop(Ialloc _ | Iintop(Icomp _) | Iintop_imm((Idiv|Imod|Icomp _), _))
  396. -> [| rax |]
  397. | Iswitch(_, _) -> [| rax; rdx |]
  398. diff -r -u -x '*.o' -x '*.cmi' -x '*.cmo' -x '*.cmt' -x '*.cmti' -x '*.cmx' ocaml-4.00.1/asmcomp/reload.ml ocaml-4.00.1.orig/asmcomp/reload.ml
  399. --- ocaml-4.00.1/asmcomp/reload.ml 2013-06-19 12:17:11.826037442 -0400
  400. +++ ocaml-4.00.1.orig/asmcomp/reload.ml 2013-06-19 12:48:27.760037083 -0400
  401. @@ -74,8 +74,6 @@
  402. in registers *)
  403. super#reload_operation op arg res
  404. | Iintop(Idiv | Imod | Ilsl | Ilsr | Iasr)
  405. - | Iintop_nonpow2div(_, _, _)
  406. - | Iintop_nonpow2mod(_, _, _)
  407. | Iintop_imm(_, _) ->
  408. (* The argument(s) and results can be either in register or on stack *)
  409. (* Note: Idiv, Imod: arg(0) and res(0) already forced in regs
  410. diff -r -u -x '*.o' -x '*.cmi' -x '*.cmo' -x '*.cmt' -x '*.cmti' -x '*.cmx' ocaml-4.00.1/asmcomp/selectgen.ml ocaml-4.00.1.orig/asmcomp/selectgen.ml
  411. --- ocaml-4.00.1/asmcomp/selectgen.ml 2013-06-19 12:17:11.820037273 -0400
  412. +++ ocaml-4.00.1.orig/asmcomp/selectgen.ml 2013-06-19 12:48:27.426037085 -0400
  413. @@ -76,60 +76,6 @@
  414. fatal_error "Selection.size_expr"
  415. in size Tbl.empty exp
  416.  
  417. -(* idiv and imod optimization *)
  418. -
  419. -let div_opt_number div =
  420. - let zero, one, two = Int64.zero ,Int64.one, Int64.of_int 2 in
  421. - let ( + ), ( - ), ( * ) = Int64.add, Int64.sub, Int64.mul in
  422. - let (lsr), (asr), ( & ) = Int64.shift_right_logical, Int64.shift_right, Int64.logand in
  423. - (* unsigned comparison *)
  424. - let greater l r eq =
  425. - let comp = Int64.compare l r in
  426. - if eq && 0 = comp then true else
  427. - let s_l = Int64.compare l Int64.zero in
  428. - let s_r = Int64.compare r Int64.zero in
  429. - match l, r with
  430. - | l, r when (s_l = -1 && s_r = -1) || (s_l <> -1 && s_r <> -1) ->
  431. - if -1 = comp then false else true
  432. - | l, _r when s_l = -1 -> true
  433. - | _l, _r -> false
  434. - in
  435. - (* unsigned division *)
  436. - let ( / ) n d =
  437. - let n' = n & (Int64.lognot (d asr 63)) in
  438. - let q = (Int64.div (n' lsr 1) d) * two in
  439. - let r = n - (q * d) in
  440. - if greater r d true then q + one else q
  441. - in
  442. - let d = Int64.of_int div in
  443. - let two63 = Int64.min_int in
  444. - let w_size = Int64.of_int 64 in
  445. - let t = two63 + (d lsr 63) in
  446. - let ad = Int64.abs d in
  447. - let tdivad = t / ad in
  448. - let anc = t - one - (t - (tdivad * ad)) in
  449. - let q1o = two63 / anc in
  450. - let q2o = two63 / ad in
  451. - let r1o = two63 - (q1o * anc) in
  452. - let r2o = two63 - (q2o * ad) in
  453. - let rec loop p q1 r1 q2 r2 =
  454. - let q1n, r1n =
  455. - match greater r1 anc true with
  456. - | true -> q1 + one, r1 - anc
  457. - | false -> q1, r1
  458. - in
  459. - let q2n, r2n =
  460. - match greater r2 ad true with
  461. - | true -> q2 + one, r2 - ad
  462. - | false -> q2, r2
  463. - in
  464. - let delta = ad - r2 in
  465. - match (greater delta q1 false) || (q1 = delta && r1 = zero) with
  466. - | true -> loop (p+one) (two*q1n) (two*r1n) (two*q2n) (two*r2n)
  467. - | false -> q2 + one, Int64.to_int (p - w_size)
  468. - in
  469. - loop w_size (two*q1o) (two*r1o) (two*q2o) (two*r2o)
  470. -
  471. (* Swap the two arguments of an integer comparison *)
  472.  
  473. let swap_intcomp = function
  474. @@ -321,51 +267,24 @@
  475. | (Ccheckbound _, _) -> self#select_arith Icheckbound args
  476. | _ -> fatal_error "Selection.select_oper"
  477.  
  478. -method private select_arith_comm op args =
  479. - match op with
  480. - | Imod ->
  481. - begin match args with
  482. - [arg; Cconst_int n] when self#is_immediate n
  483. - && (n = 1 lsl (Misc.log2 n)
  484. - || n = (-1) * (1 lsl (Misc.log2 ((-1) *n)))) ->
  485. - (Iintop_imm(Imod, n), [arg])
  486. - | [arg; Cconst_int n] ->
  487. - let m, s = div_opt_number n in
  488. - (Iintop_nonpow2mod(n, m, s), [arg])
  489. - | _ -> (Iintop Imod, args)
  490. - end
  491. - | _ ->
  492. - match args with
  493. - [arg; Cconst_int n] when self#is_immediate n ->
  494. - (Iintop_imm(op, n), [arg])
  495. - | [arg; Cconst_pointer n] when self#is_immediate n ->
  496. +method private select_arith_comm op = function
  497. + [arg; Cconst_int n] when self#is_immediate n ->
  498. (Iintop_imm(op, n), [arg])
  499. - | [Cconst_int n; arg] when self#is_immediate n ->
  500. + | [arg; Cconst_pointer n] when self#is_immediate n ->
  501. + (Iintop_imm(op, n), [arg])
  502. + | [Cconst_int n; arg] when self#is_immediate n ->
  503. (Iintop_imm(op, n), [arg])
  504. - | [Cconst_pointer n; arg] when self#is_immediate n ->
  505. + | [Cconst_pointer n; arg] when self#is_immediate n ->
  506. (Iintop_imm(op, n), [arg])
  507. - | args ->
  508. + | args ->
  509. (Iintop op, args)
  510.  
  511. -method private select_arith op args =
  512. - match op with
  513. - | Idiv ->
  514. - begin match args with
  515. - [arg; Cconst_int n] when n = 1 lsl (Misc.log2 n)
  516. - || n = (-1) * (1 lsl (Misc.log2 ((-1) *n))) ->
  517. - (Iintop_imm(Idiv, n), [arg])
  518. - | [arg; Cconst_int n] ->
  519. - let m, s = div_opt_number n in
  520. - (Iintop_nonpow2div(n, m, s), [arg])
  521. - | _ -> (Iintop Idiv, args)
  522. - end
  523. - | _ ->
  524. - match args with
  525. - [arg; Cconst_int n] when self#is_immediate n ->
  526. - (Iintop_imm(op, n), [arg])
  527. - | [arg; Cconst_pointer n] when self#is_immediate n ->
  528. +method private select_arith op = function
  529. + [arg; Cconst_int n] when self#is_immediate n ->
  530. (Iintop_imm(op, n), [arg])
  531. - | args ->
  532. + | [arg; Cconst_pointer n] when self#is_immediate n ->
  533. + (Iintop_imm(op, n), [arg])
  534. + | args ->
  535. (Iintop op, args)
  536.  
  537. method private select_shift op = function
  538. diff -r -u -x '*.o' -x '*.cmi' -x '*.cmo' -x '*.cmt' -x '*.cmti' -x '*.cmx' ocaml-4.00.1/asmcomp/selectgen.mli ocaml-4.00.1.orig/asmcomp/selectgen.mli
  539. --- ocaml-4.00.1/asmcomp/selectgen.mli 2013-06-19 12:17:11.819037589 -0400
  540. +++ ocaml-4.00.1.orig/asmcomp/selectgen.mli 2013-06-19 12:48:27.313036931 -0400
  541. @@ -19,8 +19,6 @@
  542.  
  543. val size_expr : environment -> Cmm.expression -> int
  544.  
  545. -val div_opt_number : int -> int64 * int
  546. -
  547. class virtual selector_generic : object
  548. (* The following methods must or can be overridden by the processor
  549. description *)
  550. diff -r -u -x '*.o' -x '*.cmi' -x '*.cmo' -x '*.cmt' -x '*.cmti' -x '*.cmx' ocaml-4.00.1/asmcomp/selection.ml ocaml-4.00.1.orig/asmcomp/selection.ml
  551. --- ocaml-4.00.1/asmcomp/selection.ml 2013-06-19 12:17:11.826037442 -0400
  552. +++ ocaml-4.00.1.orig/asmcomp/selection.ml 2013-06-19 12:48:27.756037143 -0400
  553. @@ -20,7 +20,6 @@
  554. open Cmm
  555. open Reg
  556. open Mach
  557. -open Selectgen
  558.  
  559. (* Auxiliary for recognizing addressing modes *)
  560.  
  561. @@ -107,8 +106,6 @@
  562. ([| rax; rcx |], [| rdx |])
  563. (* For div and mod with immediate operand, arg must not be in rax.
  564. Keep it simple, force it in rdx. *)
  565. - | Iintop_nonpow2mod(_, _, _)
  566. - | Iintop_nonpow2div(_, _, _)
  567. | Iintop_imm((Idiv|Imod), _) ->
  568. ([| rdx |], [| rdx |])
  569. (* Other instructions are regular *)
  570. @@ -168,25 +165,18 @@
  571. (* Recognize (x / cst) and (x % cst) only if cst is a power of 2. *)
  572. | Cdivi ->
  573. begin match args with
  574. - [arg1; Cconst_int n] when n = 1 lsl (Misc.log2 n)
  575. - || n = (-1) * (1 lsl (Misc.log2 ((-1) *n))) ->
  576. - (Iintop_imm(Idiv, n), [arg1])
  577. - | [arg1; Cconst_int n] ->
  578. - let m, s = div_opt_number n in
  579. - (Iintop_nonpow2div(n, m, s), [arg1])
  580. + [arg1; Cconst_int n] when self#is_immediate n
  581. + && n = 1 lsl (Misc.log2 n) ->
  582. + (Iintop_imm(Idiv, n), [arg1])
  583. | _ -> (Iintop Idiv, args)
  584. end
  585. | Cmodi ->
  586. - begin match args with
  587. + begin match args with
  588. [arg1; Cconst_int n] when self#is_immediate n
  589. - && (n = 1 lsl (Misc.log2 n)
  590. - || n = (-1) * (1 lsl (Misc.log2 ((-1) *n)))) ->
  591. - (Iintop_imm(Imod, n), [arg1])
  592. - | [arg1; Cconst_int n] ->
  593. - let m, s = div_opt_number n in
  594. - (Iintop_nonpow2mod(n, m, s), [arg1])
  595. + && n = 1 lsl (Misc.log2 n) ->
  596. + (Iintop_imm(Imod, n), [arg1])
  597. | _ -> (Iintop Imod, args)
  598. - end
  599. + end
  600. (* Recognize float arithmetic with memory. *)
  601. | Caddf ->
  602. self#select_floatarith true Iaddf Ifloatadd args
Add Comment
Please, Sign In to add comment