diff --git a/core/src/main/java/org/teavm/backend/c/intrinsic/LongIntrinsic.java b/core/src/main/java/org/teavm/backend/c/intrinsic/LongIntrinsic.java index 3b7ed7a21..9940f7402 100644 --- a/core/src/main/java/org/teavm/backend/c/intrinsic/LongIntrinsic.java +++ b/core/src/main/java/org/teavm/backend/c/intrinsic/LongIntrinsic.java @@ -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; } } diff --git a/core/src/main/resources/org/teavm/backend/c/core.h b/core/src/main/resources/org/teavm/backend/c/core.h index c8bc01709..ee629c129 100644 --- a/core/src/main/resources/org/teavm/backend/c/core.h +++ b/core/src/main/resources/org/teavm/backend/c/core.h @@ -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); }