From 22e2b40ffe344c98fcb0405ab7ecefac1201a6c7 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 27 Jul 2025 18:57:48 -0400 Subject: [PATCH] xo-expression: + operator >= --- include/xo/expression/Apply.hpp | 4 +++- include/xo/expression/Primitive.hpp | 2 ++ src/expression/Apply.cpp | 8 ++++++++ src/expression/Primitive.cpp | 19 +++++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/include/xo/expression/Apply.hpp b/include/xo/expression/Apply.hpp index f01fe2a5..dc961feb 100644 --- a/include/xo/expression/Apply.hpp +++ b/include/xo/expression/Apply.hpp @@ -43,7 +43,9 @@ namespace xo { /** 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 for greater-than-or-equal comparison of two 64-bit integers **/ + static rp make_cmp_ge_i64(const rp & lhs, + const rp & rhs); /** create apply-expression to add two 64-bit integers **/ static rp make_add2_i64(const rp & lhs, const rp & rhs); diff --git a/include/xo/expression/Primitive.hpp b/include/xo/expression/Primitive.hpp index 619d943e..43b4690c 100644 --- a/include/xo/expression/Primitive.hpp +++ b/include/xo/expression/Primitive.hpp @@ -210,6 +210,8 @@ namespace xo { static rp make_cmp_le2_i64(); /** gt2_i64: compare two 64-bit integers for greaterthan **/ static rp make_cmp_gt2_i64(); + /** ge2_i64: compare two 64-bit integers for greaterthan **/ + static rp make_cmp_ge2_i64(); }; /** builtin primitives :: i64 x i64 -> i64 **/ diff --git a/src/expression/Apply.cpp b/src/expression/Apply.cpp index 70f4bf95..86582bdc 100644 --- a/src/expression/Apply.cpp +++ b/src/expression/Apply.cpp @@ -72,6 +72,14 @@ namespace xo { {lhs, rhs}); } + rp + Apply::make_cmp_ge_i64(const rp & lhs, + const rp & rhs) + { + return Apply::make(Primitive_cmp_i64::make_cmp_ge2_i64(), + {lhs, rhs}); + } + // ----- integer arithmetic ----- rp diff --git a/src/expression/Primitive.cpp b/src/expression/Primitive.cpp index 234edd88..d6657b55 100644 --- a/src/expression/Primitive.cpp +++ b/src/expression/Primitive.cpp @@ -37,6 +37,11 @@ extern "C" { return x > y; } + bool + cmp_ge2_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; @@ -150,6 +155,20 @@ namespace xo { return s_retval; } + auto + Primitive_cmp_i64::make_cmp_ge2_i64() -> rp + { + static rp s_retval; + + if (!s_retval) + s_retval = Primitive::make("cmp_ge2_i64", + &cmp_ge2_i64, + true /*explicit_symbol_def*/, + llvmintrinsic::i_sge); + + return s_retval; + } + /* TODO: remaining integer arithmetic */ auto