Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Timing Ocaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Dmitry Bely <dbely@m...>
Subject: Re: [Caml-list] Timing Ocaml
"Lionel Fourquaux" <lionel.fourquaux@wanadoo.fr> writes:

>> Thank a lot for the explanation. But why then not to use inline asm
> for
>> MSVC, something like that:
>
> 	Because any fragment of inline asm disable a lot of
> optimisations in MSVC, and you end up with a much slower interpreter.

I see... But there is another solution: use C switch() operator in interp
main loop that is translated to jump table by MSVC optimizer (don't know if
gcc is capable to do this). A small example:

int f( int i )
{
  int j = 0;
  switch( i ){ 
    case 1: j = 2; break;
    case 2: j = 4; break;
    case 3: j = 8; break;
    case 4: j = 16; break;
  }
  return j;
}

cl -c -Ox -Fatest.lst test.c

	TITLE	test.c
	.386P
include listing.inc
if @Version gt 510
.model FLAT
else
_TEXT	SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT	ENDS
_DATA	SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA	ENDS
CONST	SEGMENT DWORD USE32 PUBLIC 'CONST'
CONST	ENDS
_BSS	SEGMENT DWORD USE32 PUBLIC 'BSS'
_BSS	ENDS
_TLS	SEGMENT DWORD USE32 PUBLIC 'TLS'
_TLS	ENDS
FLAT	GROUP _DATA, CONST, _BSS
	ASSUME	CS: FLAT, DS: FLAT, SS: FLAT
endif
PUBLIC	_f
_TEXT	SEGMENT
_i$ = 8
_f	PROC NEAR
; File test.c
; Line 4
	mov	ecx, DWORD PTR _i$[esp-4]
	xor	eax, eax
	dec	ecx
	cmp	ecx, 3
	ja	SHORT $L526
	jmp	DWORD PTR $L536[ecx*4]
$L529:
; Line 5
	mov	eax, 2
; Line 11
	ret	0
$L530:
; Line 6
	mov	eax, 4
; Line 11
	ret	0
$L531:
; Line 7
	mov	eax, 8
; Line 11
	ret	0
$L532:
; Line 8
	mov	eax, 16					; 00000010H
$L526:
; Line 11
	ret	0
	npad	1
$L536:
	DD	$L529
	DD	$L530
	DD	$L531
	DD	$L532
_f	ENDP
_TEXT	ENDS
END

Hope to hear from you soon,
Dmitry


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners