C: implement Long.compareUnsigned

This commit is contained in:
Alexey Andreev 2023-09-19 10:05:31 +02:00
parent c245eb08cd
commit 2e7e11292b
2 changed files with 11 additions and 0 deletions

View File

@ -27,6 +27,7 @@ public class LongIntrinsic implements Intrinsic {
switch (method.getName()) {
case "divideUnsigned":
case "remainderUnsigned":
case "compareUnsigned":
return true;
default:
return false;
@ -42,6 +43,13 @@ public class LongIntrinsic implements Intrinsic {
case "remainderUnsigned":
writeBinary(context, invocation, "%");
break;
case "compareUnsigned":
context.writer().print("teavm_compare_u64(");
context.emit(invocation.getArguments().get(0));
context.writer().print(", ");
context.emit(invocation.getArguments().get(1));
context.writer().print(")");
break;
}
}

View File

@ -135,6 +135,9 @@ static inline int32_t teavm_compare_u32(int32_t a, int32_t b) {
static inline int32_t teavm_compare_i64(int64_t a, int64_t b) {
return a > b ? INT32_C(1) : a < b ? INT32_C(-1) : INT32_C(0);
}
static inline int32_t teavm_compare_u64(int64_t a, int64_t b) {
return (uint64_t) a > (uint64_t) b ? INT32_C(1) : (uint64_t) a < (uint64_t) b ? INT32_C(-1) : INT32_C(0);
}
static inline int32_t teavm_compare_float(float a, float b) {
return a > b ? INT32_C(1) : a < b ? INT32_C(-1) : a == b ? INT32_C(0) : INT32_C(1);
}