Hi all, Back in 1982 when trying to understand the ZX81 (Z80 based personal computer) I ran into the Floating point routines. At first it was a bit difficult to understand, but after a few hours it became clear: An FPnum consisted of three machine words for the mantissa and one machine word for the exponent. It nicely fitted inside a Z80 QuadWord. Our latest 2014 FPGA processor (and hence the emulator) uses 1/4 machineword for the exponent and 3/4 machineword for the mantissa. Why don't we use one 32-bit integer for the exponent and one 32 bit word for the mantissa? It would make things so much more easier. And faster. Now each FPnum must be shifted, masked, shifted back, remasked, etc. All of it is unnecessary. It is a tribute to the ZX81 Basic. We could even go one step beyond! Define an FPnum as 32 bits exponent and 64 bit mantissa. This results in a 1 billion digit exponent (10^10^9) and an 18 digit mantissa. -- Groetjes Jan Verhoeven
Hi, my 2cts: This sounds like best thinking for the emulator, but it makes a difference for the FPGA, where it is like it's with most embedded systems: "size matters". That was done to keep memory requirements low (well, even lower). Thanks, Holger On 15/04/14 10:33, Jan Verhoeven wrote:
Hi all,
Back in 1982 when trying to understand the ZX81 (Z80 based personal computer) I ran into the Floating point routines. At first it was a bit difficult to understand, but after a few hours it became clear:
An FPnum consisted of three machine words for the mantissa and one machine word for the exponent. It nicely fitted inside a Z80 QuadWord.
Our latest 2014 FPGA processor (and hence the emulator) uses 1/4 machineword for the exponent and 3/4 machineword for the mantissa.
Why don't we use one 32-bit integer for the exponent and one 32 bit word for the mantissa? It would make things so much more easier. And faster. Now each FPnum must be shifted, masked, shifted back, remasked, etc. All of it is unnecessary. It is a tribute to the ZX81 Basic.
We could even go one step beyond! Define an FPnum as 32 bits exponent and 64 bit mantissa. This results in a 1 billion digit exponent (10^10^9) and an 18 digit mantissa.
Holger Goetz wrote:
Hi,
my 2cts:
Appreciated!
This sounds like best thinking for the emulator, but it makes a difference for the FPGA, where it is like it's with most embedded systems: "size matters". That was done to keep memory requirements low (well, even lower).
We are talking about an FPGA board with 1.000.000 bytes of RAM. Not a PIC32 SBC with 256 bytewide registers. Or a ZX81 with a whopping 1024 bytes of 250 ns SRAM. And the extra cost is just one 32 bit word.... And, let's face it, who ever needs floating point numbers when you can use scaled integers? NW says: make it as simple as possible. An FPnum format consisting of 1/4 word exponent and 3/4 word mantissa is *not* simple. We should act on his words and improve this, now that things are still in the infant phase. Have you seen the FP routines in the emulator? It's complex math. And it's unnecessary. -- Groetjes Jan Verhoeven
Hi, can happily agree to these of your statements ;-) Was just like the first best idea of why it was done that way - it's left to Others to answer then... Thanks, Holger On 15/04/14 10:56, Jan Verhoeven wrote:
NW says: make it as simple as possible. An FPnum format consisting of 1/4 word exponent and 3/4 word mantissa is *not* simple. We should act on his words and improve this, now that things are still in the infant phase.
Have you seen the FP routines in the emulator? It's complex math. And it's unnecessary.
Hi all The international form how FP numbers look like is defined by IEEE. Sometimes it's easier to take standards instead of inventing everything anew: http://en.wikipedia.org/wiki/IEEE_754-2008 Jörg -----Original Message----- From: Holger Goetz [mailto:holgerg@hgsys.de] Sent: Dienstag, 15. April 2014 11:23 To: ETH Oberon and related systems Subject: Re: [Oberon] FP Hi, can happily agree to these of your statements ;-) Was just like the first best idea of why it was done that way - it's left to Others to answer then... Thanks, Holger On 15/04/14 10:56, Jan Verhoeven wrote:
NW says: make it as simple as possible. An FPnum format consisting of 1/4 word exponent and 3/4 word mantissa is *not* simple. We should act on his words and improve this, now that things are still in the infant phase.
Have you seen the FP routines in the emulator? It's complex math. And it's unnecessary.
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
On Tue, 15 Apr 2014 10:33:08 +0200 Jan Verhoeven <jan@verhoeven272.nl> wrote:
Our latest 2014 FPGA processor (and hence the emulator) uses 1/4 machineword for the exponent and 3/4 machineword for the mantissa.
One of the reasons behind it is distribution of numbers: you want more precision as you get closer to 0. I didn't look close at part of Project Oberon describing construction of computer yet, but I guess that REAL is single precision floating point number. Most standard implementations of float do exactly what you described. I would welcome double point precision float numbers in Oberon instead, but mantissa:exponent size ratio in standard implementations is far from 1:1. Double according to IEEE uses 53-bit mantissa and 11-bit exponent. This representation is well recognized and studied - you can find information about numerical analysis of those numbers easily, which isn't true for what you propose. There is book written by Randall Hyde called "Art of Assembly", which has wonderful section which describes data representation, including floating point numbers (nice diagrams and such). It is available for free in HTML form [1]. [1] http://goo.gl/PdOQlx -- Paul Onyschuk
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 -----Original Message----- From: Paul Onyschuk [mailto:ptmelville@gmail.com] Sent: Dienstag, 15. April 2014 11:33 To: ETH Oberon and related systems Subject: Re: [Oberon] FP On Tue, 15 Apr 2014 10:33:08 +0200 Jan Verhoeven <jan@verhoeven272.nl> wrote:
Our latest 2014 FPGA processor (and hence the emulator) uses 1/4 machineword for the exponent and 3/4 machineword for the mantissa.
One of the reasons behind it is distribution of numbers: you want more precision as you get closer to 0. I didn't look close at part of Project Oberon describing construction of computer yet, but I guess that REAL is single precision floating point number. Most standard implementations of float do exactly what you described. I would welcome double point precision float numbers in Oberon instead, but mantissa:exponent size ratio in standard implementations is far from 1:1. Double according to IEEE uses 53-bit mantissa and 11-bit exponent. This representation is well recognized and studied - you can find information about numerical analysis of those numbers easily, which isn't true for what you propose. There is book written by Randall Hyde called "Art of Assembly", which has wonderful section which describes data representation, including floating point numbers (nice diagrams and such). It is available for free in HTML form [1]. [1] http://goo.gl/PdOQlx -- Paul Onyschuk -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
participants (4)
-
Holger Goetz -
Jan Verhoeven -
Jörg -
Paul Onyschuk