Commit f372bc56 authored by qinsoon's avatar qinsoon Committed by Isaac Oscar Gariano

fix bugs

parent 2f6f011a
......@@ -65,6 +65,12 @@ testmuc:test_swapstack:
- *build_muc
- LD_LIBRARY_PATH=mu-tool-compiler/lib/ MUC=mu-tool-compiler/muc python2 -m pytest test_thread_and_stack.py -v
testmuc:test_cmp:
stage: test
script:
- *build_muc
- LD_LIBRARY_PATH=mu-tool-compiler/lib/ MUC=mu-tool-compiler/muc python2 -m pytest test_cmp.py -v
testjit:milestones:
stage: test
script:
......
......@@ -1731,17 +1731,17 @@ impl ASMCodeGen {
let inst = inst.to_string() + &op_postfix(len);
trace!("emit: {} {} {}", inst, op1, op2);
let (mem, mut uses) = self.prepare_mem(op2, inst.len() + 1);
let (reg, id1, loc1) = self.prepare_reg(op1, inst.len() + 1 + mem.len() + 1);
let (reg, id, loc) = self.prepare_reg(op1, inst.len() + 1);
let (mem, mut uses) = self.prepare_mem(op2, inst.len() + 1 + reg.len() + 1);
if uses.contains_key(&id1) {
let mut locs = uses.get_mut(&id1).unwrap();
vec_utils::add_unique(locs, loc1.clone());
if uses.contains_key(&id) {
let mut locs = uses.get_mut(&id).unwrap();
vec_utils::add_unique(locs, loc.clone());
} else {
uses.insert(id1, vec![loc1.clone()]);
uses.insert(id, vec![loc.clone()]);
}
let asm = format!("{} {},{}", inst, mem, reg);
let asm = format!("{} {},{}", inst, reg, mem);
self.add_asm_inst(asm, linked_hashmap!{}, uses, true)
}
......
......@@ -5111,7 +5111,7 @@ impl<'a> InstructionSelection {
let mem_op1 = self.emit_mem(op1, f_content, f_context, vm);
let reg_op2 = self.emit_ireg(op2, f_content, f_context, vm);
self.backend.emit_cmp_r_mem(&mem_op1, &reg_op2);
self.backend.emit_cmp_r_mem(&reg_op2, &mem_op1);
return op;
} else if self.match_ireg(op1) && self.match_ireg(op2) {
......@@ -6129,12 +6129,22 @@ impl<'a> InstructionSelection {
}
Instruction_::Load { mem_loc, .. } => {
trace!("MEM from LOAD");
self.emit_inst_addr_to_value_inner(
&inst.ops[mem_loc],
f_content,
f_context,
vm
)
let ref mem_op = inst.ops[mem_loc];
match mem_op.v {
TreeNode_::Instruction(_) => {
self.emit_inst_addr_to_value_inner(mem_op, f_content, f_context, vm)
}
TreeNode_::Value(ref pv) => {
assert!(pv.ty.is_heap_reference() || pv.ty.is_ptr());
MemoryLocation::Address {
base: pv.clone(),
offset: None,
index: None,
scale: None
}
}
}
}
_ => panic!("MEM from general ireg inst: {}", op)
}
......
# Copyright 2017 The Australian National University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from util import execute, compile_bundle, load_bundle, get_function;
import pytest;
import ctypes;
def test_gt_mem_r():
lib = load_bundle(
"""
.funcsig sig = (int<64> uptr<int<64>>) -> (int<64>)
.funcdef test_gt_mem_r <sig>
{
entry(<int<64>> x <uptr<int<64>>> ptr):
y = LOAD PTR <int<64>> ptr
cond = SGT <int<64>> x y
BRANCH2 cond ret1() ret0()
ret1():
RET <int<64>> 1
ret0():
RET <int<64>> 0
}
""", "test_gt_mem_r"
)
zero = ctypes.c_int64(0);
ptr = ctypes.addressof(zero);
cmp_gt_zero = get_function(lib.test_gt_mem_r, [ctypes.c_int64, ctypes.c_int64], ctypes.c_int64)
assert(cmp_gt_zero(ctypes.c_int64(1), ptr) == 1)
assert(cmp_gt_zero(ctypes.c_int64(0), ptr) == 0)
assert(cmp_gt_zero(ctypes.c_int64(-1), ptr) == 0)
def test_gt_val_mem_r():
lib = load_bundle(
"""
.funcsig sig = (int<64> uptr<int<64>>) -> (int<8>)
.funcdef test_gt_val_mem_r <sig>
{
entry(<int<64>> x <uptr<int<64>>> ptr):
y = LOAD PTR <int<64>> ptr
cond = SGT <int<64>> x y
res = ZEXT <int<1> int<8>> cond
RET res
}
""", "test_gt_val_mem_r"
)
zero = ctypes.c_int64(0);
ptr = ctypes.addressof(zero);
cmp_gt_zero = get_function(lib.test_gt_val_mem_r, [ctypes.c_int64, ctypes.c_voidp], ctypes.c_int8)
assert(cmp_gt_zero(ctypes.c_int64(1), ptr) == 1)
assert(cmp_gt_zero(ctypes.c_int64(0), ptr) == 0)
assert(cmp_gt_zero(ctypes.c_int64(-1), ptr) == 0)
def test_gt_r_mem():
lib = load_bundle(
"""
.funcsig sig = (uptr<int<64>> int<64>) -> (int<64>)
.funcdef test_gt_r_mem <sig>
{
entry(<uptr<int<64>>> ptr <int<64>> y):
x = LOAD PTR <int<64>> ptr
cond = SGT <int<64>> x y
BRANCH2 cond ret1() ret0()
ret1():
RET <int<64>> 1
ret0():
RET <int<64>> 0
}
""", "test_gt_r_mem"
)
zero = ctypes.c_int64(0);
ptr = ctypes.addressof(zero);
cmp_gt_zero = get_function(lib.test_gt_r_mem, [ctypes.c_int64, ctypes.c_int64], ctypes.c_int64)
assert(cmp_gt_zero(ptr, ctypes.c_int64(1)) == 0)
assert(cmp_gt_zero(ptr, ctypes.c_int64(0)) == 0)
assert(cmp_gt_zero(ptr, ctypes.c_int64(-1)) == 1)
def test_gt_mem_f():
lib = load_bundle(
"""
.funcsig sig = (double uptr<double>) -> (int<64>)
.funcdef test_gt_mem_f <sig>
{
entry(<double> x <uptr<double>> ptr):
y = LOAD PTR <double> ptr
cond = FOGT <double> x y
BRANCH2 cond ret1() ret0()
ret1():
RET <int<64>> 1
ret0():
RET <int<64>> 0
}
""", "test_gt_mem_f"
)
zero = ctypes.c_double(0);
ptr = ctypes.addressof(zero);
cmp_gt_zero = get_function(lib.test_gt_mem_f, [ctypes.c_double, ctypes.c_voidp], ctypes.c_int64)
assert(cmp_gt_zero(ctypes.c_double(1), ptr) == 1)
assert(cmp_gt_zero(ctypes.c_double(0), ptr) == 0)
assert(cmp_gt_zero(ctypes.c_double(-1), ptr) == 0)
def test_gt_f_mem():
lib = load_bundle(
"""
.funcsig sig = (uptr<double> double) -> (int<64>)
.funcdef test_gt_f_mem <sig>
{
entry(<uptr<double>> ptr <double> y):
x = LOAD PTR <double> ptr
cond = FOGT <double> x y
BRANCH2 cond ret1() ret0()
ret1():
RET <int<64>> 1
ret0():
RET <int<64>> 0
}
""", "test_gt_f_mem"
)
zero = ctypes.c_double(0);
ptr = ctypes.addressof(zero);
cmp_gt_zero = get_function(lib.test_gt_f_mem, [ctypes.c_voidp, ctypes.c_double], ctypes.c_int64)
assert(cmp_gt_zero(ptr, ctypes.c_double(1)) == 0)
assert(cmp_gt_zero(ptr, ctypes.c_double(0)) == 0)
assert(cmp_gt_zero(ptr, ctypes.c_double(-1)) == 1)
def test_eq_f_zero():
lib = load_bundle(
"""
.funcsig sig = (double) -> (int<8>)
.funcdef test_eq_f_zero <sig>
{
entry(<double> x):
cond = FOEQ <double> x <double> 0.00 d
res = ZEXT <int<1> int<8>> cond
RET res
}
""", "test_eq_f_zero"
)
eq_zero = get_function(lib.test_eq_f_zero, [ctypes.c_double], ctypes.c_int8)
assert(eq_zero(ctypes.c_double(0)) == 1)
assert(eq_zero(ctypes.c_double(1)) == 0)
assert(eq_zero(ctypes.c_double(-1)) == 0)
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