31 December 2022, 21:20 | #41 | |
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,178
|
@Bruce Abbot
Quote:
Damn, you reminded me how much I disliked actually implementing the assembler for MC64K and it is terrible (basic AF, incomplete feature set, bugs galore, etc.) Last edited by Karlos; 31 December 2022 at 21:27. |
|
02 January 2023, 19:01 | #42 |
Registered User
Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 2,590
|
So I installed the latest vasmm68k_mot_aos68000, and fed my fpu test code into it.
Source code: Code:
OPT P=68881 output ram:testfp section 1,code main: fmove.s #9.9999999999999999999,fp0 fmove.d #9.9999999999999999999,fp1 fmove.x #9.9999999999999999999,fp3 fmove.s #1e1,fp6 fmove.s #1e10,fp5 fmove.d #1e1,fp2 fmove.d #1e10,fp5 fmove.d #1e100,fp6 fmove.d #1e200,fp6 fmove.d #1e300,fp7 fmove.x #1e1,fp4 fmove.x #1e10,fp5 fmove.x #1e100,fp6 fmove.x #1e200,fp6 fmove.x #1e300,fp7 rts Now for the interesting part, disassembly of code produced by vasm... Code:
fmove.s #$411fffff,fp0 fmove.d #$4023ffffffffffff,fp1 fmove.x #$400200009ffffffffffff800,fp3 fmove.s #$41200000,fp6 fmove.s #$501502f9,fp5 fmove.d #$4024000000000000,fp2 fmove.d #$4202a05f20000000,fp5 fmove.d #$54b249ad2594c379,fp6 fmove.d #$6974e718d7d76251,fp6 fmove.d #$7e37e43c8800758c,fp7 fmove.x #$40020000a000000000000000,fp4 fmove.x #$402000009502f90000000000,fp5 fmove.x #$414b0000924d692ca61bc800,fp6 fmove.x #$42970000a738c6bebb128800,fp6 fmove.x #$43e30000bf21e44003ac6000,fp7 Code:
fmove.s #$411fffff,fp0 fmove.d #$4023ffffffffffff,fp1 fmove.x #$400200009ffffffffffff800,fp3 fmove.s #$41200000,fp6 fmove.s #$501502f9,fp5 fmove.d #$4024000000000000,fp2 fmove.d #$4202a05f20000000,fp5 fmove.d #$54b249ad2594c37c,fp6 fmove.d #$6974e718d7d7625a,fp6 fmove.d #$7e37e43c8800759b,fp7 fmove.x #$40020000a000000000000000,fp4 fmove.x #$402000009502f90000000000,fp5 fmove.x #$414b0000924d692ca61be000,fp6 fmove.x #$42970000a738c6bebb12d000,fp6 fmove.x #$43e30000bf21e44003acd800,fp7 However the good news is that in -devpac mode vasm supports the same 96 bit hex format, so it can produce an exact representation of disassembled code. |
03 January 2023, 19:05 | #43 |
Registered User
Join Date: Feb 2017
Location: Denmark
Posts: 1,113
|
Looks like they're both only using double precision for the decimal constants, and vasm isn't doing a great job here (I know it just relies on strtold from the C library it was compiled again).
I think the closest extended precision number to 1e100 is $414b924d692ca61be758 (devpac is OK here, but truncating, not sure what vasm is up to). Determined with a lazy python script: Code:
def decode(n): #Only handles normal numbers s=n>>79 # Sign e=((n>>64)&0x7fff)-16383 # Exponent m=n&((1<<64)-1) # Mantissa shift = e-63 if shift < 0: r = m*2**(e-63) else: r = m<<shift if s < 0: r = -r return r x = 0x414b924d692ca61bc800 best=-1 target=10**100 bestdist=target for i in range(0x8000): n = decode(x+i) dist = abs(target-n) if dist<bestdist: best=x+i bestdist=dist print("$%x"%best) |
03 January 2023, 21:22 | #44 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
|
Yes, vasm uses double precision to read floating point constants (
doublein C), so some precision is lost for the 80-bit format. I may improve that at some point, but I didn't feel like writing my own portable high precision floating point parser. And if you really need exact floating point constants you should write them in hexadecimal anyway, as a portable assembler can always have deviations in the least significant bits, depending on the host environment it is running on. |
03 January 2023, 21:47 | #45 | |
Registered User
Join Date: Feb 2017
Location: Denmark
Posts: 1,113
|
Quote:
|
|
03 January 2023, 22:52 | #46 | |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,233
|
Quote:
In assembler, it requires 64-bit shifts and bit manipulations. All of that is possible in C, but it is a lot more complicated there as C is ill-prepared for such low-level bit juggling. Modern C compilers can still generate excellent code by recognizing such primitives, but it is still a lot of work to write such C code in first place. |
|
03 January 2023, 22:55 | #47 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,233
|
Historical remark: Aztec C also implemented its double to string and string to double implementation in C, using double with the mathieeedoubbas.library. Of course, these functions were all but precise. They were rather sub-standard.
|
04 January 2023, 04:13 | #48 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,767
|
The Cephes software floating point library supports large floats (up to 336 bit) including conversion functions and is written in C: https://netlib.org/cephes/
|
04 January 2023, 13:29 | #49 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
|
Thanks for that link! Indeed, the Cephes library (did they lose an 'u' there?) looks like a pretty good approach in portable ISO-C, without any GNU extensions. Compiling and linking ieee.c, econst.c and mtherr.c from 128bit.tgz would give me all 128-bit float arithmetic I need, including asctoe113() for converting an ASCII string into 128-bit float format. This should provide sufficient precision to convert it into any other IEEE format.
MIT license seems nice. Will definitely look into it! |
09 January 2023, 18:06 | #50 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
|
I had a look at the deviations again, and took
1e100as an example, which is: Code:
Devpac: 54b249ad2594c37c vasm: 54b249ad2594c379 Cephes: 54b249ad2594c37d Code:
frank@nerthus cat x.c #include <stdio.h> #include <stdlib.h> double x=1e100,y; int main() { y=strtod("1e100",0); printf("%X %X\n",((int*)&x)[0],((int*)&x)[1]); printf("%X %X\n",((int*)&y)[0],((int*)&y)[1]); } frank@nerthus gcc x.c frank@nerthus ./a.out 2594C37D 54B249AD 2594C37D 54B249AD Code:
frank@nerthus vc +aos68k x.c -lmieee frank@nerthus vamos -S -H disable -m 4096 -- ./a.out 54B249AD 2594C380 54B249AD 2594C37D frank@nerthus vc +aos68k x.c -lmsoft frank@nerthus vamos -S -H disable -m 4096 -- ./a.out 54B249AD 2594C380 54B249AD 2594C37D Code:
Ram Disk:> vc +aos68k x.c -lmieee Ram Disk:> a.out 54B249AD 2594C380 54B249AD 2594C37D Ram Disk:> vc +morphos x.c -lm Ram Disk:> a.out 54B249AD 2594C380 54B249AD 2594C37D Code:
7.Ram Disk:> vc +aos68k x.c -lmieee 7.Ram Disk:> a.out 54B249AD 2594C380 54B249AD 2594C37A 7.Ram Disk:> vc +aos68k x.c -lmsoft 7.Ram Disk:> a.out 54B249AD 2594C380 54B249AD 2594C37D |
09 January 2023, 18:20 | #51 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,233
|
It depends on what you describe as "problem". Remember, up to Os 3.1.4, the convention for the math libraries was "round to zero", and in 3.2, it is "round to nearest". The results you provided show a deviation of 1ulp, which is readily explained by exactly that rounding mode difference.
|
09 January 2023, 22:38 | #52 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
|
Makes sense. Thanks for the explanation!
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
how to convert this code to cpu instructions? | jotd | Coders. Asm / Hardware | 4 | 31 December 2020 21:08 |
Sprite editor: software to convert image to C code | Toki | Coders. Language | 5 | 28 June 2020 11:36 |
GCC 3.4.0 and soft-float | TomSoniq | Coders. C/C++ | 4 | 22 April 2020 10:36 |
REQ: Amiga Format code tutorials | AlfaRomeo | AMR suggestions and feedback | 6 | 24 January 2008 10:05 |
Req: Tanks 'n' Stuff Src Code | kevingpo | request.Old Rare Games | 1 | 07 July 2003 12:07 |
|
|