www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/25/19:15:45

From: George Foot <mert0407 AT sable DOT ox DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: WATCOM #pragma to DJGPP __asm__ ?!!
Date: 26 Jan 1998 00:08:50 GMT
Organization: Oxford University, England
Lines: 43
Message-ID: <6agk6i$ab8$1@news.ox.ac.uk>
References: <01bc0b04$94dfc940$6089f1c3 AT faktor21>
NNTP-Posting-Host: sable.ox.ac.uk
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On 25 Jan 1998 21:13:39 GMT in comp.os.msdos.djgpp d-range!
<d-range AT thefridge DOT et DOT fnt DOT hvu DOT nl> wrote:

: My question: how can I make inline functions like this one to work with
: DJGPP. I read the DJGPP assembler tutorial, and I know you can #define the
: function like this,

: #define FixSHR(arg1,arg2,arg3) __asm__ \
:             "sarl %1,%0" \
: 	: "=r" (arg3) \
: 	: "0" (arg1), "1" (arg2) \
: 	: "0";

Assuming the above is correct (I haven't checked it), try this:

inline Fixed FixSHR (Fixed arg1, char arg2) {
	Fixed arg3;
	__asm__ ("sarl %1,%0" : "=r" (arg3) : "0" (arg1), "1" (arg2) :
"0");
	return arg3;
}

I haven't tested this I'm afraid (no djgpp here) so there could be
errors -- in particular, I'm not sure about your use of "0", "1" in
the parameter lists (I thought you put "r", "g", etc) -- but I could
easily be wrong.

The trick here is to trust gcc's optimiser to make good code -- the
function above is explicitly requested to be inlined, and since you've
used the extended syntax the optimiser knows a great deal about how to
use the function.

Alternatively, you can make macros that do compilcated things still
return a value; e.g. (from memory):

#define weird(a,b) ({ a*=b; b })

This would multiply a by b, and the expression would take the value of
b.  Check this in the gcc info pages, though, under C extensions -- my
memory could have got the syntax wrong.

-- 
george DOT foot AT merton DOT oxford DOT ac DOT uk

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019