From mint-bounce@lists.fishpool.fi  Wed Jun  9 13:52:33 2010
X-ME-UUID: 20100609174828271.421F38002460@mwinf2816.orange.fr
Date: Wed, 9 Jun 2010 19:48:27 +0200
From: Patrice Mandin <mandin.patrice@orange.fr>
To: Mint list <mint@lists.fishpool.fi>
Subject: [MiNT] Optimisation bug in gcc 4 ?
Message-Id: <20100609194827.0a54c39a.mandin.patrice@orange.fr>
Organization: Chez moi
X-Mailer: Sylpheed 2.5.0 (GTK+ 2.12.12; i486-pc-linux-gnu)
Mime-Version: 1.0
Content-Type: multipart/mixed;
 boundary="Multipart=_Wed__9_Jun_2010_19_48_27_+0200_3YKPt5bfZiQ1BDzD"
X-ecartis-version: Ecartis v1.0.0
Sender: mint-bounce@lists.fishpool.fi
Errors-to: mint-bounce@lists.fishpool.fi
X-original-sender: mandin.patrice@orange.fr
Precedence: bulk
List-help: <mailto:ecartis@lists.fishpool.fi?Subject=help>
List-unsubscribe: <mailto:mint-request@lists.fishpool.fi?Subject=unsubscribe>
List-Id: <mint.lists.fishpool.fi>
X-List-ID: <mint.lists.fishpool.fi>
List-subscribe: <mailto:mint-request@lists.fishpool.fi?Subject=subscribe>
List-owner: <mailto:tjhukkan@fishpool.fi>
List-post: <mailto:mint@lists.fishpool.fi>

This is a multi-part message in MIME format.

--Multipart=_Wed__9_Jun_2010_19_48_27_+0200_3YKPt5bfZiQ1BDzD
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hello,

I just encountered a strange optimisation bug with gcc 4 (4.4.2 more
precisely), I hope it's fixed with 4.5.

Source is attached, this is a small test case.

I have a variable 'vidix_capability_t vidx_cap'.
The purpose of the function vdxGetCapability() (which is xbios #404) is
to fill this structure.
Then I test the field vidx_cap.flags for a given combination of bits in
this field.
Depending on this test, I either exit the program, or call myvidix_func().

The bug:

with gcc 4.4.2 (starting at -O1 level), it assumes the field has a
constant value, optimizes the test by removing it, and the code that
follows, thus also wiping out entirely the function myvidix_func from
the generated assembly code (use -save-temps to prevent deletion of it).
It does not happen with -O0, or with gcc 3.

I don't know if it's a problem in gcc, or in the definition of the
function (that uses mintlib defined trap_14_wl macro).

Note: both 4.4.2 and 3.x are cross-compilers.

--=20
Patrice Mandin
WWW: http://pmandin.atari.org/
Programmeur Linux, Atari
Sp=E9cialit=E9: D=E9veloppement, jeux

"who writes the code, decides"

--Multipart=_Wed__9_Jun_2010_19_48_27_+0200_3YKPt5bfZiQ1BDzD
Content-Type: text/x-csrc;
 name="yuvtest.c"
Content-Disposition: attachment;
 filename="yuvtest.c"
Content-Transfer-Encoding: 7bit

#include <mint/osbind.h>

typedef struct vidix_capability_s
{
	char	name[64];	/* Driver name */
	char	author[64];	/* Author name */
#define TYPE_OUTPUT	0x00000000	/* Is a video playback device */
#define TYPE_CAPTURE	0x00000001	/* Is a capture device */
#define TYPE_CODEC	0x00000002	/* Device supports hw (de)coding */
#define TYPE_FX		0x00000004	/* Is a video effects device */
	int	type;		/* Device type, see below */
	unsigned reserved0[4];
	int	maxwidth;
	int	maxheight;
	int	minwidth;
	int	minheight;
	int	maxframerate;   /* -1 if unlimited */
#define FLAG_NONE		0x00000000 /* No flags defined */
#define FLAG_DMA		0x00000001 /* Card can use DMA */
#define FLAG_EQ_DMA		0x00000002 /* Card can use DMA only if src pitch == dest pitch */
#define FLAG_UPSCALER		0x00000010 /* Card supports hw upscaling */
#define FLAG_DOWNSCALER		0x00000020 /* Card supports hw downscaling */
#define FLAG_SUBPIC		0x00001000 /* Card supports DVD subpictures */
#define FLAG_EQUALIZER		0x00002000 /* Card supports equalizer */
	unsigned flags;		/* Feature flags, see above */
	unsigned short vendor_id;
	unsigned short device_id;
	unsigned reserved1[4];
}vidix_capability_t;

#define vdxGetCapability(to) (long)trap_14_wl((short)(404),(long)(to)) 

static void myvidix_func(void);

void main(void)
{
	vidix_capability_t vidx_cap;

	if (vdxGetCapability(&vidx_cap) != 0) {
		Cconws("vidix: Get capability failed\r\n");
		return;
	}

	if ((vidx_cap.flags & (FLAG_UPSCALER|FLAG_DOWNSCALER)) != FLAG_UPSCALER|FLAG_DOWNSCALER) {
		Cconws("vidix: Need upscaler and downscaler\n");
		return;
	}

	myvidix_func();
}

static void myvidix_func(void)
{
	Cconws("Hello vidix\r\n");
}

--Multipart=_Wed__9_Jun_2010_19_48_27_+0200_3YKPt5bfZiQ1BDzD--


