🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #53261

using gcc with dbm on sparc

#53261
From: Alexander Dupuy
Date: Sat, 22 Feb 1992 01:20
78 lines
2459 bytes
I thought about this a bit more last night, and with some more magic assembler
cookies, it is also possible to create gcc-compiled routines which can return
aggregates to either Sun-compiled or gcc-compiled code.

Here are the macros - one using two asm() calls, and another which eliminates a
NOP instruction (using the branch annul bit) for those people who can't waste
a single instruction cycle :-)  You should place a call to either one at the
beginning of the function; it should be called at least once before any return
statements are executed.  It takes a single argument, just like sizeof, which
should be of the aggregate type being returned.

#ifdef __sparc__
#ifdef __GNUC__
#define _ret_struct(type) \
	{ \
		int instruction; \
	  \
		__asm ("ld [%%i7+8],%0" : "=r" (instruction)); \
		if (instruction == (sizeof (type) & 0xfff)) \
			__asm ("add %i7,4,%i7"); \
	}
#else
#define _ret_struct(type) 
#endif
#else
#define _ret_struct(type)
#endif

#ifdef __sparc__
#ifdef __GNUC__
#define _ret_struct_no_nop(type) \
	{ __asm ("ld [%%i7+8],%%o0;cmp %%o0,%0;be,a 0f;add %%i7,4,%%i7;0:" \
		 : : "i" (sizeof (type) & 0xfff) : "%o0"); }
#else
#define _ret_struct_no_nop(type) 
#endif
#else
#define _ret_struct_no_nop(type)
#endif

struct small {
	int a,b;
};


struct large {
	int a[64];
};

struct small return_s ()
{
	struct small s;

	_ret_struct (s);

	s.a = 0xaa;
	s.b = 0xbb;

	return (s);
}

struct large return_l ()
{
	struct large l;

	_ret_struct_no_nop (l);

	l.a[0] = 0xaa00;
	l.a[63] = 0xaa63;

	return (l);
}

@alex
--
--
inet: dupuy@cs.columbia.edu
Member of the League for Programming Freedom -- write to league@prep.ai.mit.edu
Technical Details
Message-ID: <DUPUY.92Feb21202028@tiemann.cs.columbia.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!cs.columbia.edu!dupuy
References: <9202211012.AA04986@news.cis.ohio-state.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,f46ad052c9d8235c
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1992-02-21 22:49:57 PST
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!cs.columbia.edu!dupuy
From: dupuy@cs.columbia.edu (Alexander Dupuy)
Subject: using gcc with dbm on sparc
Message-ID: <DUPUY.92Feb21202028@tiemann.cs.columbia.edu>
Sender: news@cs.columbia.edu (The Daily News)
Nntp-Posting-Host: tiemann.cs.columbia.edu
Reply-To: dupuy@cs.columbia.edu
Organization: Columbia University Computer Science Department
References: <9202211012.AA04986@news.cis.ohio-state.edu>
Distribution: gnu
Date: Sat, 22 Feb 1992 01:20:28 GMT