diff --git a/include/xo/expression/Apply.hpp b/include/xo/expression/Apply.hpp index aae28585..69e830c4 100644 --- a/include/xo/expression/Apply.hpp +++ b/include/xo/expression/Apply.hpp @@ -34,6 +34,12 @@ namespace xo { /** create apply-expression to compare two 64-bit integers **/ static rp make_cmp_ne_i64(const rp & lhs, const rp & rhs); + /** create apply-expression for less-than comparison of two 64-bit integers **/ + static rp make_cmp_lt_i64(const rp & lhs, + const rp & rhs); + /** create apply-expression for greater-than comparison of two 64-bit integers **/ + static rp make_cmp_gt_i64(const rp & lhs, + const rp & rhs); /** create apply-expression to add two 64-bit integers **/ static rp make_add2_i64(const rp & lhs, diff --git a/include/xo/expression/Primitive.hpp b/include/xo/expression/Primitive.hpp index cb940092..e2283f33 100644 --- a/include/xo/expression/Primitive.hpp +++ b/include/xo/expression/Primitive.hpp @@ -204,6 +204,10 @@ namespace xo { static rp make_cmp_eq2_i64(); /** ne2_i64: compare two 64-bit integers for inequality **/ static rp make_cmp_ne2_i64(); + /** lt2_i64: compare two 64-bit integers for lessthan **/ + static rp make_cmp_lt2_i64(); + /** gt2_i64: compare two 64-bit integers for greaterthan **/ + static rp make_cmp_gt2_i64(); }; /** builtin primitives :: i64 x i64 -> i64 **/ diff --git a/src/expression/Apply.cpp b/src/expression/Apply.cpp index d3403784..3dfc5a6c 100644 --- a/src/expression/Apply.cpp +++ b/src/expression/Apply.cpp @@ -48,6 +48,22 @@ namespace xo { {lhs, rhs}); } + rp + Apply::make_cmp_lt_i64(const rp & lhs, + const rp & rhs) + { + return Apply::make(Primitive_cmp_i64::make_cmp_lt2_i64(), + {lhs, rhs}); + } + + rp + Apply::make_cmp_gt_i64(const rp & lhs, + const rp & rhs) + { + return Apply::make(Primitive_cmp_i64::make_cmp_gt2_i64(), + {lhs, rhs}); + } + // ----- integer arithmetic ----- rp diff --git a/src/expression/Primitive.cpp b/src/expression/Primitive.cpp index db44d820..cafaffb1 100644 --- a/src/expression/Primitive.cpp +++ b/src/expression/Primitive.cpp @@ -22,6 +22,16 @@ extern "C" { return x != y; } + bool + cmp_lt2_i64(std::int64_t x, std::int64_t y) { + return x < y; + } + + bool + cmp_gt2_i64(std::int64_t x, std::int64_t y) { + return x > y; + } + std::int64_t add2_i64(std::int64_t x, std::int64_t y) { return x + y; @@ -93,6 +103,34 @@ namespace xo { return s_retval; } + auto + Primitive_cmp_i64::make_cmp_lt2_i64() -> rp + { + static rp s_retval; + + if (!s_retval) + s_retval = Primitive::make("cmp_lt2_i64", + &cmp_lt2_i64, + true /*explicit_symbol_def*/, + llvmintrinsic::i_slt); + + return s_retval; + } + + auto + Primitive_cmp_i64::make_cmp_gt2_i64() -> rp + { + static rp s_retval; + + if (!s_retval) + s_retval = Primitive::make("cmp_gt2_i64", + &cmp_gt2_i64, + true /*explicit_symbol_def*/, + llvmintrinsic::i_sgt); + + return s_retval; + } + /* TODO: remaining integer arithmetic */ auto