...
 
......@@ -118,6 +118,7 @@ impl Instruction {
| CommonInst_Tr64ToTag(_)
| Move(_)
| PrintHex(_)
| PrintBool(_)
| SetRetval(_)
| GetVMThreadLocal
| KillStack(_)
......@@ -180,6 +181,7 @@ impl Instruction {
| CommonInst_Unpin(_)
| CommonInst_GetAddr(_)
| PrintHex(_)
| PrintBool(_)
| SetRetval(_)
| KillStack(_) => true,
BinOp(_, _, _)
......@@ -280,6 +282,7 @@ impl Instruction {
| CommonInst_Tr64ToTag(_)
| Move(_)
| PrintHex(_)
| PrintBool(_)
| SetRetval(_)
| GetVMThreadLocal
| KillStack(_)
......@@ -362,6 +365,7 @@ impl Instruction {
| CommonInst_Tr64ToTag(_)
| Move(_)
| PrintHex(_)
| PrintBool(_)
| SetRetval(_)
| GetVMThreadLocal
| KillStack(_)
......@@ -439,6 +443,7 @@ impl Instruction {
CommonInst_Tr64ToTag(_) |
Move(_) |
PrintHex(_) |
PrintBool(_) |
SetRetval(_) |
GetVMThreadLocal |
KillStack(_) |
......@@ -885,6 +890,7 @@ impl Instruction {
&Instruction_::Move(from) => format!("MOVE<{}> {}", ops[from].ty(), ops[from]),
// print hex
&Instruction_::PrintHex(i) => format!("PRINTHEX<{}> {}", ops[i].ty(), ops[i]),
&Instruction_::PrintBool(i) => format!("PRINTBOOL<{}> {}", ops[i].ty(), ops[i]),
// set retval
&Instruction_::SetRetval(val) => format!("SETRETVAL {}", ops[val]),
// get vm thread local
......@@ -943,7 +949,10 @@ pub enum Instruction_ {
/// a non-terminating CCall instruction (the call does not have an exceptional branch)
/// This instruction is not in the Mu spec, but is documented in the HOL formal spec
ExprCCall { data: CallData, is_abort: bool },
ExprCCall {
data: CallData,
is_abort: bool,
},
/// load instruction
Load {
......@@ -1044,7 +1053,7 @@ pub enum Instruction_ {
/// clear the cpu set of a thread, so that it contains not CPUs
/// args:
/// - threadref for the target thread
AffinityZero(OpIndex),
AffinityZero(OpIndex), // TODO Check aff zero and equal and probably remove them
/// add a cpu to the cpu set of a thread
/// args:
......@@ -1099,7 +1108,10 @@ pub enum Instruction_ {
},
/// get internal reference to an element in hybrid var part
GetVarPartIRef { is_ptr: bool, base: OpIndex },
GetVarPartIRef {
is_ptr: bool,
base: OpIndex,
},
/// a fence of certain memory order
Fence(MemoryOrder),
......@@ -1241,6 +1253,7 @@ pub enum Instruction_ {
Move(OpIndex),
/// internal use: print op as hex value
PrintHex(OpIndex),
PrintBool(OpIndex),
/// internal use: set return value for main
SetRetval(OpIndex),
/// internal use: get zebu thread local
......
......@@ -2002,10 +2002,6 @@ impl<'a> InstructionSelection {
let ref thread = ops[thread];
let ref priority = ops[priority];
// let tmp_priority = {
// self.make_int64_const(priority as u64, vm)
// };
let tmp_thread = self.emit_ireg(thread, f_content, f_context, vm);
let tmp_priority = self.emit_ireg(priority, f_content, f_context, vm);
......@@ -2231,6 +2227,23 @@ impl<'a> InstructionSelection {
);
}
Instruction_::PrintBool(index) => {
trace!("instsel on PRINTBOOL");
let ref ops = inst.ops;
let ref op = ops[index];
self.emit_runtime_entry(
&entrypoints::PRINT_BOOL,
vec![op.clone_value()],
None,
Some(node),
f_content,
f_context,
vm,
);
}
Instruction_::SetRetval(index) => {
trace!("instsel on SETRETVAL");
......
......@@ -707,7 +707,7 @@ pub fn estimate_insts_for_ir(inst: &Instruction) -> usize {
// others
Move(_) => 0,
PrintHex(_) => 10,
PrintHex(_) | PrintBool(_) => 10,
SetRetval(_) => 10,
GetVMThreadLocal => 10,
ExnInstruction { ref inner, .. } => estimate_insts_for_ir(&inner),
......
......@@ -57,6 +57,7 @@ fn is_suitable_child(inst: &Instruction) -> bool {
| Switch { .. }
| ExnInstruction { .. }
| PrintHex(_)
| PrintBool(_)
| SetRetval(_)
| KillStack(_)
| CurrentStack
......
......@@ -351,6 +351,8 @@ lazy_static! {
lazy_static! {
pub static ref PRINT_HEX: RuntimeEntrypoint =
RuntimeEntrypoint::new("muentry_print_hex", vec![UINT64_TYPE.clone()], vec![]);
pub static ref PRINT_BOOL: RuntimeEntrypoint =
RuntimeEntrypoint::new("muentry_print_bool", vec![UINT1_TYPE.clone()], vec![]);
pub static ref MEM_ZERO: RuntimeEntrypoint = RuntimeEntrypoint::new(
"muentry_mem_zero",
vec![IREF_VOID_TYPE.clone(), UINT64_TYPE.clone()],
......
......@@ -320,6 +320,12 @@ pub extern "C" fn muentry_print_hex(x: u64) {
println!("PRINTHEX: 0x{:x}", x);
}
/// runtime function to print a boolean value (for PRINTBOOL instruction for debugging use)
#[no_mangle]
pub extern "C" fn muentry_print_bool(x: bool) {
println!("PRINTBOOL: {}", x);
}
#[no_mangle]
pub unsafe extern "C" fn muentry_mem_zero(dest: *mut u8, size: usize) {
std::ptr::write_bytes(dest, 0, size);
......
......@@ -206,7 +206,7 @@ impl MuStack {
pub fn setup_args(&mut self, vals: Vec<ValueLocation>) {
use compiler::backend::RegGroup;
use compiler::backend::{ARGUMENT_FPRS, ARGUMENT_GPRS};
use utils::Word;
// use utils::Word;
use utils::WORD_SIZE;
let mut gpr_used = vec![];
......@@ -266,7 +266,7 @@ impl MuStack {
/// prints n * POINTER_SIZE slots from the stack top (upper bound)
/// prints either n slots or until meet the stack bottom (lower bound)
pub fn print_stack(&self, n_entries: Option<usize>) {
use utils::Word;
// use utils::Word;
use utils::WORD_SIZE;
let mut cursor = self.upper_bound - WORD_SIZE;
......
......@@ -135,7 +135,8 @@ pub fn muthread_apply_rtattr(muthread: &MuThread, attr: Arc<RTAttr>) -> SysResul
pub unsafe extern "C" fn muthread_set_priority(muthread: *mut MuThread, priority: u64) {
let tid = {
if muthread.is_null() {
sys_thread_self()
let mut cur_thread = MuThread::current_mut();
cur_thread.sys_thread_id
} else {
(*muthread).sys_thread_id
}
......@@ -164,7 +165,8 @@ pub unsafe extern "C" fn muthread_get_priority(muthread: *const MuThread) -> u64
let tid = {
if muthread.is_null() {
sys_thread_self()
let mut cur_thread = MuThread::current_mut();
cur_thread.sys_thread_id
} else {
(*muthread).sys_thread_id
}
......@@ -198,8 +200,15 @@ pub unsafe extern "C" fn muthread_get_priority(muthread: *const MuThread) -> u64
// }
#[no_mangle]
pub extern "C" fn muthread_affinity_zero(muthread: &mut MuThread) {
sys_affinity_zero(&mut (muthread.rt_attr.affinity))
pub extern "C" fn muthread_affinity_zero(muthread: *mut MuThread) {
let cur_muthread = {
if muthread.is_null() {
MuThread::current_mut() as *const MuThread as *mut MuThread
} else {
muthread
}
};
unsafe { sys_affinity_zero(&mut ((*cur_muthread).rt_attr.affinity)) }
}
pub fn mu_new_affinity() -> SysAffinityMask {
......@@ -207,24 +216,64 @@ pub fn mu_new_affinity() -> SysAffinityMask {
}
#[no_mangle]
pub extern "C" fn muthread_affinity_set(muthread: &mut MuThread, cpu: usize) {
sys_affinity_set(cpu, &mut (muthread.rt_attr.affinity))
pub extern "C" fn muthread_affinity_set(muthread: *mut MuThread, cpu: usize) {
let cur_muthread = {
if muthread.is_null() {
MuThread::current_mut() as *const MuThread as *mut MuThread
} else {
muthread
}
};
unsafe { sys_affinity_set(cpu, &mut (*cur_muthread).rt_attr.affinity) }
}
#[no_mangle]
pub extern "C" fn muthread_affinity_clear(muthread: &mut MuThread, cpu: usize) {
sys_affinity_clear(cpu, &mut (muthread.rt_attr.affinity))
pub extern "C" fn muthread_affinity_clear(muthread: *mut MuThread, cpu: usize) {
let cur_muthread = {
if muthread.is_null() {
MuThread::current_mut() as *const MuThread as *mut MuThread
} else {
muthread
}
};
unsafe { sys_affinity_clear(cpu, &mut (*cur_muthread).rt_attr.affinity) }
}
#[no_mangle]
pub extern "C" fn muthread_affinity_isset(muthread: &mut MuThread, cpu: usize) -> bool {
sys_affinity_isset(cpu, &(muthread.rt_attr.affinity))
pub extern "C" fn muthread_affinity_isset(muthread: *mut MuThread, cpu: usize) -> bool {
let cur_muthread = {
if muthread.is_null() {
MuThread::current_mut() as *const MuThread as *mut MuThread
} else {
muthread
}
};
unsafe { sys_affinity_isset(cpu, &mut (*cur_muthread).rt_attr.affinity) }
}
#[no_mangle]
pub extern "C" fn muthread_affinity_equal(
muthread1: &mut MuThread,
muthread2: &mut MuThread,
muthread1: *mut MuThread,
muthread2: *mut MuThread,
) -> bool {
sys_affinity_equal(&(muthread1.rt_attr.affinity), &(muthread2.rt_attr.affinity))
let cur_muthread1 = {
if muthread1.is_null() {
MuThread::current_mut() as *const MuThread as *mut MuThread
} else {
muthread1
}
};
let cur_muthread2 = {
if muthread2.is_null() {
MuThread::current_mut() as *const MuThread as *mut MuThread
} else {
muthread2
}
};
unsafe {
sys_affinity_equal(
&(*cur_muthread1).rt_attr.affinity,
&(*cur_muthread2).rt_attr.affinity,
)
}
}
......@@ -680,6 +680,16 @@ macro_rules! inst {
});
};
// PRINTBOOL
(($vm: expr, $fv: ident) $name: ident: PRINTBOOL $val: ident) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: None,
ops: vec![$val.clone()],
v: Instruction_::PrintBool(0)
});
};
// SET_RETVAL
(($vm: expr, $fv: ident) $name: ident: SET_RETVAL $val: ident) => {
let $name = $fv.new_inst(Instruction{
......@@ -825,6 +835,61 @@ macro_rules! inst_rt {
v: Instruction_::SetPriority(0, 1),
});
};
// AffinityIsset
(($vm: expr, $fv: ident) $name: ident:
$res: ident = AFFISSET $thread: ident, $cpu: ident) => {
let $name = $fv.new_inst(Instruction {
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![$res.clone_value()]),
ops: vec![$thread.clone(), $cpu.clone()],
v: Instruction_::AffinityIsset(0, 1),
});
};
// AffinitySet
(($vm: expr, $fv: ident) $name: ident:
AFFSET $thread: ident, $cpu: ident) => {
let $name = $fv.new_inst(Instruction {
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![]),
ops: vec![$thread.clone(), $cpu.clone()],
v: Instruction_::AffinitySet(0, 1),
});
};
// AffinityClear
(($vm: expr, $fv: ident) $name: ident:
AFFCLEAR $thread: ident, $cpu: ident) => {
let $name = $fv.new_inst(Instruction {
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![]),
ops: vec![$thread.clone(), $cpu.clone()],
v: Instruction_::AffinityClear(0, 1),
});
};
// AffinityZero
(($vm: expr, $fv: ident) $name: ident:
AFFZERO $thread: ident) => {
let $name = $fv.new_inst(Instruction {
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![]),
ops: vec![$thread.clone()],
v: Instruction_::AffinityIsset(0),
});
};
// AffinityEqual
(($vm: expr, $fv: ident) $name: ident:
$res: ident = AFFEQUAL $thread1: ident, $thread2: ident) => {
let $name = $fv.new_inst(Instruction {
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![$res.clone_value()]),
ops: vec![$thread1.clone(), $thread2.clone()],
v: Instruction_::AffinityEqual(0, 1),
});
};
}
/**************************************
......@@ -1522,7 +1587,7 @@ macro_rules! build_and_run_test {
///
/// where `compare_op` is a compare operation such as `EQ` or any other operation from `CmpOp::...`
///
macro_rules! mu_test_assert_eq {
macro_rules! mu_test_assert {
(
($vm:expr, $fv: ident, $blk_name: ident) $res: ident $cmpopr: ident $exp: ident
) => {
......