kstenerud / Musashi

Motorola 680x0 emulator written in C
427 stars 96 forks source link

FPU support? #30

Open davidgiven opened 6 years ago

davidgiven commented 6 years ago

I notice that the version of Musashi in mame has support for more architectures, and the FPU; are there any plans to import that version here? (I'm using the emulator to run compiler tests, and some of them use floating point.)

zelurker commented 5 years ago

I have made a fork of this repository where I tried to import a few patches from mame if you are interested, they include the support for the fpu, but only the beginning, I mean my goal when merging the patch was keeping musashi outside of mame internals but it becomes hard to do very quickly, around version 125 only. It's a basic support, no definition for a specific cpu+fpu combination, but the fpu opcodes are handled and it compiles so it should be usable for what you have. I also updated the example to be able to compile it in linux so that I could quickly test that everything at least compiles.

bebbo commented 4 years ago

the pc is not yet updated correctly, the additional read words are not added to the pc.

EDIT: never mind - my setup was bogus.

Thanks for the fpu support!

zelurker commented 4 years ago

Would you have some example code using the 040 fpu ? I looked on the wab, but it seems it's not easy to find. I mean something usable without a 68040 assembler preferably, instructions

As previously said there are still a lot of patches to merge, but the big problem is that after this point musashi was made very dependant on the mame core and it becomes very difficult to follow the patches after that if you want to remain independent from mame, it's not impossible, but very hard.

Le dim. 8 déc. 2019 à 11:14, bebbo notifications@github.com a écrit :

the pc is not yet updated correctly, the additional read words are not added to the pc.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kstenerud/Musashi/issues/30?email_source=notifications&email_token=AAV3SD6XNR6EADT4PMFYK23QXTCG7A5CNFSM4FDW2IR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGG2NHI#issuecomment-562931357, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAV3SD6RFQSIVYQ33ATWQOTQXTCG7ANCNFSM4FDW2IRQ .

bebbo commented 4 years ago

Would you have some example code using the 040 fpu ? I looked on the wab, but it seems it's not easy to find. I mean something usable without a 68040 assembler preferably, instructions + opcodes if possible... Just for info, I never see this kind of code...

do you need https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=2ahUKEwj0g-mH4qbmAhXLsaQKHUkCDjcQFjAAegQIAxAC&url=https%3A%2F%2Fwww.nxp.com%2Ffiles-static%2Farchives%2Fdoc%2Fref_manual%2FM68000PRM.pdf&usg=AOvVaw3HdjcVYsrGb6tkIzqytdzC or https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=2ahUKEwiF0oij4qbmAhXKjKQKHW83DlEQFjAAegQIAhAC&url=http%3A%2F%2Fbitsavers.trailing-edge.com%2Fcomponents%2Fmotorola%2F68000%2FMC68881_MC68882_Floating-Point_Coprocessor_Users_Manual_1ed_1987.pdf&usg=AOvVaw1peNHzJ7TEGbmW9qB-Wy3t ?

As previously said there are still a lot of patches to merge, ...

I also implemented some more instructions - so it runs what I want it to run. I'm using https://github.com/bebbo/amitools so I integrated you upated version into it. To create and run programs I'm using the Amiga gcc toolchain https://github.com/bebbo/amiga-gcc

zelurker commented 4 years ago

Yeah I know m68000prm but I had hoped for some short code examples, easy to read a to follow, oh well forget it... Well let us know if you merge some more patches then Karl always welcomes more pull requests, that's the way to make them public ! On my side my main interest was for 68000 to 68020, so musashi as it is now is enough for me, but I might take another look anyway at merging more patches later...

Le dim. 8 déc. 2019 à 20:23, bebbo notifications@github.com a écrit :

Would you have some example code using the 040 fpu ? I looked on the wab, but it seems it's not easy to find. I mean something usable without a 68040 assembler preferably, instructions + opcodes if possible... Just for info, I never see this kind of code...

do you need https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=2ahUKEwj0g-mH4qbmAhXLsaQKHUkCDjcQFjAAegQIAxAC&url=https%3A%2F%2Fwww.nxp.com%2Ffiles-static%2Farchives%2Fdoc%2Fref_manual%2FM68000PRM.pdf&usg=AOvVaw3HdjcVYsrGb6tkIzqytdzC or https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=2ahUKEwiF0oij4qbmAhXKjKQKHW83DlEQFjAAegQIAhAC&url=http%3A%2F%2Fbitsavers.trailing-edge.com%2Fcomponents%2Fmotorola%2F68000%2FMC68881_MC68882_Floating-Point_Coprocessor_Users_Manual_1ed_1987.pdf&usg=AOvVaw1peNHzJ7TEGbmW9qB-Wy3t ?

As previously said there are still a lot of patches to merge, ...

I also implemented some more instructions - so it runs what I want it to run. I'm using https://github.com/bebbo/amitools so I integrated you upated version into it. To create and run programs I'm using the Amiga gcc toolchain https://github.com/bebbo/amiga-gcc

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kstenerud/Musashi/issues/30?email_source=notifications&email_token=AAV3SDY3UGMTEYYFS6BIDIDQXVCTZA5CNFSM4FDW2IR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGHHCWI#issuecomment-562983257, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAV3SDYJFPKADWDKJINCU3DQXVCTZANCNFSM4FDW2IRQ .

bebbo commented 4 years ago

an convenient way to "get some fpu asm code" is to use https://franke.ms/cex/ enter some c /c++ code and use -m68040 as compiler options and you'll see the corresponding asm.

zelurker commented 4 years ago

Interesting site, thanks, but it doesn't seem to work for this purpose, if you type double x = 1.5*num; you get 2 function calls from a library instead of the direct instructions : move.l (8,a5),-(sp) jbsr extendsfdf2 addq.l #4,sp clr.l -(sp) move.l #1073217536,-(sp) move.l d1,-(sp) move.l d0,-(sp) jbsr muldf3 lea (16,sp),sp move.l d0,(-8,a5) move.l d1,(-4,a5)

But I'll keep the url of the site, thanks !

Le mar. 10 déc. 2019 à 22:27, bebbo notifications@github.com a écrit :

an convenient way to "get some fpu asm code" is to use https://franke.ms/cex/ enter some c /c++ code and use -m68040 as compiler options and you'll see the corresponding asm.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kstenerud/Musashi/issues/30?email_source=notifications&email_token=AAV3SD75LP3R5CNGSZEVXKTQYACVLA5CNFSM4FDW2IR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGRALVQ#issuecomment-564266454, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAV3SD77TLZMTHK7UDLROZTQYACVLANCNFSM4FDW2IRQ .

michalsc commented 4 years ago

You need to pass compiler options (e.g. -m68040 -m68881), otherwise 68000 mode without FPU will be used

bebbo commented 4 years ago

try this: https://franke.ms/cex/z/m0HstT

zelurker commented 4 years ago

Nice but without the opcodes, it's useless. I tried "compile the binary and disassemble the output", but it says "no output, objdump returned 1", I guess it doesn't like the -m68040 option. By the way I had used the -m68040 option too of course, no idea why it produces the instructions here and the library calls instead before. Anyway... !

Le mar. 10 déc. 2019 à 23:07, bebbo notifications@github.com a écrit :

try this: https://franke.ms/cex/z/m0HstT

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kstenerud/Musashi/issues/30?email_source=notifications&email_token=AAV3SD3QU47TJ7CSESYZP7LQYAHILA5CNFSM4FDW2IR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGRD5QA#issuecomment-564281024, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAV3SD4ZU7TQ4OBJG23XUSTQYAHILANCNFSM4FDW2IRQ .

michalsc commented 4 years ago

Would you have some example code using the 040 fpu ? I looked on the wab, but it seems it's not easy to find. I mean something usable without a 68040 assembler preferably, instructions + opcodes if possible... Just for info, I never see this kind of code...

If you like you can have a look at my M68k JIT for ARM processors, especially the examples added there: https://github.com/michalsc/Emu68/tree/master/Examples. Two of the examples, Buddha and SmallPT, use FPU very intensively. If you like I can provide you disassemble output of both of them - asm code plus opcodes.

bebbo commented 4 years ago

Nice but without the opcodes, it's useless. I tried "compile the binary and disassemble the output", but it says "no output, objdump returned 1", I guess it doesn't like the -m68040 option. By the way I had used the -m68040 option too of course, no idea why it produces the instructions here and the library calls instead before. Anyway... !

try again - I updated the config

zelurker commented 4 years ago

Le mer. 11 déc. 2019 à 10:58, bebbo notifications@github.com a écrit :

try again - I updated the config

Thanks for the objdump fix, now it's perfect ! Well to come back to what started this topic, all the instructions I tried so far increase correctly the pc. I didn't try all of them of course, just a copy of this simple compilation.

I tried this to have some operand after the instruction :

f22d 5444 0008 which translates to fdmoved 8(a5),fp0 works fine, it reads correctly the 8 offset using read_immediate which correctly increases the pc.

Anyway might be a good idea to try to add some example for the fpu too, I'll look more into this later...

bebbo commented 4 years ago

Well to come back to what started this topic, all the instructions I tried so far increase correctly the pc. I didn't try all of them of course, just a copy of this simple compilation. I tried this to have some operand after the instruction : f22d 5444 0008 which translates to fdmoved 8(a5),fp0 works fine, it reads correctly the 8 offset using read_immediate which correctly increases the pc. Anyway might be a good idea to try to add some example for the fpu too, I'll look more into this later...

I'm using vamos/musashi to run the gcc-check tests (> 14000) and for now there are no open issues related to musashi.

zelurker commented 4 years ago

At least it gave me the motivation to propose a new pull request to Karl, it's about some more patches from mame, until the emulation of the 68030 this time. It's just the beginning, for the 030, but it's better than nothing. The patches are harder to process, but it's not so bad... ! Plenty of new stuff to test then... Sorry no update for the fpu for now...

Le mer. 11 déc. 2019 à 16:15, bebbo notifications@github.com a écrit :

Well to come back to what started this topic, all the instructions I tried so far increase correctly the pc. I didn't try all of them of course, just a copy of this simple compilation. I tried this to have some operand after the instruction : f22d 5444 0008 which translates to fdmoved 8(a5),fp0 works fine, it reads correctly the 8 offset using read_immediate which correctly increases the pc. Anyway might be a good idea to try to add some example for the fpu too, I'll look more into this later...

I'm using vamos/musashi to run the gcc-check tests (> 14000) and for now there are no open issues related to musashi.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kstenerud/Musashi/issues/30?email_source=notifications&email_token=AAV3SD7TAZXWUVXI3QE54TTQYD7YNA5CNFSM4FDW2IR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGTPR7Q#issuecomment-564590846, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAV3SD4WYKT4ZHNVJ6T3ECTQYD7YNANCNFSM4FDW2IRQ .

jotd666 commented 4 years ago

I've modded the FPU source code, supporting more 68040 FPU instructions.

Someone is interested?

bebbo commented 4 years ago

@jotd: what's your repo?

davidgiven commented 4 years ago

If you mean interested in general, yes --- I'm using Musashi to run compiler tests for the Amsterdam Compiler Kit (at http://github.com/davidgiven/ack), and having FPU support would allow testing floating point code.

jotd666 commented 4 years ago

@bebbo I don't have any repo right now. I'm willing to contribute but I'm still unsure about 100% correctness of my additions. My app isn't running properly yet (it may be because of other incompatibilities). I wouldn't like to give false hopes like "it's working" and it's not. But I can share the "m68kfpu.c" file I have changed, or create a fork with my changes / create a repo in my personal space (680x0 that I know, but I'm still pretty new to git)

Good news for everyone is that the code I want to emulate uses a lot of 040 FPU stuff, and it's for work, so I cannot just let it rot, I have to make it work in reasonable time (like, this semester). The other good news is that I'm not going to keep the changes for myself if they prove okay.

musashi design is VERY good given that it's a C program. Very easy to use & to modify. Really, impressive.

jotd666 commented 4 years ago

ok, update after working all week on that, with success. I updated FPU but also some exotic scalar instructions like CHK2/CMP2

m68k_in.c:

m68kfpu.c:

The number of cycles isn't accurate. But the modified sources allowed to run a complex avionic program that computes a plane trajectory, exactly the same way as it's done using Basilisk UAE emulation core (and even better since Basilisk doesn't support proper rounding in FPU instructions)

jotd666 commented 4 years ago

@bebbo I have created a new repo (completely copied from musashi) with the 2 .c files updated: here: https://github.com/jotd666/musashi040

I suck at git, couldn't do something like a fork. I hope my changes will be officialized, so I can delete my repo afterwards

bebbo commented 4 years ago

@jotd666 thanks a lot - I cloned your repo and will look into it

kstenerud commented 4 years ago

Awesome! I look forward to it!

jotd666 commented 4 years ago

I hope I didn't create too much noise with my changes. As I forked main repo, created another one on my account, and posted attached fixed files too... I don't mind creating issues, with attached files, and let you commit changes (or not).

Le lun. 9 mars 2020 à 08:29, Karl Stenerud notifications@github.com a écrit :

Awesome! I look forward to it!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kstenerud/Musashi/issues/30?email_source=notifications&email_token=AD54CESWMXB2JPKOKVRU2U3RGSLFZA5CNFSM4FDW2IR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOF6GXQ#issuecomment-596370270, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD54CEV4J2MOPISI7L7LPGLRGSLFZANCNFSM4FDW2IRQ .

kstenerud commented 4 years ago

I'm usually massively swamped, so every bit of assistance helps. I'm hoping @bebbo can verify from his test set, and then I'll add in the modifications.

But for future, you'd probably save a lot of work on yourself by just forking the repo, making changes on your copy of the repo, and then opening a PR from there to here. Github makes it pretty painless :)

jotd666 commented 4 years ago

Yes, I'm still getting used to github/git. Long time clearcase/UCM user...

Needless to say your emulator is saving my life at work right now because of the nice licence :)

Le mar. 10 mars 2020 à 22:35, Karl Stenerud notifications@github.com a écrit :

I'm usually massively swamped, so every bit of assistance helps. I'm hoping @bebbo https://github.com/bebbo can verify from his test set, and then I'll add in the modifications.

But for future, you'd probably save a lot of work on yourself by just forking the repo, making changes on your copy of the repo, and then opening a PR from there to here. Github makes it pretty painless :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kstenerud/Musashi/issues/30?email_source=notifications&email_token=AD54CEQYYQYBRZHEO33NMYTRG2XCTA5CNFSM4FDW2IR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEONIMXI#issuecomment-597329501, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD54CERENYGACVXY6EKUSLLRG2XCTANCNFSM4FDW2IRQ .

shoggoth77 commented 2 years ago

It seems to me that there's no clean way to turn off FPU support, and it adds quite a lot of code. That's sort of a regression for my particular case. It would be nice if this could be optional.