Implement float math and type conversion instructions (054-067)

This commit is contained in:
Arturo
2026-03-30 23:44:10 -06:00
parent 0015387d60
commit 7d3781681d
2 changed files with 207 additions and 20 deletions

View File

@@ -4,39 +4,69 @@
*/
#include <spider/runtime/cpu/CPU.hpp>
#include <cmath> // provides std::fmod, std::fma and cast support
namespace spider {
// ── 0x060 — F2D: Float (f32) to Double (f64) ─────────────────────────────
// Widening conversion — no precision is lost
void CPU::F2D() {
// TODO: Implement F2D
fetchOperDst();
_dst->_f64 = static_cast<f64>(_dst->_f32);
(this->*_post)();
}
// ── 0x061 — D2F: Double (f64) to Float (f32) ─────────────────────────────
// Narrowing conversion — precision may be lost
void CPU::D2F() {
// TODO: Implement D2F
fetchOperDst();
_dst->_f32 = static_cast<f32>(_dst->_f64);
(this->*_post)();
}
// ── 0x062 — I2F: Integer (i32) to Float (f32) ────────────────────────────
void CPU::I2F() {
// TODO: Implement I2F
fetchOperDst();
_dst->_f32 = static_cast<f32>(_dst->_u32);
(this->*_post)();
}
// ── 0x063 — I2D: Integer (i32) to Double (f64) ───────────────────────────
void CPU::I2D() {
// TODO: Implement I2D
fetchOperDst();
_dst->_f64 = static_cast<f64>(_dst->_u32);
(this->*_post)();
}
// ── 0x064 — L2F: Long (i64) to Float (f32) ───────────────────────────────
void CPU::L2F() {
// TODO: Implement L2F
fetchOperDst();
_dst->_f32 = static_cast<f32>(_dst->_u64);
(this->*_post)();
}
// ── 0x065 — L2D: Long (i64) to Double (f64) ──────────────────────────────
void CPU::L2D() {
// TODO: Implement L2D
fetchOperDst();
_dst->_f64 = static_cast<f64>(_dst->_u64);
(this->*_post)();
}
// ── 0x066 — F2I: Float (f32) to Integer (i32) ────────────────────────────
// Truncates toward zero
void CPU::F2I() {
// TODO: Implement F2I
fetchOperDst();
_dst->_u32 = static_cast<u32>(_dst->_f32);
(this->*_post)();
}
// ── 0x067 — F2L: Float (f32) to Long (i64) ───────────────────────────────
// Truncates toward zero
void CPU::F2L() {
// TODO: Implement F2L
fetchOperDst();
_dst->_u64 = static_cast<u64>(_dst->_f32);
(this->*_post)();
}
void CPU::D2I() {