Home | History | Annotate | only in /src/sys/arch/powerpc/fpu
History log of /src/sys/arch/powerpc/fpu
RevisionDateAuthorComments
 1.1 13-Jun-2001  simonb branches: 1.1.8;
Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.8.2 13-Jun-2001  simonb Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.8.1 13-Jun-2001  simonb file files.fpu was added on branch nathanw_sa on 2001-06-13 06:01:47 +0000
 1.7 06-Sep-2022  rin Fix priority for NaN propagation: frA > frB > frC.
 1.6 01-Sep-2022  rin Do not raise SNaN exception for QNaN.
 1.5 27-Jun-2020  rin Sort headers. No functional changes intended.
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.2 15-Jul-2003  lukem __KERNEL_RCSID()
 1.1 13-Jun-2001  simonb branches: 1.1.8; 1.1.24;
Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.24.1 03-Aug-2004  skrll Sync with HEAD
 1.1.8.2 13-Jun-2001  simonb Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.8.1 13-Jun-2001  simonb file fpu_add.c was added on branch nathanw_sa on 2001-06-13 06:01:47 +0000
 1.4 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 07-Aug-2003  agc branches: 1.2.16;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.1 13-Jun-2001  simonb branches: 1.1.8; 1.1.24;
Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.24.1 03-Aug-2004  skrll Sync with HEAD
 1.1.8.2 13-Jun-2001  simonb Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.8.1 13-Jun-2001  simonb file fpu_arith.h was added on branch nathanw_sa on 2001-06-13 06:01:48 +0000
 1.2.16.1 21-Jun-2006  yamt sync with head.
 1.8 08-Sep-2022  rin fpu_compare(): Assign r by using return value from fpu_sub(),
instead of directly using &fe->fe_f3. NFC; only for clarity.
 1.7 08-Sep-2022  rin fpu_compare(): Fix inverted logic and comment it out for now.

VXVC is raised for SNaN if VE == 0.

As we still do not support enabled exception bits, comment out
this if statement for consistency at the moment.
 1.6 04-Sep-2022  rin Fix logic for FI, FR, and FPRF fields of FPSCR.

They are not sticky bits and updated by arithmetic and round
insns at the same time.

Comparison insns update only FPCC sub-field of FPRF.

For other insns, these field are left untouched.

Also, for single-precision insns, exception bits should be set by
the first fpu_implode(), which rounds the value to float.
 1.5 27-Jun-2020  rin Sort headers. No functional changes intended.
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.2 15-Jul-2003  lukem __KERNEL_RCSID()
 1.1 13-Jun-2001  simonb branches: 1.1.8; 1.1.24;
Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.24.1 03-Aug-2004  skrll Sync with HEAD
 1.1.8.2 13-Jun-2001  simonb Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.8.1 13-Jun-2001  simonb file fpu_compare.c was added on branch nathanw_sa on 2001-06-13 06:01:48 +0000
 1.9 06-Sep-2022  rin Fix priority for NaN propagation: frA > frB > frC.
 1.8 04-Sep-2022  rin Trailing white-space/TAB.
 1.7 01-Sep-2022  rin Do not raise SNaN exception for QNaN.
 1.6 15-Jul-2020  rin Do not raise divide-by-zero exception when dividend is zero.
 1.5 27-Jun-2020  rin Sort headers. No functional changes intended.
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.2 15-Jul-2003  lukem __KERNEL_RCSID()
 1.1 13-Jun-2001  simonb branches: 1.1.8; 1.1.24;
Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.24.1 03-Aug-2004  skrll Sync with HEAD
 1.1.8.2 13-Jun-2001  simonb Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.8.1 13-Jun-2001  simonb file fpu_div.c was added on branch nathanw_sa on 2001-06-13 06:01:48 +0000
 1.60 20-Sep-2022  rin Typo in comment. No binary changes.
 1.59 20-Sep-2022  rin stfs{,x}{,u}: Switch to conversion algorithm specified by Power ISA.

The ISA specifies algorithm for most bit patterns in double format, that
are not representable in float. I believe that sane people do not rely on
such a specification detail, but *REAL* programmers may utilize it ;)

Instead of complicating fpu_explode(), single-purpose helper function,
fpu_to_single(), is introduced. See comment therein for more details.
 1.58 15-Sep-2022  rin fnm{add,sub}{,s}: Do not negate NaN.
 1.57 15-Sep-2022  rin fpu_execute(): Use FR() macro. No binary changes.
 1.56 09-Sep-2022  rin G/C ``notyet''; OPC_load_st_62 == std{,u} are integer insns.
No binary changes.
 1.55 07-Sep-2022  rin Fix mnemonics for fm{add,sub}. NFC except for evcnt(9) names.
 1.54 05-Sep-2022  rin static-fy fpu_execute().
 1.53 04-Sep-2022  rin Trailing white-space/TAB.
 1.52 04-Sep-2022  rin Simplify; no need to override ``type'' here. NFC.
 1.51 04-Sep-2022  rin Update FR and FI (and undefined FPRF) for ``round to integer'' insns.
 1.50 04-Sep-2022  rin Fix logic for FI, FR, and FPRF fields of FPSCR.

They are not sticky bits and updated by arithmetic and round
insns at the same time.

Comparison insns update only FPCC sub-field of FPRF.

For other insns, these field are left untouched.

Also, for single-precision insns, exception bits should be set by
the first fpu_implode(), which rounds the value to float.
 1.49 03-Sep-2022  rin Localize addr and buf. NFC.
 1.48 03-Sep-2022  rin Fix weird logic. NFC.

Set both type and size to double by default, and change both to
single if required.
 1.47 03-Sep-2022  rin Do not use ``cond'' for two purposes: flag and bit field.
For the latter, use ``bits'' instead. Switch ``cond'' to int.
NFC.
 1.46 02-Sep-2022  rin Fix fres and frsqrte.
- Pass correct fp to succeeding fpu_implode().
- fres calculates 1 / frB; not 1 / sqrt(frB).
 1.45 02-Sep-2022  rin Make fpu_explode() and fpu_implode() take uint64_t and uint64_t *,
instead of register number, respectively. NFC.
 1.44 01-Sep-2022  rin Set FPSCR[FPRF] for calculated result, for all instructions
that are documented to update this field.

Exceptions are fcti{w,d}{,z}; FPSCR[FPRF] becomes undefined,
according to Power ISA. We do not overwrite this field for
these insns at the moment.
 1.43 30-Aug-2022  rin Fix fcti{w,d}{,z}.

- Treat 64-bit integer correctly for fctid{,z}.
- Respect round mode specified by FPSCR[RN].

XXX
- Set FPSCR[FR] and [FI] appropriately.
- Also set FPSCR[FPRF]?
- fctid{,z} traps on powerpc32 (confirmed on 603e and G4).
 1.42 30-Aug-2022  rin Fix fsel; frB is chosen when frA is negative or NaN.

For fpu_emu.c rev 1.41 or prior, wrong register was chosen for
NaN with sign bit being cleared.
 1.41 30-Aug-2022  rin Fix mcrfs; Clear copied exception bits, and do not raise any exception.
 1.40 30-Aug-2022  rin Misc clean up for mtfsf{,i}. NFC.
 1.39 30-Aug-2022  rin Fix mtfsb[01]; these can clear/set any FPSCR bits other than FEX and VX.
 1.38 30-Aug-2022  rin Fix logic for FPSCR[FEX].

It is logical OR (similar to FPSCR[VX]) of raised exception bits for
enabled exceptions.
 1.37 30-Aug-2022  rin Revert rev 1.29:

http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/arch/powerpc/fpu/fpu_emu.c#rev1.29

> FPSCR[FEX] is not a sticky bit; it is always cleared when read from
> userland via mffs on real hardware.

This turned out to be wrong. FEX is actually observed for 603e.
 1.36 27-Jul-2022  rin Correct stale comment. Thanks rillig@ for pointed out. NFC.
 1.35 26-Jul-2022  rin Fix copy-paste in comment. No binary changes.
 1.34 26-Jul-2022  rin Fix inverted logic; cr was completely broken by FPU insn with Rc == 1.

Why haven't we noticed this so far...
 1.33 15-Jul-2020  rin Now, FPU emulation for booke and ibm4xx works fine at a level where
all the related ATF tests pass correctly. However, there still remain
problems:

- FEX and VX bits for FPSCR cannot be modified by mcrfs, mtfsf{,i},
and mtfsb[01].
- Invalid operations should be treated differently depending on
FPSCR[VE].

Therefore, comment them in order not to be forgotten.

No binary changes.
 1.32 15-Jul-2020  rin Try to fix FPSCR bits in the end of emulation:

- FPSCR[FEX] is not a sticky bit.
- Turn on FPSCR[FEX] if the emulated instruction causes invalid operation,
and invalid operation exception is not masked out.
- FPSCR[VX] is not a sticky bit, however it should be set when at least
one of FPSCR[VXfoo] bits (they are sticky!) is set.
- FPSCR[FX] is a sticky bit, and it should be set if FPSCR is modified by
instructions other than mtfsf{,i}.
 1.31 15-Jul-2020  rin Set ksi_code correctly via fpu_get_fault_code() for SIGFPE.
 1.30 15-Jul-2020  rin Do not raise SIGFPE unless MSR[FE0] or MSR[FE1] is set via fenv(3).
 1.29 15-Jul-2020  rin FPSCR[FEX] is not a sticky bit; it is always cleared when read from
userland via mffs on real hardware.
 1.28 15-Jul-2020  rin PR port-powerpc/55425

Fix emulation for mtfsf; source register is frB here.

Now, userland processes successfully change rounding mode, by which
FPU-optimized code in OpenSSL works just fine as far as I can see.
 1.27 15-Jul-2020  rin For trap instruction, ksi_code should be TRAP_BRKPT not TRAP_TRACE.
 1.26 15-Jul-2020  rin Do not set ksi->ksi_addr twice. No functional changes.
 1.25 15-Jul-2020  rin Remove old workaround foe cache problem on ibm4xx.
The problem seems gone already.
 1.24 06-Jul-2020  rin Include missing opt_ppcarch.h.
 1.23 06-Jul-2020  rin Style and cosmetic changes. No binary changes intended.
 1.22 27-Jun-2020  rin fpu_dumpfpn(): Add KASSERT to check argument != NULL.
 1.21 27-Jun-2020  rin fpu_dumpfpn(): Add missing \n in printf() format.
 1.20 27-Jun-2020  rin Sort headers. No functional changes intended.
 1.19 28-Dec-2016  rin PR port-powerpc/51368: powerpc FPU emulation fails for single precision
floating point arithmetic

For single precision instruction, calculate first in double precision,
and then round it. With this fix, single precision arithmetic gets sane
on ibm4xx and booke.

Taken from FreeBSD commit r258250:
https://svnweb.freebsd.org/base?view=revision&revision=258250

Ok matt and simonb.
 1.18 15-Dec-2016  rin Fix build without DDB.
 1.17 12-Aug-2014  joerg branches: 1.17.2; 1.17.4;
Avoid unncessary use of double in the kernel. With this change,
a LLVM build kernel fully works on TWRP1025.
 1.16 23-Jul-2012  matt branches: 1.16.2; 1.16.14; 1.16.18;
Add support for PPC FP emulation to BookE.
Pass a ksiginfo_t to fpu_emulation so it can give more detailed
info on signals.
 1.15 18-Jan-2011  matt branches: 1.15.6;
Add support for BookE Freescale MPC85xx (e500 core) processors.
Add fast softint support for PowerPC (though only booke uses it).
Redo FPU/VEC support and add e500 SPE support.
Rework trap/intrs to use a common trapframe format.
Support SOFTFLOAT (no hardfloat or fpu emulation) for BookE.
 1.14 11-Dec-2005  christos branches: 1.14.100; 1.14.104; 1.14.106;
merge ktrace-lwp.
 1.13 03-Jun-2005  scw Appease -Wcast-qual
 1.12 15-Sep-2004  scw It helps to call fpu_sqrt() when dealing with the frsqrte instruction.
 1.11 30-Mar-2004  simonb Make the "cond" variable an unsigned variable. Stops sign extension
problems when we shift it left and right while creating the new value
for the condition register.

Fixes problems reported by Juergen Hannken-Illjes in toolchain/24938.
 1.10 27-Oct-2003  simonb branches: 1.10.2;
Fix a bogus uninitialised warning.
 1.9 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.8 15-Jul-2003  lukem __KERNEL_RCSID()
 1.7 07-Feb-2003  thorpej branches: 1.7.2;
Fix some printf formats.
 1.6 25-Nov-2002  thorpej Avoid strict-alias warnings.
 1.5 25-Nov-2002  thorpej Remove an unnecessary token-paste, as pointed out by GCC 3.3.
 1.4 24-Nov-2002  thorpej Instrument FP emulation traps.
 1.3 22-Jul-2001  wiz branches: 1.3.6;
bcopy -> memcpy, bzero -> memset, bcmp -> memcmp.
Reviewed by Matt Thomas, ok'd by Tsubai Masanari.
 1.2 22-Jun-2001  simonb branches: 1.2.2;
Make this compile when DEBUG isn't defined.
 1.1 13-Jun-2001  simonb Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.2.2.1 03-Aug-2001  lukem update to -current
 1.3.6.2 11-Dec-2002  thorpej Sync with HEAD.
 1.3.6.1 22-Jul-2001  thorpej file fpu_emu.c was added on branch nathanw_sa on 2002-12-11 06:11:37 +0000
 1.7.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.7.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.7.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.7.2.1 03-Aug-2004  skrll Sync with HEAD
 1.10.2.1 30-Mar-2004  jmc Pullup rev 1.11 (requested by simonb in ticket #18)

Make the "cond" variable an unsigned variable. PR#24938
 1.14.106.1 06-Jun-2011  jruoho Sync with HEAD.
 1.14.104.1 07-Jan-2011  matt Adapt to new trapframe.
 1.14.100.1 05-Mar-2011  rmind sync with head
 1.15.6.1 30-Oct-2012  yamt sync with head
 1.16.18.1 18-Jan-2017  skrll Sync with netbsd-5
 1.16.14.2 03-Jan-2017  snj Pull up following revision(s) (requested by rin in ticket #1342):
sys/arch/powerpc/fpu/fpu_emu.c: revision 1.18
Fix build without DDB.
 1.16.14.1 03-Jan-2017  snj Pull up following revision(s) (requested by rin in ticket #1341):
sys/arch/powerpc/fpu/fpu_emu.c: revision 1.19
sys/arch/powerpc/fpu/fpu_explode.c: revision 1.7
- add missing default from FreeBSD
- remove duplicate panic pointed out by matt
--
PR port-powerpc/51368: powerpc FPU emulation fails for single precision
floating point arithmetic
For single precision instruction, calculate first in double precision,
and then round it. With this fix, single precision arithmetic gets sane
on ibm4xx and booke.
Taken from FreeBSD commit r258250:
https://svnweb.freebsd.org/base?view=revision&revision=258250
Ok matt and simonb.
 1.16.2.1 03-Dec-2017  jdolecek update from HEAD
 1.17.4.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.17.2.1 05-Feb-2017  skrll Sync with HEAD
 1.12 07-Sep-2022  rin Turn fpu_sub() macro into static inline function for clarity.
No binary changes.
 1.11 06-Sep-2022  rin fpu_sub(): Do not invert sign bit of NaN.

Taken from FreeBSD:
https://cgit.freebsd.org/src/commit/lib/libc/sparc64/fpu?h=releng/12.3&id=8ff9d52cd08cbf31efde4052d3593a5680eaa2a5
 1.10 05-Sep-2022  rin Clean up fpu_extern.h; only a function public to external is fpu_emulate().

Other functions are private to fpu_*.c and therefore live in fpu_emu.h.

Also, drop needless forward struct declarations.

NFC.
 1.9 04-Sep-2022  rin Fix logic for FI, FR, and FPRF fields of FPSCR.

They are not sticky bits and updated by arithmetic and round
insns at the same time.

Comparison insns update only FPCC sub-field of FPRF.

For other insns, these field are left untouched.

Also, for single-precision insns, exception bits should be set by
the first fpu_implode(), which rounds the value to float.
 1.8 02-Sep-2022  rin Make fpu_explode() and fpu_implode() take uint64_t and uint64_t *,
instead of register number, respectively. NFC.
 1.7 01-Sep-2022  rin Set FPSCR[FPRF] for calculated result, for all instructions
that are documented to update this field.

Exceptions are fcti{w,d}{,z}; FPSCR[FPRF] becomes undefined,
according to Power ISA. We do not overwrite this field for
these insns at the moment.
 1.6 30-Aug-2022  rin Fix fcti{w,d}{,z}.

- Treat 64-bit integer correctly for fctid{,z}.
- Respect round mode specified by FPSCR[RN].

XXX
- Set FPSCR[FR] and [FI] appropriately.
- Also set FPSCR[FPRF]?
- fctid{,z} traps on powerpc32 (confirmed on 603e and G4).
 1.5 30-Aug-2022  rin Move FTYPE_* definitions from instr.h to fpu_emu.h.

They are not defined by architecture, and used only for FPU emulation.
 1.4 23-Jul-2012  matt Add support for PPC FP emulation to BookE.
Pass a ksiginfo_t to fpu_emulation so it can give more detailed
info on signals.
 1.3 11-Dec-2005  christos branches: 1.3.112;
merge ktrace-lwp.
 1.2 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.1 13-Jun-2001  simonb branches: 1.1.8; 1.1.24;
Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.24.1 03-Aug-2004  skrll Sync with HEAD
 1.1.8.2 13-Jun-2001  simonb Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.8.1 13-Jun-2001  simonb file fpu_emu.h was added on branch nathanw_sa on 2001-06-13 06:01:48 +0000
 1.3.112.1 30-Oct-2012  yamt sync with head
 1.14 07-Sep-2022  rin fpu_explode(): Fix sign for FTYPE_INT.

NFC for now; conversion for this type is used only for immediate 1.
 1.13 05-Sep-2022  rin static-fy fpu_[ixsd]tof(). NFC.
 1.12 02-Sep-2022  rin Make fpu_explode() and fpu_implode() take uint64_t and uint64_t *,
instead of register number, respectively. NFC.
 1.11 02-Sep-2022  rin Use hi and lo for higher and lower words, instead of i and j.
No binary changes.
 1.10 28-Aug-2022  rin u_int64_t --> uint64_t. No binary changes.
 1.9 27-Jun-2020  rin Remove extra newline in DPRINTF().
 1.8 27-Jun-2020  rin Sort headers. No functional changes intended.
 1.7 28-Dec-2016  rin - add missing default from FreeBSD
- remove duplicate panic pointed out by matt
 1.6 11-Dec-2005  christos branches: 1.6.122; 1.6.140; 1.6.142; 1.6.146; 1.6.148;
merge ktrace-lwp.
 1.5 28-Oct-2003  chs make this compile again.
 1.4 27-Oct-2003  simonb Remove (the now non-compiling) support for 128bit FP emulation, which
isn't needed for PowerPC anyway.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.2 15-Jul-2003  lukem __KERNEL_RCSID()
 1.1 13-Jun-2001  simonb branches: 1.1.8; 1.1.24;
Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.24.1 03-Aug-2004  skrll Sync with HEAD
 1.1.8.2 13-Jun-2001  simonb Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.8.1 13-Jun-2001  simonb file fpu_explode.c was added on branch nathanw_sa on 2001-06-13 06:01:48 +0000
 1.6.148.1 18-Jan-2017  skrll Sync with netbsd-5
 1.6.146.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.6.142.1 05-Feb-2017  skrll Sync with HEAD
 1.6.140.1 03-Jan-2017  snj Pull up following revision(s) (requested by rin in ticket #1341):
sys/arch/powerpc/fpu/fpu_emu.c: revision 1.19
sys/arch/powerpc/fpu/fpu_explode.c: revision 1.7
- add missing default from FreeBSD
- remove duplicate panic pointed out by matt
--
PR port-powerpc/51368: powerpc FPU emulation fails for single precision
floating point arithmetic
For single precision instruction, calculate first in double precision,
and then round it. With this fix, single precision arithmetic gets sane
on ibm4xx and booke.
Taken from FreeBSD commit r258250:
https://svnweb.freebsd.org/base?view=revision&revision=258250
Ok matt and simonb.
 1.6.122.1 03-Dec-2017  jdolecek update from HEAD
 1.12 05-Sep-2022  rin Clean up fpu_extern.h; only a function public to external is fpu_emulate().

Other functions are private to fpu_*.c and therefore live in fpu_emu.h.

Also, drop needless forward struct declarations.

NFC.
 1.11 05-Sep-2022  rin static-fy fpu_execute().
 1.10 05-Sep-2022  rin static-fy fpu_[ixsd]tof(). NFC.
 1.9 02-Sep-2022  rin Make fpu_explode() and fpu_implode() take uint64_t and uint64_t *,
instead of register number, respectively. NFC.
 1.8 01-Sep-2022  rin static-fy fpu_fto[ixsd](). NFC.
 1.7 30-Aug-2022  rin Fix fcti{w,d}{,z}.

- Treat 64-bit integer correctly for fctid{,z}.
- Respect round mode specified by FPSCR[RN].

XXX
- Set FPSCR[FR] and [FI] appropriately.
- Also set FPSCR[FPRF]?
- fctid{,z} traps on powerpc32 (confirmed on 603e and G4).
 1.6 28-Aug-2022  rin u_int64_t --> uint64_t. No binary changes.
 1.5 23-Jul-2012  matt Add support for PPC FP emulation to BookE.
Pass a ksiginfo_t to fpu_emulation so it can give more detailed
info on signals.
 1.4 28-Apr-2008  martin branches: 1.4.34;
Remove clause 3 and 4 from TNF licenses
 1.3 11-Dec-2005  christos branches: 1.3.74; 1.3.76; 1.3.78;
merge ktrace-lwp.
 1.2 27-Oct-2003  simonb Remove (the now non-compiling) support for 128bit FP emulation, which
isn't needed for PowerPC anyway.
 1.1 13-Jun-2001  simonb branches: 1.1.8; 1.1.24;
Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.24.1 03-Aug-2004  skrll Sync with HEAD
 1.1.8.2 13-Jun-2001  simonb Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.8.1 13-Jun-2001  simonb file fpu_extern.h was added on branch nathanw_sa on 2001-06-13 06:01:48 +0000
 1.3.78.1 16-May-2008  yamt sync with head.
 1.3.76.1 18-May-2008  yamt sync with head.
 1.3.74.1 02-Jun-2008  mjf Sync with HEAD.
 1.4.34.1 30-Oct-2012  yamt sync with head
 1.24 14-Sep-2022  rin Fix logic for FPSCR[OX]; set FPSCR[FI] (and therefore FPSCR[XX]).
 1.23 14-Sep-2022  rin Fix logic for FPSCR[UX]:
- Correct FPSCR[FPRF] field when round to 0.0 or 0.0f.
- Simplify.
 1.22 04-Sep-2022  rin Simplify logic to remove needless goto. NFC.
 1.21 04-Sep-2022  rin Fix logic for FI, FR, and FPRF fields of FPSCR.

They are not sticky bits and updated by arithmetic and round
insns at the same time.

Comparison insns update only FPCC sub-field of FPRF.

For other insns, these field are left untouched.

Also, for single-precision insns, exception bits should be set by
the first fpu_implode(), which rounds the value to float.
 1.20 04-Sep-2022  rin Fix debug printf. Unbreak DEBUG build.
 1.19 04-Sep-2022  rin Remove extra break.
 1.18 02-Sep-2022  rin fpu_implode(): Clear lower word for float just for sure.
 1.17 02-Sep-2022  rin Make fpu_explode() and fpu_implode() take uint64_t and uint64_t *,
instead of register number, respectively. NFC.
 1.16 02-Sep-2022  rin Fix off-by-one error in exponent when round a double to the
largest normalized value; QNaN was wrongly generated here.
 1.15 02-Sep-2022  rin Make fpu_ftod() return uint64_t value. NFC.
 1.14 01-Sep-2022  rin Set FPSCR[FPRF] for calculated result, for all instructions
that are documented to update this field.

Exceptions are fcti{w,d}{,z}; FPSCR[FPRF] becomes undefined,
according to Power ISA. We do not overwrite this field for
these insns at the moment.
 1.13 01-Sep-2022  rin static-fy fpu_fto[ixsd](). NFC.
 1.12 01-Sep-2022  rin Further fix for fcti{w,d}{,z}.

- Treat {Q,S}NaN correctly.
- Set exception bits appropriately.
- Introduce round_int().
 1.11 01-Sep-2022  rin Remove stale comment.
 1.10 30-Aug-2022  rin Fix fcti{w,d}{,z}.

- Treat 64-bit integer correctly for fctid{,z}.
- Respect round mode specified by FPSCR[RN].

XXX
- Set FPSCR[FR] and [FI] appropriately.
- Also set FPSCR[FPRF]?
- fctid{,z} traps on powerpc32 (confirmed on 603e and G4).
 1.9 30-Aug-2022  rin Do not assert FPSCR[UX] when overflow.
 1.8 28-Aug-2022  rin u_int64_t --> uint64_t. No binary changes.
 1.7 27-Jun-2020  rin Sort headers. No functional changes intended.
 1.6 11-Dec-2005  christos merge ktrace-lwp.
 1.5 27-Jul-2005  simonb KNF nit.
 1.4 27-Oct-2003  simonb branches: 1.4.16;
Remove (the now non-compiling) support for 128bit FP emulation, which
isn't needed for PowerPC anyway.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.2 15-Jul-2003  lukem __KERNEL_RCSID()
 1.1 13-Jun-2001  simonb branches: 1.1.8; 1.1.24;
Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.24.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.24.1 03-Aug-2004  skrll Sync with HEAD
 1.1.8.2 13-Jun-2001  simonb Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.8.1 13-Jun-2001  simonb file fpu_implode.c was added on branch nathanw_sa on 2001-06-13 06:01:48 +0000
 1.4.16.1 21-Jun-2006  yamt sync with head.
 1.8 06-Sep-2022  rin fpu_mul(): Do not multiply sign bits for NaN.
 1.7 06-Sep-2022  rin Fix priority for NaN propagation: frA > frB > frC.
 1.6 01-Sep-2022  rin Do not raise SNaN exception for QNaN.
 1.5 27-Jun-2020  rin Sort headers. No functional changes intended.
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.2 15-Jul-2003  lukem __KERNEL_RCSID()
 1.1 13-Jun-2001  simonb branches: 1.1.8; 1.1.24;
Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.24.1 03-Aug-2004  skrll Sync with HEAD
 1.1.8.2 13-Jun-2001  simonb Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.8.1 13-Jun-2001  simonb file fpu_mul.c was added on branch nathanw_sa on 2001-06-13 06:01:48 +0000
 1.14 06-Sep-2022  rin Style sync with other parts of this file, as well as FreeBSD:
https://cgit.freebsd.org/src/commit/sys/powerpc/fpu/fpu_sqrt.c?id=81dd9c5e69a2709ae3317dd383093e1c8a970d9e

NFC since q is initialized to zero just above.
 1.13 06-Sep-2022  rin Fix errors in calculation of intermediate mantissa bits > 95.

NFC since this does not affect the final results; we do not
support any extended-precision formats at the moment (never?).

Taken from FreeBSD:
https://cgit.freebsd.org/src/commit/sys/powerpc/fpu/fpu_sqrt.c?id=81dd9c5e69a2709ae3317dd383093e1c8a970d9e
except for stylistic changes that will be committed soon.
 1.12 06-Sep-2022  rin IEEE 754 and Power ISA require sqrt(+0) = +0 and sqrt(-0) = -0, not Inf.
 1.11 01-Sep-2022  rin Do not raise SNaN exception for QNaN.
 1.10 24-May-2022  andvar s/equivalant/equivalent/ in copy pasted comment.
 1.9 27-Jun-2020  rin Return +INF without exception for +INF, as required by the architecture.
Also, avoid NULL dereference for fpu_dumpfpn() aka DUMPFPN().

Taken from (remaining part of) FreeBSD Revision 343078:
https://svnweb.freebsd.org/base?view=revision&revision=343078
 1.8 27-Jun-2020  rin Fix typo in DPRINTF.
 1.7 27-Jun-2020  rin Set FPSCR[VXSQRT] for non-zero negative operand.

Taken from (a part of) FreeBSD Revision 343078:
https://svnweb.freebsd.org/base?view=revision&revision=343078
 1.6 27-Jun-2020  rin Sort headers. No functional changes intended.
 1.5 25-Feb-2014  martin Mark a temporary as __USEd
 1.4 11-Dec-2005  christos branches: 1.4.112; 1.4.122; 1.4.128;
merge ktrace-lwp.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.2 15-Jul-2003  lukem __KERNEL_RCSID()
 1.1 13-Jun-2001  simonb branches: 1.1.8; 1.1.24;
Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.24.1 03-Aug-2004  skrll Sync with HEAD
 1.1.8.2 13-Jun-2001  simonb Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.8.1 13-Jun-2001  simonb file fpu_sqrt.c was added on branch nathanw_sa on 2001-06-13 06:01:48 +0000
 1.4.128.1 18-May-2014  rmind sync with head
 1.4.122.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.112.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.9 06-Sep-2022  rin FPU generates QNaN with all payload bits being cleared.
 1.8 04-Sep-2022  rin Unconditionally include <sys/systm.h> for KASSERT{,MSG}().
Fix (!DIAGNOSTIC && !DEBUG) build.
 1.7 02-Sep-2022  rin fpu_subr.c: Convert #ifdef DIAGNOSTIC panic() --> KASSERT{,MSG}().
 1.6 01-Sep-2022  rin Do not raise SNaN exception for QNaN.
 1.5 27-Jun-2020  rin Sort headers. No functional changes intended.
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.2 15-Jul-2003  lukem __KERNEL_RCSID()
 1.1 13-Jun-2001  simonb branches: 1.1.8; 1.1.24;
Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.24.1 03-Aug-2004  skrll Sync with HEAD
 1.1.8.2 13-Jun-2001  simonb Add a port to IBM's PPC405GP Reference Board (the "walnut")
by Eduardo Horvath and Simon Burge of Wasabi Systems.

IBM 4xx series CPU features:
- New pmap and revised trap handler.
- Support on-chip timers, PCI controller, UARTs
- Framework for on-chip ethernet and watchdog timer.
General PowerPC features:
- Add in-kernel PPC floating point emulation
- New in{,4}_cksum that is between 1.5 and 5 times faster than the
old version depending on CPU type.
General changes:
- Kernel support for generic dbsym-style symbols.
 1.1.8.1 13-Jun-2001  simonb file fpu_subr.c was added on branch nathanw_sa on 2001-06-13 06:01:48 +0000

RSS XML Feed