GDC for dummies

bearophile bearophileHUGS at lycos.com
Wed Nov 28 00:02:53 PST 2007


Jerome:
> That's your problem right there. You can install MinGW wherever you
> want (although it's probably best to avoid spaces in the path),
> but you *must* install gdc to the *same* folder.
> Then add c:\mingw\bin to the path if it didn't do it

It works, thank you very much :-)

As a first test I have tried to benchmark the templated Bitfield accessors:

Timings (seconds), n=4_000_000*25:
  C:   0.80
  GDC: 1.30
  DMD: 3.18

Compiled with:
  gcc version 3.4.5 (mingw special) (gdc 0.24, using dmd 1.020)

  DMD v1.023

  gcc version 3.4.2 (mingw-special)

Compilation parameters I have used:
  gcc -O3 -s -finline-functions -ffast-math -fomit-frame-pointer -funroll-loops -march=pentiumpro bitfieldsC.c -o bitfieldsC

  gdc -O3 -s -frelease -finline-functions -ffast-math -fomit-frame-pointer -funroll-loops -march=pentiumpro bitfieldsD.d -o bitfieldsD2

  dmd -O -release -inline bitfieldsD.d


And for reference here is the assembly too, it's interesting.

ASM from GCC:

	.file	"bitfieldsC.c"
	.def	___main;	.scl	2;	.type	32;	.endef
	.data
	.align 4
LC0:
	.long	1628676761
	.long	1620574103
	.long	1237153253
	.long	1098880307
	.long	87513741
	.long	13181925
	.long	14686126
	.long	7429435
	.long	16286706
	.long	6474381
	.long	4879794
	.long	7734725
	.long	3745958
	.long	13353858
	.long	4236193
	.long	7587
	.long	4309
	.long	28846
	.long	7313
	.long	14516
	.long	126
	.long	143
	.long	171
	.long	221
	.long	156
	.section .rdata,"dr"
LC1:
	.ascii "%d\12\0"
	.text
	.p2align 4,,15
.globl _main
	.def	_main;	.scl	2;	.type	32;	.endef
_main:
	pushl	%ebp
	movl	$16, %eax
	movl	%esp, %ebp
	pushl	%edi
	pushl	%esi
	pushl	%ebx
	subl	$140, %esp
	andl	$-16, %esp
	call	__alloca
	call	___main
	leal	-136(%ebp), %eax
	movl	$100, %ecx
	movl	$LC0, %edx
	movl	%ecx, 8(%esp)
	xorl	%esi, %esi
	xorl	%edi, %edi
	movl	%edx, 4(%esp)
	movl	%eax, (%esp)
	call	_memcpy
L9:
	xorl	%ebx, %ebx
	.p2align 4,,15
L8:
	movl	-136(%ebp,%ebx,4), %eax
	movl	-132(%ebp,%ebx,4), %edx
	movl	%eax, %ecx
	shrl	$2, %ecx
	andl	$1, %eax
	andl	$127, %ecx
	addl	%eax, %ecx
	leal	(%esi,%ecx), %ecx
	movl	%edx, %esi
	movl	-128(%ebp,%ebx,4), %eax
	shrl	$2, %esi
	andl	$1, %edx
	andl	$127, %esi
	addl	%edx, %esi
	addl	%esi, %ecx
	movl	-124(%ebp,%ebx,4), %edx
	movl	%eax, %esi
	shrl	$2, %esi
	andl	$1, %eax
	andl	$127, %esi
	addl	%eax, %esi
	movl	%edx, %eax
	addl	%esi, %ecx
	shrl	$2, %eax
	movl	-120(%ebp,%ebx,4), %esi
	andl	$127, %eax
	andl	$1, %edx
	addl	%edx, %eax
	addl	$5, %ebx
	addl	%eax, %ecx
	movl	%esi, %eax
	shrl	$2, %eax
	andl	$1, %esi
	andl	$127, %eax
	addl	%esi, %eax
	cmpl	$24, %ebx
	leal	(%ecx,%eax), %esi
	jle	L8
	incl	%edi
	cmpl	$3999999, %edi
	jle	L9
	movl	%esi, 4(%esp)
	movl	$LC1, (%esp)
	call	_printf
	leal	-12(%ebp), %esp
	xorl	%eax, %eax
	popl	%ebx
	popl	%esi
	popl	%edi
	popl	%ebp
	ret
	.def	_memcpy;	.scl	3;	.type	32;	.endef
	.def	_printf;	.scl	3;	.type	32;	.endef

----------------------

ASM from GDC:

	.file	"bitfieldsD.d"
.globl __D34TypeInfo_S10bitfieldsD10INTORFLOAT6__initZ
	.section	.data$_D34TypeInfo_S10bitfieldsD10INTORFLOAT6__initZ,"w"
	.linkonce same_size
	.align 4
__D34TypeInfo_S10bitfieldsD10INTORFLOAT6__initZ:
	.long	__D15TypeInfo_Struct6__vtblZ
	.long	0
	.long	21
	.long	__D34TypeInfo_S10bitfieldsD10INTORFLOAT6__initZ+44
	.long	4
	.long	0
	.long	0
	.long	0
	.long	0
	.long	0
	.long	0
	.ascii "bitfieldsD.INTORFLOAT\0"
.globl __D10bitfieldsD10INTORFLOAT6__initZ
	.section .rdata,"dr"
	.align 4
__D10bitfieldsD10INTORFLOAT6__initZ:
	.space 4
LC0:
	.ascii "%d\12\0"
	.text
	.p2align 4,,15
.globl __Dmain
	.def	__Dmain;	.scl	2;	.type	32;	.endef
__Dmain:
	pushl	%ebp
	movl	$25, %ecx
	movl	$25, %edx
	pushl	%edi
	xorl	%ebp, %ebp
	xorl	%edi, %edi
	pushl	%esi
	pushl	%ebx
	subl	$140, %esp
	movl	%ecx, %ebx
	movl	%edx, 4(%esp)
	sall	$2, %ebx
	leal	16(%esp), %esi
	movl	$__D11TypeInfo_Ak6__initZ, (%esp)
	call	__d_newarrayT
	movl	$1628676761, (%edx)
	movl	$1620574103, 4(%edx)
	movl	$1237153253, 8(%edx)
	movl	$1098880307, 12(%edx)
	movl	$87513741, 16(%edx)
	movl	$13181925, 20(%edx)
	movl	$14686126, 24(%edx)
	movl	$7429435, 28(%edx)
	movl	$16286706, 32(%edx)
	movl	$6474381, 36(%edx)
	movl	$4879794, 40(%edx)
	movl	$7734725, 44(%edx)
	movl	$3745958, 48(%edx)
	movl	$13353858, 52(%edx)
	movl	$4236193, 56(%edx)
	movl	$7587, 60(%edx)
	movl	$4309, 64(%edx)
	movl	$28846, 68(%edx)
	movl	$7313, 72(%edx)
	movl	$14516, 76(%edx)
	movl	$126, 80(%edx)
	movl	$143, 84(%edx)
	movl	$171, 88(%edx)
	movl	$221, 92(%edx)
	movl	$156, 96(%edx)
	movl	%ebx, 8(%esp)
	xorl	%ebx, %ebx
	movl	%edx, 4(%esp)
	movl	%esi, (%esp)
	call	_memcpy
	cmpl	$4000000, %ebx
	jge	L9
L25:
	xorl	%ecx, %ecx
	jmp	L11
	.p2align 4,,7
L23:
	movl	16(%esp,%ecx,4), %edx
	xorl	%esi, %esi
	movl	%edx, %eax
	shrl	$2, %eax
	andl	$1, %edx
	andl	$127, %eax
	addl	%edx, %eax
	movl	20(%esp,%ecx,4), %edx
	addl	%eax, %edi
	adcl	%esi, %ebp
	xorl	%esi, %esi
	movl	%edx, %eax
	shrl	$2, %eax
	andl	$1, %edx
	andl	$127, %eax
	addl	%edx, %eax
	movl	24(%esp,%ecx,4), %edx
	addl	%eax, %edi
	adcl	%esi, %ebp
	xorl	%esi, %esi
	movl	%edx, %eax
	shrl	$2, %eax
	andl	$1, %edx
	andl	$127, %eax
	addl	%edx, %eax
	movl	28(%esp,%ecx,4), %edx
	addl	%eax, %edi
	adcl	%esi, %ebp
	xorl	%esi, %esi
	movl	%edx, %eax
	shrl	$2, %eax
	andl	$1, %edx
	andl	$127, %eax
	addl	%edx, %eax
	movl	32(%esp,%ecx,4), %edx
	addl	%eax, %edi
	adcl	%esi, %ebp
	xorl	%esi, %esi
	movl	%edx, %eax
	shrl	$2, %eax
	andl	$1, %edx
	andl	$127, %eax
	addl	%edx, %eax
	addl	%eax, %edi
	adcl	%esi, %ebp
	addl	$5, %ecx
L11:
	cmpl	$25, %ecx
	jl	L23
	incl	%ebx
	cmpl	$4000000, %ebx
	jl	L25
L9:
	movl	%edi, 4(%esp)
	movl	%ebp, 8(%esp)
	movl	$LC0, (%esp)
	call	_printf
	addl	$140, %esp
	xorl	%eax, %eax
	popl	%ebx
	popl	%esi
	popl	%edi
	popl	%ebp
	ret
	.section .rdata,"dr"
LC1:
	.ascii "bitfieldsD\0"
.globl __D10bitfieldsD12__ModuleInfoZ
	.data
	.align 4
__D10bitfieldsD12__ModuleInfoZ:
	.long	0
	.long	0
	.long	10
	.long	LC1
	.long	1
	.long	__D10bitfieldsD12__ModuleInfoZ+48
	.long	0
	.long	0
	.long	0
	.long	0
	.long	0
	.long	0
	.long	__D3std5stdio12__ModuleInfoZ
	.align 4
___mod_ref.0:
	.long	0
	.long	__D10bitfieldsD12__ModuleInfoZ
	.section	.ctors,"w"
	.align 4
	.long	__D10bitfieldsD9__modinitFZv
	.text
	.p2align 4,,15
.globl __D10bitfieldsD10INTORFLOAT4signMFZk
	.def	__D10bitfieldsD10INTORFLOAT4signMFZk;	.scl	2;	.type	32;	.endef
__D10bitfieldsD10INTORFLOAT4signMFZk:
	movl	4(%esp), %eax
	movl	(%eax), %eax
	andl	$1, %eax
	ret
	.p2align 4,,15
.globl __D10bitfieldsD10INTORFLOAT4signMFkZv
	.def	__D10bitfieldsD10INTORFLOAT4signMFkZv;	.scl	2;	.type	32;	.endef
__D10bitfieldsD10INTORFLOAT4signMFkZv:
	movl	4(%esp), %eax
	movl	8(%esp), %ecx
	movl	(%eax), %edx
	andl	$1, %ecx
	andl	$-2, %edx
	orl	%ecx, %edx
	movl	%edx, (%eax)
	ret
	.p2align 4,,15
.globl __D10bitfieldsD10INTORFLOAT14biasedexponentMFZk
	.def	__D10bitfieldsD10INTORFLOAT14biasedexponentMFZk;	.scl	2;	.type	32;	.endef
__D10bitfieldsD10INTORFLOAT14biasedexponentMFZk:
	movl	4(%esp), %eax
	movl	(%eax), %eax
	shrl	%eax
	andl	$255, %eax
	ret
	.p2align 4,,15
.globl __D10bitfieldsD10INTORFLOAT14biasedexponentMFkZv
	.def	__D10bitfieldsD10INTORFLOAT14biasedexponentMFkZv;	.scl	2;	.type	32;	.endef
__D10bitfieldsD10INTORFLOAT14biasedexponentMFkZv:
	movzbl	8(%esp), %eax
	movl	4(%esp), %ecx
	movl	(%ecx), %edx
	addl	%eax, %eax
	andl	$-511, %edx
	orl	%eax, %edx
	movl	%edx, (%ecx)
	ret
	.p2align 4,,15
.globl __D10bitfieldsD10INTORFLOAT11significandMFZk
	.def	__D10bitfieldsD10INTORFLOAT11significandMFZk;	.scl	2;	.type	32;	.endef
__D10bitfieldsD10INTORFLOAT11significandMFZk:
	movl	4(%esp), %eax
	movl	(%eax), %eax
	shrl	$9, %eax
	ret
	.p2align 4,,15
.globl __D10bitfieldsD10INTORFLOAT11significandMFkZv
	.def	__D10bitfieldsD10INTORFLOAT11significandMFkZv;	.scl	2;	.type	32;	.endef
__D10bitfieldsD10INTORFLOAT11significandMFkZv:
	movl	4(%esp), %ecx
	movl	8(%esp), %eax
	movl	(%ecx), %edx
	andl	$8388607, %eax
	sall	$9, %eax
	andl	$511, %edx
	orl	%eax, %edx
	movl	%edx, (%ecx)
	ret
	.p2align 4,,15
	.def	__D10bitfieldsD9__modinitFZv;	.scl	3;	.type	32;	.endef
__D10bitfieldsD9__modinitFZv:
	movl	__Dmodule_ref, %eax
	movl	$___mod_ref.0, %edx
	movl	%edx, __Dmodule_ref
	movl	%eax, ___mod_ref.0
	ret
	.def	_memcpy;	.scl	2;	.type	32;	.endef


Bye,
bearophile


More information about the Digitalmars-d-learn mailing list