No, that wouldn't work. Every architecture does floating point differently. And RISC FP in particular doesn't implement the full IEEE standard, for example it doesn't support infinities and denormal numbers. The current code in the emulator isn't pretty or fast but at least it's accurate.
float *a = (float *)(&x);
And don't do that, that invokes undefined behavior. To emulate C++'s reinterpret_cast, use an union: union { uint32_t x; float f; } float_hack; float_hack.x = x; return float_hack.f; On 15-04-14 13:17, Jörg wrote:
Hi all
Indeed. The FP code in the emulator is an example of "backporting assembler to C". PdW could have taken the "normal" FP arithmetic offered by C and let the C compiler decide to generate the code. The FP format NW uses is the same as C, namely IEEE single precision.
So, PdW could have written something like: uint32_t fp_add(uint32_t x, uint32_t y, bool u, bool v); { float *a = (float *)(&x); /* aka reinterpret_cast in C++ */ float *b = (float *)(&y);
/* do whatever you want to do with the FP numbers a and b */ float sum, prod; sum = *a + *b; prod = *a * *b; ... }
Jörg
On Tue, 15 Apr 2014 14:49:22 +0200 Peter De Wachter <pdewacht@gmail.com> wrote:
No, that wouldn't work. Every architecture does floating point differently. And RISC FP in particular doesn't implement the full IEEE standard, for example it doesn't support infinities and denormal numbers. The current code in the emulator isn't pretty or fast but at least it's accurate.
I did read/hear few times that translating whole floating point IEEE standard into hardware requires at least 500 thousand transistors. Hardly a surprise that RISC Oberon uses only part of that. Every architecture right now means pretty much Intel and ARM (a little bit of MIPS also, but that can be neglected). As far I know when you're using newer x86 processor (or x86_64 for that manner) floating point numbers behave almost exactly the same, to the point where you don't need to worry about it. With ARM it is very different world. Some older SoC don't have support for floating points, some only have single precision, other aren't completely standardized. This is reflected by Linux distributions like Debian that have both armel (software floating point) and armhf (hardware floating point) ports. Yet again in C world different architecture can mean standard library. You can expect that functions can yield different results, especially when it comes to math library (libm) - rounding and so on, dependant on implementation. Correct me if I'm wrong. To not make complete offtopic out of this, I'll provide one more scrap of information. Floating point numbers are tricky, to the point where even IBM got it wrong at one point [1] - serious issues with precision related to their model. Guess this is best explanation why floating point numbers from RISC Oberon were modeled after IEEE. [1] http://en.wikipedia.org/wiki/IBM_Floating_Point_Architecture -- Paul Onyschuk
-----Original Message----- From: Paul Onyschuk [mailto:ptmelville@gmail.com] Sent: Tuesday, 15 April 2014 11:20 PM To: ETH Oberon and related systems Subject: Re: [Oberon] FP
To not make complete offtopic out of this, I'll provide one more scrap of information. Floating point numbers are tricky, to the point where even IBM got it wrong at one point [1] - serious issues with precision related to their model. Guess this is best explanation why floating point numbers from RISC Oberon were modeled after IEEE.
[1] http://en.wikipedia.org/wiki/IBM_Floating_Point_Architecture
If you want to delve even deeper read "What Every Computer Scientist Should Know About Floating-Point Arithmetic" by David Goldberg: http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html He explains some of the reasons why the IEEE format was designed the way it was in the sections following the heading "The IEEE Standard", Regards, Chris
The real question should be: do we *need* floating point numbers? And if so, do we, Oberon developers, need to confirm to old fashioned standards? A standard FP num ranges from 10^-38 to 10^38 but with just 7 of the 76 decimals significant. So FP numbers are only useful when the full set of them is within a narrow range between 'x' and 'x.10^8' Now suppose one would omit the FP number and use 64 bit integers. That would yield a range of [-10^19 .. +10^19] with 20 significant digits... Yet, at no additional cost for processing the numbers. Or, if that is not acceptable, the scaled integer could be useful: a 32 bit mantissa plus 32 bit exponent. I know this is not standard but neither is Oberon. If you are to use an 80487 then you need to supply the numbers in the correct format. If you create your own CPU you can create your own format. No IEEE required. And in software, anything goes. Yes, 30 years ago, the 24+8 format was great. On 8 bit machines. Times have changed, but the 24+8 format hasn't. For the user, it doesn't matter. (s)he will just use the type REAL. And for him/her it make no difference how we have defined the high precision number in firmware. -- Groetjes Jan Verhoeven
On 15 April 2014 14:40, Jan Verhoeven <jan@verhoeven272.nl> wrote (in part):
Times have changed, but the 24+8 format hasn't.
It has: http://en.wikipedia.org/wiki/IEEE_floating_point#Basic_formats N.
participants (5)
-
Chris Burrows -
Jan Verhoeven -
Nemo -
Paul Onyschuk -
Peter De Wachter