Implemented unsigned int comparisons.

This commit is contained in:
Jared Cone 2022-04-24 14:42:02 -07:00
parent 2ab0bc1226
commit c0780aad92
No known key found for this signature in database
GPG key ID: 99D4217479603EA1
2 changed files with 108 additions and 4 deletions

View file

@ -6667,10 +6667,34 @@ fn build_int_binop<'a, 'ctx, 'env>(
&LLVM_MUL_WITH_OVERFLOW[int_width], &LLVM_MUL_WITH_OVERFLOW[int_width],
&[lhs.into(), rhs.into()], &[lhs.into(), rhs.into()],
), ),
NumGt => bd.build_int_compare(SGT, lhs, rhs, "int_gt").into(), NumGt => {
NumGte => bd.build_int_compare(SGE, lhs, rhs, "int_gte").into(), if int_width.is_signed() {
NumLt => bd.build_int_compare(SLT, lhs, rhs, "int_lt").into(), bd.build_int_compare(SGT, lhs, rhs, "gt_int").into()
NumLte => bd.build_int_compare(SLE, lhs, rhs, "int_lte").into(), } else {
bd.build_int_compare(UGT, lhs, rhs, "gt_uint").into()
}
}
NumGte => {
if int_width.is_signed() {
bd.build_int_compare(SGE, lhs, rhs, "gte_int").into()
} else {
bd.build_int_compare(UGE, lhs, rhs, "gte_uint").into()
}
}
NumLt => {
if int_width.is_signed() {
bd.build_int_compare(SLT, lhs, rhs, "lt_int").into()
} else {
bd.build_int_compare(ULT, lhs, rhs, "lt_uint").into()
}
}
NumLte => {
if int_width.is_signed() {
bd.build_int_compare(SLE, lhs, rhs, "lte_int").into()
} else {
bd.build_int_compare(ULE, lhs, rhs, "lte_uint").into()
}
}
NumRemUnchecked => { NumRemUnchecked => {
if int_width.is_signed() { if int_width.is_signed() {
bd.build_int_signed_rem(lhs, rhs, "rem_int").into() bd.build_int_signed_rem(lhs, rhs, "rem_int").into()

View file

@ -1210,6 +1210,86 @@ fn bitwise_or() {
assert_evals_to!("Num.bitwiseOr 1 2", 3, i64); assert_evals_to!("Num.bitwiseOr 1 2", 3, i64);
} }
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn lt_u8() {
assert_evals_to!("1u8 < 2u8", true, bool);
assert_evals_to!("1u8 < 1u8", false, bool);
assert_evals_to!("2u8 < 1u8", false, bool);
assert_evals_to!("0u8 < 0u8", false, bool);
assert_evals_to!("128u8 < 0u8", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn lte_u8() {
assert_evals_to!("1u8 <= 1u8", true, bool);
assert_evals_to!("2u8 <= 1u8", false, bool);
assert_evals_to!("1u8 <= 2u8", true, bool);
assert_evals_to!("0u8 <= 0u8", true, bool);
assert_evals_to!("128u8 <= 0u8", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn gt_u8() {
assert_evals_to!("2u8 > 1u8", true, bool);
assert_evals_to!("2u8 > 2u8", false, bool);
assert_evals_to!("1u8 > 1u8", false, bool);
assert_evals_to!("0u8 > 0u8", false, bool);
assert_evals_to!("0u8 > 128u8", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn gte_u8() {
assert_evals_to!("1u8 >= 1u8", true, bool);
assert_evals_to!("1u8 >= 2u8", false, bool);
assert_evals_to!("2u8 >= 1u8", true, bool);
assert_evals_to!("0u8 >= 0u8", true, bool);
assert_evals_to!("0u8 >= 128u8", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn lt_u64() {
assert_evals_to!("1u64 < 2u64", true, bool);
assert_evals_to!("1u64 < 1u64", false, bool);
assert_evals_to!("2u64 < 1u64", false, bool);
assert_evals_to!("0u64 < 0u64", false, bool);
assert_evals_to!("9223372036854775808u64 < 0u64", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn lte_u64() {
assert_evals_to!("1u64 <= 1u64", true, bool);
assert_evals_to!("2u64 <= 1u64", false, bool);
assert_evals_to!("1u64 <= 2u64", true, bool);
assert_evals_to!("0u64 <= 0u64", true, bool);
assert_evals_to!("9223372036854775808u64 <= 0u64", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn gt_u64() {
assert_evals_to!("2u64 > 1u64", true, bool);
assert_evals_to!("2u64 > 2u64", false, bool);
assert_evals_to!("1u64 > 1u64", false, bool);
assert_evals_to!("0u64 > 0u64", false, bool);
assert_evals_to!("0u64 > 9223372036854775808u64", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn gte_u64() {
assert_evals_to!("1u64 >= 1u64", true, bool);
assert_evals_to!("1u64 >= 2u64", false, bool);
assert_evals_to!("2u64 >= 1u64", true, bool);
assert_evals_to!("0u64 >= 0u64", true, bool);
assert_evals_to!("0u64 >= 9223372036854775808u64", false, bool);
}
#[test] #[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn lt_i64() { fn lt_i64() {