9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] fp: stack underflow error
@ 2004-07-02  0:35 YAMANASHI Takeshi
  2004-07-02  1:02 ` Kenji Okamoto
  0 siblings, 1 reply; 12+ messages in thread
From: YAMANASHI Takeshi @ 2004-07-02  0:35 UTC (permalink / raw)
  To: 9fans

> Probably, you see some comment in a ghostscript program
> gshtscr.c by Russ (ssearch RSC string).   Because now Russ is out.

Sorry.  I couldn't find the comment in /sys/src/cmd/gs/src/gshtscr.c.
I fetched it from sources.  Had I looked into wrong one?

If it is a compiler bug as Rog and Forsyth mentioned in other mail,
I will walk around it by using int-typed arguments for the present
and sleep soundly tonight.

Thank you,
--
Sincerely,
YAMANASHI Takeshi




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] fp: stack underflow error
  2004-07-02  0:35 [9fans] fp: stack underflow error YAMANASHI Takeshi
@ 2004-07-02  1:02 ` Kenji Okamoto
  2004-07-02  1:04   ` Kenji Okamoto
  0 siblings, 1 reply; 12+ messages in thread
From: Kenji Okamoto @ 2004-07-02  1:02 UTC (permalink / raw)
  To: 9fans

> Sorry.  I couldn't find the comment in /sys/src/cmd/gs/src/gshtscr.c.
> I fetched it from sources.  Had I looked into wrong one?

Oh, sorry, RSC was added by me.?

It was like this:

/* RSC: THIS DOES NOT WORK WITH ken 8c
	sample = (ht_sample_t) ((value + 1) * max_ht_sample);
*/
	sample = (ht_sample_t) (value * max_ht_sample);
	sample += max_ht_sample;	/* convert from signed to biased */

Kenji



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] fp: stack underflow error
  2004-07-02  1:02 ` Kenji Okamoto
@ 2004-07-02  1:04   ` Kenji Okamoto
  2004-07-02  1:05     ` Kenji Okamoto
  0 siblings, 1 reply; 12+ messages in thread
From: Kenji Okamoto @ 2004-07-02  1:04 UTC (permalink / raw)
  To: 9fans

> Oh, sorry, RSC was added by me.?

Hmm, interesting
try again

☺

Kenji



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] fp: stack underflow error
  2004-07-02  1:04   ` Kenji Okamoto
@ 2004-07-02  1:05     ` Kenji Okamoto
  0 siblings, 0 replies; 12+ messages in thread
From: Kenji Okamoto @ 2004-07-02  1:05 UTC (permalink / raw)
  To: 9fans

> ☺

Once agian,

けんじ

Kenji



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] fp: stack underflow error
  2004-07-02 10:25     ` Geoff Collyer
@ 2004-07-02 10:53       ` Charles Forsyth
  0 siblings, 0 replies; 12+ messages in thread
From: Charles Forsyth @ 2004-07-02 10:53 UTC (permalink / raw)
  To: 9fans

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

i assumed the list of opcodes and short instruction descriptions was
correct, and that indeed, being a manly lot, the floating-point implementers
who wrote that section loftily regarded 32-bits as being the bare minimum for a `word',
and included decent 64-bits within the term.  (hence the reference to `short-integer'
for the 16-bit runts.)

still, in this case i think the

8.out 708: suicide: sys: fp: stack underflow fppc=0x1118 status=0x80a1 pc=0x0000118f

is saying stack underflow only because /sys/src/9/pc/main.c isn't reading the
status correctly, unless i'm getting the bits wrong myself compared to the handbook.
i think it's `inexact result (precision error)'.  0x40 is set for stack fault;
it's checking for (status & 0x30), although perhaps
(status & 0x30) == 0 was intended, to avoid masking other faults?
the exception flags are sticky.

that would be good because i couldn't see the incorrect stacking in
the 8c code.

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

From: Geoff Collyer <geoff@collyer.net>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] fp: stack underflow error
Date: Fri, 2 Jul 2004 03:25:41 -0700
Message-ID: <bfd50da8c268dabff0270c7f2df911d0@collyer.net>

`word- or short-integer format' only can't be right, since `word' in
intel manuals means 16-bits (even in their 64-bit processor manuals, I
imagine), and 32-bit signed integers do work.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] fp: stack underflow error
  2004-07-02  9:34   ` Charles Forsyth
@ 2004-07-02 10:25     ` Geoff Collyer
  2004-07-02 10:53       ` Charles Forsyth
  0 siblings, 1 reply; 12+ messages in thread
From: Geoff Collyer @ 2004-07-02 10:25 UTC (permalink / raw)
  To: 9fans

`word- or short-integer format' only can't be right, since `word' in
intel manuals means 16-bits (even in their 64-bit processor manuals, I
imagine), and 32-bit signed integers do work.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] fp: stack underflow error
  2004-07-01 19:24 ` rog
  2004-07-01 20:32   ` Charles Forsyth
@ 2004-07-02  9:34   ` Charles Forsyth
  2004-07-02 10:25     ` Geoff Collyer
  1 sibling, 1 reply; 12+ messages in thread
From: Charles Forsyth @ 2004-07-02  9:34 UTC (permalink / raw)
  To: 9fans

[-- 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);
}

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] fp: stack underflow error
  2004-07-01 20:32   ` Charles Forsyth
@ 2004-07-01 20:38     ` boyd, rounin
  0 siblings, 0 replies; 12+ messages in thread
From: boyd, rounin @ 2004-07-01 20:38 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> to add 2^32 to adjust it.

the shifts looked like an invitation for woe.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] fp: stack underflow error
  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
  1 sibling, 1 reply; 12+ messages in thread
From: Charles Forsyth @ 2004-07-01 20:32 UTC (permalink / raw)
  To: 9fans

>>convoluted code? what's that comparison for?

getting the right answer for unsigned to double conversion.
if the integer value is negative, the conversion needs
to add 2^32 to adjust it.
i haven't looked it up but i imagine that the stcw/ldcw is to
set the control word to the right rounding mode for the conversion,
because it's in a global machine word not the instruction.
the source operand is required to be a memory location.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] fp: stack underflow error
  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-02  9:34   ` Charles Forsyth
  1 sibling, 2 replies; 12+ messages in thread
From: rog @ 2004-07-01 19:24 UTC (permalink / raw)
  To: 9fans

> 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);
}



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] fp: stack underflow error
  2004-07-01  4:50 YAMANASHI Takeshi
@ 2004-07-01  8:55 ` Kenji Okamoto
  2004-07-01 19:24 ` rog
  1 sibling, 0 replies; 12+ messages in thread
From: Kenji Okamoto @ 2004-07-01  8:55 UTC (permalink / raw)
  To: 9fans

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

Probably, you see some comment in a ghostscript program
gshtscr.c by Russ (ssearch RSC string).   Because now Russ is out.

Kenji

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

From: YAMANASHI Takeshi <uncover@beat.cc.titech.ac.jp>
To: 9fans@cse.psu.edu
Subject: [9fans] fp: stack underflow error
Date: Thu, 1 Jul 2004 13:50:35 +0900
Message-ID: <b974470c3e357a7efd16b8345fb68e94@orthanc.cc.titech.ac.jp>

I encountered a "sys: fp: stack underflow" error in my program.
When I change the uint arguments of a2b() to int, the modified program
ran successfully.  What's wrong with my program?

Thanks in advance.

++ program and acid stack trace are attached below ++

% nashi@valinore cat suflow.c
#include <u.h>
#include <libc.h>

/*{
	8c suflow.c; 8l suflow.8; ./8.out
}*/

ulong
a2b(uint fr, uint fg, uint fb, uint tr, uint tg, uint tb, double dis)
{
	uchar r, g, b;

	r = fr + (tr - fr)*dis;
	g = fg + (tg - fg)*dis;
	b = fb + (tb - fb)*dis;

	return (r<<24)+(g<<16)+(b<<8)+0xFF;
}

void
main()
{
	int i;
	ulong p;

	for(i=0; i<256; i++)
		p=a2b(0, 0, 0xFF, 00, 0xFF, 00, 2.0*i/256.0);
	exits(nil);
}



% nashi@valinore ./8.out
8.out 1167: suicide: sys: fp: stack underflow fppc=0x1118 status=0x80a1 pc=0x0000118f


% nashi@valinore acid 1167
/proc/1167/text:386 plan 9 executable

/sys/lib/acid/port
/sys/lib/acid/386
acid: stk()
At pc:0x0000118f:main+0x46 /usr/nashi/src/test/suflow.c:27
main() /usr/nashi/src/test/suflow.c:21
	called from _main+0x31 /sys/src/libc/386/main9.s:16

--

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [9fans] fp: stack underflow error
@ 2004-07-01  4:50 YAMANASHI Takeshi
  2004-07-01  8:55 ` Kenji Okamoto
  2004-07-01 19:24 ` rog
  0 siblings, 2 replies; 12+ messages in thread
From: YAMANASHI Takeshi @ 2004-07-01  4:50 UTC (permalink / raw)
  To: 9fans

I encountered a "sys: fp: stack underflow" error in my program.
When I change the uint arguments of a2b() to int, the modified program
ran successfully.  What's wrong with my program?

Thanks in advance.

++ program and acid stack trace are attached below ++

% nashi@valinore cat suflow.c
#include <u.h>
#include <libc.h>

/*{
	8c suflow.c; 8l suflow.8; ./8.out
}*/

ulong
a2b(uint fr, uint fg, uint fb, uint tr, uint tg, uint tb, double dis)
{
	uchar r, g, b;

	r = fr + (tr - fr)*dis;
	g = fg + (tg - fg)*dis;
	b = fb + (tb - fb)*dis;

	return (r<<24)+(g<<16)+(b<<8)+0xFF;
}

void
main()
{
	int i;
	ulong p;

	for(i=0; i<256; i++)
		p=a2b(0, 0, 0xFF, 00, 0xFF, 00, 2.0*i/256.0);
	exits(nil);
}



% nashi@valinore ./8.out
8.out 1167: suicide: sys: fp: stack underflow fppc=0x1118 status=0x80a1 pc=0x0000118f


% nashi@valinore acid 1167
/proc/1167/text:386 plan 9 executable

/sys/lib/acid/port
/sys/lib/acid/386
acid: stk()
At pc:0x0000118f:main+0x46 /usr/nashi/src/test/suflow.c:27
main() /usr/nashi/src/test/suflow.c:21
	called from _main+0x31 /sys/src/libc/386/main9.s:16

--




^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2004-07-02 10:53 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-02  0:35 [9fans] fp: stack underflow error YAMANASHI Takeshi
2004-07-02  1:02 ` Kenji Okamoto
2004-07-02  1:04   ` Kenji Okamoto
2004-07-02  1:05     ` Kenji Okamoto
  -- strict thread matches above, loose matches on Subject: below --
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
2004-07-02 10:25     ` Geoff Collyer
2004-07-02 10:53       ` Charles Forsyth

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).