2020-02-28 16:04:28 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2021-10-23 19:00:31 +00:00
|
|
|
Copyright (C) 2018-21 divingkatae and maximum
|
2020-02-28 16:04:28 +00:00
|
|
|
(theweirdo) spatium
|
|
|
|
|
|
|
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
// The floating point opcodes for the processor - ppcfpopcodes.cpp
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2019-12-27 19:10:36 +00:00
|
|
|
#include "ppcemu.h"
|
2019-12-27 19:00:53 +00:00
|
|
|
#include "ppcmmu.h"
|
2020-05-12 18:55:45 +00:00
|
|
|
#include <array>
|
2019-07-12 05:27:14 +00:00
|
|
|
#include <cfenv>
|
2021-10-09 22:08:53 +00:00
|
|
|
#include <cfloat>
|
2020-05-12 18:55:45 +00:00
|
|
|
#include <cinttypes>
|
2019-07-02 02:15:33 +00:00
|
|
|
#include <cmath>
|
2020-05-12 18:55:45 +00:00
|
|
|
#include <iostream>
|
2019-07-02 02:15:33 +00:00
|
|
|
#include <limits>
|
2020-05-12 18:55:45 +00:00
|
|
|
#include <map>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unordered_map>
|
2021-09-15 22:46:38 +00:00
|
|
|
#include <loguru.hpp>
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
// Used for FP calcs
|
2020-01-22 02:25:50 +00:00
|
|
|
uint64_t ppc_result64_b;
|
|
|
|
uint64_t ppc_result64_d;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
double ppc_dblresult64_d;
|
|
|
|
|
|
|
|
double snan = std::numeric_limits<double>::signaling_NaN();
|
|
|
|
double qnan = std::numeric_limits<double>::quiet_NaN();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
// Storage and register retrieval functions for the floating point functions.
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-01-24 22:06:33 +00:00
|
|
|
#define GET_FPR(reg) ppc_state.fpr[(reg)].dbl64_r
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
double fp_return_double(uint32_t reg) {
|
2020-03-05 04:29:04 +00:00
|
|
|
return ppc_state.fpr[reg].dbl64_r;
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t fp_return_uint64(uint32_t reg) {
|
2020-03-05 04:29:04 +00:00
|
|
|
return ppc_state.fpr[reg].int64_r;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2021-01-25 16:17:02 +00:00
|
|
|
#define ppc_store_sfpresult_int(reg) \
|
|
|
|
ppc_state.fpr[(reg)].int64_r = ppc_result64_d;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-01-25 16:17:02 +00:00
|
|
|
#define ppc_store_sfpresult_flt(reg) \
|
|
|
|
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d;
|
2021-01-24 18:59:16 +00:00
|
|
|
|
2021-01-25 16:17:02 +00:00
|
|
|
#define ppc_store_dfpresult_int(reg) \
|
|
|
|
ppc_state.fpr[(reg)].int64_r = ppc_result64_d;
|
2021-01-24 18:59:16 +00:00
|
|
|
|
2021-01-25 16:17:02 +00:00
|
|
|
#define ppc_store_dfpresult_flt(reg) \
|
|
|
|
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d;
|
2020-01-22 02:25:50 +00:00
|
|
|
|
2021-01-24 22:06:33 +00:00
|
|
|
#define ppc_grab_regsfpdb() \
|
|
|
|
int reg_d = (ppc_cur_instruction >> 21) & 31; \
|
|
|
|
int reg_b = (ppc_cur_instruction >> 11) & 31;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-01-25 00:29:58 +00:00
|
|
|
#define ppc_grab_regsfpdiab() \
|
|
|
|
int reg_d = (ppc_cur_instruction >> 21) & 31; \
|
|
|
|
int reg_a = (ppc_cur_instruction >> 16) & 31; \
|
|
|
|
int reg_b = (ppc_cur_instruction >> 11) & 31; \
|
|
|
|
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
|
|
|
|
uint32_t val_reg_b = ppc_state.gpr[reg_b];
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-01-25 00:29:58 +00:00
|
|
|
#define ppc_grab_regsfpdia() \
|
|
|
|
int reg_d = (ppc_cur_instruction >> 21) & 31; \
|
|
|
|
int reg_a = (ppc_cur_instruction >> 16) & 31; \
|
|
|
|
uint32_t val_reg_a = ppc_state.gpr[reg_a];
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-01-25 00:29:58 +00:00
|
|
|
#define ppc_grab_regsfpsia() \
|
|
|
|
int reg_s = (ppc_cur_instruction >> 21) & 31; \
|
|
|
|
int reg_a = (ppc_cur_instruction >> 16) & 31; \
|
|
|
|
uint32_t val_reg_a = ppc_state.gpr[reg_a];
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-01-25 00:29:58 +00:00
|
|
|
#define ppc_grab_regsfpsiab() \
|
|
|
|
int reg_s = (ppc_cur_instruction >> 21) & 31; \
|
|
|
|
int reg_a = (ppc_cur_instruction >> 16) & 31; \
|
|
|
|
int reg_b = (ppc_cur_instruction >> 11) & 31; \
|
|
|
|
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
|
|
|
|
uint32_t val_reg_b = ppc_state.gpr[reg_b];
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-01-25 01:27:58 +00:00
|
|
|
#define ppc_grab_regsfpsab() \
|
|
|
|
int reg_a = (ppc_cur_instruction >> 16) & 31; \
|
|
|
|
int reg_b = (ppc_cur_instruction >> 11) & 31; \
|
|
|
|
int crf_d = (ppc_cur_instruction >> 21) & 0x1C; \
|
|
|
|
double db_test_a = GET_FPR(reg_a); \
|
|
|
|
double db_test_b = GET_FPR(reg_b);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-01-25 01:27:58 +00:00
|
|
|
#define ppc_grab_regsfpdab() \
|
|
|
|
int reg_d = (ppc_cur_instruction >> 21) & 31; \
|
|
|
|
int reg_a = (ppc_cur_instruction >> 16) & 31; \
|
|
|
|
int reg_b = (ppc_cur_instruction >> 11) & 31; \
|
|
|
|
double val_reg_a = GET_FPR(reg_a); \
|
|
|
|
double val_reg_b = GET_FPR(reg_b);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-01-25 01:27:58 +00:00
|
|
|
#define ppc_grab_regsfpdac() \
|
|
|
|
int reg_d = (ppc_cur_instruction >> 21) & 31; \
|
|
|
|
int reg_a = (ppc_cur_instruction >> 16) & 31; \
|
|
|
|
int reg_c = (ppc_cur_instruction >> 6) & 31; \
|
|
|
|
double val_reg_a = GET_FPR(reg_a); \
|
|
|
|
double val_reg_c = GET_FPR(reg_c);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-01-25 01:27:58 +00:00
|
|
|
#define ppc_grab_regsfpdabc() \
|
|
|
|
int reg_d = (ppc_cur_instruction >> 21) & 31; \
|
|
|
|
int reg_a = (ppc_cur_instruction >> 16) & 31; \
|
|
|
|
int reg_b = (ppc_cur_instruction >> 11) & 31; \
|
|
|
|
int reg_c = (ppc_cur_instruction >> 6) & 31; \
|
|
|
|
double val_reg_a = GET_FPR(reg_a); \
|
|
|
|
double val_reg_b = GET_FPR(reg_b); \
|
|
|
|
double val_reg_c = GET_FPR(reg_c);
|
2020-01-22 02:25:50 +00:00
|
|
|
|
|
|
|
void fp_save_float(float entry) {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.fpr[reg_d].dbl64_r = (double)entry;
|
|
|
|
ppc_state.fpr[reg_d].int64_r = (uint64_t)entry;
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void fp_save_double(double entry) {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.fpr[reg_d].dbl64_r = entry;
|
|
|
|
ppc_state.fpr[reg_d].int64_r = *(uint64_t*)&entry;
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void fp_save_uint64(uint64_t entry) {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.fpr[reg_d].int64_r = entry;
|
|
|
|
ppc_state.fpr[reg_d].dbl64_r = (double)entry;
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void fp_save_uint32(uint32_t entry) {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.fpr[reg_d].int64_r = entry;
|
|
|
|
ppc_state.fpr[reg_d].dbl64_r = (double)entry;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-12 01:43:47 +00:00
|
|
|
void ppc_fp_changecrf1() {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.fpscr |= 0xf0000000;
|
2020-01-12 01:43:47 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 20:40:55 +00:00
|
|
|
int64_t round_to_nearest(double f) {
|
|
|
|
if (f >= 0.0) {
|
2021-10-10 02:42:25 +00:00
|
|
|
return static_cast<int32_t>(static_cast<int64_t> (ceil(f)));
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2021-10-10 02:42:25 +00:00
|
|
|
return static_cast<int32_t>(static_cast<int64_t> (floor(f)));
|
2020-02-16 20:40:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t round_to_zero(double f) {
|
2021-02-05 19:45:57 +00:00
|
|
|
return static_cast<int32_t>(trunc(f));
|
2020-02-16 20:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int64_t round_to_pos_inf(double f) {
|
2021-02-05 19:45:57 +00:00
|
|
|
return static_cast<int32_t>(ceil(f));
|
2020-02-16 20:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int64_t round_to_neg_inf(double f) {
|
2021-02-05 19:45:57 +00:00
|
|
|
return static_cast<int32_t>(floor(f));
|
2020-02-16 20:40:55 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
|
2021-10-10 14:48:49 +00:00
|
|
|
void update_fex() {
|
2021-10-09 22:08:53 +00:00
|
|
|
int fex_result = !!((ppc_state.fpscr & (ppc_state.fpscr << 22)) & 0x3E000000);
|
|
|
|
ppc_state.fpscr = (ppc_state.fpscr & ~0x40000000) | (fex_result << 30);
|
2020-02-21 03:00:20 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 03:31:10 +00:00
|
|
|
template <typename T, const FPOP fpop>
|
2021-10-19 14:16:15 +00:00
|
|
|
void ppc_confirm_inf_nan(int chosen_reg_1, int chosen_reg_2, int chosen_reg_3, bool rc_flag = false) {
|
2021-10-09 22:08:53 +00:00
|
|
|
T input_a = T(ppc_state.fpr[chosen_reg_1].int64_r);
|
|
|
|
T input_b = T(ppc_state.fpr[chosen_reg_2].int64_r);
|
|
|
|
T input_c = T(ppc_state.fpr[chosen_reg_3].int64_r);
|
2020-02-21 03:00:20 +00:00
|
|
|
|
2021-10-09 22:08:53 +00:00
|
|
|
ppc_state.fpscr &= 0x7fbfffff;
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2021-10-15 03:31:10 +00:00
|
|
|
switch (fpop) {
|
2021-10-09 22:08:53 +00:00
|
|
|
case FPOP::DIV:
|
2021-10-24 21:00:35 +00:00
|
|
|
if (isinf(input_a) && isinf(input_b)) {
|
2021-10-10 14:48:49 +00:00
|
|
|
ppc_state.fpscr |= (FPSCR::FX | FPSCR::VXIDI);
|
2021-10-09 22:08:53 +00:00
|
|
|
} else if ((input_a == FP_ZERO) && (input_b == FP_ZERO)) {
|
2021-10-10 14:48:49 +00:00
|
|
|
ppc_state.fpscr |= (FPSCR::FX | FPSCR::VXZDZ);
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
2021-10-10 14:48:49 +00:00
|
|
|
update_fex();
|
2020-01-22 02:25:50 +00:00
|
|
|
break;
|
2021-10-09 22:08:53 +00:00
|
|
|
case FPOP::SUB:
|
|
|
|
if (isnan(input_a) && isnan(input_b)) {
|
2021-10-10 14:48:49 +00:00
|
|
|
ppc_state.fpscr |= (FPSCR::FX | FPSCR::VXISI);
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
2021-10-10 14:48:49 +00:00
|
|
|
update_fex();
|
2020-01-22 02:25:50 +00:00
|
|
|
break;
|
2021-10-09 22:08:53 +00:00
|
|
|
case FPOP::ADD:
|
2021-10-10 14:48:49 +00:00
|
|
|
if (isnan(input_a) && isnan(input_b)) {
|
|
|
|
ppc_state.fpscr |= (FPSCR::FX | FPSCR::VXISI);
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
2021-10-10 14:48:49 +00:00
|
|
|
update_fex();
|
2020-01-22 02:25:50 +00:00
|
|
|
break;
|
2021-10-09 22:08:53 +00:00
|
|
|
case FPOP::MUL:
|
|
|
|
if (((input_a == FP_ZERO) && (input_c == FP_INFINITE)) ||
|
|
|
|
((input_c == FP_ZERO) && (input_a == FP_INFINITE))) {
|
|
|
|
ppc_state.fpscr |=
|
2021-10-10 14:48:49 +00:00
|
|
|
(FPSCR::FX | FPSCR::VXSNAN |
|
|
|
|
FPSCR::VXIMZ);
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
2021-10-10 14:48:49 +00:00
|
|
|
update_fex();
|
2020-01-22 02:25:50 +00:00
|
|
|
break;
|
2021-10-09 22:08:53 +00:00
|
|
|
case FPOP::FMSUB:
|
|
|
|
case FPOP::FNMSUB:
|
|
|
|
if (isnan(input_a) || isnan(input_b) || isnan(input_c)) {
|
2021-10-23 20:05:20 +00:00
|
|
|
ppc_state.fpscr |= (FPSCR::FX | FPSCR::VXSNAN);
|
2021-10-09 22:08:53 +00:00
|
|
|
if (((input_a == FP_ZERO) && (input_c == FP_INFINITE)) ||
|
|
|
|
((input_c == FP_ZERO) && (input_a == FP_INFINITE))) {
|
2021-10-10 14:48:49 +00:00
|
|
|
ppc_state.fpscr |= FPSCR::VXIMZ;
|
2021-10-09 22:08:53 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
2021-10-09 22:08:53 +00:00
|
|
|
|
2021-10-10 14:48:49 +00:00
|
|
|
update_fex();
|
2020-01-22 02:25:50 +00:00
|
|
|
break;
|
2021-10-09 22:08:53 +00:00
|
|
|
case FPOP::FMADD:
|
|
|
|
case FPOP::FNMADD:
|
|
|
|
if (isnan(input_a) || isnan(input_b) || isnan(input_c)) {
|
2021-10-19 14:16:15 +00:00
|
|
|
ppc_state.fpscr |= (FPSCR::VXSNAN | FPSCR::FPCC_FUNAN);
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
2021-10-10 14:48:49 +00:00
|
|
|
update_fex();
|
2020-01-22 02:25:50 +00:00
|
|
|
break;
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
2021-10-17 21:41:53 +00:00
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
|
2022-02-16 23:11:14 +00:00
|
|
|
static void fpresult_update(double set_result, bool confirm_arc) {
|
2021-10-19 14:16:15 +00:00
|
|
|
if (ppc_state.fpscr & 0x3)
|
|
|
|
ppc_state.cr |= 0x2;
|
|
|
|
|
|
|
|
if (set_result > 0.0) {
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_state.fpscr |= FPCC_POS;
|
|
|
|
} else if (set_result < 0.0) {
|
|
|
|
ppc_state.fpscr |= FPCC_NEG;
|
|
|
|
} else {
|
|
|
|
ppc_state.fpscr |= FPCC_ZERO;
|
|
|
|
}
|
2021-10-24 21:00:35 +00:00
|
|
|
|
|
|
|
if (isnan(set_result) || isinf(set_result)) {
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_state.fpscr |= FPCC_FPRCD;
|
2021-10-19 14:16:15 +00:00
|
|
|
}
|
2021-10-30 23:43:13 +00:00
|
|
|
}
|
2021-10-19 14:16:15 +00:00
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
void ppc_changecrf1(double set_result) {
|
|
|
|
cmp_c = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
if (isnan(set_result)) {
|
|
|
|
cmp_c |= (1 << CRx_bit::CR_SO);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
if (set_result > 0.0) {
|
|
|
|
cmp_c |= (1 << CRx_bit::CR_GT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (set_result < 0.0) {
|
|
|
|
cmp_c |= (1 << CRx_bit::CR_LT);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
if (set_result == 0.0) {
|
|
|
|
cmp_c |= (1 << CRx_bit::CR_EQ);
|
|
|
|
}*/
|
|
|
|
|
|
|
|
ppc_state.cr = ((ppc_state.cr & ~(CR_select::CR1_field)) | ((cmp_c) >> crf_d));
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
// Floating Point Arithmetic
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fadd() {
|
2021-01-25 01:27:58 +00:00
|
|
|
ppc_grab_regsfpdab();
|
2021-10-17 21:41:53 +00:00
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_dblresult64_d = double(val_reg_a + val_reg_b);
|
2021-10-17 21:41:53 +00:00
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_dfpresult_flt(reg_d);
|
2022-02-16 23:11:14 +00:00
|
|
|
fpresult_update(ppc_dblresult64_d, rc_flag);
|
|
|
|
}
|
2021-10-30 23:43:13 +00:00
|
|
|
else {
|
2021-10-19 14:16:15 +00:00
|
|
|
ppc_confirm_inf_nan<double, ADD>(reg_a, reg_b, 0, rc_flag);
|
2020-01-12 04:17:29 +00:00
|
|
|
}
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fsub() {
|
2021-01-25 01:27:58 +00:00
|
|
|
ppc_grab_regsfpdab();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_dblresult64_d = double(val_reg_a - val_reg_b);
|
2021-10-15 03:31:10 +00:00
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_dfpresult_flt(reg_d);
|
2022-02-16 23:11:14 +00:00
|
|
|
fpresult_update(ppc_dblresult64_d, rc_flag);
|
2021-10-15 03:31:10 +00:00
|
|
|
} else {
|
2021-10-19 14:16:15 +00:00
|
|
|
ppc_confirm_inf_nan<double, SUB>(reg_a, reg_b, 0, rc_flag);
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fdiv() {
|
2021-01-25 01:27:58 +00:00
|
|
|
ppc_grab_regsfpdab();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-15 03:31:10 +00:00
|
|
|
ppc_dblresult64_d = val_reg_a / val_reg_b;
|
|
|
|
|
2021-10-24 21:00:35 +00:00
|
|
|
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_dfpresult_flt(reg_d);
|
2022-02-16 23:11:14 +00:00
|
|
|
fpresult_update(ppc_dblresult64_d, rc_flag);
|
2021-10-15 03:31:10 +00:00
|
|
|
} else {
|
2021-10-19 14:16:15 +00:00
|
|
|
ppc_confirm_inf_nan<double, DIV>(reg_a, reg_b, 0, rc_flag);
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2021-01-24 03:51:42 +00:00
|
|
|
void dppc_interpreter::ppc_fmul() {
|
2021-01-25 01:27:58 +00:00
|
|
|
ppc_grab_regsfpdac();
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2021-10-15 03:31:10 +00:00
|
|
|
ppc_dblresult64_d = val_reg_a * val_reg_c;
|
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_dfpresult_flt(reg_d);
|
2022-02-16 23:11:14 +00:00
|
|
|
fpresult_update(ppc_dblresult64_d, rc_flag);
|
2021-10-15 03:31:10 +00:00
|
|
|
} else {
|
2021-10-19 14:16:15 +00:00
|
|
|
ppc_confirm_inf_nan<double, MUL>(reg_a, reg_b, 0, rc_flag);
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fmadd() {
|
2021-01-25 01:27:58 +00:00
|
|
|
ppc_grab_regsfpdabc();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-15 03:31:10 +00:00
|
|
|
ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, val_reg_b);
|
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
|
2021-10-09 22:08:53 +00:00
|
|
|
ppc_store_dfpresult_flt(reg_d);
|
2022-02-16 23:11:14 +00:00
|
|
|
fpresult_update(ppc_dblresult64_d, rc_flag);
|
2021-10-15 03:31:10 +00:00
|
|
|
} else {
|
|
|
|
ppc_confirm_inf_nan<double, FMADD>(reg_a, reg_b, reg_c);
|
2020-02-21 03:00:20 +00:00
|
|
|
}
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fmsub() {
|
2021-01-25 01:27:58 +00:00
|
|
|
ppc_grab_regsfpdabc();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-15 03:31:10 +00:00
|
|
|
ppc_dblresult64_d = (val_reg_a * val_reg_c);
|
|
|
|
ppc_dblresult64_d -= val_reg_b;
|
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
|
2021-10-09 22:08:53 +00:00
|
|
|
ppc_store_dfpresult_flt(reg_d);
|
2022-02-16 23:11:14 +00:00
|
|
|
fpresult_update(ppc_dblresult64_d, rc_flag);
|
2021-10-15 03:31:10 +00:00
|
|
|
} else {
|
|
|
|
ppc_confirm_inf_nan<double, FMSUB>(reg_a, reg_b, reg_c);
|
2020-02-21 03:00:20 +00:00
|
|
|
}
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fnmadd() {
|
2021-01-25 01:27:58 +00:00
|
|
|
ppc_grab_regsfpdabc();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-15 03:31:10 +00:00
|
|
|
ppc_dblresult64_d = (val_reg_a * val_reg_c);
|
|
|
|
ppc_dblresult64_d += val_reg_b;
|
2021-10-24 21:00:35 +00:00
|
|
|
ppc_dblresult64_d = -(ppc_dblresult64_d);
|
2021-10-15 03:31:10 +00:00
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
|
2021-10-09 22:08:53 +00:00
|
|
|
ppc_store_dfpresult_flt(reg_d);
|
2022-02-16 23:11:14 +00:00
|
|
|
fpresult_update(ppc_dblresult64_d, rc_flag);
|
2021-10-17 21:41:53 +00:00
|
|
|
}
|
2021-10-15 03:31:10 +00:00
|
|
|
else {
|
|
|
|
ppc_confirm_inf_nan<double, FNMADD>(reg_a, reg_b, reg_c);
|
2020-02-21 03:00:20 +00:00
|
|
|
}
|
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fnmsub() {
|
2021-01-25 01:27:58 +00:00
|
|
|
ppc_grab_regsfpdabc();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-15 03:31:10 +00:00
|
|
|
ppc_dblresult64_d = (val_reg_a * val_reg_c);
|
|
|
|
ppc_dblresult64_d -= val_reg_b;
|
2021-10-24 21:00:35 +00:00
|
|
|
ppc_dblresult64_d = -(ppc_dblresult64_d);
|
2021-10-15 03:31:10 +00:00
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
|
2021-10-09 22:08:53 +00:00
|
|
|
ppc_store_dfpresult_flt(reg_d);
|
2022-02-16 23:11:14 +00:00
|
|
|
fpresult_update(ppc_dblresult64_d, rc_flag);
|
2021-10-15 03:31:10 +00:00
|
|
|
} else {
|
|
|
|
ppc_confirm_inf_nan<double, FNMSUB>(reg_a, reg_b, reg_c);
|
2020-02-21 03:00:20 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fadds() {
|
2021-01-25 01:27:58 +00:00
|
|
|
ppc_grab_regsfpdab();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_dblresult64_d = (float)(val_reg_a + val_reg_b);
|
2021-10-15 03:31:10 +00:00
|
|
|
|
|
|
|
if (!isnan(ppc_dblresult64_d)) {
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_sfpresult_flt(reg_d);
|
2022-02-16 23:11:14 +00:00
|
|
|
fpresult_update(ppc_dblresult64_d, rc_flag);
|
|
|
|
}
|
2021-10-30 23:43:13 +00:00
|
|
|
else {
|
2021-10-15 03:31:10 +00:00
|
|
|
ppc_confirm_inf_nan<float, ADD>(reg_a, reg_b, 0);
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fsubs() {
|
2021-01-25 01:27:58 +00:00
|
|
|
ppc_grab_regsfpdab();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-23 20:05:20 +00:00
|
|
|
ppc_dblresult64_d = (float)(val_reg_a - val_reg_b);
|
2021-10-15 03:31:10 +00:00
|
|
|
|
|
|
|
if (!isnan(ppc_dblresult64_d)) {
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_sfpresult_flt(reg_d);
|
2022-02-16 23:11:14 +00:00
|
|
|
fpresult_update(ppc_dblresult64_d, rc_flag);
|
2021-10-15 03:31:10 +00:00
|
|
|
} else {
|
|
|
|
ppc_confirm_inf_nan<float, SUB>(reg_a, reg_b, 0);
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 03:31:10 +00:00
|
|
|
void dppc_interpreter::ppc_fdivs() {
|
|
|
|
ppc_grab_regsfpdab();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-23 20:05:20 +00:00
|
|
|
ppc_dblresult64_d = (float)(val_reg_a / val_reg_b);
|
2021-10-15 03:31:10 +00:00
|
|
|
|
|
|
|
if (!isnan(ppc_dblresult64_d)) {
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_sfpresult_flt(reg_d);
|
2022-02-16 23:11:14 +00:00
|
|
|
fpresult_update(ppc_dblresult64_d, rc_flag);
|
2021-10-15 03:31:10 +00:00
|
|
|
} else {
|
|
|
|
ppc_confirm_inf_nan<float, DIV>(reg_a, reg_b, 0);
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 03:31:10 +00:00
|
|
|
void dppc_interpreter::ppc_fmuls() {
|
|
|
|
ppc_grab_regsfpdac();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-23 20:05:20 +00:00
|
|
|
ppc_dblresult64_d = (float)(val_reg_a * val_reg_c);
|
2021-10-15 03:31:10 +00:00
|
|
|
|
|
|
|
if (!isnan(ppc_dblresult64_d)) {
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_sfpresult_flt(reg_d);
|
2022-02-16 23:11:14 +00:00
|
|
|
fpresult_update(ppc_dblresult64_d, rc_flag);
|
2021-10-15 03:31:10 +00:00
|
|
|
} else {
|
|
|
|
ppc_confirm_inf_nan<float, MUL>(reg_a, 0, reg_c);
|
2020-01-22 02:25:50 +00:00
|
|
|
}
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fmadds() {
|
2021-01-25 01:27:58 +00:00
|
|
|
ppc_grab_regsfpdabc();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-15 03:31:10 +00:00
|
|
|
ppc_dblresult64_d = static_cast<double>(
|
|
|
|
std::fma((float)val_reg_a, (float)val_reg_c, (float)val_reg_b));
|
2020-02-25 14:15:42 +00:00
|
|
|
|
2021-10-15 03:31:10 +00:00
|
|
|
if (!isnan(ppc_dblresult64_d)) {
|
2021-10-09 22:08:53 +00:00
|
|
|
ppc_store_sfpresult_flt(reg_d);
|
2022-02-16 23:11:14 +00:00
|
|
|
fpresult_update(ppc_dblresult64_d, rc_flag);
|
2021-10-15 03:31:10 +00:00
|
|
|
} else {
|
|
|
|
ppc_confirm_inf_nan<float, FMADD>(reg_a, reg_b, reg_c);
|
2020-02-21 03:00:20 +00:00
|
|
|
}
|
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fmsubs() {
|
2021-01-25 01:27:58 +00:00
|
|
|
ppc_grab_regsfpdabc();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
float intermediate = float(val_reg_a * val_reg_c);
|
2021-10-15 03:31:10 +00:00
|
|
|
intermediate -= (float)val_reg_b;
|
|
|
|
ppc_dblresult64_d = static_cast<double>(intermediate);
|
2020-02-25 14:15:42 +00:00
|
|
|
|
2021-10-15 03:31:10 +00:00
|
|
|
if (!isnan(ppc_dblresult64_d)) {
|
2021-10-09 22:08:53 +00:00
|
|
|
ppc_store_sfpresult_flt(reg_d);
|
2022-02-16 23:11:14 +00:00
|
|
|
fpresult_update(ppc_dblresult64_d, rc_flag);
|
2021-10-15 03:31:10 +00:00
|
|
|
} else {
|
|
|
|
ppc_confirm_inf_nan<float, FMSUB>(reg_a, reg_b, reg_c);
|
2020-02-21 03:00:20 +00:00
|
|
|
}
|
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fnmadds() {
|
2021-01-25 01:27:58 +00:00
|
|
|
ppc_grab_regsfpdabc();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-15 03:31:10 +00:00
|
|
|
float intermediate = (float)val_reg_a * (float)val_reg_c;
|
|
|
|
intermediate += (float)val_reg_b;
|
|
|
|
intermediate = -intermediate;
|
|
|
|
ppc_dblresult64_d = static_cast<double>(intermediate);
|
2020-02-25 14:15:42 +00:00
|
|
|
|
2021-10-15 03:31:10 +00:00
|
|
|
if (!isnan(ppc_dblresult64_d)) {
|
2021-10-09 22:08:53 +00:00
|
|
|
ppc_store_sfpresult_flt(reg_d);
|
2022-02-16 23:11:14 +00:00
|
|
|
fpresult_update(ppc_dblresult64_d, rc_flag);
|
2021-10-15 03:31:10 +00:00
|
|
|
} else {
|
|
|
|
ppc_confirm_inf_nan<float, FNMADD>(reg_a, reg_b, reg_c);
|
2020-02-21 03:00:20 +00:00
|
|
|
}
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fnmsubs() {
|
2021-01-25 01:27:58 +00:00
|
|
|
ppc_grab_regsfpdabc();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-15 03:31:10 +00:00
|
|
|
float intermediate = (float)val_reg_a * (float)val_reg_c;
|
|
|
|
intermediate -= (float)val_reg_b;
|
|
|
|
intermediate = -intermediate;
|
|
|
|
ppc_dblresult64_d = static_cast<double>(intermediate);
|
2020-02-25 14:15:42 +00:00
|
|
|
|
2021-10-17 21:41:53 +00:00
|
|
|
|
2021-10-15 03:31:10 +00:00
|
|
|
if (!isnan(ppc_dblresult64_d)) {
|
2021-10-09 22:08:53 +00:00
|
|
|
ppc_store_sfpresult_flt(reg_d);
|
2022-02-16 23:11:14 +00:00
|
|
|
fpresult_update(ppc_dblresult64_d, rc_flag);
|
2021-10-15 03:31:10 +00:00
|
|
|
} else {
|
|
|
|
ppc_confirm_inf_nan<float, FNMSUB>(reg_a, reg_b, reg_c);
|
2020-02-21 03:00:20 +00:00
|
|
|
}
|
2020-02-25 14:15:42 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fabs() {
|
2021-01-24 22:06:33 +00:00
|
|
|
ppc_grab_regsfpdb();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-01-24 22:06:33 +00:00
|
|
|
ppc_dblresult64_d = abs(GET_FPR(reg_b));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_dfpresult_flt(reg_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fnabs() {
|
2021-01-24 22:06:33 +00:00
|
|
|
ppc_grab_regsfpdb();
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2021-01-24 22:06:33 +00:00
|
|
|
ppc_dblresult64_d = abs(GET_FPR(reg_b));
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_dblresult64_d = -ppc_dblresult64_d;
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_dfpresult_flt(reg_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fneg() {
|
2021-01-24 22:06:33 +00:00
|
|
|
ppc_grab_regsfpdb();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-01-24 22:06:33 +00:00
|
|
|
ppc_dblresult64_d = -(GET_FPR(reg_b));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_dfpresult_flt(reg_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fsel() {
|
2021-01-25 01:27:58 +00:00
|
|
|
ppc_grab_regsfpdabc();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-10 02:42:25 +00:00
|
|
|
ppc_dblresult64_d = (val_reg_a >= -0.0) ? val_reg_c : val_reg_b;
|
2020-01-22 02:25:50 +00:00
|
|
|
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_dfpresult_flt(reg_d);
|
2020-01-22 02:25:50 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fsqrt() {
|
2021-01-24 22:06:33 +00:00
|
|
|
ppc_grab_regsfpdb();
|
|
|
|
ppc_dblresult64_d = std::sqrt(GET_FPR(reg_b));
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_dfpresult_flt(reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fsqrts() {
|
2021-01-24 22:06:33 +00:00
|
|
|
ppc_grab_regsfpdb();
|
2021-10-07 01:59:31 +00:00
|
|
|
uint32_t test = (uint32_t)(GET_FPR(reg_b));
|
2019-07-02 02:15:33 +00:00
|
|
|
test += 127 << 23;
|
|
|
|
test >>= 1;
|
2020-01-22 02:25:50 +00:00
|
|
|
uint64_t* pre_final = (uint64_t*)&test;
|
2020-05-12 18:55:45 +00:00
|
|
|
ppc_result64_d = *pre_final;
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_sfpresult_flt(reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_frsqrte() {
|
2021-01-24 22:06:33 +00:00
|
|
|
ppc_grab_regsfpdb();
|
2021-10-07 01:59:31 +00:00
|
|
|
double testd2 = (double)(GET_FPR(reg_b));
|
2020-01-26 02:30:55 +00:00
|
|
|
for (int i = 0; i < 10; i++) {
|
2019-07-02 02:15:33 +00:00
|
|
|
testd2 = testd2 * (1.5 - (testd2 * .5) * testd2 * testd2);
|
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_dblresult64_d = testd2;
|
|
|
|
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_dfpresult_flt(reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_frsp() {
|
2021-01-24 22:06:33 +00:00
|
|
|
ppc_grab_regsfpdb();
|
|
|
|
ppc_dblresult64_d = (float)(GET_FPR(reg_b));
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_dfpresult_flt(reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fres() {
|
2021-01-24 22:06:33 +00:00
|
|
|
ppc_grab_regsfpdb();
|
2021-10-10 02:42:25 +00:00
|
|
|
double start_num = GET_FPR(reg_b);
|
|
|
|
float testf2 = (float)start_num;
|
2020-05-12 18:55:45 +00:00
|
|
|
testf2 = 1 / testf2;
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_dblresult64_d = (double)testf2;
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_dfpresult_flt(reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-10 02:42:25 +00:00
|
|
|
if (start_num == 0.0) {
|
2021-10-10 14:48:49 +00:00
|
|
|
ppc_state.fpscr |= FPSCR::ZX;
|
2021-10-10 02:42:25 +00:00
|
|
|
}
|
|
|
|
else if (std::isnan(start_num)) {
|
2021-10-10 14:48:49 +00:00
|
|
|
ppc_state.fpscr |= FPSCR::VXSNAN;
|
2021-10-17 21:41:53 +00:00
|
|
|
}
|
2021-10-10 02:42:25 +00:00
|
|
|
else if (std::isinf(start_num)){
|
2021-10-10 14:48:49 +00:00
|
|
|
ppc_state.fpscr |= FPSCR::VXSNAN;
|
2021-10-10 02:42:25 +00:00
|
|
|
ppc_state.fpscr &= 0xFFF9FFFF;
|
|
|
|
}
|
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fctiw() {
|
2021-01-24 22:06:33 +00:00
|
|
|
ppc_grab_regsfpdb();
|
2021-01-25 01:27:58 +00:00
|
|
|
double val_reg_b = GET_FPR(reg_b);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-02-05 19:45:57 +00:00
|
|
|
if (std::isnan(val_reg_b)) {
|
|
|
|
ppc_state.fpr[reg_d].int64_r = 0x80000000;
|
2021-10-10 14:48:49 +00:00
|
|
|
ppc_state.fpscr |= FPSCR::VXSNAN | FPSCR::VXCVI;
|
2021-08-03 14:01:32 +00:00
|
|
|
}
|
2021-02-05 19:45:57 +00:00
|
|
|
else if (val_reg_b > static_cast<double>(0x7fffffff)) {
|
|
|
|
ppc_state.fpr[reg_d].int64_r = 0x7fffffff;
|
2021-10-10 14:48:49 +00:00
|
|
|
ppc_state.fpscr |= FPSCR::VXCVI;
|
2021-08-03 14:01:32 +00:00
|
|
|
}
|
2021-02-05 19:45:57 +00:00
|
|
|
else if (val_reg_b < -static_cast<double>(0x80000000)) {
|
|
|
|
ppc_state.fpr[reg_d].int64_r = 0x80000000;
|
2021-10-10 14:48:49 +00:00
|
|
|
ppc_state.fpscr |= FPSCR::VXCVI;
|
2020-02-16 20:40:55 +00:00
|
|
|
}
|
2021-02-05 19:45:57 +00:00
|
|
|
else {
|
|
|
|
switch (ppc_state.fpscr & 0x3) {
|
|
|
|
case 0:
|
|
|
|
ppc_result64_d = round_to_nearest(val_reg_b);
|
2021-10-09 22:08:53 +00:00
|
|
|
break;
|
2021-02-05 19:45:57 +00:00
|
|
|
case 1:
|
|
|
|
ppc_result64_d = round_to_zero(val_reg_b);
|
2021-10-09 22:08:53 +00:00
|
|
|
break;
|
2021-02-05 19:45:57 +00:00
|
|
|
case 2:
|
|
|
|
ppc_result64_d = round_to_pos_inf(val_reg_b);
|
2021-10-09 22:08:53 +00:00
|
|
|
break;
|
2021-02-05 19:45:57 +00:00
|
|
|
case 3:
|
|
|
|
ppc_result64_d = round_to_neg_inf(val_reg_b);
|
2021-10-09 22:08:53 +00:00
|
|
|
break;
|
2021-02-05 19:45:57 +00:00
|
|
|
}
|
2020-02-16 20:40:55 +00:00
|
|
|
|
2021-02-05 19:45:57 +00:00
|
|
|
ppc_store_dfpresult_int(reg_d);
|
2021-08-03 14:01:32 +00:00
|
|
|
|
2021-02-05 19:45:57 +00:00
|
|
|
}
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fctiwz() {
|
2021-01-24 22:06:33 +00:00
|
|
|
ppc_grab_regsfpdb();
|
2021-02-05 19:45:57 +00:00
|
|
|
double val_reg_b = GET_FPR(reg_b);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-02-05 19:45:57 +00:00
|
|
|
if (std::isnan(val_reg_b)) {
|
|
|
|
ppc_state.fpr[reg_d].int64_r = 0x80000000;
|
2021-10-10 14:48:49 +00:00
|
|
|
ppc_state.fpscr |= FPSCR::VXSNAN | FPSCR::VXCVI;
|
2021-08-03 14:01:32 +00:00
|
|
|
}
|
2021-02-05 19:45:57 +00:00
|
|
|
else if (val_reg_b > static_cast<double>(0x7fffffff)) {
|
|
|
|
ppc_state.fpr[reg_d].int64_r = 0x7fffffff;
|
2021-10-10 14:48:49 +00:00
|
|
|
ppc_state.fpscr |= FPSCR::VXCVI;
|
2021-08-03 14:01:32 +00:00
|
|
|
}
|
2021-02-05 19:45:57 +00:00
|
|
|
else if (val_reg_b < -static_cast<double>(0x80000000)) {
|
|
|
|
ppc_state.fpr[reg_d].int64_r = 0x80000000;
|
2021-10-10 14:48:49 +00:00
|
|
|
ppc_state.fpscr |= FPSCR::VXCVI;
|
2021-08-03 14:01:32 +00:00
|
|
|
}
|
2021-02-05 19:45:57 +00:00
|
|
|
else {
|
|
|
|
ppc_result64_d = round_to_zero(val_reg_b);
|
|
|
|
|
|
|
|
ppc_store_dfpresult_int(reg_d);
|
|
|
|
}
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-10-17 21:30:37 +00:00
|
|
|
if (rc_flag)
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_changecrf1(ppc_dblresult64_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
// Floating Point Store and Load
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lfs() {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_grab_regsfpdia();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_effective_address += (reg_a) ? val_reg_a : 0;
|
2021-08-03 14:01:32 +00:00
|
|
|
ppc_result64_d = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
|
|
|
//ppc_result64_d = mem_grab_dword(ppc_effective_address);
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_sfpresult_int(reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lfsu() {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_grab_regsfpdia();
|
|
|
|
if (reg_a) {
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_effective_address += (reg_a) ? val_reg_a : 0;
|
2021-08-03 14:01:32 +00:00
|
|
|
ppc_result64_d = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
|
|
|
//ppc_result64_d = mem_grab_dword(ppc_effective_address);
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_sfpresult_int(reg_d);
|
|
|
|
ppc_state.gpr[reg_a] = ppc_effective_address;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
2020-01-26 02:30:55 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lfsx() {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_grab_regsfpdiab();
|
|
|
|
ppc_effective_address = (reg_a) ? val_reg_a + val_reg_b : val_reg_b;
|
2021-08-03 14:01:32 +00:00
|
|
|
ppc_result64_d = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
|
|
|
//ppc_result64_d = mem_grab_dword(ppc_effective_address);
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_sfpresult_int(reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lfsux() {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_grab_regsfpdiab();
|
|
|
|
if (reg_a) {
|
|
|
|
ppc_effective_address = val_reg_a + val_reg_b;
|
2021-08-03 14:01:32 +00:00
|
|
|
ppc_result64_d = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
|
|
|
//ppc_result64_d = mem_grab_dword(ppc_effective_address);
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_sfpresult_int(reg_d);
|
|
|
|
ppc_state.gpr[reg_a] = ppc_effective_address;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
2020-01-26 02:30:55 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lfd() {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_grab_regsfpdia();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_effective_address += (reg_a) ? val_reg_a : 0;
|
2021-06-20 20:33:03 +00:00
|
|
|
//ppc_result64_d = mem_grab_qword(ppc_effective_address);
|
|
|
|
ppc_result64_d = mmu_read_vmem<uint64_t>(ppc_effective_address);
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_dfpresult_int(reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lfdu() {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_grab_regsfpdia();
|
2020-11-29 13:52:01 +00:00
|
|
|
if (reg_a != 0) {
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_effective_address += val_reg_a;
|
2021-06-20 20:33:03 +00:00
|
|
|
//ppc_result64_d = mem_grab_qword(ppc_effective_address);
|
|
|
|
ppc_result64_d = mmu_read_vmem<uint64_t>(ppc_effective_address);
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_dfpresult_int(reg_d);
|
|
|
|
ppc_state.gpr[reg_a] = ppc_effective_address;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
2020-01-26 02:30:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lfdx() {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_grab_regsfpdiab();
|
|
|
|
ppc_effective_address = (reg_a) ? val_reg_a + val_reg_b : val_reg_b;
|
2021-06-20 20:33:03 +00:00
|
|
|
//ppc_result64_d = mem_grab_qword(ppc_effective_address);
|
|
|
|
ppc_result64_d = mmu_read_vmem<uint64_t>(ppc_effective_address);
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_dfpresult_int(reg_d);
|
2020-01-26 02:30:55 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lfdux() {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_grab_regsfpdiab();
|
|
|
|
if (reg_a) {
|
|
|
|
ppc_effective_address = val_reg_a + val_reg_b;
|
2021-06-20 20:33:03 +00:00
|
|
|
//ppc_result64_d = mem_grab_qword(ppc_effective_address);
|
|
|
|
ppc_result64_d = mmu_read_vmem<uint64_t>(ppc_effective_address);
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_store_dfpresult_int(reg_d);
|
|
|
|
ppc_state.gpr[reg_a] = ppc_effective_address;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
2020-01-26 02:30:55 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_stfs() {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_grab_regsfpsia();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_effective_address += (reg_a) ? val_reg_a : 0;
|
2021-08-03 14:01:32 +00:00
|
|
|
mmu_write_vmem<uint32_t>(ppc_effective_address, uint32_t(ppc_state.fpr[reg_s].int64_r));
|
|
|
|
//mem_write_dword(ppc_effective_address, uint32_t(ppc_state.fpr[reg_s].int64_r));
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_stfsu() {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_grab_regsfpsia();
|
2020-11-29 13:52:01 +00:00
|
|
|
if (reg_a != 0) {
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_effective_address += val_reg_a;
|
2021-08-03 14:01:32 +00:00
|
|
|
mmu_write_vmem<uint32_t>(ppc_effective_address, uint32_t(ppc_state.fpr[reg_s].int64_r));
|
|
|
|
//mem_write_dword(ppc_effective_address, uint32_t(ppc_state.fpr[reg_s].int64_r));
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_state.gpr[reg_a] = ppc_effective_address;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
2020-01-26 02:30:55 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_stfsx() {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_grab_regsfpsiab();
|
|
|
|
ppc_effective_address = (reg_a) ? val_reg_a + val_reg_b : val_reg_b;
|
2021-08-03 14:01:32 +00:00
|
|
|
mmu_write_vmem<uint32_t>(ppc_effective_address, uint32_t(ppc_state.fpr[reg_s].int64_r));
|
|
|
|
//mem_write_dword(ppc_effective_address, uint32_t(ppc_state.fpr[reg_s].int64_r));
|
2020-01-26 02:30:55 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_stfsux() {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_grab_regsfpsiab();
|
|
|
|
if (reg_a) {
|
|
|
|
ppc_effective_address = val_reg_a + val_reg_b;
|
2021-08-03 14:01:32 +00:00
|
|
|
mmu_write_vmem<uint32_t>(ppc_effective_address, uint32_t(ppc_state.fpr[reg_s].int64_r));
|
|
|
|
//mem_write_dword(ppc_effective_address, uint32_t(ppc_state.fpr[reg_s].int64_r));
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_state.gpr[reg_a] = ppc_effective_address;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
2020-01-26 02:30:55 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_stfd() {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_grab_regsfpsia();
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_effective_address += (reg_a) ? val_reg_a : 0;
|
2021-08-03 14:01:32 +00:00
|
|
|
mmu_write_vmem<uint64_t>(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
|
|
|
|
//mem_write_qword(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_stfdu() {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_grab_regsfpsia();
|
2020-11-29 13:52:01 +00:00
|
|
|
if (reg_a != 0) {
|
2020-01-26 02:30:55 +00:00
|
|
|
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_effective_address += val_reg_a;
|
2021-08-03 14:01:32 +00:00
|
|
|
mmu_write_vmem<uint64_t>(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
|
|
|
|
//mem_write_qword(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_state.gpr[reg_a] = ppc_effective_address;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
2020-01-26 02:30:55 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_stfdx() {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_grab_regsfpsiab();
|
|
|
|
ppc_effective_address = (reg_a) ? val_reg_a + val_reg_b : val_reg_b;
|
2021-08-03 14:01:32 +00:00
|
|
|
mmu_write_vmem<uint64_t>(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
|
|
|
|
//mem_write_qword(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_stfdux() {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_grab_regsfpsiab();
|
2020-11-29 13:52:01 +00:00
|
|
|
if (reg_a != 0) {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_effective_address = val_reg_a + val_reg_b;
|
2021-08-03 14:01:32 +00:00
|
|
|
mmu_write_vmem<uint64_t>(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
|
|
|
|
//mem_write_qword(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
|
2021-01-25 16:17:02 +00:00
|
|
|
ppc_state.gpr[reg_a] = ppc_effective_address;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
2020-01-26 02:30:55 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_stfiwx() {
|
2021-01-25 00:29:58 +00:00
|
|
|
ppc_grab_regsfpsiab();
|
|
|
|
ppc_effective_address = (reg_a) ? val_reg_a + val_reg_b : val_reg_b;
|
2021-08-03 14:01:32 +00:00
|
|
|
mmu_write_vmem<uint32_t>(ppc_effective_address, (uint32_t)(ppc_state.fpr[reg_s].int64_r));
|
|
|
|
//mem_write_dword(ppc_effective_address, (uint32_t)(ppc_state.fpr[reg_s].int64_r));
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-22 02:25:50 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
// Floating Point Register Transfer
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fmr() {
|
2021-01-24 22:06:33 +00:00
|
|
|
ppc_grab_regsfpdb();
|
|
|
|
ppc_state.fpr[reg_d].dbl64_r = ppc_state.fpr[reg_b].dbl64_r;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mffs() {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_grab_regsda();
|
2021-10-10 14:48:49 +00:00
|
|
|
uint64_t fpstore1 = ppc_state.fpr[reg_d].int64_r & ((uint64_t)0xFFF80000 << 32);
|
|
|
|
fpstore1 |= (uint64_t)ppc_state.fpscr;
|
2020-01-22 02:25:50 +00:00
|
|
|
fp_save_uint64(fpstore1);
|
2021-10-10 02:42:25 +00:00
|
|
|
|
|
|
|
if (rc_flag)
|
|
|
|
ppc_fp_changecrf1();
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mtfsf() {
|
2020-05-12 18:55:45 +00:00
|
|
|
reg_b = (ppc_cur_instruction >> 11) & 31;
|
2019-07-02 02:15:33 +00:00
|
|
|
uint32_t fm_mask = (ppc_cur_instruction >> 17) & 255;
|
2020-01-22 02:25:50 +00:00
|
|
|
crm += ((fm_mask & 1) == 1) ? 0xF0000000 : 0x00000000;
|
|
|
|
crm += (((fm_mask >> 1) & 1) == 1) ? 0x0F000000 : 0x00000000;
|
|
|
|
crm += (((fm_mask >> 2) & 1) == 1) ? 0x00F00000 : 0x00000000;
|
|
|
|
crm += (((fm_mask >> 3) & 1) == 1) ? 0x000F0000 : 0x00000000;
|
|
|
|
crm += (((fm_mask >> 4) & 1) == 1) ? 0x0000F000 : 0x00000000;
|
|
|
|
crm += (((fm_mask >> 5) & 1) == 1) ? 0x00000F00 : 0x00000000;
|
|
|
|
crm += (((fm_mask >> 6) & 1) == 1) ? 0x000000F0 : 0x00000000;
|
|
|
|
crm += (((fm_mask >> 7) & 1) == 1) ? 0x0000000F : 0x00000000;
|
2020-03-05 04:29:04 +00:00
|
|
|
uint32_t quickfprval = (uint32_t)ppc_state.fpr[reg_b].int64_r;
|
2020-05-12 18:55:45 +00:00
|
|
|
ppc_state.fpscr = (quickfprval & crm) | (quickfprval & ~(crm));
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2021-10-10 02:42:25 +00:00
|
|
|
if (rc_flag)
|
|
|
|
ppc_fp_changecrf1();
|
2020-01-12 01:43:47 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mtfsfi() {
|
2020-05-12 18:55:45 +00:00
|
|
|
ppc_result_b = (ppc_cur_instruction >> 11) & 15;
|
|
|
|
crf_d = (ppc_cur_instruction >> 23) & 7;
|
|
|
|
crf_d = crf_d << 2;
|
|
|
|
ppc_state.fpscr = (ppc_state.cr & ~(0xF0000000UL >> crf_d)) |
|
|
|
|
((ppc_state.spr[SPR::XER] & 0xF0000000UL) >> crf_d);
|
2020-01-12 01:43:47 +00:00
|
|
|
|
2021-10-10 02:42:25 +00:00
|
|
|
if (rc_flag)
|
|
|
|
ppc_fp_changecrf1();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mtfsb0() {
|
2021-07-08 23:02:44 +00:00
|
|
|
crf_d = (ppc_cur_instruction >> 21) & 0x1F;
|
2020-01-22 02:25:50 +00:00
|
|
|
if ((crf_d == 0) || (crf_d > 2)) {
|
2021-07-08 23:02:44 +00:00
|
|
|
ppc_state.fpscr &= ~(0x80000000UL >> crf_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2021-10-10 02:42:25 +00:00
|
|
|
if (rc_flag)
|
|
|
|
ppc_fp_changecrf1();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mtfsb1() {
|
2021-07-08 23:02:44 +00:00
|
|
|
crf_d = (ppc_cur_instruction >> 21) & 0x1F;
|
2020-01-22 02:25:50 +00:00
|
|
|
if ((crf_d == 0) || (crf_d > 2)) {
|
2021-07-08 23:02:44 +00:00
|
|
|
ppc_state.fpscr |= (0x80000000UL >> crf_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2021-10-10 02:42:25 +00:00
|
|
|
if (rc_flag)
|
|
|
|
ppc_fp_changecrf1();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mcrfs() {
|
2020-05-12 18:55:45 +00:00
|
|
|
crf_d = (ppc_cur_instruction >> 23) & 7;
|
|
|
|
crf_d = crf_d << 2;
|
|
|
|
crf_s = (ppc_cur_instruction >> 18) & 7;
|
|
|
|
crf_s = crf_d << 2;
|
2021-01-24 18:59:16 +00:00
|
|
|
ppc_state.cr = ~(ppc_state.cr & ((15 << (28 - crf_d)))) +
|
2020-05-12 18:55:45 +00:00
|
|
|
(ppc_state.fpscr & (15 << (28 - crf_s)));
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
// Floating Point Comparisons
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fcmpo() {
|
2021-01-25 01:27:58 +00:00
|
|
|
ppc_grab_regsfpsab();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.fpscr &= 0xFFFF0FFF;
|
2021-10-30 23:43:13 +00:00
|
|
|
cmp_c = 0;
|
|
|
|
crf_d = 4;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
2021-10-30 23:43:13 +00:00
|
|
|
cmp_c |= (1 << CRx_bit::CR_SO);
|
|
|
|
}
|
2022-02-16 23:11:14 +00:00
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
if (db_test_a < db_test_b) {
|
|
|
|
cmp_c |= (1 << CRx_bit::CR_LT);
|
2022-02-16 23:11:14 +00:00
|
|
|
}
|
2021-10-30 23:43:13 +00:00
|
|
|
else if (db_test_a > db_test_b) {
|
|
|
|
cmp_c |= (1 << CRx_bit::CR_GT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cmp_c |= (1 << CRx_bit::CR_EQ);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_state.fpscr &= ~(FPSCR::FPRF);
|
|
|
|
ppc_state.fpscr |= (cmp_c << 12);
|
|
|
|
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000 >> crf_d)) | ((cmp_c) >> crf_d));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-09 22:08:53 +00:00
|
|
|
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_state.fpscr |= FPSCR::FX | FPSCR::VXSNAN;
|
|
|
|
if ((ppc_state.fpscr & FPSCR::VE) == 0) {
|
2021-10-10 14:48:49 +00:00
|
|
|
ppc_state.fpscr |= FPSCR::VXVC;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-05-12 18:55:45 +00:00
|
|
|
} else if ((db_test_a == qnan) || (db_test_b == qnan)) {
|
2021-10-10 14:48:49 +00:00
|
|
|
ppc_state.fpscr |= FPSCR::VXVC;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_fcmpu() {
|
2021-01-25 01:27:58 +00:00
|
|
|
ppc_grab_regsfpsab();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
cmp_c = 0;
|
|
|
|
crf_d = 4;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
2021-10-30 23:43:13 +00:00
|
|
|
cmp_c |= (1 << CRx_bit::CR_SO);
|
|
|
|
}
|
2022-02-16 23:11:14 +00:00
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
if (db_test_a < db_test_b) {
|
|
|
|
cmp_c |= (1 << CRx_bit::CR_LT);
|
2022-02-16 23:11:14 +00:00
|
|
|
}
|
2021-10-30 23:43:13 +00:00
|
|
|
else if (db_test_a > db_test_b) {
|
|
|
|
cmp_c |= (1 << CRx_bit::CR_GT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cmp_c |= (1 << CRx_bit::CR_EQ);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
ppc_state.fpscr &= ~(FPSCR::FPRF);
|
|
|
|
ppc_state.fpscr |= (cmp_c << 12);
|
|
|
|
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000 >> crf_d)) | ((cmp_c) >> crf_d));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-30 23:43:13 +00:00
|
|
|
//if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
|
|
|
// ppc_state.fpscr |= FPSCR::VX | FPSCR::VXSNAN;
|
|
|
|
//}
|
2020-02-04 13:20:10 +00:00
|
|
|
}
|