9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Charles Forsyth <forsyth@terzarima.net>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] fp: stack underflow error
Date: Fri,  2 Jul 2004 10:34:41 +0100	[thread overview]
Message-ID: <626179c9c80b6b82cfbaa9789a485bac@terzarima.net> (raw)
In-Reply-To: <d66164ffbf07b27c99685ea41599f1a3@vitanuova.com>

[-- Attachment #1: Type: text/plain, Size: 750 bytes --]

that produced invalid operation when i tried it,
not the stack underflow of the previous example.
the result won't fit in a signed integer, and unsigned
integer isn't supported by the hardware, so you get a trap
as documented.  in fact,
the compiler could and probably should compensate by
converting to and from 64-bit signed integers,
which would also eliminate the test-and-skip mentioned earlier.
i think 64-bit is supported, since it's listed with an opcode,
although the textual description then claims `word- or short-integer format'
only.  it's an Intel handbook.  ``beware DEC manuals''

the stack underflow is more likely to be a compiler problem.
(stack overflow on the other hand is quite likely to be a missing prototype.)

[-- Attachment #2: Type: message/rfc822, Size: 2879 bytes --]

From: rog@vitanuova.com
To: 9fans@cse.psu.edu
Subject: Re: [9fans] fp: stack underflow error
Date: Thu, 1 Jul 2004 20:24:23 +0100
Message-ID: <d66164ffbf07b27c99685ea41599f1a3@vitanuova.com>

> I encountered a "sys: fp: stack underflow" error in my program.

looks like a compiler bug.

here's a simpler version of the code that does the same thing.
who'd've thought that a2b() would generate such
convoluted code? what's that comparison for?

	TEXT	a2b+0(SB),0,$12
	MOVL	tb+4(FP),CX
	SUBL	fb+0(FP),CX
	MOVL	CX,.safe+-4(SP)
	FMOVL	.safe+-4(SP),F0
	CMPL	CX,$0
	JGE	,2(PC)
	FADDD	$(4.29496729600000000e+09),F0
	FMULD	dis+8(FP),F0
	FSTCW	,.safe+-8(SP)
	MOVW	$3967,.safe+-6(SP)
	FLDCW	.safe+-6(SP),
	FMOVLP	F0,.safe+-4(SP)
	FLDCW	.safe+-8(SP),
	MOVL	.safe+-4(SP),AX
	RET	,

#include <u.h>
#include <libc.h>
int
a2b(int fb, uint tb, double dis)
{
	return (tb - fb)*dis;
}

void
main(void)
{
	a2b(1, 0, 65);
	a2b(1, 0, 66);
}

  parent reply	other threads:[~2004-07-02  9:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-01  4:50 YAMANASHI Takeshi
2004-07-01  8:55 ` Kenji Okamoto
2004-07-01 19:24 ` rog
2004-07-01 20:32   ` Charles Forsyth
2004-07-01 20:38     ` boyd, rounin
2004-07-02  9:34   ` Charles Forsyth [this message]
2004-07-02 10:25     ` Geoff Collyer
2004-07-02 10:53       ` Charles Forsyth
2004-07-02  0:35 YAMANASHI Takeshi
2004-07-02  1:02 ` Kenji Okamoto
2004-07-02  1:04   ` Kenji Okamoto
2004-07-02  1:05     ` Kenji Okamoto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=626179c9c80b6b82cfbaa9789a485bac@terzarima.net \
    --to=forsyth@terzarima.net \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).