Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e037d167f41a
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2a9e370840f6
Choose a head ref
  • 4 commits
  • 24 files changed
  • 1 contributor

Commits on Oct 16, 2016

  1. Copy the full SHA
    fee75bd View commit details
  2. runtime: port ksupport to Rust.

    whitequark committed Oct 16, 2016
    Copy the full SHA
    a8c017b View commit details
  3. runtime: use i64 for watchdog timeout, not i32.

    whitequark committed Oct 16, 2016
    Copy the full SHA
    7618907 View commit details
  4. Copy the full SHA
    2a9e370 View commit details
7 changes: 0 additions & 7 deletions artiq/compiler/module.py
Original file line number Diff line number Diff line change
@@ -81,13 +81,6 @@ def build_llvm_ir(self, target):
embedding_map=self.embedding_map)
return llvm_ir_generator.process(self.artiq_ir, attribute_writeback=True)

def entry_point(self):
"""Return the name of the function that is the entry point of this module."""
if self.name != "":
return self.name + ".__modinit__"
else:
return "__modinit__"

def __repr__(self):
printer = types.TypePrinter()
globals = ["%s: %s" % (var, printer.name(self.globals[var])) for var in self.globals]
7 changes: 3 additions & 4 deletions artiq/compiler/targets.py
Original file line number Diff line number Diff line change
@@ -161,9 +161,9 @@ def assemble(self, llmodule):

return llmachine.emit_object(llmodule)

def link(self, objects, init_fn):
def link(self, objects):
"""Link the relocatable objects into a shared library for this target."""
with RunTool([self.triple + "-ld", "-shared", "--eh-frame-hdr", "-init", init_fn] +
with RunTool([self.triple + "-ld", "-shared", "--eh-frame-hdr"] +
["{{obj{}}}".format(index) for index in range(len(objects))] +
["-o", "{output}"],
output=b"",
@@ -177,8 +177,7 @@ def link(self, objects, init_fn):
return library

def compile_and_link(self, modules):
return self.link([self.assemble(self.compile(module)) for module in modules],
init_fn=modules[0].entry_point())
return self.link([self.assemble(self.compile(module)) for module in modules])

def strip(self, library):
with RunTool([self.triple + "-strip", "--strip-debug", "{library}", "-o", "{output}"],
4 changes: 2 additions & 2 deletions artiq/compiler/testbench/perf_embedding.py
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ def embed():
target = OR1KTarget()
llvm_ir = target.compile(module)
elf_obj = target.assemble(llvm_ir)
elf_shlib = target.link([elf_obj], init_fn=module.entry_point())
elf_shlib = target.link([elf_obj])

benchmark(lambda: embed(),
"ARTIQ embedding")
@@ -61,7 +61,7 @@ def embed():
benchmark(lambda: target.assemble(llvm_ir),
"LLVM machine code emission")

benchmark(lambda: target.link([elf_obj], init_fn=module.entry_point()),
benchmark(lambda: target.link([elf_obj]),
"Linking")

benchmark(lambda: target.strip(elf_shlib),
2 changes: 1 addition & 1 deletion artiq/compiler/transforms/artiq_ir_generator.py
Original file line number Diff line number Diff line change
@@ -821,7 +821,7 @@ def visit_With(self, node):
timeout = self.visit(context_expr_node.args[0])
timeout_ms = self.append(ir.Arith(ast.Mult(loc=None), timeout,
ir.Constant(1000, builtins.TFloat())))
timeout_ms_int = self.append(ir.Coerce(timeout_ms, builtins.TInt32()))
timeout_ms_int = self.append(ir.Coerce(timeout_ms, builtins.TInt64()))

watchdog_id = self.append(ir.Builtin("watchdog_set", [timeout_ms_int],
builtins.TInt32()))
12 changes: 6 additions & 6 deletions artiq/compiler/transforms/llvm_ir_generator.py
Original file line number Diff line number Diff line change
@@ -323,8 +323,6 @@ def llbuiltin(self, name):
llty = ll.FunctionType(llvoid, [])
elif name == "llvm.floor.f64":
llty = ll.FunctionType(lldouble, [lldouble])
elif name == "llvm.round.f64":
llty = ll.FunctionType(lldouble, [lldouble])
elif name == "llvm.pow.f64":
llty = ll.FunctionType(lldouble, [lldouble, lldouble])
elif name == "llvm.powi.f64":
@@ -349,14 +347,16 @@ def llbuiltin(self, name):
llty = ll.FunctionType(lli32, [llptr])
elif name == "strcmp":
llty = ll.FunctionType(lli32, [llptr, llptr])
elif name == "lround":
llty = ll.FunctionType(lli32, [lldouble])
elif name == "send_rpc":
llty = ll.FunctionType(llvoid, [lli32, llptr, llptrptr])
elif name == "recv_rpc":
llty = ll.FunctionType(lli32, [llptr])
elif name == "now":
llty = lli64
elif name == "watchdog_set":
llty = ll.FunctionType(lli32, [lli32])
llty = ll.FunctionType(lli32, [lli64])
elif name == "watchdog_clear":
llty = ll.FunctionType(llvoid, [lli32])
else:
@@ -1041,9 +1041,8 @@ def process_Builtin(self, insn):
name=insn.name)
elif insn.op == "round":
llarg = self.map(insn.operands[0])
llvalue = self.llbuilder.call(self.llbuiltin("llvm.round.f64"), [llarg])
return self.llbuilder.fptosi(llvalue, self.llty_of_type(insn.type),
name=insn.name)
return self.llbuilder.call(self.llbuiltin("lround"), [llarg],
name=insn.name)
elif insn.op == "globalenv":
def get_outer(llenv, env_ty):
if "$outer" in env_ty.params:
@@ -1290,6 +1289,7 @@ def ret_error_handler(typ):

self.llbuilder.position_at_end(llalloc)
llalloca = self.llbuilder.alloca(lli8, llsize, name="rpc.alloc")
llalloca.align = 4 # maximum alignment required by OR1K ABI
llphi.add_incoming(llalloca, llalloc)
self.llbuilder.branch(llhead)

4 changes: 4 additions & 0 deletions artiq/runtime.rs/libksupport/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions artiq/runtime.rs/libksupport/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
authors = ["The ARTIQ Project Developers"]
name = "ksupport"
version = "0.0.0"

[lib]
name = "ksupport"
path = "lib.rs"
crate-type = ["staticlib"]

[profile.dev]
panic = 'unwind'
opt-level = 2
120 changes: 120 additions & 0 deletions artiq/runtime.rs/libksupport/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
use libc::{c_void, c_char, size_t};

macro_rules! api {
($i:ident) => ({
extern { static $i: c_void; }
api!($i = &$i as *const _)
});
($i:ident, $d:item) => ({
$d
api!($i = $i)
});
($i:ident = $e:expr) => {
(stringify!($i), unsafe { $e as *const () })
}
}

pub fn resolve(required: &str) -> usize {
unsafe {
API.iter()
.find(|&&(exported, _)| exported == required)
.map(|&(_, ptr)| ptr as usize)
.unwrap_or(0)
}
}

#[allow(unused_unsafe)]
static mut API: &'static [(&'static str, *const ())] = &[
api!(__divsi3),
api!(__modsi3),
api!(__ledf2),
api!(__gedf2),
api!(__unorddf2),
api!(__eqdf2),
api!(__ltdf2),
api!(__nedf2),
api!(__gtdf2),
api!(__negsf2),
api!(__negdf2),
api!(__addsf3),
api!(__subsf3),
api!(__mulsf3),
api!(__divsf3),
api!(__lshrdi3),
api!(__muldi3),
api!(__divdi3),
api!(__ashldi3),
api!(__ashrdi3),
api!(__udivmoddi4),
api!(__floatsisf),
api!(__floatunsisf),
api!(__fixsfsi),
api!(__fixunssfsi),
api!(__adddf3),
api!(__subdf3),
api!(__muldf3),
api!(__divdf3),
api!(__floatsidf),
api!(__floatunsidf),
api!(__floatdidf),
api!(__fixdfsi),
api!(__fixdfdi),
api!(__fixunsdfsi),
api!(__clzsi2),
api!(__ctzsi2),
api!(__udivdi3),
api!(__umoddi3),
api!(__moddi3),
api!(__powidf2),

/* libc */
api!(strcmp),
api!(strlen, extern { fn strlen(s: *const c_char) -> size_t; }),
api!(abort = ::abort),

/* libm */
api!(sqrt),
api!(lround),

/* exceptions */
api!(_Unwind_Resume),
api!(__artiq_personality),
api!(__artiq_raise),
api!(__artiq_reraise),

/* proxified syscalls */
api!(core_log),

api!(now = &::NOW as *const _),

api!(watchdog_set = ::watchdog_set),
api!(watchdog_clear = ::watchdog_clear),

api!(send_rpc = ::send_rpc),
api!(recv_rpc = ::recv_rpc),

api!(cache_get = ::cache_get),
api!(cache_put = ::cache_put),

/* direct syscalls */
api!(rtio_init),
api!(rtio_get_counter),
api!(rtio_log),
api!(rtio_output),
api!(rtio_input_timestamp),
api!(rtio_input_data),

// #if ((defined CONFIG_RTIO_DDS_COUNT) && (CONFIG_RTIO_DDS_COUNT > 0))
api!(dds_init),
api!(dds_init_sync),
api!(dds_batch_enter),
api!(dds_batch_exit),
api!(dds_set),
// #endif

api!(i2c_init),
api!(i2c_start),
api!(i2c_stop),
api!(i2c_write),
api!(i2c_read),
];
57 changes: 57 additions & 0 deletions artiq/runtime.rs/libksupport/dyld.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use core::{ptr, slice, str};
use core::slice::SliceExt;
use libc::{c_void, c_char, c_int, size_t};

#[allow(non_camel_case_types)]
#[repr(C)]
#[derive(Default)]
struct dyld_info {
__opaque: [usize; 7]
}

extern {
fn dyld_load(shlib: *const c_void, base: usize,
resolve: extern fn(*mut c_void, *const c_char) -> usize,
resolve_data: *mut c_void,
info: *mut dyld_info, error_out: *mut *const c_char) -> c_int;
fn dyld_lookup(symbol: *const c_char, info: *const dyld_info) -> *const c_void;

fn strlen(ptr: *const c_char) -> size_t;
}

pub struct Library {
lower: dyld_info
}

impl Library {
pub unsafe fn load<F>(shlib: &[u8], base: usize, mut resolve: F)
-> Result<Library, &'static str>
where F: Fn(&str) -> usize {
extern fn wrapper<F>(data: *mut c_void, name: *const c_char) -> usize
where F: Fn(&str) -> usize {
unsafe {
let f = data as *mut F;
let name = slice::from_raw_parts(name as *const u8, strlen(name));
(*f)(str::from_utf8_unchecked(name))
}
}

let mut library = Library { lower: dyld_info::default() };
let mut error: *const c_char = ptr::null();
if dyld_load(shlib.as_ptr() as *const _, base,
wrapper::<F>, &mut resolve as *mut _ as *mut _,
&mut library.lower, &mut error) == 0 {
let error = slice::from_raw_parts(error as *const u8, strlen(error));
Err(str::from_utf8_unchecked(error))
} else {
Ok(library)
}
}

pub unsafe fn lookup(&self, symbol: &str) -> usize {
assert!(symbol.len() < 32);
let mut buf = [0u8; 32];
buf[0..symbol.as_bytes().len()].copy_from_slice(symbol.as_bytes());
dyld_lookup(&buf as *const _ as *const c_char, &self.lower) as usize
}
}
Loading