Compare commits

...

15 Commits

Author SHA1 Message Date
GitHubProUser67 af82b98ff7
Merge 0a8c54514c into 1fff69b0aa 2024-12-30 18:53:44 -06:00
Tyler Wilding 1fff69b0aa
translations: Syncing Crowdin translations (#12141)
* New translations pcsx2-qt_en.ts (Romanian)
[ci skip]

* New translations pcsx2-qt_en.ts (French)
[ci skip]

* New translations pcsx2-qt_en.ts (Spanish)
[ci skip]

* New translations pcsx2-qt_en.ts (Afrikaans)
[ci skip]

* New translations pcsx2-qt_en.ts (Arabic)
[ci skip]

* New translations pcsx2-qt_en.ts (Bulgarian)
[ci skip]

* New translations pcsx2-qt_en.ts (Catalan)
[ci skip]

* New translations pcsx2-qt_en.ts (Czech)
[ci skip]

* New translations pcsx2-qt_en.ts (Danish)
[ci skip]

* New translations pcsx2-qt_en.ts (German)
[ci skip]

* New translations pcsx2-qt_en.ts (Greek)
[ci skip]

* New translations pcsx2-qt_en.ts (Finnish)
[ci skip]

* New translations pcsx2-qt_en.ts (Hebrew)
[ci skip]

* New translations pcsx2-qt_en.ts (Hungarian)
[ci skip]

* New translations pcsx2-qt_en.ts (Italian)
[ci skip]

* New translations pcsx2-qt_en.ts (Japanese)
[ci skip]

* New translations pcsx2-qt_en.ts (Georgian)
[ci skip]

* New translations pcsx2-qt_en.ts (Korean)
[ci skip]

* New translations pcsx2-qt_en.ts (Lithuanian)
[ci skip]

* New translations pcsx2-qt_en.ts (Dutch)
[ci skip]

* New translations pcsx2-qt_en.ts (Norwegian)
[ci skip]

* New translations pcsx2-qt_en.ts (Polish)
[ci skip]

* New translations pcsx2-qt_en.ts (Portuguese)
[ci skip]

* New translations pcsx2-qt_en.ts (Russian)
[ci skip]

* New translations pcsx2-qt_en.ts (Serbian (Cyrillic))
[ci skip]

* New translations pcsx2-qt_en.ts (Swedish)
[ci skip]

* New translations pcsx2-qt_en.ts (Turkish)
[ci skip]

* New translations pcsx2-qt_en.ts (Ukrainian)
[ci skip]

* New translations pcsx2-qt_en.ts (Chinese Simplified)
[ci skip]

* New translations pcsx2-qt_en.ts (Chinese Traditional)
[ci skip]

* New translations pcsx2-qt_en.ts (Vietnamese)
[ci skip]

* New translations pcsx2-qt_en.ts (Portuguese, Brazilian)
[ci skip]

* New translations pcsx2-qt_en.ts (Indonesian)
[ci skip]

* New translations pcsx2-qt_en.ts (Persian)
[ci skip]

* New translations pcsx2-qt_en.ts (Croatian)
[ci skip]

* New translations pcsx2-qt_en.ts (Latvian)
[ci skip]

* New translations pcsx2-qt_en.ts (Hindi)
[ci skip]

* New translations pcsx2-qt_en.ts (Quechua)
[ci skip]

* New translations pcsx2-qt_en.ts (Guarani)
[ci skip]

* New translations pcsx2-qt_en.ts (Spanish, Latin America)
[ci skip]
2024-12-30 19:19:40 -05:00
GitHubProUser67 0a8c54514c [Soft-Float] - Implemented stop-gap Div rounding mode + implements softfloat on some extra obscure VU ops and fixes a denormals check on the checkDivideByZero method in the FPU.
Fixes:

- Final Fantasy X (fully playable)
- Klonoa 2

Partially Fixes:

- Mortal combat Shaloin Monks
- Gran Turismo 4 (game patch will be neceassary to skip Licence Test CRC check).
- Tourist Trophy (game patch will be neceassary to skip Licence Test CRC check).

The stop gap div measure is not yet enough to fully fix GT4/TouristTrophy (they will need different rounding modes per licences). Currently this is bridged on the Div Rounding Mode setting.
2024-12-27 19:45:14 +01:00
GitHubProUser67 5b94f53efc [Soft-Float] - Fixes MAC-OS compile error + moves the bitUtils methods to their respectives place.
I don't like the SIMD way of doing it, it can be slower and less practical to use (expensive casting).
2024-12-19 17:33:40 +01:00
GitHubProUser67 745e4746fc [Soft-Float] - Improves the PS2Float class by using a raw float to speed-up simple calculations.
This greatly improves performance while using Soft-Floats.
2024-12-07 22:47:19 +01:00
GitHubProUser67 8bc2ed9282 [Soft-Float] - Code review Part1.
Applies some recommendations from the review.

The next batch will come later.
2024-11-23 16:02:35 +01:00
GitHubProUser67 b0b65fa248 [Soft-Float] - Removes Div "special" normalization constant.
This broke stuff on very high floats, 0x40 is an un-biased value that can't be changed from IEEE standard.

We now 100% match the PS3's SPEs, but not the PS2 Div result (can be off by one bit). However, this is still way better than IEEE754.
2024-11-22 00:11:26 +01:00
GitHubProUser67 34753ae109 Arrange code style to accommodate requested changes.
More in line with the PCSX2 code-base.
2024-11-21 23:33:38 +01:00
GitHubProUser67 98e3df3cb9 [Soft-Float] - Implements fully accurate Mul operations.
Fixes : https://github.com/PCSX2/pcsx2/issues/5169

All the credits belongs to TellowKrinkle from the PCSX2 team.

Also removes a useless rounding towards zero in DoAdd.
2024-11-21 21:25:13 +01:00
GitHubProUser67 d5e50284ff [Soft-Float] - Removes "special" COP1 mode.
It isn't accurate at all.
2024-11-16 19:04:42 +01:00
GitHubProUser67 3fe4277555 [Soft-Float] - Fixes Operand checking for denormals Add/Sub operations. 2024-11-16 15:45:18 +01:00
GitHubProUser67 3bd88f7e8e [VUops] - Implements accurate SQRT/RSQRT + removal of TriAce hack.
Implements accurate SQRT options, also removes Tri-Ace hack, which isn't needed anymore on the interpreter.
2024-11-13 21:15:21 +01:00
GitHubProUser67 b09bfb0c02 [FPU] - Uses Soft-Float comparison.
More accurate approach to compare.
2024-11-13 18:19:37 +01:00
GitHubProUser67 b7f38061df [Soft-Float] - Fixes Tony Hawk Pro Skater 4 Mul issue.
The game sends some super low floats to the Mul unit.

On PS2, floats with exponent zero should return zero, but this is not the case in Mul, the multiplier can work with denormals internally.

I love when undocumented stuff is used by some games for their 3D engine ^^.
2024-11-13 16:09:02 +01:00
GitHubProUser67 de047eaa40 [Soft-Float] - Initial Interpreter Implementation of Ps2's floating point unit specification.
This Pull Request implements the first take ever on real Soft-Float support in PCSX2.

This work is a combination or several efforts and researches done prior.

Credits:

- https://www.gregorygaines.com/blog/emulating-ps2-floating-point-nums-ieee-754-diffs-part-1/

- https://github.com/GitHubProUser67/MultiServer3/blob/main/BackendServices/CastleLibrary/EmotionEngine.Emulator/Ps2Float.cs

- https://github.com/Goatman13/pcsx2/tree/accurate_int_add_sub

- PCSX2 Team for their help and support in this massive journey.

This pull request should be tested with every games requiring a clamping/rounding mode (cf: GameDatabase).

Currently, this PR fixes on the interpreters:

- https://github.com/PCSX2/pcsx2/issues/354

- https://github.com/PCSX2/pcsx2/issues/11507

- https://github.com/PCSX2/pcsx2/issues/10519

- https://github.com/PCSX2/pcsx2/issues/8068

- https://github.com/PCSX2/pcsx2/issues/7642

- https://github.com/PCSX2/pcsx2/issues/5257

This is important to note, that this implementation, while technically fixing Gran Turismo 4 and Klonoa 2, makes the games crash due to very high floats being passed in the emu code, and failing at some points later in the process. This has not yet been ironed-out.

Other than that, this sets the floor for Soft-Float in PCSX2, a long awaited contribution.
2024-11-12 21:48:10 +01:00
55 changed files with 134999 additions and 86240 deletions

View File

@ -28,6 +28,25 @@ static inline int _BitScanReverse(unsigned long* const Index, const unsigned lon
namespace Common
{
static constexpr s8 msb[256] = {
-1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
static constexpr s32 debruijn32[64] = {
32, 8, 17, -1, -1, 14, -1, -1, -1, 20, -1, -1, -1, 28, -1, 18,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 26, 25, 24,
4, 11, 23, 31, 3, 7, 10, 16, 22, 30, -1, -1, 2, 6, 13, 9,
-1, 15, -1, 21, -1, 29, 19, -1, -1, -1, -1, -1, 1, 27, 5, 12};
static constexpr s32 normalizeAmounts[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 24, 24, 24, 24, 24, 24, 24};
template <typename T>
static constexpr __fi bool IsAligned(T value, unsigned int alignment)
{
@ -84,6 +103,22 @@ namespace Common
// Perform our count leading zero.
return std::countl_zero(static_cast<u32>(n));
}
__fi static s32 clz(s32 x)
{
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
return debruijn32[(u32)x * 0x8c0b2891u >> 26];
}
__fi static s32 BitScanReverse8(s32 b)
{
return msb[b];
}
} // namespace Common
template <typename T>

View File

@ -48,6 +48,16 @@ AdvancedSettingsWidget::AdvancedSettingsWidget(SettingsWindow* dialog, QWidget*
connect(m_ui.vu0ClampMode, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) { setClampingMode(0, index); });
connect(m_ui.vu1ClampMode, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) { setClampingMode(1, index); });
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.eeSoftAddSub, "EmuCore/CPU/Recompiler", "fpuSoftAddSub", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.eeSoftMulDiv, "EmuCore/CPU/Recompiler", "fpuSoftMulDiv", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.eeSoftSqrt, "EmuCore/CPU/Recompiler", "fpuSoftSqrt", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.vu0SoftAddSub, "EmuCore/CPU/Recompiler", "vu0SoftAddSub", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.vu0SoftMulDiv, "EmuCore/CPU/Recompiler", "vu0SoftMulDiv", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.vu0SoftSqrt, "EmuCore/CPU/Recompiler", "vu0SoftSqrt", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.vu1SoftAddSub, "EmuCore/CPU/Recompiler", "vu1SoftAddSub", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.vu1SoftMulDiv, "EmuCore/CPU/Recompiler", "vu1SoftMulDiv", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.vu1SoftSqrt, "EmuCore/CPU/Recompiler", "vu1SoftSqrt", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.iopRecompiler, "EmuCore/CPU/Recompiler", "EnableIOP", true);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.gameFixes, "EmuCore", "EnableGameFixes", true);

View File

@ -34,7 +34,7 @@
<x>0</x>
<y>-447</y>
<width>790</width>
<height>1049</height>
<height>1283</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -94,10 +94,10 @@
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="eeDivRoundingLabel">
<item row="2" column="0">
<widget class="QLabel" name="eeClampLabel">
<property name="text">
<string extracomment="Rounding refers here to the mathematical term.">Division Rounding Mode:</string>
<string extracomment="Clamping: Forcing out of bounds things in bounds by changing them to the closest possible value. In this case, this refers to clamping large PS2 floating point values (which map to infinity or NaN in PCs' IEEE754 floats) to non-infinite ones.">Clamping Mode:</string>
</property>
</widget>
</item>
@ -125,38 +125,7 @@
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="eeClampLabel">
<property name="text">
<string extracomment="Clamping: Forcing out of bounds things in bounds by changing them to the closest possible value. In this case, this refers to clamping large PS2 floating point values (which map to infinity or NaN in PCs' IEEE754 floats) to non-infinite ones.">Clamping Mode:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="eeClampMode">
<item>
<property name="text">
<string comment="ClampMode">None</string>
</property>
</item>
<item>
<property name="text">
<string>Normal (Default)</string>
</property>
</item>
<item>
<property name="text">
<string extracomment="Sign: refers here to the mathematical meaning (plus/minus).">Extra + Preserve Sign</string>
</property>
</item>
<item>
<property name="text">
<string>Full</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0" colspan="2">
<item row="4" column="0" colspan="2">
<layout class="QGridLayout" name="eeSettingsMisc">
<item row="1" column="0">
<widget class="QCheckBox" name="eeWaitLoopDetection">
@ -208,6 +177,67 @@
</widget>
</item>
</layout>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="eeClampMode">
<item>
<property name="text">
<string comment="ClampMode">None</string>
</property>
</item>
<item>
<property name="text">
<string>Normal (Default)</string>
</property>
</item>
<item>
<property name="text">
<string extracomment="Sign: refers here to the mathematical meaning (plus/minus).">Extra + Preserve Sign</string>
</property>
</item>
<item>
<property name="text">
<string>Full</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="eeDivRoundingLabel">
<property name="text">
<string extracomment="Rounding refers here to the mathematical term.">Division Rounding Mode:</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QGroupBox" name="eeSoftFloat">
<property name="title">
<string>Software Float</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="1">
<widget class="QCheckBox" name="eeSoftMulDiv">
<property name="text">
<string>Multiplication/Division</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="eeSoftAddSub">
<property name="text">
<string>Addition/Subtraction</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="eeSoftSqrt">
<property name="text">
<string>Square Root</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
@ -218,7 +248,7 @@
<string extracomment="Vector Unit/VU: refers to two of PS2's processors. Do not translate the full text or do so as a comment. Leave the acronym as-is.">Vector Units (VU)</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="vu1RoundingLabel">
<property name="text">
<string>VU1 Rounding Mode:</string>
@ -249,7 +279,129 @@
</item>
</widget>
</item>
<item row="4" column="0" colspan="2">
<item row="4" column="0">
<widget class="QLabel" name="vu1ClampLabel">
<property name="text">
<string>VU1 Clamping Mode:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="vu0RoundingLabel">
<property name="text">
<string>VU0 Rounding Mode:</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QGroupBox" name="vu1SoftFloat">
<property name="title">
<string>VU1 Software Float</string>
</property>
<layout class="QGridLayout" name="gridLayout_8">
<item row="0" column="1">
<widget class="QCheckBox" name="vu1SoftMulDiv">
<property name="text">
<string>Multiplication/Division</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="vu1SoftAddSub">
<property name="text">
<string>Addition/Subtraction</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="vu1SoftSqrt">
<property name="text">
<string>Float Square Root</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="vu0SoftFloat">
<property name="title">
<string>VU0 Software Float</string>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="1">
<widget class="QCheckBox" name="vu0SoftMulDiv">
<property name="text">
<string>Multiplication/Division</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="vu0SoftAddSub">
<property name="text">
<string>Addition/Subtraction</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="vu0SoftSqrt">
<property name="text">
<string>Square Root</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="vu1RoundingMode">
<item>
<property name="text">
<string>Nearest</string>
</property>
</item>
<item>
<property name="text">
<string>Negative</string>
</property>
</item>
<item>
<property name="text">
<string>Positive</string>
</property>
</item>
<item>
<property name="text">
<string>Chop/Zero (Default)</string>
</property>
</item>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="vu0ClampMode">
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>Normal (Default)</string>
</property>
</item>
<item>
<property name="text">
<string>Extra</string>
</property>
</item>
<item>
<property name="text">
<string>Extra + Preserve Sign</string>
</property>
</item>
</widget>
</item>
<item row="6" column="0" colspan="2">
<layout class="QGridLayout" name="vuSettingsLayout">
<item row="1" column="0">
<widget class="QCheckBox" name="vuFlagHack">
@ -281,30 +433,6 @@
</item>
</layout>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="vu0ClampMode">
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>Normal (Default)</string>
</property>
</item>
<item>
<property name="text">
<string>Extra</string>
</property>
</item>
<item>
<property name="text">
<string>Extra + Preserve Sign</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="vu0ClampLabel">
<property name="text">
@ -312,45 +440,7 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="vu0RoundingLabel">
<property name="text">
<string>VU0 Rounding Mode:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="vu1ClampLabel">
<property name="text">
<string>VU1 Clamping Mode:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="vu1RoundingMode">
<item>
<property name="text">
<string>Nearest</string>
</property>
</item>
<item>
<property name="text">
<string>Negative</string>
</property>
</item>
<item>
<property name="text">
<string>Positive</string>
</property>
</item>
<item>
<property name="text">
<string>Chop/Zero (Default)</string>
</property>
</item>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QComboBox" name="vu1ClampMode">
<item>
<property name="text">

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -93,6 +93,7 @@ set(pcsx2Sources
MTGS.cpp
MTVU.cpp
Patch.cpp
PS2Float.cpp
Pcsx2Config.cpp
PerformanceMetrics.cpp
PrecompiledHeader.cpp
@ -173,6 +174,7 @@ set(pcsx2Headers
MTVU.h
Memory.h
MemoryTypes.h
PS2Float.h
Patch.h
PerformanceMetrics.h
PrecompiledHeader.h

View File

@ -598,17 +598,32 @@ struct Pcsx2Config
vu0ExtraOverflow : 1,
vu0SignOverflow : 1,
vu0Underflow : 1;
bool
vu0SoftAddSub : 1,
vu0SoftMulDiv : 1,
vu0SoftSqrt : 1;
bool
vu1Overflow : 1,
vu1ExtraOverflow : 1,
vu1SignOverflow : 1,
vu1Underflow : 1;
bool
vu1SoftAddSub : 1,
vu1SoftMulDiv : 1,
vu1SoftSqrt : 1;
bool
fpuOverflow : 1,
fpuExtraOverflow : 1,
fpuFullMode : 1;
bool
fpuSoftAddSub : 1,
fpuSoftMulDiv : 1,
fpuSoftSqrt : 1;
bool
EnableEECache : 1;
@ -1428,11 +1443,19 @@ namespace EmuFolders
#define CHECK_VU_SIGN_OVERFLOW(vunum) (((vunum) == 0) ? EmuConfig.Cpu.Recompiler.vu0SignOverflow : EmuConfig.Cpu.Recompiler.vu1SignOverflow)
#define CHECK_VU_UNDERFLOW(vunum) (((vunum) == 0) ? EmuConfig.Cpu.Recompiler.vu0Underflow : EmuConfig.Cpu.Recompiler.vu1Underflow)
#define CHECK_VU_SOFT_ADDSUB(vunum) (((vunum) == 0) ? EmuConfig.Cpu.Recompiler.vu0SoftAddSub : EmuConfig.Cpu.Recompiler.vu1SoftAddSub)
#define CHECK_VU_SOFT_MULDIV(vunum) (((vunum) == 0) ? EmuConfig.Cpu.Recompiler.vu0SoftMulDiv : EmuConfig.Cpu.Recompiler.vu1SoftMulDiv)
#define CHECK_VU_SOFT_SQRT(vunum) (((vunum) == 0) ? EmuConfig.Cpu.Recompiler.vu0SoftSqrt : EmuConfig.Cpu.Recompiler.vu1SoftSqrt)
#define CHECK_FPU_OVERFLOW (EmuConfig.Cpu.Recompiler.fpuOverflow)
#define CHECK_FPU_EXTRA_OVERFLOW (EmuConfig.Cpu.Recompiler.fpuExtraOverflow) // If enabled, Operands are checked for infinities before being used in the FPU recs
#define CHECK_FPU_EXTRA_FLAGS 1 // Always enabled now // Sets D/I flags on FPU instructions
#define CHECK_FPU_FULL (EmuConfig.Cpu.Recompiler.fpuFullMode)
#define CHECK_FPU_SOFT_ADDSUB (EmuConfig.Cpu.Recompiler.fpuSoftAddSub)
#define CHECK_FPU_SOFT_MULDIV (EmuConfig.Cpu.Recompiler.fpuSoftMulDiv)
#define CHECK_FPU_SOFT_SQRT (EmuConfig.Cpu.Recompiler.fpuSoftSqrt)
//------------ EE Recompiler defines - Comment to disable a recompiler ---------------
#define SHIFT_RECOMPILE // Speed majorly reduced if disabled

View File

@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0+
#include "Common.h"
#include "PS2Float.h"
#include <cmath>
// Helper Macros
@ -63,28 +63,57 @@
// If we have an infinity value, then Overflow has occured.
bool checkOverflow(u32& xReg, u32 cFlagsToSet)
{
if ((xReg & ~0x80000000) == PosInfinity) {
/*Console.Warning( "FPU OVERFLOW!: Changing to +/-Fmax!!!!!!!!!!!!\n" );*/
xReg = (xReg & 0x80000000) | posFmax;
_ContVal_ |= (cFlagsToSet);
return true;
if (CHECK_FPU_SOFT_ADDSUB || CHECK_FPU_SOFT_MULDIV || CHECK_FPU_SOFT_SQRT)
{
if (xReg == PS2Float::MAX_FLOATING_POINT_VALUE || xReg == PS2Float::MIN_FLOATING_POINT_VALUE)
{
_ContVal_ |= (cFlagsToSet);
return true;
}
else if (cFlagsToSet & FPUflagO)
_ContVal_ &= ~FPUflagO;
}
else
{
if ((xReg & ~0x80000000) == PosInfinity)
{
/*Console.Warning( "FPU OVERFLOW!: Changing to +/-Fmax!!!!!!!!!!!!\n" );*/
xReg = (xReg & 0x80000000) | posFmax;
_ContVal_ |= (cFlagsToSet);
return true;
}
else if (cFlagsToSet & FPUflagO)
_ContVal_ &= ~FPUflagO;
}
else if (cFlagsToSet & FPUflagO)
_ContVal_ &= ~FPUflagO;
return false;
}
// If we have a denormal value, then Underflow has occured.
bool checkUnderflow(u32& xReg, u32 cFlagsToSet) {
if ( ( (xReg & 0x7F800000) == 0 ) && ( (xReg & 0x007FFFFF) != 0 ) ) {
/*Console.Warning( "FPU UNDERFLOW!: Changing to +/-0!!!!!!!!!!!!\n" );*/
xReg &= 0x80000000;
_ContVal_ |= (cFlagsToSet);
return true;
if (CHECK_FPU_SOFT_ADDSUB || CHECK_FPU_SOFT_MULDIV || CHECK_FPU_SOFT_SQRT)
{
if (PS2Float(xReg).IsDenormalized())
{
_ContVal_ |= (cFlagsToSet);
return true;
}
else if (cFlagsToSet & FPUflagU)
_ContVal_ &= ~FPUflagU;
}
else
{
if (((xReg & 0x7F800000) == 0) && ((xReg & 0x007FFFFF) != 0))
{
/*Console.Warning( "FPU UNDERFLOW!: Changing to +/-0!!!!!!!!!!!!\n" );*/
xReg &= 0x80000000;
_ContVal_ |= (cFlagsToSet);
return true;
}
else if (cFlagsToSet & FPUflagU)
_ContVal_ &= ~FPUflagU;
}
else if (cFlagsToSet & FPUflagU)
_ContVal_ &= ~FPUflagU;
return false;
}
@ -106,9 +135,41 @@ __fi u32 fp_min(u32 a, u32 b)
*/
bool checkDivideByZero(u32& xReg, u32 yDivisorReg, u32 zDividendReg, u32 cFlagsToSet1, u32 cFlagsToSet2) {
if ( (yDivisorReg & 0x7F800000) == 0 ) {
_ContVal_ |= ( (zDividendReg & 0x7F800000) == 0 ) ? cFlagsToSet2 : cFlagsToSet1;
xReg = ( (yDivisorReg ^ zDividendReg) & 0x80000000 ) | posFmax;
if (CHECK_FPU_SOFT_ADDSUB || CHECK_FPU_SOFT_MULDIV || CHECK_FPU_SOFT_SQRT)
{
PS2Float yMatrix = PS2Float(yDivisorReg);
PS2Float zMatrix = PS2Float(zDividendReg);
// Check Final Fantasy X controls and Klonoa 2 to test this code, they send a bunch of denormals which are often hack-fixed on the game code.
if (zMatrix.IsDenormalized() || yMatrix.IsDenormalized())
{
_ContVal_ |= 0;
xReg = PS2Float::SolveDivisionDenormalizedOperation(zMatrix, yMatrix).raw;
return true;
}
if (zMatrix.IsZero())
{
bool dividendZero = yMatrix.IsZero();
_ContVal_ |= dividendZero ? cFlagsToSet2 : cFlagsToSet1;
bool IsSigned = zMatrix.Sign() ^ yMatrix.Sign();
if (dividendZero)
xReg = IsSigned ? PS2Float::MIN_FLOATING_POINT_VALUE : PS2Float::MAX_FLOATING_POINT_VALUE;
else
{
xReg = PS2Float(IsSigned, 0, 0).raw;
}
return true;
}
}
else if ((yDivisorReg & 0x7F800000) == 0)
{
_ContVal_ |= ((zDividendReg & 0x7F800000) == 0) ? cFlagsToSet2 : cFlagsToSet1;
xReg = ((yDivisorReg ^ zDividendReg) & 0x80000000) | posFmax;
return true;
}
@ -125,25 +186,6 @@ bool checkDivideByZero(u32& xReg, u32 yDivisorReg, u32 zDividendReg, u32 cFlagsT
_ContVal_ &= ~( cFlags ) ; \
}
#ifdef comparePrecision
// This compare discards the least-significant bit(s) in order to solve some rounding issues.
#define C_cond_S(cond) { \
FPRreg tempA, tempB; \
tempA.UL = _FsValUl_ & comparePrecision; \
tempB.UL = _FtValUl_ & comparePrecision; \
_ContVal_ = ( ( tempA.f ) cond ( tempB.f ) ) ? \
( _ContVal_ | FPUflagC ) : \
( _ContVal_ & ~FPUflagC ); \
}
#else
// Used for Comparing; This compares if the floats are exactly the same.
#define C_cond_S(cond) { \
_ContVal_ = ( fpuDouble(_FsValUl_) cond fpuDouble(_FtValUl_) ) ? \
( _ContVal_ | FPUflagC ) : \
( _ContVal_ & ~FPUflagC ); \
}
#endif
// Conditional Branch
#define BC1(cond) \
if ( ( _ContVal_ & FPUflagC ) cond 0 ) { \
@ -182,19 +224,94 @@ float fpuDouble(u32 f)
}
}
static __fi u32 fpuAccurateAdd(u32 a, u32 b)
{
if (CHECK_FPU_SOFT_ADDSUB) return PS2Float(a).Add(PS2Float(b)).raw;
return std::bit_cast<u32>(fpuDouble(a) + fpuDouble(b));
}
static __fi u32 fpuAccurateSub(u32 a, u32 b)
{
if (CHECK_FPU_SOFT_ADDSUB) return PS2Float(a).Sub(PS2Float(b)).raw;
return std::bit_cast<u32>(fpuDouble(a) - fpuDouble(b));
}
static __fi u32 fpuAccurateMul(u32 a, u32 b)
{
if (CHECK_FPU_SOFT_MULDIV) return PS2Float(a).Mul(PS2Float(b)).raw;
return std::bit_cast<u32>(fpuDouble(a) * fpuDouble(b));
}
static __fi u32 fpuAccurateDiv(u32 a, u32 b)
{
if (CHECK_FPU_SOFT_MULDIV) return PS2Float(a).Div(PS2Float(b)).raw;
return std::bit_cast<u32>(fpuDouble(a) / fpuDouble(b));
}
static __fi s32 double_to_int(double value)
{
if (value >= 2147483647.0)
return 2147483647LL;
if (value <= -2147483648.0)
return -2147483648LL;
return value;
}
static __fi void C_cond_S(uint8_t mode)
{
switch (mode)
{
case 0: // ==
if (CHECK_FPU_SOFT_ADDSUB || CHECK_FPU_SOFT_MULDIV || CHECK_FPU_SOFT_SQRT)
{
_ContVal_ = (PS2Float(_FsValUl_).CompareTo(PS2Float(_FtValUl_)) == 0) ? (_ContVal_ | FPUflagC) : (_ContVal_ & ~FPUflagC);
}
else
{
_ContVal_ = (fpuDouble(_FsValUl_) == fpuDouble(_FtValUl_)) ? (_ContVal_ | FPUflagC) : (_ContVal_ & ~FPUflagC);
}
break;
case 1: // <=
if (CHECK_FPU_SOFT_ADDSUB || CHECK_FPU_SOFT_MULDIV || CHECK_FPU_SOFT_SQRT)
{
int32_t cmpResult = PS2Float(_FsValUl_).CompareTo(PS2Float(_FtValUl_));
_ContVal_ = (cmpResult == 0 || cmpResult == -1) ? (_ContVal_ | FPUflagC) : (_ContVal_ & ~FPUflagC);
}
else
{
_ContVal_ = (fpuDouble(_FsValUl_) <= fpuDouble(_FtValUl_)) ? (_ContVal_ | FPUflagC) : (_ContVal_ & ~FPUflagC);
}
break;
case 2: // <
if (CHECK_FPU_SOFT_ADDSUB || CHECK_FPU_SOFT_MULDIV || CHECK_FPU_SOFT_SQRT)
{
_ContVal_ = (PS2Float(_FsValUl_).CompareTo(PS2Float(_FtValUl_)) == -1) ? (_ContVal_ | FPUflagC) : (_ContVal_ & ~FPUflagC);
}
else
{
_ContVal_ = (fpuDouble(_FsValUl_) < fpuDouble(_FtValUl_)) ? (_ContVal_ | FPUflagC) : (_ContVal_ & ~FPUflagC);
}
break;
}
}
void ABS_S() {
_FdValUl_ = _FsValUl_ & 0x7fffffff;
clearFPUFlags( FPUflagO | FPUflagU );
}
void ADD_S() {
_FdValf_ = fpuDouble( _FsValUl_ ) + fpuDouble( _FtValUl_ );
_FdValUl_ = fpuAccurateAdd(_FsValUl_, _FtValUl_);
if (checkOverflow( _FdValUl_, FPUflagO | FPUflagSO)) return;
checkUnderflow( _FdValUl_, FPUflagU | FPUflagSU);
}
void ADDA_S() {
_FAValf_ = fpuDouble( _FsValUl_ ) + fpuDouble( _FtValUl_ );
_FAValUl_ = fpuAccurateAdd(_FsValUl_, _FtValUl_);
if (checkOverflow( _FAValUl_, FPUflagO | FPUflagSO)) return;
checkUnderflow( _FAValUl_, FPUflagU | FPUflagSU);
}
@ -216,7 +333,7 @@ void BC1TL() {
}
void C_EQ() {
C_cond_S(==);
C_cond_S(0);
}
void C_F() {
@ -224,11 +341,11 @@ void C_F() {
}
void C_LE() {
C_cond_S(<=);
C_cond_S(1);
}
void C_LT() {
C_cond_S(<);
C_cond_S(2);
}
void CFC1() {
@ -253,14 +370,30 @@ void CVT_S() {
}
void CVT_W() {
if ( ( _FsValUl_ & 0x7F800000 ) <= 0x4E800000 ) { _FdValSl_ = (s32)_FsValf_; }
else if ( ( _FsValUl_ & 0x80000000 ) == 0 ) { _FdValUl_ = 0x7fffffff; }
else { _FdValUl_ = 0x80000000; }
if (CHECK_FPU_SOFT_ADDSUB || CHECK_FPU_SOFT_MULDIV || CHECK_FPU_SOFT_SQRT)
{
_FdValSl_ = double_to_int(PS2Float(_FsValUl_).ToDouble());
}
else
{
if ((_FsValUl_ & 0x7F800000) <= 0x4E800000)
{
_FdValSl_ = (s32)_FsValf_;
}
else if ((_FsValUl_ & 0x80000000) == 0)
{
_FdValUl_ = 0x7fffffff;
}
else
{
_FdValUl_ = 0x80000000;
}
}
}
void DIV_S() {
if (checkDivideByZero( _FdValUl_, _FtValUl_, _FsValUl_, FPUflagD | FPUflagSD, FPUflagI | FPUflagSI)) return;
_FdValf_ = fpuDouble( _FsValUl_ ) / fpuDouble( _FtValUl_ );
_FdValUl_ = fpuAccurateDiv(_FsValUl_, _FtValUl_);
if (checkOverflow( _FdValUl_, 0)) return;
checkUnderflow( _FdValUl_, 0);
}
@ -270,15 +403,13 @@ void DIV_S() {
method provides a similar outcome and is faster. (cottonvibes)
*/
void MADD_S() {
FPRreg temp;
temp.f = fpuDouble( _FsValUl_ ) * fpuDouble( _FtValUl_ );
_FdValf_ = fpuDouble( _FAValUl_ ) + fpuDouble( temp.UL );
_FdValUl_ = fpuAccurateAdd(_FAValUl_, fpuAccurateMul(_FsValUl_, _FtValUl_));
if (checkOverflow( _FdValUl_, FPUflagO | FPUflagSO)) return;
checkUnderflow( _FdValUl_, FPUflagU | FPUflagSU);
}
void MADDA_S() {
_FAValf_ += fpuDouble( _FsValUl_ ) * fpuDouble( _FtValUl_ );
_FAValUl_ = fpuAccurateAdd(_FAValUl_, fpuAccurateMul(_FsValUl_, _FtValUl_));
if (checkOverflow( _FAValUl_, FPUflagO | FPUflagSO)) return;
checkUnderflow( _FAValUl_, FPUflagU | FPUflagSU);
}
@ -303,15 +434,13 @@ void MOV_S() {
}
void MSUB_S() {
FPRreg temp;
temp.f = fpuDouble( _FsValUl_ ) * fpuDouble( _FtValUl_ );
_FdValf_ = fpuDouble( _FAValUl_ ) - fpuDouble( temp.UL );
_FdValUl_ = fpuAccurateSub(_FAValUl_, fpuAccurateMul(_FsValUl_, _FtValUl_));
if (checkOverflow( _FdValUl_, FPUflagO | FPUflagSO)) return;
checkUnderflow( _FdValUl_, FPUflagU | FPUflagSU);
}
void MSUBA_S() {
_FAValf_ -= fpuDouble( _FsValUl_ ) * fpuDouble( _FtValUl_ );
_FAValUl_ = fpuAccurateSub(_FAValUl_, fpuAccurateMul(_FsValUl_, _FtValUl_));
if (checkOverflow( _FAValUl_, FPUflagO | FPUflagSO)) return;
checkUnderflow( _FAValUl_, FPUflagU | FPUflagSU);
}
@ -321,13 +450,13 @@ void MTC1() {
}
void MUL_S() {
_FdValf_ = fpuDouble( _FsValUl_ ) * fpuDouble( _FtValUl_ );
_FdValUl_ = fpuAccurateMul(_FsValUl_, _FtValUl_);
if (checkOverflow( _FdValUl_, FPUflagO | FPUflagSO)) return;
checkUnderflow( _FdValUl_, FPUflagU | FPUflagSU);
}
void MULA_S() {
_FAValf_ = fpuDouble( _FsValUl_ ) * fpuDouble( _FtValUl_ );
_FAValUl_ = fpuAccurateMul(_FsValUl_, _FtValUl_);
if (checkOverflow( _FAValUl_, FPUflagO | FPUflagSO)) return;
checkUnderflow( _FAValUl_, FPUflagU | FPUflagSU);
}
@ -341,17 +470,45 @@ void RSQRT_S() {
FPRreg temp;
clearFPUFlags(FPUflagD | FPUflagI);
if ( ( _FtValUl_ & 0x7F800000 ) == 0 ) { // Ft is zero (Denormals are Zero)
_ContVal_ |= FPUflagD | FPUflagSD;
_FdValUl_ = ( _FtValUl_ & 0x80000000 ) | posFmax;
return;
if (CHECK_FPU_SOFT_SQRT)
{
PS2Float value = PS2Float(_FtValUl_);
if (value.IsDenormalized())
{
_ContVal_ |= FPUflagD | FPUflagSD;
_FdValUl_ = value.Sign() ? PS2Float::MIN_FLOATING_POINT_VALUE : PS2Float::MAX_FLOATING_POINT_VALUE;
return;
}
else if (_FtValUl_ & 0x80000000) // Ft is negative
{
_ContVal_ |= FPUflagI | FPUflagSI;
_FdValUl_ = PS2Float(_FsValUl_).Rsqrt(PS2Float(value.Abs())).raw;
}
else // Ft is positive and not zero
{
_FdValUl_ = PS2Float(_FsValUl_).Rsqrt(value).raw;
}
}
else if ( _FtValUl_ & 0x80000000 ) { // Ft is negative
_ContVal_ |= FPUflagI | FPUflagSI;
temp.f = sqrt( fabs( fpuDouble( _FtValUl_ ) ) );
_FdValf_ = fpuDouble( _FsValUl_ ) / fpuDouble( temp.UL );
else
{
if ((_FtValUl_ & 0x7F800000) == 0) // Ft is zero (Denormals are Zero)
{
_ContVal_ |= FPUflagD | FPUflagSD;
_FdValUl_ = (_FtValUl_ & 0x80000000) | posFmax;
return;
}
else if (_FtValUl_ & 0x80000000) // Ft is negative
{
_ContVal_ |= FPUflagI | FPUflagSI;
temp.f = sqrt(fabs(fpuDouble(_FtValUl_)));
_FdValf_ = fpuDouble(_FsValUl_) / fpuDouble(temp.UL);
}
else // Ft is positive and not zero
{
_FdValf_ = fpuDouble(_FsValUl_) / sqrt(fpuDouble(_FtValUl_));
}
}
else { _FdValf_ = fpuDouble( _FsValUl_ ) / sqrt( fpuDouble( _FtValUl_ ) ); } // Ft is positive and not zero
if (checkOverflow( _FdValUl_, 0)) return;
checkUnderflow( _FdValUl_, 0);
@ -360,23 +517,40 @@ void RSQRT_S() {
void SQRT_S() {
clearFPUFlags(FPUflagI | FPUflagD);
if ( ( _FtValUl_ & 0x7F800000 ) == 0 ) // If Ft = +/-0
_FdValUl_ = _FtValUl_ & 0x80000000;// result is 0
else if ( _FtValUl_ & 0x80000000 ) { // If Ft is Negative
_ContVal_ |= FPUflagI | FPUflagSI;
_FdValf_ = sqrt( fabs( fpuDouble( _FtValUl_ ) ) );
} else
_FdValf_ = sqrt( fpuDouble( _FtValUl_ ) ); // If Ft is Positive
if (CHECK_FPU_SOFT_SQRT)
{
PS2Float value = PS2Float(_FtValUl_);
if (_FtValUl_ & 0x80000000) // If Ft is Negative
{
_ContVal_ |= FPUflagI | FPUflagSI;
_FdValUl_ = PS2Float(value.Abs()).Sqrt().raw;
}
else
_FdValUl_ = value.Sqrt().raw; // If Ft is Positive
}
else
{
if ((_FtValUl_ & 0x7F800000) == 0) // If Ft = +/-0
_FdValUl_ = _FtValUl_ & 0x80000000; // result is 0
else if (_FtValUl_ & 0x80000000) // If Ft is Negative
{
_ContVal_ |= FPUflagI | FPUflagSI;
_FdValf_ = sqrt(fabs(fpuDouble(_FtValUl_)));
}
else
_FdValf_ = sqrt(fpuDouble(_FtValUl_)); // If Ft is Positive
}
}
void SUB_S() {
_FdValf_ = fpuDouble( _FsValUl_ ) - fpuDouble( _FtValUl_ );
_FdValUl_ = fpuAccurateSub(_FsValUl_, _FtValUl_);
if (checkOverflow( _FdValUl_, FPUflagO | FPUflagSO)) return;
checkUnderflow( _FdValUl_, FPUflagU | FPUflagSU);
}
void SUBA_S() {
_FAValf_ = fpuDouble( _FsValUl_ ) - fpuDouble( _FtValUl_ );
_FAValUl_ = fpuAccurateSub(_FsValUl_, _FtValUl_);
if (checkOverflow( _FAValUl_, FPUflagO | FPUflagSO)) return;
checkUnderflow( _FAValUl_, FPUflagU | FPUflagSU);
}

759
pcsx2/PS2Float.cpp Normal file
View File

@ -0,0 +1,759 @@
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
// SPDX-License-Identifier: GPL-3.0+
#include <stdexcept>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <iostream>
#include <bit>
#include "common/Pcsx2Defs.h"
#include "common/BitUtils.h"
#include "PS2Float.h"
#include "Common.h"
//****************************************************************
// Booth Multiplier
//****************************************************************
PS2Float::BoothRecode PS2Float::Booth(u32 a, u32 b, u32 bit)
{
u32 test = (bit ? b >> (bit * 2 - 1) : b << 1) & 7;
a <<= (bit * 2);
a += (test == 3 || test == 4) ? a : 0;
u32 neg = (test >= 4 && test <= 6) ? ~0u : 0;
u32 pos = 1 << (bit * 2);
a ^= (neg & -pos);
a &= (test >= 1 && test <= 6) ? ~0u : 0;
return {a, neg & pos};
}
PS2Float::AddResult PS2Float::Add3(u32 a, u32 b, u32 c)
{
u32 u = a ^ b;
return {u ^ c, ((u & c) | (a & b)) << 1};
}
u64 PS2Float::MulMantissa(u32 a, u32 b)
{
u64 full = static_cast<u64>(a) * static_cast<u64>(b);
BoothRecode b0 = Booth(a, b, 0);
BoothRecode b1 = Booth(a, b, 1);
BoothRecode b2 = Booth(a, b, 2);
BoothRecode b3 = Booth(a, b, 3);
BoothRecode b4 = Booth(a, b, 4);
BoothRecode b5 = Booth(a, b, 5);
BoothRecode b6 = Booth(a, b, 6);
BoothRecode b7 = Booth(a, b, 7);
// First cycle
AddResult t0 = Add3(b1.data, b2.data, b3.data);
AddResult t1 = Add3(b4.data & ~0x7ffu, b5.data & ~0xfffu, b6.data);
// A few adds get skipped, squeeze them back in
t1.hi |= b6.negate | (b5.data & 0x800);
b7.data |= (b5.data & 0x400) + b5.negate;
// Second cycle
AddResult t2 = Add3(b0.data, t0.lo, t0.hi);
AddResult t3 = Add3(b7.data, t1.lo, t1.hi);
// Third cycle
AddResult t4 = Add3(t2.hi, t3.lo, t3.hi);
// Fourth cycle
AddResult t5 = Add3(t2.lo, t4.lo, t4.hi);
// Discard bits and sum
t5.hi += b7.negate;
t5.lo &= ~0x7fffu;
t5.hi &= ~0x7fffu;
u32 ps2lo = t5.lo + t5.hi;
return full - ((ps2lo ^ full) & 0x8000);
}
//****************************************************************
// Float Processor
//****************************************************************
PS2Float::PS2Float(s32 value) { raw = (u32)value; }
PS2Float::PS2Float(u32 value) { raw = value; }
PS2Float::PS2Float(float value) { raw = std::bit_cast<u32>(value); }
PS2Float::PS2Float(bool sign, u8 exponent, u32 mantissa)
{
raw = 0;
raw |= (sign ? 1u : 0u) << 31;
raw |= (u32)(exponent << 23);
raw |= mantissa & 0x7FFFFF;
}
PS2Float PS2Float::Max()
{
return PS2Float(MAX_FLOATING_POINT_VALUE);
}
PS2Float PS2Float::Min()
{
return PS2Float(MIN_FLOATING_POINT_VALUE);
}
PS2Float PS2Float::One()
{
return PS2Float(ONE);
}
PS2Float PS2Float::MinOne()
{
return PS2Float(MIN_ONE);
}
PS2Float PS2Float::Add(PS2Float addend)
{
if (IsDenormalized() || addend.IsDenormalized())
return SolveAddSubDenormalizedOperation(*this, addend, true);
if (IsAbnormal() && addend.IsAbnormal())
return SolveAbnormalAdditionOrSubtractionOperation(*this, addend, true);
u32 a = raw;
u32 b = addend.raw;
//exponent difference
s32 exp_diff = ((a >> 23) & 0xFF) - ((b >> 23) & 0xFF);
//diff = 25 .. 255 , expt < expd
if (exp_diff >= 25)
{
b = b & SIGNMASK;
}
//diff = 1 .. 24, expt < expd
else if (exp_diff > 0)
{
exp_diff = exp_diff - 1;
b = (MIN_FLOATING_POINT_VALUE << exp_diff) & b;
}
//diff = -255 .. -25, expd < expt
else if (exp_diff <= -25)
{
a = a & SIGNMASK;
}
//diff = -24 .. -1 , expd < expt
else if (exp_diff < 0)
{
exp_diff = -exp_diff;
exp_diff = exp_diff - 1;
a = a & (MIN_FLOATING_POINT_VALUE << exp_diff);
}
return PS2Float(a).DoAdd(PS2Float(b));
}
PS2Float PS2Float::Sub(PS2Float subtrahend)
{
if (IsDenormalized() || subtrahend.IsDenormalized())
return SolveAddSubDenormalizedOperation(*this, subtrahend, false);
if (IsAbnormal() && subtrahend.IsAbnormal())
return SolveAbnormalAdditionOrSubtractionOperation(*this, subtrahend, false);
u32 a = raw;
u32 b = subtrahend.raw;
//exponent difference
s32 exp_diff = ((a >> 23) & 0xFF) - ((b >> 23) & 0xFF);
//diff = 25 .. 255 , expt < expd
if (exp_diff >= 25)
{
b = b & SIGNMASK;
}
//diff = 1 .. 24, expt < expd
else if (exp_diff > 0)
{
exp_diff = exp_diff - 1;
b = (MIN_FLOATING_POINT_VALUE << exp_diff) & b;
}
//diff = -255 .. -25, expd < expt
else if (exp_diff <= -25)
{
a = a & SIGNMASK;
}
//diff = -24 .. -1 , expd < expt
else if (exp_diff < 0)
{
exp_diff = -exp_diff;
exp_diff = exp_diff - 1;
a = a & (MIN_FLOATING_POINT_VALUE << exp_diff);
}
return PS2Float(a).DoAdd(PS2Float(b).Negate());
}
PS2Float PS2Float::Mul(PS2Float mulend)
{
if (IsDenormalized() || mulend.IsDenormalized())
return SolveMultiplicationDenormalizedOperation(*this, mulend);
if (IsAbnormal() && mulend.IsAbnormal())
return SolveAbnormalMultiplicationOrDivisionOperation(*this, mulend, true);
if (IsZero() || mulend.IsZero())
return PS2Float(DetermineMultiplicationDivisionOperationSign(*this, mulend), 0, 0);
return DoMul(mulend);
}
PS2Float PS2Float::Div(PS2Float divend)
{
if (IsDenormalized() || divend.IsDenormalized())
return SolveDivisionDenormalizedOperation(*this, divend);
if (IsAbnormal() && divend.IsAbnormal())
return SolveAbnormalMultiplicationOrDivisionOperation(*this, divend, false);
if (IsZero())
return PS2Float(DetermineMultiplicationDivisionOperationSign(*this, divend), 0, 0);
else if (divend.IsZero())
return DetermineMultiplicationDivisionOperationSign(*this, divend) ? Min() : Max();
return DoDiv(divend);
}
// Rounding can be slightly off: (PS2: rsqrt(0x7FFFFFF0) -> 0x5FB504ED | SoftFloat/IEEE754 rsqrt(0x7FFFFFF0) -> 0x5FB504EE).
PS2Float PS2Float::Sqrt()
{
s32 t;
s32 s = 0;
s32 q = 0;
u32 r = 0x01000000; /* r = moving bit from right to left */
if (IsDenormalized())
return PS2Float(0);
// PS2 only takes positive numbers for SQRT, and convert if necessary.
s32 ix = (s32)PS2Float(false, Exponent(), Mantissa()).raw;
/* extract mantissa and unbias exponent */
s32 m = (ix >> 23) - BIAS;
ix = (ix & 0x007FFFFF) | 0x00800000;
if ((m & 1) == 1)
{
/* odd m, double x to make it even */
ix += ix;
}
m >>= 1; /* m = [m/2] */
/* generate sqrt(x) bit by bit */
ix += ix;
while (r != 0)
{
t = s + (s32)(r);
if (t <= ix)
{
s = t + (s32)(r);
ix -= t;
q += (s32)(r);
}
ix += ix;
r >>= 1;
}
/* use floating add to find out rounding direction */
if (ix != 0)
{
q += q & 1;
}
ix = (q >> 1) + 0x3F000000;
ix += m << 23;
return PS2Float((u32)(ix));
}
PS2Float PS2Float::Rsqrt(PS2Float other)
{
return Div(other.Sqrt());
}
PS2Float PS2Float::Pow(s32 exponent)
{
PS2Float result = PS2Float::One(); // Start with 1, since any number raised to the power of 0 is 1
if (exponent != 0)
{
s32 exp = abs(exponent);
for (s32 i = 0; i < exp; i++)
{
result = result.Mul(*this);
}
}
if (exponent < 0)
return PS2Float::One().Div(result);
else
return result;
}
bool PS2Float::IsDenormalized()
{
return Exponent() == 0;
}
bool PS2Float::IsAbnormal()
{
u32 val = raw;
return val == MAX_FLOATING_POINT_VALUE || val == MIN_FLOATING_POINT_VALUE ||
val == POSITIVE_INFINITY_VALUE || val == NEGATIVE_INFINITY_VALUE;
}
bool PS2Float::IsZero()
{
return Abs() == 0;
}
u32 PS2Float::Abs()
{
return (raw & MAX_FLOATING_POINT_VALUE);
}
PS2Float PS2Float::Negate()
{
return PS2Float(raw ^ 0x80000000);
}
s32 PS2Float::CompareTo(PS2Float other)
{
s32 selfTwoComplementVal = (s32)Abs();
if (Sign())
selfTwoComplementVal = -selfTwoComplementVal;
s32 otherTwoComplementVal = (s32)other.Abs();
if (other.Sign())
otherTwoComplementVal = -otherTwoComplementVal;
if (selfTwoComplementVal < otherTwoComplementVal)
return -1;
else if (selfTwoComplementVal == otherTwoComplementVal)
return 0;
else
return 1;
}
s32 PS2Float::CompareOperand(PS2Float other)
{
s32 selfTwoComplementVal = (s32)Abs();
s32 otherTwoComplementVal = (s32)other.Abs();
if (selfTwoComplementVal < otherTwoComplementVal)
return -1;
else if (selfTwoComplementVal == otherTwoComplementVal)
return 0;
else
return 1;
}
double PS2Float::ToDouble()
{
return std::bit_cast<double>(((u64)Sign() << 63) | ((((u64)Exponent() - BIAS) + 1023ULL) << 52) | ((u64)Mantissa() << 29));
}
std::string PS2Float::ToString()
{
double res = ToDouble();
u32 value = raw;
std::ostringstream oss;
oss << std::fixed << std::setprecision(6);
if (IsDenormalized())
{
oss << "Denormalized(" << res << ")";
}
else if (value == MAX_FLOATING_POINT_VALUE)
{
oss << "Fmax(" << res << ")";
}
else if (value == MIN_FLOATING_POINT_VALUE)
{
oss << "-Fmax(" << res << ")";
}
else if (value == POSITIVE_INFINITY_VALUE)
{
oss << "Inf(" << res << ")";
}
else if (value == NEGATIVE_INFINITY_VALUE)
{
oss << "-Inf(" << res << ")";
}
else
{
oss << "PS2Float(" << res << ")";
}
return oss.str();
}
PS2Float PS2Float::DoAdd(PS2Float other)
{
const u8 roundingMultiplier = 6;
u8 selfExponent = Exponent();
s32 resExponent = selfExponent - other.Exponent();
if (resExponent < 0)
return other.DoAdd(*this);
else if (resExponent >= 25)
return *this;
// http://graphics.stanford.edu/~seander/bithacks.html#ConditionalNegate
u32 sign1 = (u32)((s32)raw >> 31);
s32 selfMantissa = (s32)(((Mantissa() | 0x800000) ^ sign1) - sign1);
u32 sign2 = (u32)((s32)other.raw >> 31);
s32 otherMantissa = (s32)(((other.Mantissa() | 0x800000) ^ sign2) - sign2);
// PS2 multiply by 2 before doing the Math here.
s32 man = (selfMantissa << roundingMultiplier) + ((otherMantissa << roundingMultiplier) >> resExponent);
s32 absMan = abs(man);
if (absMan == 0)
return PS2Float(0);
// Remove from exponent the PS2 Multiplier value.
s32 rawExp = selfExponent - roundingMultiplier;
s32 amount = Common::normalizeAmounts[Common::clz(absMan)];
rawExp -= amount;
absMan <<= amount;
s32 msbIndex = Common::BitScanReverse8(absMan >> 23);
rawExp += msbIndex;
absMan >>= msbIndex;
if (rawExp > 255)
return man < 0 ? Min() : Max();
else if (rawExp <= 0)
return PS2Float(man < 0, 0, 0);
return PS2Float(((u32)man & SIGNMASK) | (u32)rawExp << 23 | ((u32)absMan & 0x7FFFFF));
}
PS2Float PS2Float::DoMul(PS2Float other)
{
u8 selfExponent = Exponent();
u8 otherExponent = other.Exponent();
u32 selfMantissa = Mantissa() | 0x800000;
u32 otherMantissa = other.Mantissa() | 0x800000;
u32 sign = (raw ^ other.raw) & SIGNMASK;
s32 resExponent = selfExponent + otherExponent - 127;
u32 resMantissa = (u32)(MulMantissa(selfMantissa, otherMantissa) >> 23);
if (resMantissa > 0xFFFFFF)
{
resMantissa >>= 1;
resExponent++;
}
if (resExponent > 255)
return PS2Float(sign | MAX_FLOATING_POINT_VALUE);
else if (resExponent <= 0)
return PS2Float(sign);
return PS2Float(sign | (u32)(resExponent << 23) | (resMantissa & 0x7FFFFF));
}
// Rounding can be slightly off: (PS2: 0x3F800000 / 0x3F800001 = 0x3F7FFFFF | SoftFloat/IEEE754: 0x3F800000 / 0x3F800001 = 0x3F7FFFFE).
PS2Float PS2Float::DoDiv(PS2Float other)
{
bool sign = DetermineMultiplicationDivisionOperationSign(*this, other);
u32 selfMantissa = Mantissa() | 0x800000;
u32 otherMantissa = other.Mantissa() | 0x800000;
s32 resExponent = Exponent() - other.Exponent() + BIAS;
u64 selfMantissa64;
if (resExponent > 255)
return sign ? Min() : Max();
else if (resExponent <= 0)
return PS2Float(sign, 0, 0);
if (selfMantissa < otherMantissa)
{
--resExponent;
if (resExponent == 0)
return PS2Float(sign, 0, 0);
selfMantissa64 = (u64)(selfMantissa) << 31;
}
else
{
selfMantissa64 = (u64)(selfMantissa) << 30;
}
u32 resMantissa = (u32)(selfMantissa64 / otherMantissa);
if ((resMantissa & 0x3F) == 0)
resMantissa |= ((u64)otherMantissa * resMantissa != selfMantissa64) ? 1U : 0;
FPRoundMode roundingMode = EmuConfig.Cpu.FPUDivFPCR.GetRoundMode();
bool roundNearEven = roundingMode == FPRoundMode::Nearest;
u32 roundIncrement = (!roundNearEven) ? ((roundingMode == (sign ? FPRoundMode::NegativeInfinity : FPRoundMode::PositiveInfinity)) ? 0x7FU : 0) : 0x40U;
u32 roundBits = resMantissa & 0x7F;
if (0x80000000 <= resMantissa + roundIncrement)
return sign ? Min() : Max();
resMantissa = (resMantissa + roundIncrement) >> 7;
resMantissa &= ~(((roundBits ^ 0x40) == 0 & roundNearEven) ? 1U : 0U);
if (resMantissa == 0)
resExponent = 0;
return PS2Float(sign, (u8)resExponent, resMantissa);
}
PS2Float PS2Float::SolveAbnormalAdditionOrSubtractionOperation(PS2Float a, PS2Float b, bool add)
{
u32 aval = a.raw;
u32 bval = b.raw;
if (aval == MAX_FLOATING_POINT_VALUE && bval == MAX_FLOATING_POINT_VALUE)
return add ? Max() : PS2Float(0);
if (aval == MIN_FLOATING_POINT_VALUE && bval == MIN_FLOATING_POINT_VALUE)
return add ? Min() : PS2Float(0);
if (aval == MIN_FLOATING_POINT_VALUE && bval == MAX_FLOATING_POINT_VALUE)
return add ? PS2Float(0) : Min();
if (aval == MAX_FLOATING_POINT_VALUE && bval == MIN_FLOATING_POINT_VALUE)
return add ? PS2Float(0) : Max();
if (aval == POSITIVE_INFINITY_VALUE && bval == POSITIVE_INFINITY_VALUE)
return add ? Max() : PS2Float(0);
if (aval == NEGATIVE_INFINITY_VALUE && bval == POSITIVE_INFINITY_VALUE)
return add ? PS2Float(0) : Min();
if (aval == POSITIVE_INFINITY_VALUE && bval == NEGATIVE_INFINITY_VALUE)
return add ? PS2Float(0) : Max();
if (aval == NEGATIVE_INFINITY_VALUE && bval == NEGATIVE_INFINITY_VALUE)
return add ? Min() : PS2Float(0);
if (aval == MAX_FLOATING_POINT_VALUE && bval == POSITIVE_INFINITY_VALUE)
return add ? Max() : PS2Float(0x7F7FFFFE);
if (aval == MAX_FLOATING_POINT_VALUE && bval == NEGATIVE_INFINITY_VALUE)
return add ? PS2Float(0x7F7FFFFE) : Max();
if (aval == MIN_FLOATING_POINT_VALUE && bval == POSITIVE_INFINITY_VALUE)
return add ? PS2Float(0xFF7FFFFE) : Min();
if (aval == MIN_FLOATING_POINT_VALUE && bval == NEGATIVE_INFINITY_VALUE)
return add ? Min() : PS2Float(0xFF7FFFFE);
if (aval == POSITIVE_INFINITY_VALUE && bval == MAX_FLOATING_POINT_VALUE)
return add ? Max() : PS2Float(0xFF7FFFFE);
if (aval == POSITIVE_INFINITY_VALUE && bval == MIN_FLOATING_POINT_VALUE)
return add ? PS2Float(0xFF7FFFFE) : Max();
if (aval == NEGATIVE_INFINITY_VALUE && bval == MAX_FLOATING_POINT_VALUE)
return add ? PS2Float(0x7F7FFFFE) : Min();
if (aval == NEGATIVE_INFINITY_VALUE && bval == MIN_FLOATING_POINT_VALUE)
return add ? Min() : PS2Float(0x7F7FFFFE);
Console.Error("Unhandled abnormal add/sub floating point operation");
return PS2Float(0);
}
PS2Float PS2Float::SolveAbnormalMultiplicationOrDivisionOperation(PS2Float a, PS2Float b, bool mul)
{
u32 aval = a.raw;
u32 bval = b.raw;
if (mul)
{
if ((aval == MAX_FLOATING_POINT_VALUE && bval == MAX_FLOATING_POINT_VALUE) ||
(aval == MIN_FLOATING_POINT_VALUE && bval == MIN_FLOATING_POINT_VALUE))
return Max();
if ((aval == MAX_FLOATING_POINT_VALUE && bval == MIN_FLOATING_POINT_VALUE) ||
(aval == MIN_FLOATING_POINT_VALUE && bval == MAX_FLOATING_POINT_VALUE))
return Min();
if (aval == POSITIVE_INFINITY_VALUE && bval == POSITIVE_INFINITY_VALUE)
return Max();
if (aval == NEGATIVE_INFINITY_VALUE && bval == POSITIVE_INFINITY_VALUE)
return Min();
if (aval == POSITIVE_INFINITY_VALUE && bval == NEGATIVE_INFINITY_VALUE)
return Min();
if (aval == NEGATIVE_INFINITY_VALUE && bval == NEGATIVE_INFINITY_VALUE)
return Max();
if (aval == MAX_FLOATING_POINT_VALUE && bval == POSITIVE_INFINITY_VALUE)
return Max();
if (aval == MAX_FLOATING_POINT_VALUE && bval == NEGATIVE_INFINITY_VALUE)
return Min();
if (aval == MIN_FLOATING_POINT_VALUE && bval == POSITIVE_INFINITY_VALUE)
return Min();
if (aval == MIN_FLOATING_POINT_VALUE && bval == NEGATIVE_INFINITY_VALUE)
return Max();
if (aval == POSITIVE_INFINITY_VALUE && bval == MAX_FLOATING_POINT_VALUE)
return Max();
if (aval == POSITIVE_INFINITY_VALUE && bval == MIN_FLOATING_POINT_VALUE)
return Min();
if (aval == NEGATIVE_INFINITY_VALUE && bval == MAX_FLOATING_POINT_VALUE)
return Min();
if (aval == NEGATIVE_INFINITY_VALUE && bval == MIN_FLOATING_POINT_VALUE)
return Max();
}
else
{
if ((aval == MAX_FLOATING_POINT_VALUE && bval == MAX_FLOATING_POINT_VALUE) ||
(aval == MIN_FLOATING_POINT_VALUE && bval == MIN_FLOATING_POINT_VALUE))
return One();
if ((aval == MAX_FLOATING_POINT_VALUE && bval == MIN_FLOATING_POINT_VALUE) ||
(aval == MIN_FLOATING_POINT_VALUE && bval == MAX_FLOATING_POINT_VALUE))
return MinOne();
if (aval == POSITIVE_INFINITY_VALUE && bval == POSITIVE_INFINITY_VALUE)
return One();
if (aval == NEGATIVE_INFINITY_VALUE && bval == POSITIVE_INFINITY_VALUE)
return MinOne();
if (aval == POSITIVE_INFINITY_VALUE && bval == NEGATIVE_INFINITY_VALUE)
return MinOne();
if (aval == NEGATIVE_INFINITY_VALUE && bval == NEGATIVE_INFINITY_VALUE)
return One();
if (aval == MAX_FLOATING_POINT_VALUE && bval == POSITIVE_INFINITY_VALUE)
return PS2Float(0x3FFFFFFF);
if (aval == MAX_FLOATING_POINT_VALUE && bval == NEGATIVE_INFINITY_VALUE)
return PS2Float(0xBFFFFFFF);
if (aval == MIN_FLOATING_POINT_VALUE && bval == POSITIVE_INFINITY_VALUE)
return PS2Float(0xBFFFFFFF);
if (aval == MIN_FLOATING_POINT_VALUE && bval == NEGATIVE_INFINITY_VALUE)
return PS2Float(0x3FFFFFFF);
if (aval == POSITIVE_INFINITY_VALUE && bval == MAX_FLOATING_POINT_VALUE)
return PS2Float(0x3F000001);
if (aval == POSITIVE_INFINITY_VALUE && bval == MIN_FLOATING_POINT_VALUE)
return PS2Float(0xBF000001);
if (aval == NEGATIVE_INFINITY_VALUE && bval == MAX_FLOATING_POINT_VALUE)
return PS2Float(0xBF000001);
if (aval == NEGATIVE_INFINITY_VALUE && bval == MIN_FLOATING_POINT_VALUE)
return PS2Float(0x3F000001);
}
Console.Error("Unhandled abnormal mul/div floating point operation");
return PS2Float(0);
}
PS2Float PS2Float::SolveAddSubDenormalizedOperation(PS2Float a, PS2Float b, bool add)
{
bool sign = add ? DetermineAdditionOperationSign(a, b) : DetermineSubtractionOperationSign(a, b);
if (a.IsDenormalized() && !b.IsDenormalized())
return PS2Float(sign, b.Exponent(), b.Mantissa());
else if (!a.IsDenormalized() && b.IsDenormalized())
return PS2Float(sign, a.Exponent(), a.Mantissa());
else if (a.IsDenormalized() && b.IsDenormalized())
return PS2Float(sign, 0, 0);
else
Console.Error("Both numbers are not denormalized");
return PS2Float(0);
}
PS2Float PS2Float::SolveMultiplicationDenormalizedOperation(PS2Float a, PS2Float b)
{
return PS2Float(DetermineMultiplicationDivisionOperationSign(a, b), 0, 0);
}
PS2Float PS2Float::SolveDivisionDenormalizedOperation(PS2Float a, PS2Float b)
{
bool sign = DetermineMultiplicationDivisionOperationSign(a, b);
if (a.IsDenormalized() && !b.IsDenormalized())
return PS2Float(sign, 0, 0);
else if (!a.IsDenormalized() && b.IsDenormalized())
return sign ? Min() : Max();
else if (a.IsDenormalized() && b.IsDenormalized())
return sign ? Min() : Max();
else
Console.Error("Both numbers are not denormalized");
return PS2Float(0);
}
bool PS2Float::DetermineMultiplicationDivisionOperationSign(PS2Float a, PS2Float b)
{
return a.Sign() ^ b.Sign();
}
bool PS2Float::DetermineAdditionOperationSign(PS2Float a, PS2Float b)
{
if (a.IsZero() && b.IsZero())
{
if (!a.Sign() || !b.Sign())
return false;
else if (a.Sign() && b.Sign())
return true;
else
Console.Error("Unhandled addition operation flags");
}
return a.CompareOperand(b) >= 0 ? a.Sign() : b.Sign();
}
bool PS2Float::DetermineSubtractionOperationSign(PS2Float a, PS2Float b)
{
if (a.IsZero() && b.IsZero())
{
if (!a.Sign() || b.Sign())
return false;
else if (a.Sign() && !b.Sign())
return true;
else
Console.Error("Unhandled subtraction operation flags");
}
return a.CompareOperand(b) >= 0 ? a.Sign() : !b.Sign();
}

119
pcsx2/PS2Float.h Normal file
View File

@ -0,0 +1,119 @@
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
// SPDX-License-Identifier: GPL-3.0+
#pragma once
#include <vector>
class PS2Float
{
struct BoothRecode
{
u32 data;
u32 negate;
};
struct AddResult
{
u32 lo;
u32 hi;
};
static u64 MulMantissa(u32 a, u32 b);
static BoothRecode Booth(u32 a, u32 b, u32 bit);
static AddResult Add3(u32 a, u32 b, u32 c);
public:
static constexpr u8 BIAS = 127;
static constexpr u32 SIGNMASK = 0x80000000;
static constexpr u32 MAX_FLOATING_POINT_VALUE = 0x7FFFFFFF;
static constexpr u32 MIN_FLOATING_POINT_VALUE = 0xFFFFFFFF;
static constexpr u32 POSITIVE_INFINITY_VALUE = 0x7F800000;
static constexpr u32 NEGATIVE_INFINITY_VALUE = 0xFF800000;
static constexpr u32 ONE = 0x3F800000;
static constexpr u32 MIN_ONE = 0xBF800000;
static constexpr int IMPLICIT_LEADING_BIT_POS = 23;
u32 raw;
constexpr u32 Mantissa() const { return raw & 0x7FFFFF; }
constexpr u8 Exponent() const { return (raw >> 23) & 0xFF; }
constexpr bool Sign() const { return ((raw >> 31) & 1) != 0; }
PS2Float(s32 value);
PS2Float(u32 value);
PS2Float(float value);
PS2Float(bool sign, u8 exponent, u32 mantissa);
static PS2Float Max();
static PS2Float Min();
static PS2Float One();
static PS2Float MinOne();
static PS2Float SolveAbnormalAdditionOrSubtractionOperation(PS2Float a, PS2Float b, bool add);
static PS2Float SolveAbnormalMultiplicationOrDivisionOperation(PS2Float a, PS2Float b, bool mul);
static PS2Float SolveAddSubDenormalizedOperation(PS2Float a, PS2Float b, bool add);
static PS2Float SolveMultiplicationDenormalizedOperation(PS2Float a, PS2Float b);
static PS2Float SolveDivisionDenormalizedOperation(PS2Float a, PS2Float b);
PS2Float Add(PS2Float addend);
PS2Float Sub(PS2Float subtrahend);
PS2Float Mul(PS2Float mulend);
PS2Float Div(PS2Float divend);
PS2Float Sqrt();
PS2Float Rsqrt(PS2Float other);
PS2Float Pow(s32 exponent);
bool IsDenormalized();
bool IsAbnormal();
bool IsZero();
u32 Abs();
PS2Float Negate();
s32 CompareTo(PS2Float other);
s32 CompareOperand(PS2Float other);
double ToDouble();
std::string ToString();
protected:
private:
PS2Float DoAdd(PS2Float other);
PS2Float DoMul(PS2Float other);
PS2Float DoDiv(PS2Float other);
static bool DetermineMultiplicationDivisionOperationSign(PS2Float a, PS2Float b);
static bool DetermineAdditionOperationSign(PS2Float a, PS2Float b);
static bool DetermineSubtractionOperationSign(PS2Float a, PS2Float b);
};

View File

@ -536,14 +536,27 @@ void Pcsx2Config::RecompilerOptions::LoadSave(SettingsWrapper& wrap)
SettingsWrapBitBool(vu0ExtraOverflow);
SettingsWrapBitBool(vu0SignOverflow);
SettingsWrapBitBool(vu0Underflow);
SettingsWrapBitBool(vu0SoftAddSub);
SettingsWrapBitBool(vu0SoftMulDiv);
SettingsWrapBitBool(vu0SoftSqrt);
SettingsWrapBitBool(vu1Overflow);
SettingsWrapBitBool(vu1ExtraOverflow);
SettingsWrapBitBool(vu1SignOverflow);
SettingsWrapBitBool(vu1Underflow);
SettingsWrapBitBool(vu1SoftAddSub);
SettingsWrapBitBool(vu1SoftMulDiv);
SettingsWrapBitBool(vu1SoftSqrt);
SettingsWrapBitBool(fpuOverflow);
SettingsWrapBitBool(fpuExtraOverflow);
SettingsWrapBitBool(fpuFullMode);
SettingsWrapBitBool(fpuSoftAddSub);
SettingsWrapBitBool(fpuSoftMulDiv);
SettingsWrapBitBool(fpuSoftSqrt);
}
u32 Pcsx2Config::RecompilerOptions::GetEEClampMode() const

View File

@ -124,6 +124,7 @@ struct alignas(16) VURegs
REG_VI q;
REG_VI p;
VECTOR TMP; // Temporary vector used to stack FMA operations
uint idx; // VU index (0 or 1)
// flags/cycle are needed by VIF dma code, so they have to be here (for now)

View File

@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0+
#include "Common.h"
#include "PS2Float.h"
#include <cmath>
#include <float.h>
@ -12,21 +12,22 @@
/* NEW FLAGS */ //By asadr. Thnkx F|RES :p
/*****************************************/
static __ri u32 VU_MAC_UPDATE( int shift, VURegs * VU, float f )
static __ri u32 VU_MAC_UPDATE(int shift, VURegs* VU, u32 f)
{
u32 v = *(u32*)&f;
int exp = (v >> 23) & 0xff;
u32 s = v & 0x80000000;
PS2Float ps2f = PS2Float(f);
u32 exp = ps2f.Exponent();
u32 s = ps2f.raw & PS2Float::SIGNMASK;
if (s)
VU->macflag |= 0x0010<<shift;
else
VU->macflag &= ~(0x0010<<shift);
if( f == 0 )
if (ps2f.IsZero())
{
VU->macflag = (VU->macflag & ~(0x1100<<shift)) | (0x0001<<shift);
return v;
return f;
}
switch(exp)
@ -35,53 +36,68 @@ static __ri u32 VU_MAC_UPDATE( int shift, VURegs * VU, float f )
VU->macflag = (VU->macflag&~(0x1000<<shift)) | (0x0101<<shift);
return s;
case 255:
VU->macflag = (VU->macflag&~(0x0101<<shift)) | (0x1000<<shift);
if (CHECK_VU_OVERFLOW((VU == &VU1) ? 1 : 0))
return s | 0x7f7fffff; /* max allowed */
if (CHECK_VU_SOFT_ADDSUB((VU == &VU1) ? 1 : 0) || CHECK_VU_SOFT_MULDIV((VU == &VU1) ? 1 : 0) || CHECK_VU_SOFT_SQRT((VU == &VU1) ? 1 : 0))
{
if (f == PS2Float::MAX_FLOATING_POINT_VALUE || f == PS2Float::MIN_FLOATING_POINT_VALUE)
{
VU->macflag = (VU->macflag & ~(0x0101 << shift)) | (0x1000 << shift);
return f;
}
else
return f;
}
else if (CHECK_VU_OVERFLOW((VU == &VU1) ? 1 : 0))
{
VU->macflag = (VU->macflag & ~(0x0101 << shift)) | (0x1000 << shift);
return s | 0x7f7fffff; /* max IEEE754 allowed */
}
else
return v;
{
VU->macflag = (VU->macflag & ~(0x0101 << shift)) | (0x1000 << shift);
return f;
}
default:
VU->macflag = (VU->macflag & ~(0x1101<<shift));
return v;
return f;
}
}
__fi u32 VU_MACx_UPDATE(VURegs * VU, float x)
__fi u32 VU_MACx_UPDATE(VURegs* VU, u32 x)
{
return VU_MAC_UPDATE(3, VU, x);
}
__fi u32 VU_MACy_UPDATE(VURegs * VU, float y)
__fi u32 VU_MACy_UPDATE(VURegs* VU, u32 y)
{
return VU_MAC_UPDATE(2, VU, y);
}
__fi u32 VU_MACz_UPDATE(VURegs * VU, float z)
__fi u32 VU_MACz_UPDATE(VURegs* VU, u32 z)
{
return VU_MAC_UPDATE(1, VU, z);
}
__fi u32 VU_MACw_UPDATE(VURegs * VU, float w)
__fi u32 VU_MACw_UPDATE(VURegs* VU, u32 w)
{
return VU_MAC_UPDATE(0, VU, w);
}
__fi void VU_MACx_CLEAR(VURegs * VU)
__fi void VU_MACx_CLEAR(VURegs* VU)
{
VU->macflag&= ~(0x1111<<3);
}
__fi void VU_MACy_CLEAR(VURegs * VU)
__fi void VU_MACy_CLEAR(VURegs* VU)
{
VU->macflag&= ~(0x1111<<2);
}
__fi void VU_MACz_CLEAR(VURegs * VU)
__fi void VU_MACz_CLEAR(VURegs* VU)
{
VU->macflag&= ~(0x1111<<1);
}
__fi void VU_MACw_CLEAR(VURegs * VU)
__fi void VU_MACw_CLEAR(VURegs* VU)
{
VU->macflag&= ~(0x1111<<0);
}

View File

@ -4,12 +4,12 @@
#pragma once
#include "VU.h"
extern u32 VU_MACx_UPDATE(VURegs * VU, float x);
extern u32 VU_MACy_UPDATE(VURegs * VU, float y);
extern u32 VU_MACz_UPDATE(VURegs * VU, float z);
extern u32 VU_MACw_UPDATE(VURegs * VU, float w);
extern void VU_MACx_CLEAR(VURegs * VU);
extern void VU_MACy_CLEAR(VURegs * VU);
extern void VU_MACz_CLEAR(VURegs * VU);
extern void VU_MACw_CLEAR(VURegs * VU);
extern void VU_STAT_UPDATE(VURegs * VU);
extern u32 VU_MACx_UPDATE(VURegs* VU, u32 x);
extern u32 VU_MACy_UPDATE(VURegs* VU, u32 y);
extern u32 VU_MACz_UPDATE(VURegs* VU, u32 z);
extern u32 VU_MACw_UPDATE(VURegs* VU, u32 w);
extern void VU_MACx_CLEAR(VURegs* VU);
extern void VU_MACy_CLEAR(VURegs* VU);
extern void VU_MACz_CLEAR(VURegs* VU);
extern void VU_MACw_CLEAR(VURegs* VU);
extern void VU_STAT_UPDATE(VURegs* VU);

File diff suppressed because it is too large Load Diff

View File

@ -281,6 +281,7 @@
<ClCompile Include="PINE.cpp" />
<ClCompile Include="FW.cpp" />
<ClCompile Include="PerformanceMetrics.cpp" />
<ClCompile Include="PS2Float.cpp" />
<ClCompile Include="Recording\InputRecording.cpp" />
<ClCompile Include="Recording\InputRecordingControls.cpp" />
<ClCompile Include="Recording\InputRecordingFile.cpp" />
@ -726,6 +727,7 @@
<ClInclude Include="PINE.h" />
<ClInclude Include="FW.h" />
<ClInclude Include="PerformanceMetrics.h" />
<ClInclude Include="PS2Float.h" />
<ClInclude Include="Recording\InputRecording.h" />
<ClInclude Include="Recording\InputRecordingControls.h" />
<ClInclude Include="Recording\InputRecordingFile.h" />
@ -1025,4 +1027,4 @@
<Import Condition="$(Configuration.Contains(Debug)) Or $(Configuration.Contains(Devel))" Project="$(SolutionDir)3rdparty\winpixeventruntime\WinPixEventRuntime.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>
</Project>

View File

@ -289,6 +289,9 @@
<Filter Include="System\Ps2\EmotionEngine\EE\Dynarec\arm64">
<UniqueIdentifier>{cd8ec519-2196-43f7-86de-7faced2d4296}</UniqueIdentifier>
</Filter>
<Filter Include="System\Ps2\EmotionEngine\Shared">
<UniqueIdentifier>{9a40984b-cb23-4a54-a5e9-9c54f3c16c5b}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="Docs\License.txt">
@ -1443,6 +1446,9 @@
<ClCompile Include="SIO\Pad\PadNegcon.cpp">
<Filter>System\Ps2\Iop\SIO\PAD</Filter>
</ClCompile>
<ClCompile Include="PS2Float.cpp">
<Filter>System\Ps2\EmotionEngine\Shared</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Patch.h">
@ -2399,6 +2405,9 @@
<ClInclude Include="SIO\Pad\PadNegcon.h">
<Filter>System\Ps2\Iop\SIO\PAD</Filter>
</ClInclude>
<ClInclude Include="PS2Float.h">
<Filter>System\Ps2\EmotionEngine\Shared</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuildStep Include="rdebug\deci2.h">
@ -2428,4 +2437,4 @@
<Filter>System\Ps2\GS</Filter>
</Natvis>
</ItemGroup>
</Project>
</Project>