[futurebasic] Re: [FB] Function calls with Globals as parameters

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2009 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Mon, 19 Oct 2009 18:45:53 +1300
I wrote:

>  Modern optimizing compilers work out what your code means, then  
> implement it in the most efficient manner.

In the first example, integer division by a constant is replaced by  
multiplication and shift instructions.

local fn IntDiv5( x as UInt32 ) as UInt32
end fn = x/5

_IntDiv5:
	pushl	%ebp
	movl	%esp, %ebp
	movl	$-858993459, %eax
	mull	8(%ebp)
	shrl	$2, %edx
	movl	%edx, %eax
	leave
	ret

Here, the entire function body collapses to one instruction (fld1).

local fn TestCalc as double
dim as double d, result
d = 1 + 0.5 + 2*1 - 2/7 - 1/2 + 2/7
result = sqr( cos( d - 2.0*1.5 ) )
end fn = result

_TestCalc:
	pushl	%ebp
	movl	%esp, %ebp
	fld1
	leave
	ret

Robert P.