Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: MS compiler issue [OT]

Author: Scott Gasch

Date: 22:28:22 10/15/05

Go up one level in this thread


FWIW, here's gcc 3.4.2 with -O3 -S in ugly at&t syntax.  I also added a
__attribute__((__regparm__(3))) to the function declaration to make it a
fastcall.

getDayIndex1March00:
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %edi
        cmpl    $3, %edx
        pushl   %esi
        sbbl    $0, %ecx
        pushl   %ebx
        movl    %eax, %edi
        leal    (%ecx,%ecx,8), %esi
        movl    %ecx, %eax
        pushl   %ebx
        movl    $1374389535, %ebx
        movl    %edx, -16(%ebp)
        mull    %ebx
        leal    (%ecx,%esi,8), %eax
        movl    %edx, %ebx
        leal    (%eax,%eax,4), %eax
        shrl    $2, %ecx
        shrl    $5, %ebx
        addl    %ecx, %eax
        subl    %ebx, %eax
        shrl    $2, %ebx
        movl    -16(%ebp), %edx
        addl    %ebx, %eax
        addl    daysTilMonth.0-4(,%edx,4), %eax
        popl    %edx
        popl    %ebx
        popl    %esi
        addl    %edi, %eax
        popl    %edi
        leave
        ret

On October 15, 2005 at 12:13:32, Gerd Isenberg wrote:

>Hi,
>
>msc6 compiler has some nice optimization features. An unsigned int division by
>100 is done by reciprocal 10**37/100 multiplication. An unsigned mul 365 is done
>by three lea-instructions, which is unfortunately not the fastest on amd-cpus.
>
>Another funny thing is, that the expression
>
>  year -= (month < 3);
>
>generates following assembly using two instructions and one additional register
>more than necessary:
>
> cmp	 esi, 3
> sbb	 eax, eax
> neg	 eax
> sub	 ecx, eax
>
>instead of
>
> cmp	 esi, 3
> sbb	 ecx, 0
>
>Here is some source, first with C, second with inline assembly i like to see for
>x86-32. I am interested in generated assembly of the C-routine with more recent
>compilers (my msc2005 trial has expired and i am thinking about to buy).
>
>Thanks,
>Gerd
>
>
>
>unsigned int getDayIndex1March00(
>	unsigned int day,
>	unsigned int month,
>	unsigned int year)
>{
>	static int daysTilMonth[12] =
>	{
>		6*31 + 4*30, // jan
>		7*31 + 4*30, // feb
>		0*31 + 0*30, // mar
>		1*31 + 0*30, // apr
>		1*31 + 1*30, // may
>		2*31 + 1*30, // jun
>		2*31 + 2*30, // jul
>		3*31 + 2*30, // aug
>		4*31 + 2*30, // sep
>		4*31 + 3*30, // oct
>		5*31 + 3*30, // nov
>		5*31 + 4*30, // dec
>	};
>	unsigned int cent, didx;
>	year -= (month < 3);
>	cent  = year / 100;
>	didx  = year * 365 + (year>>2) - cent + (cent>>2)
>		  + daysTilMonth[month-1] + day;
>	return didx;
>}
>
>unsigned int _getDayIndex1March00(
>	unsigned int day,
>	unsigned int month,
>	unsigned int year)
>{
>	static int daysToMonth[12] = ...
>	__asm {
>		mov     ecx, [year]
>		mov     esi, [month]
>		cmp     esi, 3		; (month < 3)
>		mov     eax, 1374389535 ; 51eb851fH 2**37/100
>		sbb     ecx, 0  	; year -= (month < 3)
>		mul     ecx		; result in edx:eax
>		imul    eax, ecx, 365	; year*365
>		shr     edx, 5		;   centuries
>		add	eax, [day]
>		sub	eax, edx	; - centuries
>		shr     ecx, 2		;  year>>2
>		shr     edx, 2		;  centuries>>2
>		add     eax, [daysToMonth+esi*4-4]
>		add	eax, ecx	; + (year>>2)
>		add	eax, edx	; + (centuries>>2)
>	}
>}



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.