ZJIT: Allow DCE to remove some CCalls (#13363)
[ruby.git] / internal / compar.h
blob9115e4bd63a8e4c3ed1f8f30f6525c59546fbe31
1 #ifndef INTERNAL_COMPAR_H /*-*-C-*-vi:se ft=c:*/
2 #define INTERNAL_COMPAR_H
3 /**
4 * @author Ruby developers <ruby-core@ruby-lang.org>
5 * @copyright This file is a part of the programming language Ruby.
6 * Permission is hereby granted, to either redistribute and/or
7 * modify this file, provided that the conditions mentioned in the
8 * file COPYING are met. Consult the file for details.
9 * @brief Internal header for Comparable.
11 #include "internal/basic_operators.h"
13 #define STRING_P(s) (RB_TYPE_P((s), T_STRING) && CLASS_OF(s) == rb_cString)
15 #define CMP_OPTIMIZABLE(type) BASIC_OP_UNREDEFINED_P(BOP_CMP, type##_REDEFINED_OP_FLAG)
17 #define OPTIMIZED_CMP(a, b) \
18 ((FIXNUM_P(a) && FIXNUM_P(b) && CMP_OPTIMIZABLE(INTEGER)) ? \
19 (((long)a > (long)b) ? 1 : ((long)a < (long)b) ? -1 : 0) : \
20 (STRING_P(a) && STRING_P(b) && CMP_OPTIMIZABLE(STRING)) ? \
21 rb_str_cmp(a, b) : \
22 (RB_FLOAT_TYPE_P(a) && RB_FLOAT_TYPE_P(b) && CMP_OPTIMIZABLE(FLOAT)) ? \
23 rb_float_cmp(a, b) : \
24 rb_cmpint(rb_funcallv(a, id_cmp, 1, &b), a, b))
26 /* compar.c */
27 VALUE rb_invcmp(VALUE, VALUE);
29 #endif /* INTERNAL_COMPAR_H */