diff -ru ocaml/asmcomp/cmm.ml ocaml-hacked/asmcomp/cmm.ml --- ocaml/asmcomp/cmm.ml 2005-02-21 22:33:44.000000000 +1100 +++ ocaml-hacked/asmcomp/cmm.ml 2005-02-21 21:58:02.000000000 +1100 @@ -79,7 +79,7 @@ | Ccmpa of comparison | Cnegf | Cabsf | Caddf | Csubf | Cmulf | Cdivf - | Cfloatofint | Cintoffloat + | Cfloatofint | Cintoffloat | Croundtoint | Ccmpf of comparison | Craise | Ccheckbound diff -ru ocaml/asmcomp/cmm.mli ocaml-hacked/asmcomp/cmm.mli --- ocaml/asmcomp/cmm.mli 2005-02-21 22:33:44.000000000 +1100 +++ ocaml-hacked/asmcomp/cmm.mli 2005-02-21 21:58:02.000000000 +1100 @@ -65,7 +65,7 @@ | Ccmpa of comparison | Cnegf | Cabsf | Caddf | Csubf | Cmulf | Cdivf - | Cfloatofint | Cintoffloat + | Cfloatofint | Cintoffloat | Croundtoint | Ccmpf of comparison | Craise | Ccheckbound diff -ru ocaml/asmcomp/cmmgen.ml ocaml-hacked/asmcomp/cmmgen.ml --- ocaml/asmcomp/cmmgen.ml 2005-02-21 22:33:44.000000000 +1100 +++ ocaml-hacked/asmcomp/cmmgen.ml 2005-02-21 21:58:02.000000000 +1100 @@ -1056,6 +1056,8 @@ box_float(Cop(Cfloatofint, [untag_int(transl arg)])) | Pintoffloat -> tag_int(Cop(Cintoffloat, [transl_unbox_float arg])) + | Proundtoint -> + tag_int(Cop(Croundtoint, [transl_unbox_float arg])) | Pnegfloat -> box_float(Cop(Cnegf, [transl_unbox_float arg])) | Pabsfloat -> diff -ru ocaml/asmcomp/i386/emit.mlp ocaml-hacked/asmcomp/i386/emit.mlp --- ocaml/asmcomp/i386/emit.mlp 2005-02-21 22:33:44.000000000 +1100 +++ ocaml-hacked/asmcomp/i386/emit.mlp 2005-02-21 22:28:34.000000000 +1100 @@ -617,6 +617,20 @@ ` fldcw 4(%esp)\n`; ` addl $8, %esp\n`; stack_offset := !stack_offset + 8 + | Lop(Iroundtoint) -> + if not (is_tos i.arg.(0)) then + ` fldl {emit_reg i.arg.(0)}\n`; + stack_offset := !stack_offset - 8; + ` subl $8, %esp\n`; + begin match i.res.(0).loc with + Stack s -> + ` fistpl {emit_reg i.res.(0)}\n` + | _ -> + ` fistpl (%esp)\n`; + ` movl (%esp), {emit_reg i.res.(0)}\n` + end; + ` addl $8, %esp\n`; + stack_offset := !stack_offset + 8 | Lop(Ispecific(Ilea addr)) -> ` lea {emit_addressing addr i.arg 0}, {emit_reg i.res.(0)}\n` | Lop(Ispecific(Istore_int(n, addr))) -> diff -ru ocaml/asmcomp/i386/emit_nt.mlp ocaml-hacked/asmcomp/i386/emit_nt.mlp --- ocaml/asmcomp/i386/emit_nt.mlp 2005-02-21 22:33:44.000000000 +1100 +++ ocaml-hacked/asmcomp/i386/emit_nt.mlp 2005-02-21 22:28:53.000000000 +1100 @@ -594,6 +594,20 @@ ` fldcw [esp+4]\n`; ` add esp, 8\n`; stack_offset := !stack_offset + 8 + | Lop(Iroundtotint) -> + if not (is_tos i.arg.(0)) then + ` fldl {emit_reg i.arg.(0)}\n`; + stack_offset := !stack_offset - 8; + ` subl $8, %esp\n`; + begin match i.res.(0).loc with + Stack s -> + ` fistpl {emit_reg i.res.(0)}\n` + | _ -> + ` fistpl (%esp)\n`; + ` movl (%esp), {emit_reg i.res.(0)}\n` + end; + ` addl $8, %esp\n`; + stack_offset := !stack_offset + 8 | Lop(Ispecific(Ilea addr)) -> ` lea {emit_reg i.res.(0)}, DWORD PTR {emit_addressing addr i.arg 0}\n` | Lop(Ispecific(Istore_int(n, addr))) -> diff -ru ocaml/asmcomp/mach.ml ocaml-hacked/asmcomp/mach.ml --- ocaml/asmcomp/mach.ml 2005-02-21 22:33:44.000000000 +1100 +++ ocaml-hacked/asmcomp/mach.ml 2005-02-21 21:58:02.000000000 +1100 @@ -52,7 +52,7 @@ | Iintop of integer_operation | Iintop_imm of integer_operation * int | Inegf | Iabsf | Iaddf | Isubf | Imulf | Idivf - | Ifloatofint | Iintoffloat + | Ifloatofint | Iintoffloat | Iroundtoint | Ispecific of Arch.specific_operation type instruction = diff -ru ocaml/asmcomp/mach.mli ocaml-hacked/asmcomp/mach.mli --- ocaml/asmcomp/mach.mli 2005-02-21 22:33:44.000000000 +1100 +++ ocaml-hacked/asmcomp/mach.mli 2005-02-21 21:58:02.000000000 +1100 @@ -52,7 +52,7 @@ | Iintop of integer_operation | Iintop_imm of integer_operation * int | Inegf | Iabsf | Iaddf | Isubf | Imulf | Idivf - | Ifloatofint | Iintoffloat + | Ifloatofint | Iintoffloat | Iroundtoint | Ispecific of Arch.specific_operation type instruction = diff -ru ocaml/asmcomp/power/emit.mlp ocaml-hacked/asmcomp/power/emit.mlp --- ocaml/asmcomp/power/emit.mlp 2005-02-21 22:33:44.000000000 +1100 +++ ocaml-hacked/asmcomp/power/emit.mlp 2005-02-21 21:58:02.000000000 +1100 @@ -344,6 +344,7 @@ | Lop(Inegf | Iabsf | Iaddf | Isubf | Imulf | Idivf) -> 1 | Lop(Ifloatofint) -> 9 | Lop(Iintoffloat) -> 4 + | Lop(Iroundtoint) -> 4 | Lop(Ispecific sop) -> 1 | Lreloadretaddr -> 2 | Lreturn -> 2 @@ -636,6 +637,11 @@ ` stfdu {emit_fpr 0}, -8({emit_gpr 1})\n`; ` lwz {emit_reg i.res.(0)}, 4({emit_gpr 1})\n`; ` addi {emit_gpr 1}, {emit_gpr 1}, 8\n` + | Lop(Iroundtoint) -> + ` fctiw {emit_fpr 0}, {emit_reg i.arg.(0)}\n`; + ` stfdu {emit_fpr 0}, -8({emit_gpr 1})\n`; + ` lwz {emit_reg i.res.(0)}, 4({emit_gpr 1})\n`; + ` addi {emit_gpr 1}, {emit_gpr 1}, 8\n` | Lop(Ispecific sop) -> let instr = name_for_specific sop in ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, {emit_reg i.arg.(2)}\n` diff -ru ocaml/asmcomp/printcmm.ml ocaml-hacked/asmcomp/printcmm.ml --- ocaml/asmcomp/printcmm.ml 2005-02-21 22:33:44.000000000 +1100 +++ ocaml-hacked/asmcomp/printcmm.ml 2005-02-21 21:58:02.000000000 +1100 @@ -81,6 +81,7 @@ | Cdivf -> "/f" | Cfloatofint -> "floatofint" | Cintoffloat -> "intoffloat" + | Croundtoint -> "roundtoint" | Ccmpf c -> Printf.sprintf "%sf" (comparison c) | Craise -> "raise" | Ccheckbound -> "checkbound" diff -ru ocaml/asmcomp/printmach.ml ocaml-hacked/asmcomp/printmach.ml --- ocaml/asmcomp/printmach.ml 2005-02-21 22:33:44.000000000 +1100 +++ ocaml-hacked/asmcomp/printmach.ml 2005-02-21 21:58:02.000000000 +1100 @@ -136,6 +136,7 @@ | Idivf -> fprintf ppf "%a /f %a" reg arg.(0) reg arg.(1) | Ifloatofint -> fprintf ppf "floatofint %a" reg arg.(0) | Iintoffloat -> fprintf ppf "intoffloat %a" reg arg.(0) + | Iroundtoint -> fprintf ppf "roundtoint %a" reg arg.(0) | Ispecific op -> Arch.print_specific_operation reg op ppf arg diff -ru ocaml/asmcomp/selectgen.ml ocaml-hacked/asmcomp/selectgen.ml --- ocaml/asmcomp/selectgen.ml 2005-02-21 22:33:44.000000000 +1100 +++ ocaml-hacked/asmcomp/selectgen.ml 2005-02-21 21:58:02.000000000 +1100 @@ -42,6 +42,7 @@ | Cnegf | Cabsf | Caddf | Csubf | Cmulf | Cdivf -> typ_float | Cfloatofint -> typ_float | Cintoffloat -> typ_int + | Croundtoint -> typ_int | Craise -> typ_void | Ccheckbound -> typ_void @@ -268,6 +269,7 @@ | (Cdivf, _) -> (Idivf, args) | (Cfloatofint, _) -> (Ifloatofint, args) | (Cintoffloat, _) -> (Iintoffloat, args) + | (Croundtoint, _) -> (Iroundtoint, args) | (Ccheckbound, _) -> self#select_arith Icheckbound args | _ -> fatal_error "Selection.select_oper" diff -ru ocaml/bytecomp/bytegen.ml ocaml-hacked/bytecomp/bytegen.ml --- ocaml/bytecomp/bytegen.ml 2005-02-21 22:33:45.000000000 +1100 +++ ocaml-hacked/bytecomp/bytegen.ml 2005-02-21 21:58:02.000000000 +1100 @@ -291,6 +291,7 @@ | Poffsetint n -> Koffsetint n | Poffsetref n -> Koffsetref n | Pintoffloat -> Kccall("caml_int_of_float", 1) + | Proundtoint -> Kccall("caml_round_to_int", 1) | Pfloatofint -> Kccall("caml_float_of_int", 1) | Pnegfloat -> Kccall("caml_neg_float", 1) | Pabsfloat -> Kccall("caml_abs_float", 1) diff -ru ocaml/bytecomp/lambda.ml ocaml-hacked/bytecomp/lambda.ml --- ocaml/bytecomp/lambda.ml 2005-02-21 22:33:45.000000000 +1100 +++ ocaml-hacked/bytecomp/lambda.ml 2005-02-21 21:58:02.000000000 +1100 @@ -42,7 +42,7 @@ | Poffsetint of int | Poffsetref of int (* Float operations *) - | Pintoffloat | Pfloatofint + | Pintoffloat | Proundtoint | Pfloatofint | Pnegfloat | Pabsfloat | Paddfloat | Psubfloat | Pmulfloat | Pdivfloat | Pfloatcomp of comparison diff -ru ocaml/bytecomp/lambda.mli ocaml-hacked/bytecomp/lambda.mli --- ocaml/bytecomp/lambda.mli 2005-02-21 22:33:45.000000000 +1100 +++ ocaml-hacked/bytecomp/lambda.mli 2005-02-21 21:58:02.000000000 +1100 @@ -42,7 +42,7 @@ | Poffsetint of int | Poffsetref of int (* Float operations *) - | Pintoffloat | Pfloatofint + | Pintoffloat | Proundtoint | Pfloatofint | Pnegfloat | Pabsfloat | Paddfloat | Psubfloat | Pmulfloat | Pdivfloat | Pfloatcomp of comparison diff -ru ocaml/bytecomp/printlambda.ml ocaml-hacked/bytecomp/printlambda.ml --- ocaml/bytecomp/printlambda.ml 2005-02-21 22:33:45.000000000 +1100 +++ ocaml-hacked/bytecomp/printlambda.ml 2005-02-21 21:58:02.000000000 +1100 @@ -122,6 +122,7 @@ | Poffsetint n -> fprintf ppf "%i+" n | Poffsetref n -> fprintf ppf "+:=%i"n | Pintoffloat -> fprintf ppf "int_of_float" + | Proundtoint -> fprintf ppf "round_to_int" | Pfloatofint -> fprintf ppf "float_of_int" | Pnegfloat -> fprintf ppf "~." | Pabsfloat -> fprintf ppf "abs." diff -ru ocaml/bytecomp/translcore.ml ocaml-hacked/bytecomp/translcore.ml --- ocaml/bytecomp/translcore.ml 2005-02-21 22:33:45.000000000 +1100 +++ ocaml-hacked/bytecomp/translcore.ml 2005-02-21 21:58:02.000000000 +1100 @@ -168,6 +168,7 @@ "%incr", Poffsetref(1); "%decr", Poffsetref(-1); "%intoffloat", Pintoffloat; + "%roundtoint", Proundtoint; "%floatofint", Pfloatofint; "%negfloat", Pnegfloat; "%absfloat", Pabsfloat; diff -ru ocaml/byterun/floats.c ocaml-hacked/byterun/floats.c --- ocaml/byterun/floats.c 2005-02-21 22:33:45.000000000 +1100 +++ ocaml-hacked/byterun/floats.c 2005-02-21 21:58:02.000000000 +1100 @@ -15,6 +15,11 @@ /* The interface of this file is in "mlvalues.h" and "alloc.h" */ +#define _ISOC9X_SOURCE 1 +#define _ISOC99_SOURCE 1 +#define __USE_ISOC9X 1 +#define __USE_ISOC99 1 + #include <math.h> #include <stdio.h> #include <stdlib.h> @@ -134,6 +139,11 @@ return Val_long((long) Double_val(f)); } +CAMLprim value caml_round_to_int(value f) +{ + return Val_long(lrint(f)); +} + CAMLprim value caml_float_of_int(value n) { return caml_copy_double((double) Long_val(n)); diff -ru ocaml/otherlibs/threads/pervasives.ml ocaml-hacked/otherlibs/threads/pervasives.ml --- ocaml/otherlibs/threads/pervasives.ml 2005-02-21 22:33:47.000000000 +1100 +++ ocaml-hacked/otherlibs/threads/pervasives.ml 2005-02-21 21:58:02.000000000 +1100 @@ -111,6 +111,7 @@ external float_of_int : int -> float = "%floatofint" external truncate : float -> int = "%intoffloat" external int_of_float : float -> int = "%intoffloat" +external round_to_int : float -> int = "%roundtoint" external float_of_bits : int64 -> float = "caml_int64_float_of_bits" let infinity = float_of_bits 0x7F_F0_00_00_00_00_00_00L diff -ru ocaml/stdlib/pervasives.ml ocaml-hacked/stdlib/pervasives.ml --- ocaml/stdlib/pervasives.ml 2005-02-21 22:33:47.000000000 +1100 +++ ocaml-hacked/stdlib/pervasives.ml 2005-02-21 21:58:02.000000000 +1100 @@ -107,6 +107,7 @@ external float_of_int : int -> float = "%floatofint" external truncate : float -> int = "%intoffloat" external int_of_float : float -> int = "%intoffloat" +external round_to_int : float -> int = "%roundtoint" external float_of_bits : int64 -> float = "caml_int64_float_of_bits" let infinity = float_of_bits 0x7F_F0_00_00_00_00_00_00L diff -ru ocaml/stdlib/pervasives.mli ocaml-hacked/stdlib/pervasives.mli --- ocaml/stdlib/pervasives.mli 2005-02-21 22:33:47.000000000 +1100 +++ ocaml-hacked/stdlib/pervasives.mli 2005-02-21 21:58:02.000000000 +1100 @@ -338,6 +338,12 @@ The result is unspecified if it falls outside the range of representable integers. *) +external round_to_int : float -> int = "%roundtoint" +(** Round the given floating-point number to an integer + using the current rounding mode. + The result is unspecified if it falls outside the + range of representable integers. *) + val infinity : float (** Positive infinity. *)
-- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]