| Attached Files | ocamlopt-natint.patch [^] (7,218 bytes) 2010-12-14 11:40 [Show Content] [Hide Content]diff --git a/asmcomp/amd64/selection.ml b/asmcomp/amd64/selection.ml
index 4921e51..bce8104 100644
--- a/asmcomp/amd64/selection.ml
+++ b/asmcomp/amd64/selection.ml
@@ -168,6 +168,9 @@ method! select_operation op args =
[arg1; Cconst_int n] when self#is_immediate n
&& n = 1 lsl (Misc.log2 n) ->
(Iintop_imm(Idiv, n), [arg1])
+ | [arg1; Cconst_natint n] when self#is_immediate_natint n
+ && n = Nativeint.shift_left 1n (Misc.log2 (Nativeint.to_int n)) ->
+ (Iintop_imm(Idiv, Nativeint.to_int n), [arg1])
| _ -> (Iintop Idiv, args)
end
| Cmodi ->
@@ -175,6 +178,9 @@ method! select_operation op args =
[arg1; Cconst_int n] when self#is_immediate n
&& n = 1 lsl (Misc.log2 n) ->
(Iintop_imm(Imod, n), [arg1])
+ | [arg1; Cconst_natint n] when self#is_immediate_natint n
+ && n = Nativeint.shift_left 1n (Misc.log2 (Nativeint.to_int n)) ->
+ (Iintop_imm(Imod, Nativeint.to_int n), [arg1])
| _ -> (Iintop Imod, args)
end
(* Recognize float arithmetic with memory. *)
diff --git a/asmcomp/selectgen.ml b/asmcomp/selectgen.ml
index 50f949a..7daa239 100644
--- a/asmcomp/selectgen.ml
+++ b/asmcomp/selectgen.ml
@@ -201,6 +201,8 @@ method is_simple_expr = function
method virtual is_immediate : int -> bool
+method virtual is_immediate_natint : nativeint -> bool
+
(* Selection of addressing modes *)
method virtual select_addressing :
@@ -238,11 +240,21 @@ method select_operation op args =
if n = 1 lsl l
then (Iintop_imm(Ilsl, l), [arg1])
else self#select_arith_comm Imul args
+ | (Cmuli, [arg1; Cconst_natint n]) ->
+ let l = Misc.log2 (Nativeint.to_int n) in
+ if n = Nativeint.shift_left 1n l
+ then (Iintop_imm(Ilsl, l), [arg1])
+ else self#select_arith_comm Imul args
| (Cmuli, [Cconst_int n; arg1]) ->
let l = Misc.log2 n in
if n = 1 lsl l
then (Iintop_imm(Ilsl, l), [arg1])
else self#select_arith_comm Imul args
+ | (Cmuli, [Cconst_natint n; arg1]) ->
+ let l = Misc.log2 (Nativeint.to_int n) in
+ if n = Nativeint.shift_left 1n l
+ then (Iintop_imm(Ilsl, l), [arg1])
+ else self#select_arith_comm Imul args
| (Cmuli, _) -> self#select_arith_comm Imul args
| (Cdivi, _) -> self#select_arith Idiv args
| (Cmodi, _) -> self#select_arith_comm Imod args
@@ -270,38 +282,60 @@ method select_operation op args =
method private select_arith_comm op = function
[arg; Cconst_int n] when self#is_immediate n ->
(Iintop_imm(op, n), [arg])
+ | [arg; Cconst_natint n] when self#is_immediate_natint n ->
+ (Iintop_imm(op, Nativeint.to_int n), [arg])
| [arg; Cconst_pointer n] when self#is_immediate n ->
(Iintop_imm(op, n), [arg])
+ | [arg; Cconst_natpointer n] when self#is_immediate_natint n ->
+ (Iintop_imm(op, Nativeint.to_int n), [arg])
| [Cconst_int n; arg] when self#is_immediate n ->
(Iintop_imm(op, n), [arg])
+ | [Cconst_natint n; arg] when self#is_immediate_natint n ->
+ (Iintop_imm(op, Nativeint.to_int n), [arg])
| [Cconst_pointer n; arg] when self#is_immediate n ->
(Iintop_imm(op, n), [arg])
+ | [Cconst_natpointer n; arg] when self#is_immediate_natint n ->
+ (Iintop_imm(op, Nativeint.to_int n), [arg])
| args ->
(Iintop op, args)
method private select_arith op = function
[arg; Cconst_int n] when self#is_immediate n ->
(Iintop_imm(op, n), [arg])
+ | [arg; Cconst_natint n] when self#is_immediate_natint n ->
+ (Iintop_imm(op, Nativeint.to_int n), [arg])
| [arg; Cconst_pointer n] when self#is_immediate n ->
(Iintop_imm(op, n), [arg])
+ | [arg; Cconst_natpointer n] when self#is_immediate_natint n ->
+ (Iintop_imm(op, Nativeint.to_int n), [arg])
| args ->
(Iintop op, args)
method private select_shift op = function
[arg; Cconst_int n] when n >= 0 && n < Arch.size_int * 8 ->
(Iintop_imm(op, n), [arg])
+ | [arg; Cconst_natint n] when n >= 0n && n < Nativeint.of_int (Arch.size_int * 8) ->
+ (Iintop_imm(op, Nativeint.to_int n), [arg])
| args ->
(Iintop op, args)
method private select_arith_comp cmp = function
[arg; Cconst_int n] when self#is_immediate n ->
(Iintop_imm(Icomp cmp, n), [arg])
+ | [arg; Cconst_natint n] when self#is_immediate_natint n ->
+ (Iintop_imm(Icomp cmp, Nativeint.to_int n), [arg])
| [arg; Cconst_pointer n] when self#is_immediate n ->
(Iintop_imm(Icomp cmp, n), [arg])
+ | [arg; Cconst_natpointer n] when self#is_immediate_natint n ->
+ (Iintop_imm(Icomp cmp, Nativeint.to_int n), [arg])
| [Cconst_int n; arg] when self#is_immediate n ->
(Iintop_imm(Icomp(swap_intcomp cmp), n), [arg])
+ | [Cconst_natint n; arg] when self#is_immediate_natint n ->
+ (Iintop_imm(Icomp(swap_intcomp cmp), Nativeint.to_int n), [arg])
| [Cconst_pointer n; arg] when self#is_immediate n ->
(Iintop_imm(Icomp(swap_intcomp cmp), n), [arg])
+ | [Cconst_natpointer n; arg] when self#is_immediate_natint n ->
+ (Iintop_imm(Icomp(swap_intcomp cmp), Nativeint.to_int n), [arg])
| args ->
(Iintop(Icomp cmp), args)
@@ -310,12 +344,20 @@ method private select_arith_comp cmp = function
method select_condition = function
Cop(Ccmpi cmp, [arg1; Cconst_int n]) when self#is_immediate n ->
(Iinttest_imm(Isigned cmp, n), arg1)
+ | Cop(Ccmpi cmp, [arg1; Cconst_natint n]) when self#is_immediate_natint n ->
+ (Iinttest_imm(Isigned cmp, Nativeint.to_int n), arg1)
| Cop(Ccmpi cmp, [Cconst_int n; arg2]) when self#is_immediate n ->
(Iinttest_imm(Isigned(swap_comparison cmp), n), arg2)
+ | Cop(Ccmpi cmp, [Cconst_natint n; arg2]) when self#is_immediate_natint n ->
+ (Iinttest_imm(Isigned(swap_comparison cmp), Nativeint.to_int n), arg2)
| Cop(Ccmpi cmp, [arg1; Cconst_pointer n]) when self#is_immediate n ->
(Iinttest_imm(Isigned cmp, n), arg1)
+ | Cop(Ccmpi cmp, [arg1; Cconst_natpointer n]) when self#is_immediate_natint n ->
+ (Iinttest_imm(Isigned cmp, Nativeint.to_int n), arg1)
| Cop(Ccmpi cmp, [Cconst_pointer n; arg2]) when self#is_immediate n ->
(Iinttest_imm(Isigned(swap_comparison cmp), n), arg2)
+ | Cop(Ccmpi cmp, [Cconst_natpointer n; arg2]) when self#is_immediate_natint n ->
+ (Iinttest_imm(Isigned(swap_comparison cmp), Nativeint.to_int n), arg2)
| Cop(Ccmpi cmp, args) ->
(Iinttest(Isigned cmp), Ctuple args)
| Cop(Ccmpa cmp, [arg1; Cconst_pointer n]) when self#is_immediate n ->
diff --git a/asmcomp/selectgen.mli b/asmcomp/selectgen.mli
index 7c30f9f..8966ad1 100644
--- a/asmcomp/selectgen.mli
+++ b/asmcomp/selectgen.mli
@@ -23,6 +23,7 @@ class virtual selector_generic : object
(* The following methods must or can be overridden by the processor
description *)
method virtual is_immediate : int -> bool
+ method virtual is_immediate_natint : nativeint -> bool
(* Must be defined to indicate whether a constant is a suitable
immediate operand to arithmetic instructions *)
method virtual select_addressing :
|