[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MiNT] Optimisation bug in gcc 4 ?



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.

-- 
Patrice Mandin
WWW: http://pmandin.atari.org/
Programmeur Linux, Atari
Spécialité: Développement, jeux

"who writes the code, decides"
#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");
}