Skip to content
Open

SIMD #57

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions arca/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,4 @@ impl<R: Runtime> Entry<R> {
pub fn is_empty(&self) -> bool {
self.len() == 0
}

pub fn byte_size(&self) -> usize {
match self {
Entry::Null(_) => 0,
Entry::ROPage(page) => page.len(),
Entry::RWPage(page) => page.len(),
Entry::ROTable(table) => ValueRef::Table(table).byte_size(),
Entry::RWTable(table) => ValueRef::Table(table).byte_size(),
}
}
}
20 changes: 20 additions & 0 deletions arca/src/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ impl<R: Runtime, A: Into<Value<R>>, B: Into<Value<R>>, C: Into<Value<R>>, D: Int
}
}

impl<
R: Runtime,
A: Into<Value<R>>,
B: Into<Value<R>>,
C: Into<Value<R>>,
D: Into<Value<R>>,
E: Into<Value<R>>,
> From<(A, B, C, D, E)> for Tuple<R>
{
fn from(value: (A, B, C, D, E)) -> Self {
let mut tuple = Tuple::new(4);
tuple.set(0, value.0);
tuple.set(1, value.1);
tuple.set(2, value.2);
tuple.set(3, value.3);
tuple.set(4, value.4);
tuple
}
}

impl<R: Runtime> From<&mut [Value<R>]> for Tuple<R> {
fn from(value: &mut [Value<R>]) -> Self {
let mut tuple = Tuple::new(value.len());
Expand Down
41 changes: 0 additions & 41 deletions arca/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,6 @@ impl<R: Runtime> Value<R> {
Value::Function(_) => DataType::Function,
}
}

pub fn byte_size(&self) -> usize {
match self {
Value::Null(_) => 0,
Value::Word(word) => word.len(),
Value::Blob(blob) => blob.len(),
Value::Tuple(tuple) => tuple
.iter()
.map(|v| v.byte_size())
.reduce(|x, y| x + y)
.unwrap_or(0),
Value::Page(page) => page.len(),
Value::Table(table) => table
.iter()
.map(|e| e.byte_size())
.reduce(|x, y| x + y)
.unwrap(),
Value::Function(function) => function.read_cloned().byte_size(),
}
}
}

impl<R: Runtime> From<Option<Value<R>>> for Value<R> {
Expand Down Expand Up @@ -139,27 +119,6 @@ impl<'a, R: Runtime> ValueRef<'a, R> {
ValueRef::Function(x) => RawValueRef::Function(x.inner()),
}
}

pub fn byte_size(&self) -> usize {
todo!("don't call this");
// match self {
// ValueRef::Null(_) => 0,
// ValueRef::Word(word) => word.len(),
// ValueRef::Blob(blob) => blob.len(),
// ValueRef::Tuple(tuple) => tuple
// .iter()
// .map(|v| v.byte_size())
// .reduce(|x, y| x + y)
// .unwrap(),
// ValueRef::Page(page) => page.len(),
// ValueRef::Table(table) => table
// .iter()
// .map(|e| e.byte_size())
// .reduce(|x, y| x + y)
// .unwrap(),
// ValueRef::Function(function) => function.read_cloned().byte_size(),
// }
}
}

#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down
6 changes: 6 additions & 0 deletions arca/src/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ impl<R: Runtime> From<u64> for Word<R> {
Self::new(value)
}
}

impl<R: Runtime> From<Word<R>> for u64 {
fn from(value: Word<R>) -> Self {
value.read()
}
}
5 changes: 3 additions & 2 deletions common/src/elfloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ pub fn load_elf<R: arca::Runtime>(elf: &[u8]) -> Result<Function<R>, Error> {
let mut rlimit = R::create_tuple(1);
rlimit.set(0, Word::from(1 << 21));

let mut data = R::create_tuple(4);
let mut data = R::create_tuple(5);
data.set(0, Value::Tuple(registers));
data.set(1, Value::Table(table));
data.set(2, Value::Tuple(descriptors));
data.set(3, Value::Tuple(rlimit));
data.set(3, R::create_word(0));
data.set(4, R::create_null());

let args = R::create_tuple(0);
R::create_function(Tuple::from(("Arcane", data, args)).into()).map_err(|_| Error::Runtime)
Expand Down
4 changes: 4 additions & 0 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ test = false
name = "webserver"
test = false

[[example]]
name = "simd"
test = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
Expand Down
21 changes: 21 additions & 0 deletions kernel/examples/simd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#![no_std]
#![no_main]

use common::elfloader;
use kernel::prelude::*;

const USER: &[u8] = include_bytes!(env!("CARGO_BIN_FILE_USER_simd"));

#[kmain]
fn main() {
let user: Function = elfloader::load_elf(USER).unwrap();
let x = Blob::new(&[28u8; 32]);
let y = Blob::new(&[3u8; 32]);
let result: Blob = user
.apply(x)
.apply(y)
.force()
.try_into()
.expect("result was not a blob");
assert_eq!(result, Blob::new(&[31u8; 32]));
}
3 changes: 3 additions & 0 deletions kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#![feature(ptr_metadata)]
#![feature(atomic_ptr_null)]
#![feature(custom_test_frameworks)]
#![feature(portable_simd)]
#![feature(const_block_items)]
#![test_runner(testing::harness)]
#![reexport_test_harness_main = "test_main"]

Expand Down Expand Up @@ -46,6 +48,7 @@ mod pipe;
mod registers;
mod rsstart;
mod tss;
mod xstate;

#[cfg(test)]
mod testing;
Expand Down
1 change: 1 addition & 0 deletions kernel/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub use crate::{
PageTable512GBEntry,
},
print, println, shutdown,
types::arca::XSaveData,
types::{Arca, Blob, Entry, Function, Null, Page, Runtime, Table, Tuple, Value, Word},
};

Expand Down
1 change: 1 addition & 0 deletions kernel/src/rsstart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ unsafe extern "C" fn _start(
crate::tsc::init();
crate::kvmclock::init();
crate::iprofile::init();
crate::xstate::init();

let gdtr = GdtDescriptor::new(&**crate::gdt::GDT);

Expand Down
Loading
Loading