Hi all, The dragon curve is an interesting space filling curve that you can approximate by endlessly folding a slip of paper. Apparently I'm not the only one who is fascinated by it; Don Knuth has one decorating a wall in his home: https://www.youtube.com/watch?v=v678Em6qyzk (and yes, it has a bug). When making a program to draw dragon curves of different orders for Oberon V5 (Project Oberon 2013) I noticed that odd order dragons look well and healthy but even order dragons degrade into shapeless worms (see the two screenprints on my github page for dragons of order 9 and 10). The same algorithm in BASIC and Python produces nice dragons of all orders, albeit MUCH slower that my Project Oberon version. For the source files and screenprints see: https://github.com/hansklav/Fractals-in-Oberon-07/tree/main/Dragon-curves First I suspected that a difference between Oberon's MOD operator versus BASIC's MOD and Python's % operators was the culprit, so I made a function REM to mimic them, but that had no effect. Then I pinpointed a problem in the way the Oberon V5 compiler handles an expression for certain values of its variables in my code. Please run the following two commands in Oberon V5, and behold that they unexpectedly give different results: MODULE TestDragon; (* hk 11 July 2024 *) IMPORT Math, Out; (* For Math.power see: https://github.com/hansklav/Oberon-07/blob/master/Math.Mod *) CONST pi = 3.1415926535; p = 4.0; (* order of dragon curve *) PROCEDURE Correct*; (* TestDragon.Correct *) (* correct result for x2 *) VAR h, x1, x2: REAL; s: INTEGER; BEGIN s := 0; x1 := 7.499998E-01; h := 2.500000E-01; Out.String("s = "); Out.Int(s, 2); Out.String(" h ="); Out.Real(h, 14); Out.Ln; x2 := x1 + h * Math.cos( (FLT(s) - p/2.0) * pi/2.0 ); (* <-- expression tested *) Out.String("x1 ="); Out.Real(x1, 14); Out.Ln; Out.String("x2 ="); Out.Real(x2, 14); Out.Ln; Out.Ln END Correct; PROCEDURE Incorrect*; (* TestDragon.Incorrect *) (* incorrect result for x2 *) VAR h, x1, x2: REAL; s: INTEGER; BEGIN s := 0; x1 := 7.499998E-01; h := Math.power(2.0, -p/2.0); (* the result for h from Math.power() is correct: *) Out.String("s = "); Out.Int(s, 2); Out.String(" h ="); Out.Real(h, 14); Out.Ln; x2 := x1 + h * Math.cos( (FLT(s) - p/2.0) * pi/2.0 ); (* <-- why incorrect result?? *) Out.String("x1 ="); Out.Real(x1, 14); Out.Ln; Out.String("x2 ="); Out.Real(x2, 14); Out.Ln; Out.Ln END Incorrect; END TestDragon. The first command gives the correct result (0.4999998), which can easily be verified by pasting the following line in https://www.wolframalpha.com/ : 7.499998E-01 + 2.500000E-01 * cos((0 - 4/2) * pi/2.0) But why the same expression in the second command gives a wrong result (0.6249998) for the same values of its variables as the first command escapes me. Could anyone give an explanation?? Because I cannot reproduce this incorrect behaviour using the OBNC compiler, I suspect a compiler error. Regards, Hans Klaver
Hi Jörg, Thanks for your prompt reply. On 11 July 2024 you wrote:
From the screenshots you provided I assume you are using Peter de Wachter’s emulator.
Yes, I tested (in macOS) using both Peter De Wachter's emulator and Michael Schierl's enhanced emulator (a fork of PdW's). Both give the same results. The Windows version of Michael's emulator gives these same results as well. I almost forgot that I also have the 'Oberon Workstation' emulator for macOS (version 1.3.2., implemented in Swift) by Roel de Jong, presumably the one you use. Today I used that Oberon RISC emulator for the TestDragon commands, and both commands give correct output for x2; moreover the problem with the rendering of even ordered dragons does not occur, even with the original Math.Mod (which, as you know, has a not very good implementation of Math.ln). This confirms your suspicion that a bug in the emulator and not in the compiler is the culprit. It was silly of me to mention OBNC in this context because I discovered that OBNC transpiles Oberon's REAL type to 64-bit floating point (in C), so it is not a fair comparison. You also wrote:
I think I found the error in PdW’s emulator:
The Verlog line in FPAdder.v xn ? (u|yn ? 0 : y) :
got translated in fp_add() to } else if (xn) { return (u | yn) ? 0 : y;
but should be } else if (xn) { return (u || yn) ? 0 : y;
I downloaded a fresh oberon-risc-emu-master.zip for Peter De Wachter's emulator and patched the file risc-fp.c in it (dated 18-8-2020) with your proposed solution. After building the emulator unfortunately the test commands TestDragon.Correct and TestDragon.Incorrect gave the same output as in the unpatched emulators, also when using the improved version of Math.ln. So I'm afraid your proposal is not the whole solution... Regards, Hans
Hello Hans, Am 12.07.2024 um 22:18 schrieb Hans Klaver:
From the screenshots you provided I assume you are using Peter de Wachter’s emulator.
Yes, I tested (in macOS) using both Peter De Wachter's emulator and Michael Schierl's enhanced emulator (a fork of PdW's). Both give the same results. The Windows version of Michael's emulator gives these same results as well.
Thanks for the heads-up that I did not patch my fork of Peter's emulator yet. My fix is here: <https://github.com/schierlm/oberon-risc-emu-enhanced/commit/2b18c1137eb1481de79be195135609cfd76fea3a> Latest Windows binaries (will update automatically when I push changes to github): <https://nightly.link/schierlm/oberon-risc-emu-enhanced/workflows/main/master/WindowsBinaries.zip> Latest macOS binaries (will update automatically when I push changes to github): <https://nightly.link/schierlm/oberon-risc-emu-enhanced/workflows/main/master/MacOSDiskImage.zip> Peter: If you want, I can also send a pull request with just this one commit to your upstream repo. Regards, Michael
Hi Michael, You wrote:
Thanks for the heads-up that I did not patch my fork of Peter's emulator yet.
My fix is here:
Latest Windows binaries (will update automatically when I push changes to github):
<https://nightly.link/schierlm/oberon-risc-emu-enhanced/workflows/main/master/WindowsBinaries.zip>
Latest macOS binaries (will update automatically when I push changes to github):
<https://nightly.link/schierlm/oberon-risc-emu-enhanced/workflows/main/master/MacOSDiskImage.zip>
Thank you very much for this fix, it solved the issue! Dragons of odd and even orders now are rendered as they should. Also the interesting phenomenon that even ordered dragons >= 14 were are half-sized has vanished. Regards, Hans
Hi Jörg, Thanks for this multiplication test. The outcomes are quite remarkable: PdW's emulator without patch indeed gives one wrong* and two correct answers: 1.9999998 1.0000001* 2.0000002 But Michael's patched emulator gives three wrong* answers (all around 1 instead of 2): .9999999* 1.0000000* 1.0000001* For me this last result is unexpected, because apart from the fact that the problems with the even dragon curves are gone, I also did the test that I posted on this mailing list on 8 Oct 2023 (TestRealMul.Mod) and that gave all correct results using Michael's patched emulator (and many wrong results using the unpatched emulator). I did NOT also apply the change that you suggested in file risc-fp.c. Will that make any difference? Regards, Hans On 15 July 2024, at 15:40 Jörg Straube wrote:
Below you find three different REAL multiplications. As the original Verilog files for the FPGA board had an error, PdW’s emulator had the same error as well. Without patch, the second multiplications will give a wrong result. After Michael’s patch, all three multiplications should work.
MODULE Multiplication; IMPORT Out; PROCEDURE Test*; VAR r: REAL; BEGIN r := 1.45052123; Out.RealFix( r*1.3788146, 12, 7); Out.Ln; Out.RealFix( r*1.3788147, 12, 7); Out.Ln; Out.RealFix( r*1.3788148, 12, 7); Out.Ln END Test; END Multiplication.Test
Hello Hans, Hello Jörg, Am 15.07.2024 um 22:40 schrieb Hans Klaver:
Hi Jörg,
Thanks for this multiplication test.
The outcomes are quite remarkable:
PdW's emulator without patch indeed gives one wrong* and two correct answers: 1.9999998 1.0000001* 2.0000002
But Michael's patched emulator gives three wrong* answers (all around 1 instead of 2): .9999999* 1.0000000* 1.0000001*
I get three wrong results, regardless whether I use my emulator before or after the patch. Also a very old version of my emulator from 2019 returns three wrong results. Do you still have the source of the emulator that returned two correct results? In fact, even when doing Out.RealFix( FLT(2), 12, 7); Out.Ln; Out.RealFix( FLT(7), 12, 7); Out.Ln; I get 1.0000000 .8750000 Using Out.Mod by Andreas (which directly calls into Texts.WriteRealFix), so probably that is not the culprit. Out.Real works better (in the sense that with my patch, all the values look correct). Regardless, running the same disk image in my emulator that uses "Native" floating point (on x86_64 on Windows), all expressions work, so I would blame neither the compiler nor Texts.Mod. Maybe I can find time sometimes to dig into this further - at the moment I am too tired to do so. Regards, Michael
Hi Michael & Jörg, On 15 jul. 2024, at 23:29 Michael Schierl wrote:
Am 15.07.2024 um 22:40 schrieb Hans Klaver:
Hi Jörg,
Thanks for this multiplication test.
The outcomes are quite remarkable:
PdW's emulator without patch indeed gives one wrong* and two correct answers: 1.9999998 1.0000001* 2.0000002
But Michael's patched emulator gives three wrong* answers (all around 1 instead of 2): .9999999* 1.0000000* 1.0000001*
I get three wrong results, regardless whether I use my emulator before or after the patch. Also a very old version of my emulator from 2019 returns three wrong results. Do you still have the source of the emulator that returned two correct results?
I think I do. On 20 Feb. 2020 I installed Peter De Wachter's emulator for the fist time. I used a file named oberon-risc-emu-master.zip that I downloaded that same day; its files are dated 22-1-2019.
In fact, even when doing
Out.RealFix( FLT(2), 12, 7); Out.Ln; Out.RealFix( FLT(7), 12, 7); Out.Ln;
I get 1.0000000 .8750000
Using Out.Mod by Andreas (which directly calls into Texts.WriteRealFix), so probably that is not the culprit.
I'm afraid the original Texts.WriteRealFix (also used by Andreas) indeed is the culprit for the latter problem, as indicated by me in a post on this mailing list on 14 Jan. 2023 "REAL I/O in module Texts". My proposal to fix this problem can be found in that post and on my GitHub pages https://github.com/hansklav/Oberon-REAL-IO. Actually I forgot to apply these changes in Texts.Mod (which also need my Limits.Mod and Reals.Mod) to the Oberon System disc image I used with Michael's patched emulator. Hence the three seemingly wrong results. Sorry for the confusion... I used a somewhat extended Multiplication.Mod: MODULE Multiplication; IMPORT Out; PROCEDURE Test*; VAR r: REAL; BEGIN r := 1.45052123; Out.RealFix( r*1.3788146, 14, 7); Out.Hex(ORD(r*1.3788146)); Out.Ln; Out.RealFix( r*1.3788147, 14, 7); Out.Hex(ORD(r*1.3788147)); Out.Ln; Out.RealFix( r*1.3788148, 14, 7); Out.Hex(ORD(r*1.3788148)); Out.Ln; Out.Ln; Out.Real( r*1.3788146, 14); Out.Hex(ORD(r*1.3788146)); Out.Ln; Out.Real( r*1.3788147, 14); Out.Hex(ORD(r*1.3788147)); Out.Ln; Out.Real( r*1.3788148, 14); Out.Hex(ORD(r*1.3788148)); Out.Ln; Out.Ln; Out.RealFix( FLT(2), 14, 7); Out.Hex(ORD(FLT(2))); Out.Ln; Out.RealFix( FLT(7), 14, 7); Out.Hex(ORD(FLT(7))); Out.Ln; Out.RealFix( 2.0, 14, 7); Out.Hex(ORD(2.0)); Out.Ln; Out.RealFix( 7.0, 14, 7); Out.Hex(ORD(7.0)); Out.Ln END Test; END Multiplication.Test And I got the following results with Michaels patched emulator and my own Texts.Mod. Three correct results for Jörg's lines! (the third column shows the 32-bit floating point value (to at most 9 significant digits if needed) of the hexadecimal number, as verified on https://float.exposed): 1.9999998 3FFFFFFE 1.99999976 2.0000000 40000000 2.0 2.0000002 40000001 2.00000023 2.000000E+00 3FFFFFFE 2.000000E+00 40000000 2.000000E+00 40000001 2.0000000 40000000 2.0 7.0000000 40E00000 7.0 2.0000000 40000000 2.0 7.0000000 40E00000 7.0 And as you can see the problems with Out.RealFix for 2.0 and 7.0 that Michael encountered are also gone.
Out.Real works better (in the sense that with my patch, all the values look correct).
The original Texts.WriteReal works quite OK, with a few small deficiencies (see my GitHub page).
Regardless, running the same disk image in my emulator that uses "Native" floating point (on x86_64 on Windows), all expressions work, so I would blame neither the compiler nor Texts.Mod.
This I cannot explain. Possibly the floating point output routine does not use Texts.Mod. Regards, Hans
Hi To narrow done where the culprit is, you might know that Wirth’s Oberon compiler has an undocumented feature allowing to write the REALs directly in hex IEEE 754 notation. With this feature you are absolutely sure what REAL we are talking about. I use this in numerical algorithms, where it is important to have the REAL constants correct to the ulp. CONST pi = 40490FDBR; (* pi is between 40490FDAR and 40490FDBR, closer to the latter *) Out.Real(40000001R, 12); Out.RealFix(40000001R, 12, 7) IF FLT(2) = 40000000R THEN Out.String(“FLT okay”) END; IF 3.14159265 = pi THEN Out.String(“compiler okay”) ELSE Out.String("compiler bad“) END; br Jörg
Am 16.07.2024 um 02:28 schrieb Hans Klaver <hklaver@dds.nl>:
Hi Michael & Jörg,
On 15 jul. 2024, at 23:29 Michael Schierl wrote:
Am 15.07.2024 um 22:40 schrieb Hans Klaver:
Hi Jörg,
Thanks for this multiplication test.
The outcomes are quite remarkable:
PdW's emulator without patch indeed gives one wrong* and two correct answers: 1.9999998 1.0000001* 2.0000002
But Michael's patched emulator gives three wrong* answers (all around 1 instead of 2): .9999999* 1.0000000* 1.0000001*
I get three wrong results, regardless whether I use my emulator before or after the patch. Also a very old version of my emulator from 2019 returns three wrong results. Do you still have the source of the emulator that returned two correct results?
I think I do. On 20 Feb. 2020 I installed Peter De Wachter's emulator for the fist time. I used a file named oberon-risc-emu-master.zip that I downloaded that same day; its files are dated 22-1-2019.
In fact, even when doing
Out.RealFix( FLT(2), 12, 7); Out.Ln; Out.RealFix( FLT(7), 12, 7); Out.Ln;
I get 1.0000000 .8750000
Using Out.Mod by Andreas (which directly calls into Texts.WriteRealFix), so probably that is not the culprit.
I'm afraid the original Texts.WriteRealFix (also used by Andreas) indeed is the culprit for the latter problem, as indicated by me in a post on this mailing list on 14 Jan. 2023 "REAL I/O in module Texts". My proposal to fix this problem can be found in that post and on my GitHub pages https://github.com/hansklav/Oberon-REAL-IO.
Actually I forgot to apply these changes in Texts.Mod (which also need my Limits.Mod and Reals.Mod) to the Oberon System disc image I used with Michael's patched emulator. Hence the three seemingly wrong results. Sorry for the confusion...
I used a somewhat extended Multiplication.Mod:
MODULE Multiplication; IMPORT Out;
PROCEDURE Test*; VAR r: REAL; BEGIN r := 1.45052123; Out.RealFix( r*1.3788146, 14, 7); Out.Hex(ORD(r*1.3788146)); Out.Ln; Out.RealFix( r*1.3788147, 14, 7); Out.Hex(ORD(r*1.3788147)); Out.Ln; Out.RealFix( r*1.3788148, 14, 7); Out.Hex(ORD(r*1.3788148)); Out.Ln; Out.Ln; Out.Real( r*1.3788146, 14); Out.Hex(ORD(r*1.3788146)); Out.Ln; Out.Real( r*1.3788147, 14); Out.Hex(ORD(r*1.3788147)); Out.Ln; Out.Real( r*1.3788148, 14); Out.Hex(ORD(r*1.3788148)); Out.Ln; Out.Ln; Out.RealFix( FLT(2), 14, 7); Out.Hex(ORD(FLT(2))); Out.Ln; Out.RealFix( FLT(7), 14, 7); Out.Hex(ORD(FLT(7))); Out.Ln; Out.RealFix( 2.0, 14, 7); Out.Hex(ORD(2.0)); Out.Ln; Out.RealFix( 7.0, 14, 7); Out.Hex(ORD(7.0)); Out.Ln END Test;
END Multiplication.Test
And I got the following results with Michaels patched emulator and my own Texts.Mod. Three correct results for Jörg's lines! (the third column shows the 32-bit floating point value (to at most 9 significant digits if needed) of the hexadecimal number, as verified on https://float.exposed):
1.9999998 3FFFFFFE 1.99999976 2.0000000 40000000 2.0 2.0000002 40000001 2.00000023
2.000000E+00 3FFFFFFE 2.000000E+00 40000000 2.000000E+00 40000001
2.0000000 40000000 2.0 7.0000000 40E00000 7.0 2.0000000 40000000 2.0 7.0000000 40E00000 7.0
And as you can see the problems with Out.RealFix for 2.0 and 7.0 that Michael encountered are also gone.
Out.Real works better (in the sense that with my patch, all the values look correct).
The original Texts.WriteReal works quite OK, with a few small deficiencies (see my GitHub page).
Regardless, running the same disk image in my emulator that uses "Native" floating point (on x86_64 on Windows), all expressions work, so I would blame neither the compiler nor Texts.Mod.
This I cannot explain. Possibly the floating point output routine does not use Texts.Mod.
Regards,
Hans
On 16 July 2024, at 08:14 Jörg Straube wrote:
To narrow done where the culprit is, you might know that Wirth’s Oberon compiler has an undocumented feature allowing to write the REALs directly in hex IEEE 754 notation. With this feature you are absolutely sure what REAL we are talking about. I use this in numerical algorithms, where it is important to have the REAL constants correct to the ulp.
CONST pi = 40490FDBR; (* pi is between 40490FDAR and 40490FDBR, closer to the latter *) Out.Real(40000001R, 12); Out.RealFix(40000001R, 12, 7) IF FLT(2) = 40000000R THEN Out.String("FLT okay") END; IF 3.14159265 = pi THEN Out.String(“compiler okay”) ELSE Out.String("compiler bad") END;
That's a handy feature indeed, especially when testing FLT, ORD or constants. Testing with the line: IF FLT(2) = 40000000R THEN Out.String("FLT okay") END; and getting the result "FLT okay" in an emulator without your proposed patch to fp.add() in risc-fp.c I conclude that that patch is not necessary. Is that a sound conclusion? Regards, Hans
Hello, Am 16.07.2024 um 02:28 schrieb Hans Klaver:
On 15 jul. 2024, at 23:29 Michael Schierl wrote:
Am 15.07.2024 um 22:40 schrieb Hans Klaver:
Regardless, running the same disk image in my emulator that uses "Native" floating point (on x86_64 on Windows), all expressions work, so I would blame neither the compiler nor Texts.Mod.
This I cannot explain. Possibly the floating point output routine does not use Texts.Mod.
Rather, Texts.Mod is not completely broken. I traced both emulators side by side (only the floating point ops), and the only places where both return different results is for fp_add, when the v flag is set (i.e. when running a FLOOR instruction). New test case: Out.Int(FLOOR(2.0E7), 11); Returns 10000000 with Peter's emulator, and 20000000 with mine. I am not sure what range the FLOOR function is supposed to work in. While 20000000 is well within the range of integer numbers, it is larger than 16777217, which is the smallest integer number that cannot be represented exactly as a 32-bit float. Its floating point representation's binary exponent is 151, and the algorithm only works up to binary exponent 150. I hacked up a small workaround that is easy in emulation but probably hard in verilog (as it uses a loop). Obviously, if your floating point number is larger than what fits into an integer, garbage is still returned. Pushed to my fork: <https://github.com/schierlm/oberon-risc-emu-enhanced/commit/02ca0a1d51f43bb08f64336d011f5970111ecac0> Another option is to ask for fewer digits, so that the expected printed number without the decimal point is smaller than 16777216, i.e. for 7 digit precision the number must be smaller than 1.6777216. Or use a different implementation of Texts.Mod, as you did. Regards, Michael
(...) I am not sure what range the FLOOR function is supposed to work in.
(...) the same question can be asked for FLT(n). The limits of FLOOR and FLT are not described in the Oberon report, as it is implementation dependent. Even the number of bytes of an INTEGER is not defined in Oberon; however, you can detect the implementation limit with SYSTEM.SIZE(INTEGER). Only BYTE is defined in Oberon to hold values from 0..255.
The Verilog implementation of FLT(n) works for n < 2^24. So, for all INTEGER n > 2^24, FLT returns wrong results.
That functions like FLOOR and FLT have some upper and lower limits should not come as a surprise. But it is unfortunate that even experienced programmers have trouble finding them. That Wirth dropped the MAX() standard function is understandable, because not all limits are known to the compiler. But I really think we need some standard way how to find out these limits. My proposal would be to put them all in a module like Limits.Mod and give them standard names. But of course this is a different problem than the deficiencies of Texts.WriteRealFix and Texts.Scan. Regards, Hans
But I really think we need some standard way how to find out these limits. My proposal would be to put them all in a module like Limits.Mod and give them standard names.
Hans, this is a known dragon raising its ugly head again. Oberon System needs parametrizing. Your proposed Limits.Mod is only a part of it. I proposed SysDef.Mod defining the memory size, memory locations, stack, etc. These are all constants, but these are constants that must be changed when porting to a new board. For example, the 1 MB size of the memory was imposed by a particular board which was popular 10 years ago. The location and size of graphics RAM followed from this limitation. Then the peripheral addresses were defined one after another, which was sufficient only because their implementations were very simple. This again was due to hardware limitation. FPGA was 94% full and nothing else would fit. All these design decisions were hardwired all over the code without any central definition. It almost looks as if Oberon System programmers are fond of repeatedly typing hex numbers in every possible place. This makes their software genuinely non portable. The first step towards portability would be parametrizing all these numbers so they can be managed in one central location. Wirth himself made this point in his textbooks, and then nobody followed, including himself. I am attaching my proposition from 4 years ago. It was shot down using arguments whose logic I could not follow. Like for example, it would take too long to recompile the OS if this file is modified. (Recompiling the whole OS takes ~3 seconds under Michael's emulator, and this was "too long".) Also, this file can be divided into a few smaller files (RegDef.Mod, MemDef.Mod, etc). This obvious idea was ignored by the key developers. So I am not optimistic that this community will ever adopt your Limits.Mod. Your idea is both great and obvious, and therefore it is very likely to be swept under the rug. Wojtek
Hi Jörg, I would favour the "dynamic HW" approach of implementing limits (as far as possible), and where not possible the "more dynamic approach" using exported (read-only) variables.
MAXFLT := S.GET(-4); MAXFLOOR := S.GET(-4)
Surely you meant to write: S.GET(-4, MAXFLT); S.GET(-4, MAXFLOOR) And I would prefer maxFLT and maxFLOOR in stead of MAXFLT and MAXFLOOR, for two reasons: 1. It is a long standing tradition in Oberon to reserve all capitals for keywords and predeclared identifiers (with the exception of unexported constants or variables of one or a few letters). 2. I find FP.maxFLT and FP.maxFLOOR slightly better readable than FP.MAXFLT and FP.MAXFLOOR. The same goes for maxINT, maxREAL, maxSET and others. Regards, Hans
Joerg, thank you for the comment. I want to make it clear that I am not proposing a *single file*, but rather a *single place* to define constants. The place may consist of several files (MemDef, RegDef, AsciiDef, etc). The point is the following. If I am working on porting the OS to the new board, I want to make changes in *one place*. For example, if I am adding more memory, then I want to modify one file (let it be MemDef.Mod). I want to know that no other spots are hiding in some module(s), where the memory layout is affected and may become inconsistent. The memory is an obvious thing, is it not? How about peripherals? In how many places are these addresses written into the code? It should be one place. But it is not. I found these numbers written verbatim in several places. Now imagine that I want to remap the OS peripherals. I have to go over many files and change "-48" to "some other number". What happens if I overlook one such spot? A crash will happen. This is not a robust way of writing software. Are you saying that it is? There are other obscure and undocumented constants. In my opinion these should not be undocumented. They should be named, exposed, and commented in full. Four years ago I went over the entire Extended Oberon and I collected all these constants which I found in all these modules. I documented whatever I could in the SysDef.Mod.odc. I used BlackBox editor because I could fold these findings in the files itself. It is attached to this e-mail. The documentation portion starts after "END SysDef." It is unfolded in the attached file. The PDF is for those who do not have BlackBox installed. I bumped the version control of this file to July/18/2024 for reference. However, this file dates back to four years ago. Wojtek ________________________________________ From: Jörg Straube [joerg.straube@iaeth.ch] Sent: Wednesday, July 17, 2024 10:08 AM To: Skulski, Wojciech; ETH Oberon and related systems Cc: pdewacht@gmail.com Subject: AW: [EXT] Re: [Oberon] Fighting a dragon ... Wojtek The idea is good but the way you propose is not. Let’s look at the SW side first: Please understand that Oberon is a programming language allowing separate compilation. Your SysDef module is NOT just an include file like in C or assembler. The complier allocates an own module key to it. Let’s assume we do as you propose. And let’s assume the FPGA gets more memory. You have to change your constant MEMLIM and hence have to recompile SysDef. All modules importing SysDef have to be recompiled, although not necessarily needed. Eg FSOffset (FS for Filesystem) or REG12 have nothing to do with the memory. Two alternative approaches: * Split up this one monolithic SysDef.Mod in separate, logically independent modules: Eg all register constants (REG15, REG14 …) in a file def.RISC5.Mod or def.CPU.Mod. The logical register names (MT, SB SP..) in a File def.Compiler.Mod, as the complier (basically ORG.Mod) defines how RISC registers are used in Oberon. The constant FSoffset (FS = file system, has nothing to do with STACKORG) is currently used by BootLoader and Kernel and in the future perhaps by some disk inspection tool that does not want to use Kernel. This could be in an own def.Boot.Mod or def.SDCard.Mod. But it is debatable if you need an own module for one constant. * Complimentary to the above: Each module exports variables where it exposes its implementation choices. Eg Kernel defines where the heap is and allocates memory from the heap. So, it appears logical that Kernel exports its implementation choices, how Oberon organizes its heap. Actually, it does it already: your constant STACKSIZE is basically Kernel.stackSize, your constant HEAPORG is basically Kernel.heapOrg. If you have more memory, Kernel.Mod decides if and how it wants to use it, you change the IMPLEMENTATION of Kernel (NOT exported constants impacting the module key) and the rest of the system is untouched and benefits of more memory without recompiling everything as with your approach. The module Modules.Mod handles the loading of modules, so decides on ModAllocAdr, MTOrg and so forth. A lot of your “constants” are actually not needed as you can find them via MEMLIM := SYSTEM.GET(MemLimAdr); or MEMLIM := Kernel.MemLim MTOrg := SYSTEM.GET(ModRootAdr); or MTOrg := Modules.MTOrg I understand that the concept of abstraction and separate compilation brings the drawback of several files and not ONE file as you might like. Kernel.Mod decides on heap allocation, Modules.Mod on module allocation, FileDir.Mod on file allocation, Display on display memory etc. Every implementation decides independently on how it organizes its HW resources and exports its decisions to the rest of the system either via constants or more flexibly as variables or procedures. Now to the HW point of view: I agree that some of the issues you address are not solved: How does the Bootloader know, that he can set the stack pointer to 80000H? It apparently assumes that it has at least 512kB (=80000H) of memory. These bootstrapping issues should not be solved with SysDef nor with my approaches explained above. These issues should be solved with “dynamic HW”: I mean the SW should be able to ask HW capabilities. E.g “How much memory do we have installed”? “What’s the address and size of the video frame buffer?” These “constants” burnt in HW may well be at one place if you like. In the Project Oberon environment, RISC5Top.v is most probably the best place for this. One idea how the SW can “talk” to the HW is to use the last possible IO port (-4) for this. Something like this System.PUT (-4, 0); (* 0 = get info on all devices *) len := System.GET(-4); IF len = 0 THEN (* HW does not support device enumeration *) ELSE FOR i := 1 TO len DO dev[i] := System.GET(-4) END; (* this lists all devices in the system: memory, IO Ports, graphics… *) END; System.PUT (-4, dev[3]); (* Example: get info on device with number dev[3] *) ch := System.GET(-4); IF ch = 0X THEN (* HW does not support device info *) ELSE i := 0; REPEAT driver[i] := ch; INC(i) ch := SYSTEM.GET(-4) UNTIL ch = 0X; (* max 32 chars *) Modules.Load(driver, D); P := Modules.ThisCommand(D, “Init”); P; (* initializes the driver and reads the rest of the HW info of this device *) END; The HW first returns the name of the device driver of the specific device. Then, the device driver is loaded and gets the remaining device info. Such a scheme is not implemented yet. br Jörg Am 17.07.24, 12:17 schrieb "Skulski, Wojciech" <skulski@pas.rochester.edu>:
But I really think we need some standard way how to find out these limits. My proposal would be to put them all in a module like Limits.Mod and give them standard names.
Hans, this is a known dragon raising its ugly head again. Oberon System needs parametrizing. Your proposed Limits.Mod is only a part of it. I proposed SysDef.Mod defining the memory size, memory locations, stack, etc. These are all constants, but these are constants that must be changed when porting to a new board. For example, the 1 MB size of the memory was imposed by a particular board which was popular 10 years ago. The location and size of graphics RAM followed from this limitation. Then the peripheral addresses were defined one after another, which was sufficient only because their implementations were very simple. This again was due to hardware limitation. FPGA was 94% full and nothing else would fit. All these design decisions were hardwired all over the code without any central definition. It almost looks as if Oberon System programmers are fond of repeatedly typing hex numbers in every possible place. This makes their software genuinely non portable. The first step towards portability would be parametrizing all these numbers so they can be managed in one central location. Wirth himself made this point in his textbooks, and then nobody followed, including himself. I am attaching my proposition from 4 years ago. It was shot down using arguments whose logic I could not follow. Like for example, it would take too long to recompile the OS if this file is modified. (Recompiling the whole OS takes ~3 seconds under Michael's emulator, and this was "too long".) Also, this file can be divided into a few smaller files (RegDef.Mod, MemDef.Mod, etc). This obvious idea was ignored by the key developers. So I am not optimistic that this community will ever adopt your Limits.Mod. Your idea is both great and obvious, and therefore it is very likely to be swept under the rug. Wojtek
Hello,
The limits of FLOOR and FLT are not described in the Oberon report, as it is implementation dependent. Even the number of bytes of an INTEGER is not defined in Oberon; however, you can detect the implementation limit with SYSTEM.SIZE(INTEGER). Only BYTE is defined in Oberon to hold values from 0..255.
That functions like FLOOR and FLT have some upper and lower limits should not come as a surprise. But it is unfortunate that even experienced programmers have trouble finding them.
To me it was a bit of a surprise. Even the language which is infamous for its "nasal deamons" (C) has a clear specification for this. <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf>, chapter 6.3.1.4 about conversions:
6.3.1.4 Real floating and integer
1. When a finite value of real floating type is converted to an integer type other than _Bool, the fractional part is discarded (i.e., the value is truncated toward zero). If the value of the integral part cannot be represented by the integer type, the behavior is undefined.[50])
2. When a value of integer type is converted to a real floating type, if the value being converted can be represented exactly in the new type, it is unchanged. If the value being converted is in the range of values that can be represented but cannot be represented exactly, the result is either the nearest higher or nearest lower representable value, chosen in an implementation-defined manner. If the value being converted is outside the range of values that can be represented, the behavior is undefined.
[50] The remaindering operation performed when a value of integer type is converted to unsigned type need not be performed when a value of real floating type is converted to unsigned type. Thus, the range of portable real floating values is (−1, Utype_MAX+1).
Anyway, good to know that Oberon has implementation-specific limits here. The one use of FLT in ORS.Mod (only single digit) is safe - the other calls in Math.Mod and Texts.Mod (as well as the FLOOR calls) probably need to be examined, as they do not looks safe for me at first inspection. Regards, Michael
Hello Hans, Am 11.07.2024 um 18:40 schrieb Hans Klaver:
PROCEDURE Correct*; (* TestDragon.Correct *) (* correct result for x2 *) VAR h, x1, x2: REAL; s: INTEGER; BEGIN s := 0; x1 := 7.499998E-01; h := 2.500000E-01; Out.String("s = "); Out.Int(s, 2); Out.String(" h ="); Out.Real(h, 14); Out.Ln; x2 := x1 + h * Math.cos( (FLT(s) - p/2.0) * pi/2.0 ); (* <-- expression tested *) Out.String("x1 ="); Out.Real(x1, 14); Out.Ln; Out.String("x2 ="); Out.Real(x2, 14); Out.Ln; Out.Ln END Correct;
PROCEDURE Incorrect*; (* TestDragon.Incorrect *) (* incorrect result for x2 *) VAR h, x1, x2: REAL; s: INTEGER; BEGIN s := 0; x1 := 7.499998E-01; h := Math.power(2.0, -p/2.0); (* the result for h from Math.power() is correct: *) Out.String("s = "); Out.Int(s, 2); Out.String(" h ="); Out.Real(h, 14); Out.Ln; x2 := x1 + h * Math.cos( (FLT(s) - p/2.0) * pi/2.0 ); (* <-- why incorrect result?? *) Out.String("x1 ="); Out.Real(x1, 14); Out.Ln; Out.String("x2 ="); Out.Real(x2, 14); Out.Ln; Out.Ln END Incorrect;
If you use Andreas' Out.Mod, you can see with Out.RealHex(h) what is different. The "Correct" value is 3E80000H, while the "Incorrect" value is slightly different. In Peter's floating point implementation, it is 3E7FFFFEH, while in mine (that piggybacks on my processor's native float implementation) it is 3E7FFFFDH. Regardless which value, due to a bug in Peter's floating point implementation, that different value ripples through the multiplication. The value of the multiplication before adding x1 (I called it x3) is x3 = -1.250000E-01 BE000000H in both Correct and Incorrect case for my floating point implementation, while it is x3 = -2.500000E-01 BE7FFFFDH so almost double the value for the Incorrect case in Peter's implementation. As the second factor is the same in both expressions, the issue lies in the multiplication. When at that point, I had a déjà-vu. A thread on this list started by you in October 2023 ("Wrong results of selected REAL multiplications") exactly discussed this issue. Did you fix that issue in your emulator/board? Regards, Michael
participants (4)
-
Hans Klaver -
Jörg Straube -
Michael Schierl -
Skulski, Wojciech