summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris HasiƄski <krzysztof.hasinski@gmail.com>2026-04-11 22:53:18 +0200
committerTakashi Kokubun <takashikkbn@gmail.com>2026-04-14 14:04:52 -0700
commit94a8feaa0110a9c9928a46af2309ab3fd3abf689 (patch)
tree7e49f96ebd81890a44bf06b17e782ad36aaa854c
parent93f1010f70a3ac924c3b37e4ae82cf1a669fcbf0 (diff)
ZJIT: Annotate Float and Integer predicates
Adds method annotations so ZJIT can emit the fast CCall path for pure Float cfunc predicates and propagate return types for numeric builtin predicates. Float cfuncs (leaf, no_gc, elidable): nan?, finite? BoolExact infinite? Fixnum | NilClass Integer/Float builtins (BoolExact return type): Integer#zero?, even?, odd? Float#zero?, positive?, negative? All targeted C bodies are pure (isnan/isfinite/isinf, FIXNUM bit tests, FLOAT_ZERO_P) so the annotations are safe. Microbench with --zjit-call-threshold=2, tight while loop, 20M iters: Float#nan? 0.140s -> 0.110s (~21%) Float#finite? 0.145s -> 0.114s (~21%) Float#infinite? 0.129s -> 0.094s (~27%)
-rw-r--r--zjit/src/cruby_methods.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/zjit/src/cruby_methods.rs b/zjit/src/cruby_methods.rs
index e104a0f320..96db1386f1 100644
--- a/zjit/src/cruby_methods.rs
+++ b/zjit/src/cruby_methods.rs
@@ -266,9 +266,18 @@ pub fn init() -> Annotations {
annotate!(rb_cInteger, "[]", inline_integer_aref);
annotate!(rb_cInteger, "to_s", types::StringExact);
annotate!(rb_cString, "to_s", inline_string_to_s, types::StringExact);
+ annotate!(rb_cFloat, "nan?", types::BoolExact, no_gc, leaf, elidable);
+ annotate!(rb_cFloat, "finite?", types::BoolExact, no_gc, leaf, elidable);
+ annotate!(rb_cFloat, "infinite?", types::Fixnum.union(types::NilClass), no_gc, leaf, elidable);
let thread_singleton = unsafe { rb_singleton_class(rb_cThread) };
annotate!(thread_singleton, "current", inline_thread_current, types::BasicObject, no_gc, leaf);
+ annotate_builtin!(rb_cInteger, "zero?", types::BoolExact);
+ annotate_builtin!(rb_cInteger, "even?", types::BoolExact);
+ annotate_builtin!(rb_cInteger, "odd?", types::BoolExact);
+ annotate_builtin!(rb_cFloat, "zero?", types::BoolExact);
+ annotate_builtin!(rb_cFloat, "positive?", types::BoolExact);
+ annotate_builtin!(rb_cFloat, "negative?", types::BoolExact);
annotate_builtin!(rb_mKernel, "Float", types::Float);
annotate_builtin!(rb_mKernel, "Integer", types::Integer);
// TODO(max): Annotate rb_mKernel#class as returning types::Class. Right now there is a subtle