Mail Archives: djgpp/1997/01/21/11:51:50
From: | korpela AT albert DOT ssl DOT berkeley DOT edu (Eric J. Korpela)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: FPU instructions in inline assembler. Error: operands given don't match any known 386 instruction
|
Date: | 21 Jan 1997 00:48:25 GMT
|
Organization: | Cal Berkeley-- Space Sciences Lab
|
Lines: | 79
|
Message-ID: | <5c13oq$6kt@agate.berkeley.edu>
|
References: | <01bc02c4$15049a40$a6cde182 AT abcblk4 DOT rci>
|
NNTP-Posting-Host: | albert.ssl.berkeley.edu
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
In article <01bc02c4$15049a40$a6cde182 AT abcblk4 DOT rci>,
Steffen Waldersdorff Løffler <waldersdorff AT forensic DOT ku DOT dk> wrote:
>#define add_asm(t1, t2, result) \
> asm volatile \
> ( "flds %1;" \
> "fadds %2;" \
> "fstps %0;" \
> : "=g" (result) \
> : "g" (t1), "g" (t2)) \
The "g" code means any register, memory or immediate operand is allowed.
This is certainly not the case for the above code. For example, what
if GCC decides to use %eax for %1. It's not possible to load directly from
in integer register to a floating point register. Your options are...
1) tell gcc that the operands are memory locations.
asm volatile
( "flds %1"
"fadds %2"
"fstps %0"
:: "m" (result), "m" (t1), "m" (t2));
2) let gcc do the loading and storing for you (t= top of stack, u=next level)
asm volatile
(
"faddp" /* leaves the result at the top of the stack */
: "=t" (result) : "u" (t1), "0" (t2));
3) The best answer is probably a combination of both, as that will compile
to the fewest instructions.... (Or so it would seem)
asm volatile
(
"fadds %2"
: "=t" (result) : "0" (t1), "m" (t2));
Good luck,
Eric
>
>void main()
>{
> float t1=2.0;
> float t2=2.0;
> float res;
>
> add_asm(t1, t2, res);
>
> printf("%f\n", res);
>}
>
>
>If it's compiled with f.ex. the -O1 or -O2 switch it will generate the
>following error:
>
>....15: Error: operands given don't match any known 386 instruction
>
>What am I doing wrong???
>
>
>Thanks!
>
>Steffen
X-Geek-Code: GAT d-(?) H s+:-- g+ p? au--- a- w++ v++(--) C+++ US+++ P- L 3
X-Geek-Cont1: E--- N++ K? W M- V -po+(--) Y+ t+ 5++ j? R- G? tv+ b++ D+ B---
X-Geek-Cont2: e+++>++++ u- h--- f+(?) r+++ n+(---) y@(?)
X-PGP-ID: FF0C92DD
X-PGP-Fingerprint: 96 BD 9D 77 12 FE 04 9B 3E F5 5B 8D 2D D1 4C 6B
--
Eric Korpela | An object at rest can never be
korpela AT ssl DOT berkeley DOT edu | stopped.
<a href="http://www.cs.indiana.edu/finger/mofo.ssl.berkeley.edu/korpela/w">
Click here for more info.</a>
- Raw text -