9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@9fans.net
Subject: Re: [9fans] emulated fp on arm
Date: Tue, 29 Jan 2013 17:44:16 -0500	[thread overview]
Message-ID: <d1329b9babc534669c4b183f34394a01@kw.quanstro.net> (raw)
In-Reply-To: <87c109280f2fc2bdaa0c68867f849daf@hamnavoe.com>

On Tue Jan 29 17:12:15 EST 2013, 9fans@hamnavoe.com wrote:
> > i'm not a fp expert, but i think there are two problems here.  first
> > it is bad form to generate -0 in the emulator, even if it is technically
> > correct, and second, -0 is defined to be equal to 0 by the spec, so
> > -0 == 0 should always be true.
>
> I think you're right on the second point (I haven't read the IEEE spec
> lately, just looked at wikipedia), and wrong on the first.  IEEE fp
> definitely allows for positive and negative zero, so the emulator should
> be generating them when the spec calls for them to do so.

you might be right about the first point, but i'm really having a hard
time sorting this out. i don't have the standard, and it's $85.
this wiki page says there are some rules funny rules for addition/subtraction:
http://en.wikipedia.org/wiki/Signed_zero#Arithmetic

here's what i have with the as-is fpi

; for(i in ocilla ladd kw)cpu -h $i -c /tmp/awktest
Xeon 	-1 + 1 = 0 cmp 0 ok; cmp -0 ok
	1 + -1 = 0 cmp 0 ok; cmp -0 ok
Atom 	-1 + 1 = 0 cmp 0 ok; cmp -0 ok
	1 + -1 = 0 cmp 0 ok; cmp -0 ok
ARM 	-1 + 1 = -0 cmp 0 fail; cmp -0 fail
	1 + -1 = 0 cmp 0 ok; cmp -0 ok
; and gcc/amd64 + gawk
	-1 + 1 = 0 cmp 0 ok; cmp -0 ok

if you tell gawk you've got -0, it ignores the sign.
in the c world, i couldn't get the same behavior
no matter what i set the rounding mode to.
(the instruction used is ADDSD.)

> I hope we will soon be emulating vfp floating point instead of the old
> arm7500 architecture.

yes!

the fpi guts are independent of the emulation on top, aren't they?
i haven't looked too carefully at the inteface.

- erik

---
; gcc -c -ggdb -Iplan9/include  wierd.c	# no optimization
; 9l wierd.o
; ./a.out
0000	0	0.000000
0800	0	0.000000
0400	0	0.000000
0c00	0	0.000000
; cat wierd.c
#include <u.h>
#include <libc.h>
#include <stdio.h>
#include <fenv.h>

int tab[] = {
	FE_TONEAREST,
	FE_DOWNWARD,
	FE_UPWARD,
	FE_TOWARDZERO,
};

void
main(void)
{
	int i;
	double d;

	for(i = 0; i < nelem(tab); i++){
		if(fesetround(tab[i]) != 0)
			print("can't set mode %d\n", i);

		d = -1.;
		d += 1.;

		print("%.4ux	%g	%f\n", fegetround(), d, d );
	}

	exits("");
}



  reply	other threads:[~2013-01-29 22:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-28 17:08 erik quanstrom
2013-01-28 17:10 ` erik quanstrom
2013-01-29 22:10 ` Richard Miller
2013-01-29 22:44   ` erik quanstrom [this message]
2013-01-30 10:35     ` Richard Miller
2013-01-30 22:18     ` Bakul Shah
2013-01-31  3:50       ` erik quanstrom

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=d1329b9babc534669c4b183f34394a01@kw.quanstro.net \
    --to=quanstro@quanstro.net \
    --cc=9fans@9fans.net \
    /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).