Skip to content

Commit

Permalink
Merge pull request #5 from clash-lang/f-extension
Browse files Browse the repository at this point in the history
Add F extension to CPU
  • Loading branch information
hydrolarus authored Aug 1, 2023
2 parents 47da9f8 + 37ecabb commit 420f75a
Show file tree
Hide file tree
Showing 10 changed files with 11,600 additions and 710 deletions.
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

[build]
target = "riscv32imc-unknown-none-elf"
rustflags = ["-C", "target-feature=+f"]
10 changes: 10 additions & 0 deletions clash-vexriscv-sim/app/Clash.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- SPDX-FileCopyrightText: 2023 Google LLC
--
-- SPDX-License-Identifier: Apache-2.0

import Prelude
import System.Environment (getArgs)
import Clash.Main (defaultMain)

main :: IO ()
main = getArgs >>= defaultMain
21 changes: 21 additions & 0 deletions clash-vexriscv-sim/app/HdlTest.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- SPDX-FileCopyrightText: 2023 Google LLC
--
-- SPDX-License-Identifier: Apache-2.0

import Clash.Prelude
import Clash.Annotations.TH

import VexRiscv

circuit ::
"CLK" ::: Clock System ->
"RST" ::: Reset System ->
"INPUT" ::: Signal System Input ->
"OUTPUT" ::: Signal System Output
circuit clk rst input =
withClockResetEnable clk rst enableGen vexRiscv input

makeTopEntity 'circuit

main :: IO ()
main = pure ()
4 changes: 2 additions & 2 deletions clash-vexriscv-sim/app/VexRiscvSimulation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ debugConfig =
--
{-
InspectBusses
500
50
0
(Just 150)
(Just 300)
True
True
-- -}
Expand Down
15 changes: 15 additions & 0 deletions clash-vexriscv-sim/clash-vexriscv-sim.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ library
elf >= 0.31 && < 0.32,
bytestring >= 0.10 && < 0.11,

executable clash
import: common-options
main-is: app/Clash.hs
build-Depends: base, clash-ghc

executable hdl-test
import: common-options
main-is: app/HdlTest.hs
build-Depends:
base,
clash-prelude,
clash-protocols,
clash-vexriscv,
clash-vexriscv-sim,

executable clash-vexriscv-bin
import: common-options
main-is: VexRiscvSimulation.hs
Expand Down
6 changes: 6 additions & 0 deletions clash-vexriscv-sim/test-programs/src/bin/fpu_test.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This test makes sure the FPU works as expected
79823i32 as f32 = 79823
1.3 + 5.3 = 6.6000004
5.3 - 1.3 = 4
24.65 * 43.2 = 1064.88
12.6 / 4.2 = 3.0000002
54 changes: 54 additions & 0 deletions clash-vexriscv-sim/test-programs/src/bin/fpu_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-FileCopyrightText: 2022 Google LLC
//
// SPDX-License-Identifier: Apache-2.0

#![no_std]
#![cfg_attr(not(test), no_main)]

use core::fmt::Write;

#[cfg(not(test))]
use riscv_rt::entry;

#[cfg(not(test))]
extern crate panic_halt;

const ADDR: *mut u8 = 0x0000_1000 as *mut u8;

fn print(s: &str) {
for b in s.bytes() {
unsafe {
ADDR.write_volatile(b);
}
}
}

struct PrintAddr;

impl core::fmt::Write for PrintAddr {
fn write_str(&mut self, s: &str) -> core::fmt::Result {
print(s);
Ok(())
}
}

#[cfg_attr(not(test), entry)]
fn main() -> ! {
let mut addr = PrintAddr;

print("This test makes sure the FPU works as expected\n");

#[allow(clippy::unnecessary_cast)]
let _ = writeln!(addr, "79823i32 as f32 = {}", 79823i32 as f32);

let _ = writeln!(addr, "1.3 + 5.3 = {}", 1.3f32 + 5.3f32);
let _ = writeln!(addr, "5.3 - 1.3 = {}", 5.3f32 - 1.3f32);

let _ = writeln!(addr, "24.65 * 43.2 = {}", 24.65f32 * 43.2f32);

let _ = writeln!(addr, "12.6 / 4.2 = {}", 12.6f32 / 4.2f32);

loop {
continue;
}
}
Loading

0 comments on commit 420f75a

Please sign in to comment.