-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e0f856
commit 4707b06
Showing
6 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
target_sources(basic_emu PUBLIC ${SOURCE_DIR}/basicComponents/Cpu.cpp) | ||
target_sources(basic_emu PUBLIC | ||
${SOURCE_DIR}/basicComponents/Cpu.cpp | ||
${SOURCE_DIR}/basicComponents/Fpu.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <Fpu.h> | ||
|
||
RegisterFpu& Fpu::st(std::size_t index){ | ||
return stack[stack.size() - index - 1]; | ||
} | ||
|
||
bool Fpu::push(RegisterFpu val){ | ||
if(stack.size() == numRegisters) { | ||
return false; | ||
} | ||
stack.push_back(val); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
#include <Register.h> | ||
|
||
class Fpu { | ||
public: | ||
RegisterFpu& st(std::size_t index); | ||
bool push(RegisterFpu val); | ||
|
||
private: | ||
static constexpr auto numRegisters = 8; | ||
std::vector<RegisterFpu> stack; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include <basicComponents/Fpu.h> | ||
|
||
TEST(FpuTest, testStAccess){ | ||
Fpu fpu; | ||
RegisterFpu sth; | ||
sth.set<double>(1.0); | ||
fpu.push(sth); | ||
EXPECT_DOUBLE_EQ(fpu.st(0).get<double>(), 1.0); | ||
sth.set<float>(2.f); | ||
fpu.push(sth); | ||
EXPECT_DOUBLE_EQ(fpu.st(0).get<double>(), 2.0); | ||
EXPECT_DOUBLE_EQ(fpu.st(1).get<double>(), 1.0); | ||
sth.set<double>(3.0); | ||
fpu.push(sth); | ||
EXPECT_DOUBLE_EQ(fpu.st(0).get<double>(), 3.0); | ||
EXPECT_DOUBLE_EQ(fpu.st(1).get<double>(), 2.0); | ||
EXPECT_DOUBLE_EQ(fpu.st(2).get<double>(), 1.0); | ||
} | ||
|
||
TEST(FpuTest, testFpuStackOverflow){ | ||
Fpu fpu; | ||
for(size_t i = 0u ; i < 8; i++){ | ||
EXPECT_TRUE(fpu.push(RegisterFpu())); | ||
} | ||
EXPECT_FALSE(fpu.push(RegisterFpu())); | ||
} | ||
|