GitLab will continue to be upgraded from 11.4.5-ce.0 on November 25th 2019 at 4.00pm (AEDT) to 5.00pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available.

Commit 6a867884 authored by qinsoon's avatar qinsoon

load/store for int128

parent a8c87842
......@@ -747,6 +747,13 @@ impl Value {
_ => None
}
}
pub fn extract_memory_location(&self) -> Option<MemoryLocation> {
match self.v {
Value_::Memory(ref loc) => Some(loc.clone()),
_ => None
}
}
}
const DISPLAY_TYPE : bool = true;
......
......@@ -25,6 +25,7 @@ use compiler::machine_code::CompiledFunction;
use compiler::frame::Frame;
use utils::math;
use utils::POINTER_SIZE;
use std::collections::HashMap;
use std::any::Any;
......@@ -1015,6 +1016,16 @@ impl <'a> InstructionSelection {
if self.match_ireg(node) {
self.backend.emit_mov_r_mem(&res_temp, &resolved_loc);
} else if self.match_ireg_ex(node) {
let (res_l, res_h) = self.split_int128(&res_temp, f_context, vm);
// load lower half
self.backend.emit_mov_r_mem(&res_l, &resolved_loc);
// shift ptr, and load higher half
let loc = self.addr_const_offset_adjust(resolved_loc.extract_memory_location().unwrap(), POINTER_SIZE as u64, vm);
let val_loc = self.make_value_memory_location(loc, vm);
self.backend.emit_mov_r_mem(&res_h, &val_loc);
} else if self.match_fpreg(node) {
match res_temp.ty.v {
MuType_::Double => self.backend.emit_movsd_f64_mem64(&res_temp, &resolved_loc),
......@@ -1059,6 +1070,21 @@ impl <'a> InstructionSelection {
} else {
unimplemented!()
}
} else if self.match_ireg_ex(val_op) {
let (val_l, val_h) = self.emit_ireg_ex(val_op, f_content, f_context, vm);
if generate_plain_mov {
// store lower half
self.backend.emit_mov_mem_r(&resolved_loc, &val_l);
// shift pointer, and store higher hal
let loc = self.addr_const_offset_adjust(resolved_loc.extract_memory_location().unwrap(),
POINTER_SIZE as u64, vm);
let loc_val = self.make_value_memory_location(loc, vm);
self.backend.emit_mov_mem_r(&loc_val, &val_h);
} else {
unimplemented!()
}
} else if self.match_fpreg(val_op) {
let val = self.emit_fpreg(val_op, f_content, f_context, vm);
......@@ -1347,6 +1373,14 @@ impl <'a> InstructionSelection {
})
}
fn make_value_memory_location (&mut self, loc: MemoryLocation, vm: &VM) -> P<Value> {
P(Value{
hdr: MuEntityHeader::unnamed(vm.next_id()),
ty : ADDRESS_TYPE.clone(),
v : Value_::Memory(loc)
})
}
fn emit_binop (&mut self, node: &TreeNode, inst: &Instruction, op: BinOp, op1: OpIndex, op2: OpIndex, f_content: &FunctionContent, f_context: &mut FunctionContext, vm: &VM) {
let ops = inst.ops.read().unwrap();
......
......@@ -362,5 +362,67 @@ fn ashr_u128() -> VM {
define_func_ver!((vm) ashr_u128_v1 (entry: blk_entry) {blk_entry});
vm
}
#[test]
fn test_store_load_u128() {
let lib = testutil::compile_fnc("store_load_u128", &store_load_u128);
unsafe {
use mu::utils::mem::memsec::malloc;
let ptr = match malloc::<u64>(16) {
Some(ptr) => ptr,
None => panic!("failed to alloc memory for testing")
};
let store_load_u128 : libloading::Symbol<unsafe extern fn(u64, u64, *mut u64) -> (u64, u64)> = lib.get(b"store_load_u128").unwrap();
let res = store_load_u128(1, 2, ptr);
println!("store_load(1, 2, ptr) = {:?}", res);
assert!(res == (1, 2));
}
}
fn store_load_u128() -> VM {
let vm = VM::new();
typedef! ((vm) u128 = mu_int(128));
typedef! ((vm) uptr_u128 = mu_uptr(u128));
funcsig! ((vm) sig = (u128, uptr_u128) -> (u128));
funcdecl! ((vm) <sig> store_load_u128);
funcdef! ((vm) <sig> store_load_u128 VERSION store_load_u128_v1);
block! ((vm, store_load_u128_v1) blk_entry);
ssa! ((vm, store_load_u128_v1) <u128> x);
ssa! ((vm, store_load_u128_v1) <uptr_u128> ptr);
// store
inst! ((vm, store_load_u128_v1) blk_entry_store:
STORE ptr x (is_ptr: true, order: MemoryOrder::Relaxed)
);
// load
ssa! ((vm, store_load_u128_v1) <u128> val);
inst! ((vm, store_load_u128_v1) blk_entry_load:
val = LOAD ptr (is_ptr: true, order: MemoryOrder::Relaxed)
);
// ret
inst! ((vm, store_load_u128_v1) blk_entry_ret:
RET (val)
);
define_block!((vm, store_load_u128_v1) blk_entry(x, ptr) {
blk_entry_store,
blk_entry_load,
blk_entry_ret
});
define_func_ver!((vm) store_load_u128_v1(entry: blk_entry) {
blk_entry
});
vm
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment