Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
chip-ahoyto
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
João Magalhães
chip-ahoyto
Commits
eb30a230
Verified
Commit
eb30a230
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
feat: initial benchark support for neo
parent
5f80ce06
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#567
passed
2 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/benchmark/src/main.rs
+38
-5
38 additions, 5 deletions
examples/benchmark/src/main.rs
src/chip8_neo.rs
+27
-0
27 additions, 0 deletions
src/chip8_neo.rs
with
65 additions
and
5 deletions
examples/benchmark/src/main.rs
+
38
−
5
View file @
eb30a230
use
chip_ahoyto
::{
chip8
::
Chip8
,
util
::
read_file
};
use
chip_ahoyto
::{
chip8
::
Chip8
,
chip8_neo
::
Chip8Neo
,
util
::
read_file
};
use
time
::
Instant
;
const
CYCLE_COUNT
:
u64
=
1
_000_000_000
;
const
CYCLE_COUNT
:
u64
=
5
_000_000_000
;
fn
main
()
{
fn
benchmark_chip8
()
{
let
rom_path
=
"./resources/pong.ch8"
;
let
rom
=
read_file
(
rom_path
);
...
...
@@ -15,7 +15,32 @@ fn main() {
let
cycles
=
CYCLE_COUNT
;
println!
(
"Running {} cycles for {}"
,
cycles
,
rom_path
);
println!
(
"[Chip8] Running {} cycles for {}"
,
cycles
,
rom_path
);
for
_
in
0
..
CYCLE_COUNT
{
chip8
.tick
();
}
let
duration_s
=
instant
.elapsed
()
.as_seconds_f32
();
let
cycles_second
=
cycles
as
f32
/
duration_s
;
let
mega_second
=
cycles_second
/
1000.0
/
1000.0
;
println!
(
"[Chip8] Took {} seconds or {:.2} MHz CPU"
,
duration_s
,
mega_second
);
}
fn
benchmark_chip8_neo
()
{
let
rom_path
=
"./resources/pong.ch8"
;
let
mut
chip8
=
Chip8Neo
::
new
();
let
instant
=
Instant
::
now
();
let
cycles
=
CYCLE_COUNT
;
println!
(
"[Chip8Neo] Running {} cycles for {}"
,
cycles
,
rom_path
);
for
_
in
0
..
CYCLE_COUNT
{
chip8
.tick
();
...
...
@@ -25,5 +50,13 @@ fn main() {
let
cycles_second
=
cycles
as
f32
/
duration_s
;
let
mega_second
=
cycles_second
/
1000.0
/
1000.0
;
println!
(
"Took {} seconds or {:.2} MHz CPU"
,
duration_s
,
mega_second
);
println!
(
"[Chip8Neo] Took {} seconds or {:.2} MHz CPU"
,
duration_s
,
mega_second
);
}
fn
main
()
{
benchmark_chip8
();
benchmark_chip8_neo
();
}
This diff is collapsed.
Click to expand it.
src/chip8_neo.rs
+
27
−
0
View file @
eb30a230
...
...
@@ -4,6 +4,10 @@ pub const RAM_SIZE: usize = 4096;
pub
const
STACK_SIZE
:
usize
=
16
;
pub
const
REGISTERS_SIZE
:
usize
=
16
;
/// The starting address for the ROM loading, should be
/// the initial PC position.
const
ROM_START
:
usize
=
0x200
;
pub
struct
Chip8Neo
{
ram
:
[
u8
;
RAM_SIZE
],
vram
:
[
u8
;
DISPLAY_WIDTH
*
DISPLAY_HEIGHT
],
...
...
@@ -15,3 +19,26 @@ pub struct Chip8Neo {
dt
:
u8
,
st
:
u8
,
}
#[cfg_attr(feature
=
"web"
,
wasm_bindgen)]
impl
Chip8Neo
{
#[cfg_attr(feature
=
"web"
,
wasm_bindgen(constructor))]
pub
fn
new
()
->
Chip8Neo
{
let
chip8
=
Chip8Neo
{
ram
:
[
0u8
;
RAM_SIZE
],
vram
:
[
0u8
;
DISPLAY_WIDTH
*
DISPLAY_HEIGHT
],
stack
:
[
0u16
;
STACK_SIZE
],
registers
:
[
0u8
;
REGISTERS_SIZE
],
pc
:
ROM_START
as
u16
,
i
:
0x0
,
sp
:
0x0
,
dt
:
0x0
,
st
:
0x0
,
};
chip8
}
pub
fn
tick
(
&
mut
self
)
{
self
.pc
+=
0x2
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment