Implement remainder operator in aarch64 compiler
This commit is contained in:
parent
0541068c2b
commit
788e98409a
4 changed files with 18 additions and 7 deletions
|
|
@ -182,7 +182,7 @@ int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
// TODO: remove, testing-only code; should execute entry point instead
|
// TODO: remove, testing-only code; should execute entry point instead
|
||||||
auto offset = pcontext.symbols.at("test");
|
auto offset = pcontext.symbols.at("test");
|
||||||
auto fptr = (std::uint32_t(*)(std::uint32_t))(executable.data.get() + offset);
|
auto fptr = (int(*)(int))(executable.data.get() + offset);
|
||||||
auto x = fptr(0);
|
auto x = fptr(0);
|
||||||
std::cout << "Result: " << std::boolalpha << x << std::endl;
|
std::cout << "Result: " << std::boolalpha << x << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,5 +10,5 @@ func add_or_sub(add : bool) -> (u32 -> u32):
|
||||||
else:
|
else:
|
||||||
return sub1
|
return sub1
|
||||||
|
|
||||||
func test(x: u32) -> u32:
|
func test(x: i32) -> i32:
|
||||||
return (!0us) as u32
|
return 10 / 0
|
||||||
|
|
|
||||||
|
|
@ -477,8 +477,19 @@ namespace pslang::jit::aarch64
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ast::binary_operation_type::remainder:
|
case ast::binary_operation_type::remainder:
|
||||||
// TODO: implement via div & mul & sub
|
if (types::is_signed_integer_type(*node.inferred_type))
|
||||||
throw std::runtime_error("remainder operator is not implemented");
|
{
|
||||||
|
builder.sdiv_reg(1, 0, 2);
|
||||||
|
builder.mul_reg(0, 2, 0);
|
||||||
|
builder.sub_reg(1, 0, 0);
|
||||||
|
}
|
||||||
|
else if (types::is_unsigned_integer_type(*node.inferred_type))
|
||||||
|
{
|
||||||
|
builder.udiv_reg(1, 0, 2);
|
||||||
|
builder.mul_reg(0, 2, 0);
|
||||||
|
builder.sub_reg(1, 0, 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case ast::binary_operation_type::binary_and:
|
case ast::binary_operation_type::binary_and:
|
||||||
builder.and_reg(1, 0, 0);
|
builder.and_reg(1, 0, 0);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
4
spec.txt
4
spec.txt
|
|
@ -111,8 +111,8 @@ Arithmetic (only same integer/floating-point type):
|
||||||
-x
|
-x
|
||||||
x + y
|
x + y
|
||||||
x * y
|
x * y
|
||||||
x / y // in case of integers, rounds down when y>0 when x<0, consistently with %
|
x / y
|
||||||
x % y // integer only; mathematical, i.e. always in [0, y-1] when y>0 even when x<0; TODO: what if y<0?
|
x % y
|
||||||
|
|
||||||
Pointer arithmetic (any pointer type + any integer type):
|
Pointer arithmetic (any pointer type + any integer type):
|
||||||
p + x
|
p + x
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue