From: Thorsten O. <ad...@th...> - 2025-03-01 11:04:41
|
Hi, I'm currently thinking about a softfloat FPU emulation, one that emulates *all* FPU instructions, as opposed to FPSP040/060 that only emulates the ones that have been dropped from those CPU versions. So this is mainly intended for Falcons without FPU, clones with 68EC040 etc. Of course that will be much slower than a real FPU, and maybe won't be suitable for FPU heavy applications like povray, but should atleast enable them to work instead of aborting because of a missing FPU. There seem to be basically two already existing implementations that can be used as a basis, and i want to outline how they internally work, as found so far. The first is one that is used by NetBSD, and which @agranlund also used as a basis for his raven clone: https://github.com/agranlund/raven/tree/main/sw/ tools/fpu_emu It is mostly implemented in C, except for the atari-specific setup of the exception vectors. It uses a single, static set of emulated FPU registers (just like you would have on real hardware), which means it also has to emulate the fsave/frestore instruction on context switch. The other is part of linux/m68k: https://github.com/torvalds/linux/tree/ master/arch/m68k/math-emu This one implements all the <ea> calculation in assembler, only the actual artithmetic functions are implemented in C. It maintains a per-thread set of FPU registers, which only works because it is part of the kernel, and thus has access to it. Because of this, it does not have to emulate fsave/frestore. For mint that would mean we also have to make it part of the kernel (could eventually be a module). Now for the pros/cons: pros for the linux version: - obviously, doing the address calculation in assembler will be much faster. Not emulating fsave/frestore is not an option for us, since (unlike on linux), an application may switch to supervisor mode and use it itself, but implementing that should not be too hard. Not having to use them on context switch will still be a bit of speedup in a time-critical area. cons for the linux version: - it does not implement all the arithmetic function. I don't know how this is supposed to work, because either the emulation is installed, or one of the FPSP, but never both. So emulations for fasin etc. have to be written. - it maintains a slightly different layout of 96bit double internally. This is not a problem, because of course it is converted to the expected format when written to memory. There are however 3 situations where it matters: - when dumping a corefile. Does not matter for mint, since that is not implemented yet - when building a signal context. As above, this is not implemented yet in mint - When the process is traced and the FPU registers are read/written. This would actually have to be fixed in mint too, but is imho of rather low priority. pros for the netbsd version: It is easier to implement, and almost complete. Because it emulates also fsave/frestore, it could also be compiled as a standalone program, run from the auto-folder. cons for the netbsd version: It will be slower. Worst thing imho is that it will also slow down context switches, thus affecting overall performance, even if only one process uses the FPU. So what do you think? For speed reasons, i would prefer the linux version, especially because of the penalty in context switches in the netbsd version. But it requires some work to implement the missing functions. |