caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Compiler bug?
@ 2012-08-06 10:04 Dmitry Bely
  2012-08-06 10:11 ` Alain Frisch
  0 siblings, 1 reply; 30+ messages in thread
From: Dmitry Bely @ 2012-08-06 10:04 UTC (permalink / raw)
  To: caml-list

Trying to catch some very rare floating-point related bug I've
realized that I probably don't understand some basic things about
OCaml execution model. Let's consider the simplest function:

let add1 x = x +. 1.

For x86 it is compiled as

	.CODE
	ALIGN	4
	PUBLIC	_camlTest__add1_1008
_camlTest__add1_1008:
	sub	esp, 8
L100:
	mov	ebx, eax
L101:	mov	eax, _caml_young_ptr
	sub	eax, 12
	mov	_caml_young_ptr, eax
	cmp	eax, _caml_young_limit
	jb	L102
	lea	eax, [eax+4]
	mov	DWORD PTR [eax-4],2301
	fld1
	fadd	REAL8 PTR [ebx]
	fstp	REAL8 PTR [eax]
	add    esp, 8
	ret
L102:	call	_caml_call_gc
L103:	jmp	L101

X parameter is passed as a pointer to float value ([eax] which is
immediately saved to [ebx]). But If GC happens (L102), float value can
be moved around the OCaml heap and [ebx] become invalid, right? So the
generated code is just wrong. Am I missing something?

- Dmitry Bely

^ permalink raw reply	[flat|nested] 30+ messages in thread
* compiler bug?
@ 2006-05-17 23:14 Dan Koppel
  2006-05-17 23:33 ` [Caml-list] " John Carr
  2006-05-18 17:15 ` Xavier Leroy
  0 siblings, 2 replies; 30+ messages in thread
From: Dan Koppel @ 2006-05-17 23:14 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1470 bytes --]

Hello Caml Group,
  I would like to report what I think might be a bug in the Ocaml compiler.  But first I wanted to run this by this group in case there's something I'm missing.  I have some very simple code that consists of 2 nested loops.  Inside the inner loop, is a simple statement.  Furthermore, the inner loop is not "tight".  Ie. the number of iterations within the inner loop is very large and the number of iterations of the outer loop is very small.  I then manually time this.  I then change the code by inserting a simple function call between the inner and outer loops.  This should have virtually no effect whatsoever.  However, when I time this, I get exactly twice the time.  This is somewhat inexplicable.  I tried tinkering with the "-inline" option for ocamlopt but this had no effect.  Below is the actual code (main.ml):
   
  let main () =
    let dummy1 = ref 0 in
  let dummy2 = ref 0.0 in
    for i = 1 to 4 do
    for j = 1 to 1000000000 do
      dummy1 := !dummy1 + 1;
      dummy1 := !dummy1 - 1
    done;
    dummy2 := Unix.gettimeofday ()
  done
   
  let _ = main ()
   
  I compile as follows: ocamlopt unix.cmxa main.ml
and run: ./a.out
   
  Is this in fact a bug of the ocamlopt compiler?  Or is there some way currently to make this effect disappear?
   
  Thanks for any help!
Sincerely,
  Dan Koppel

			
---------------------------------
Sneak preview the  all-new Yahoo.com. It's not radically different. Just radically better. 

[-- Attachment #2: Type: text/html, Size: 1907 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2012-08-09  0:53 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-06 10:04 [Caml-list] Compiler bug? Dmitry Bely
2012-08-06 10:11 ` Alain Frisch
2012-08-06 10:20   ` Dmitry Bely
2012-08-06 10:34     ` Alain Frisch
2012-08-06 11:03       ` Dmitry Bely
2012-08-06 11:32         ` Alain Frisch
2012-08-06 12:16           ` Dmitry Bely
2012-08-07  1:35           ` Cedric Cellier
2012-08-08 16:03           ` Dmitry Bely
2012-08-08 18:03             ` Alain Frisch
2012-08-08 18:22               ` Jesper Louis Andersen
2012-08-08 18:40                 ` Dmitry Bely
2012-08-08 19:29                   ` Fabrice Le Fessant
2012-08-08 23:34                 ` Anil Madhavapeddy
2012-08-09  0:53                 ` Francois Berenger
  -- strict thread matches above, loose matches on Subject: below --
2006-05-17 23:14 compiler bug? Dan Koppel
2006-05-17 23:33 ` [Caml-list] " John Carr
2006-05-18 17:15 ` Xavier Leroy
2006-05-18 17:34   ` Jacques Carette
2006-05-18 17:46     ` Xavier Leroy
2006-05-18 19:31       ` Jacques Carette
2006-05-18 20:07         ` David Brown
2006-05-18 20:15           ` Jacques Carette
2006-05-18 20:20           ` Alain Frisch
2006-05-18 18:19     ` skaller
2006-05-18 18:53       ` Jacques Carette
2006-05-19  1:47         ` skaller
2006-05-19  2:17           ` Brian Hurt
2006-05-19  3:11             ` skaller
2006-05-19 16:48           ` Jacques Carette
2006-05-19 19:10             ` skaller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).