On Wed, Mar 31, 2010 at 9:55 PM, Jake Donham <j...@donham.org> wrote: > On Wed, Mar 31, 2010 at 10:21 AM, Dmitry Bely <dmitry.b...@gmail.com> wrote: >> let max_val (a:float array) = >> let m = ref min_float in >> for i = 0 to (Array.length a) - 1 do >> if a.(i) > !m >> then m := a.(i) >> done; >> !m >> >> !m is not unboxed (Ocaml 3.11). Should it? > > Why do you say that? It looks unboxed in the lambda code: > > (let > (max_val/58 > (function a/59 > (let (m/60 (field 13 (global Pervasives!))) > (seq > (for i/61 0 to (- (array.length a/59) 1) > (if (>. (array.get a/59 i/61) m/60) > (assign m/60 (array.get a/59 i/61)) 0a)) > m/60))))
No. "assign" is translated into memory allocation inside the loop. > My x86 assembler is not very good but it looks to me like m is kept in %esi. Ok, probably returning float makes allocation place not obvious. Try this variant: let max_val (a:float array) = let m = ref min_float in for i = 0 to (Array.length a) - 1 do if a.(i) > !m then m := a.(i) done; truncate !m It's translated into the following C-- code (-unsafe flag): (function camlT__max_val_58 (a/59: addr) (let m/60 (load (+a "camlPervasives" 52)) (let (i/61 1 bound/65 (+ (or (>>u (load (+a a/59 -4)) 10) 1) -2)) (catch (if (> i/61 bound/65) (exit 3) (loop (if (>f (load float64u (+a (+a a/59 (<< i/61 2)) -4)) (load float64u m/60)) (assign m/60 (alloc 2301 (load float64u (+a (+a a/59 (<< i/61 2)) -4)))) []) (let i/64 i/61 (assign i/61 (+ i/61 2)) (if (== i/64 bound/65) (exit 3) [])))) with(3) [])) (+ (<< (intoffloat (load float64u m/60)) 1) 1))) See "alloc 2301" inside the loop? That's boxed float. - Dmitry Bely _______________________________________________ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs