GitLab will be upgraded on June 2nd 2020 at 2.00 pm (AEDT) to 3.00 pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to local Gitlab admin team.

Commit caf2aa5a authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano

Finished and tested aarch64 ALLOCA & ALLOCAHYBRID

parent 0437c22f
......@@ -332,6 +332,7 @@ pub fn primitive_byte_size(ty : &P<MuType>) -> usize
}
}
#[allow(dead_code)]
lazy_static! {
// Note: these are the same as the ARGUMENT_GPRS
pub static ref RETURN_GPRS : [P<Value>; 8] = [
......@@ -1744,9 +1745,14 @@ fn emit_madd_u64(backend: &mut CodeGenerator, dest: &P<Value>, src1: &P<Value>,
// dest = src2 - src1
backend.emit_sub(&dest, &src2, &src1);
} else if val.is_power_of_two() {
let shift = log2(val as u64) as u8;
// dest = src1 << log2(val) + src2
backend.emit_lsl_imm(&dest, &src1, log2(val as u64) as u8);
backend.emit_add(&dest, &dest, &src2);
if shift <= 4 {
backend.emit_add_ext(&dest, &dest, &src2, false, shift);
} else {
backend.emit_lsl_imm(&dest, &src1, shift);
backend.emit_add(&dest, &dest, &src2);
}
} else {
// dest = src1 * val + src2
emit_mov_u64(backend, &dest, val as u64);
......@@ -1771,9 +1777,10 @@ fn emit_madd_u64_u64(backend: &mut CodeGenerator, dest: &P<Value>, src: &P<Value
emit_mov_u64(backend, &dest, val2);
backend.emit_sub(&dest, &dest, &src);
} else if val1.is_power_of_two() {
let shift = log2(val1 as u64) as u8;
// dest = src << log2(val1) + val2
backend.emit_lsl_imm(&dest, &src, log2(val1 as u64) as u8);
emit_add_u64(backend, &dest, &src, val2);
backend.emit_lsl_imm(&dest, &src, shift);
emit_add_u64(backend, &dest, &dest, val2);
} else {
// dest = src * val1 + val2
let tmp = make_temporary(f_context, src.ty.clone(), vm);
......
......@@ -28,7 +28,6 @@ def test_alloca_simple():
""", "test_alloca_simple");
assert(execute("test_alloca_simple") == 0);
def test_alloca():
lib = load_bundle(
"""
......@@ -57,10 +56,10 @@ def test_alloca():
STORE <type> ai_ref arg
argc_int = LOAD <int<64>> ai_ref
// sum all the *_int values togterh
res_0 = ADD <int<64>> ai_int ad_int
res_1 = ADD <int<64>> res_0 ar_int
res_2 = ADD <int<64>> res_1 argc_int
// or all the *_int values together
res_0 = OR <int<64>> ai_int ad_int
res_1 = OR <int<64>> res_0 ar_int
res_2 = OR <int<64>> res_1 argc_int
RET res_2
}
""", "test_alloca");
......@@ -68,8 +67,6 @@ def test_alloca():
alloca = get_function(lib.alloca, [ctypes.c_int64], ctypes.c_int64);
assert(alloca(-56) == -56);
def test_allocahybrid_simple():
compile_bundle(
"""
......@@ -87,9 +84,9 @@ def test_allocahybrid():
lib = load_bundle(
"""
.typedef type = hybrid<int<1> int<64>>
.funcdef allocahybrid <(int<64>)->(int<64>)>
.funcdef allocahybrid <(int<8>)->(int<64>)>
{
entry(<int<64>>n):
entry(<int<8>>n):
a = ALLOCAHYBRID <type int<64>> n
// Load the int<1> field to ai_int (as a 64-bit integer)
......@@ -98,35 +95,36 @@ def test_allocahybrid():
ai_int = ZEXT <int<1> int<64>> ai
a_var = GETVARPARTIREF <type> a
n_zero = EQ <int<64>> n <int<64>>0
n_zero = EQ <int<8>> n <int<8>>0
// If the hybrid is non empty, sum all of it's variable elements
BRANCH2 n_zero exit(ai_int) sum(a_var n ai_int)
// Sum 'sum' and the n elements of pos
// branch to exit with sum once finished
sum(<iref<int<64>>>pos <int<64>>n <int<64>>sum):
sum(<iref<int<64>>>pos <int<8>>n <int<64>>sum):
val = LOAD <int<64>> pos
new_pos = SHIFTIREF <int<64> int<1>> pos <int<1>>1
new_sum = ADD <int<64>> sum val
new_n = SUB <int<64>> n <int<64>>1
n_zero = EQ <int<64>> n <int<64>>0
new_sum = OR <int<64>> sum val
new_n = SUB <int<8>> n <int<8>>1
n_zero = EQ <int<8>> n <int<8>>1
BRANCH2 n_zero exit(new_sum) sum(new_pos new_n new_sum)
exit(<int<64>> sum):
RET sum
}
""", "test_alloca");
""", "test_allocahybrid");
allocahybrid = get_function(lib.allocahybrid, [ctypes.c_int64], ctypes.c_int64);
assert(allocahybrid(57) == 0);
allocahybrid = get_function(lib.allocahybrid, [ctypes.c_uint8], ctypes.c_uint64);
assert(allocahybrid(56) == 0);
def test_allocahybrid_imm():
bundle_template = """
.typedef type = hybrid<int<1> int<64>>
.const n <int<64>> = {}
.funcdef allocahybrid_imm <(int<64>)->(int<64>)>
{{
entry(<int<64>>n):
a = ALLOCAHYBRID <type int<64>> <int<64>>{}
entry():
a = ALLOCAHYBRID <type int<64>> n
// Load the int<1> field to ai_int (as a 64-bit integer)
ai_ref = GETFIELDIREF <type 0> a
......@@ -143,9 +141,9 @@ def test_allocahybrid_imm():
sum(<iref<int<64>>>pos <int<64>>n <int<64>>sum):
val = LOAD <int<64>> pos
new_pos = SHIFTIREF <int<64> int<1>> pos <int<1>>1
new_sum = ADD <int<64>> sum val
new_sum = OR <int<64>> sum val
new_n = SUB <int<64>> n <int<64>>1
n_zero = EQ <int<64>> n <int<64>>0
n_zero = EQ <int<64>> n <int<64>>1
BRANCH2 n_zero exit(new_sum) sum(new_pos new_n new_sum)
exit(<int<64>> sum):
......
......@@ -95,4 +95,4 @@ def test_except_stack_args():
}
""",
"test_except_stack_args");
assert(execute("test_except_stack_args") == 1);
assert(execute("test_except_stack_args") == 1);
\ No newline at end of file
......@@ -18,8 +18,10 @@ import struct;
muc = os.environ.get('MUC', 'muc'); #type: str
emit = os.environ.get('MU_EMIT_DIR', 'emit'); #type: str
libext = '.dylib' if sys.platform.startswith('darwin') else \
'.so' if sys.platform.startswith('linux') else sys.exit("Unsupported platform");
'.so' if sys.platform.startswith('linux') else sys.exit("Unsupported platform"); #type: str
libmu = os.path.join(os.environ.get('MU_ZEBU', os.path.dirname(os.path.dirname(os.getcwd()))),
'target', os.environ.get('ZEBU_BUILD', 'debug'),
"libmu" + libext); #type: str
prelude = """
/*--------------------------------------------------------*/
.funcsig exit_sig = (int<32>) -> ()
......@@ -63,8 +65,9 @@ def execute(name, args = []): # type: (str, Optional[List[str]]) -> int
return subprocess.call([get_output_file(name)] + args);
def load_bundle(bundle, name): # type: (str, str) -> ctypes.CDLL
ctypes.CDLL(libmu, ctypes.RTLD_GLOBAL);
execute_muc(prelude + bundle, name + libext);
return ctypes.CDLL(get_output_file(name + libext));
return ctypes.CDLL(get_output_file(name + libext), ctypes.RTLD_GLOBAL);
def get_function(func, argtypes, restype): # type: (ctypes._FuncPtr) -> (ctypes._FuncPtr)
func.argtypes = argtypes;
......
  • The following tests are broken on this commit on aarch64. I am not sure if they passed in previous commit. @igariano01

          test_compiler::test_mem_inst::test_get_elem_iref_array_ele_9bytes
          test_compiler::test_mem_inst::test_shift_iref_ele_16bytes
          test_compiler::test_mem_inst::test_shift_iref_ele_4bytes
          test_compiler::test_mem_inst::test_shift_iref_ele_8bytes
          test_compiler::test_mem_inst::test_shift_iref_ele_9bytes
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