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
|
||||
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);
|
||||
std::cout << "Result: " << std::boolalpha << x << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@ func add_or_sub(add : bool) -> (u32 -> u32):
|
|||
else:
|
||||
return sub1
|
||||
|
||||
func test(x: u32) -> u32:
|
||||
return (!0us) as u32
|
||||
func test(x: i32) -> i32:
|
||||
return 10 / 0
|
||||
|
|
|
|||
|
|
@ -477,8 +477,19 @@ namespace pslang::jit::aarch64
|
|||
}
|
||||
break;
|
||||
case ast::binary_operation_type::remainder:
|
||||
// TODO: implement via div & mul & sub
|
||||
throw std::runtime_error("remainder operator is not implemented");
|
||||
if (types::is_signed_integer_type(*node.inferred_type))
|
||||
{
|
||||
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:
|
||||
builder.and_reg(1, 0, 0);
|
||||
break;
|
||||
|
|
|
|||
4
spec.txt
4
spec.txt
|
|
@ -111,8 +111,8 @@ Arithmetic (only same integer/floating-point type):
|
|||
-x
|
||||
x + y
|
||||
x * y
|
||||
x / y // in case of integers, rounds down when y>0 when x<0, consistently with %
|
||||
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
|
||||
x % y
|
||||
|
||||
Pointer arithmetic (any pointer type + any integer type):
|
||||
p + x
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue