delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/16/21:30:27

From: "Mr R. Hopkins" <r.hopkins*@ic.ac.uk>
Newsgroups: comp.os.msdos.djgpp,comp.os.linux.misc
Subject: Floating point + inline assembly + C =?
Date: Tue, 16 Dec 1997 12:37:07 +0000
Organization: Electronic Engineering Dept. Imperial College
Lines: 48
Message-ID: <349675F3.2781E494@ic.ac.uk>
NNTP-Posting-Host: pint.ee.ic.ac.uk
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi there, I have an interesting problem:
I am trying to write a short program which has some inline asm in gcc
(either gcc on Linux or DJGPP on DOS). The problem I am having is
passing a couple of floating point variables to the __asm__ part. What
appears to happen when I use the suggested (by gcc info) method of:
__asm__ (
	" fblahblah %1 \n"
	" faddstuff %%st(2), %%st(0) \n"
	" fldd %2 \n"
	" fstd %0 \n" /* etc. etc. */
	: "=r" (output_var)
	: "f" (input1), "f" (input2)
	: "%st" /* clobbers */
);

This approach does not work, since in lines (2)and (3) above notice how
the floating point stack gets shuffled about. This causes the input
param %2 to be further down the stack than expected, and so the value
of %st which gcc inserts for param %2 is now incorrect.
As a consequence, the code produces unexpecte (an undesireable) answers.

Any suggestions about how I could implement this assembly in a way which
I know the values of %1 and %2 are correct. 
Some of my ideas:
-some fxch at the very start of the __asm__?
-an external assembly module?
-load the parameters onto the fpu stack myself?

(Note the same problem occurs both under DOS as with Linux)

Any help would be gladly received!


-- 
Hoppy

To reply please remove the * from my email address

http://www.geocities.com/CapeCanaveral/5003/
is the place to go if you ever wanted to know how to write fractal
programs or make 3D programs

_____

Polite notice to people who obtain email addresses from usenet postings
so that they can send innocent people junk mail

GO KILL YOURSELVES YOU GITS

- Raw text -


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