From 5dc87d5ba3093db578260b33d99ba00b500e7c95 Mon Sep 17 00:00:00 2001
From: nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Fri, 13 Jan 2017 05:49:43 +0000
Subject: insns.def: float comparison

* insns.def (opt_lt, opt_le, opt_gt, opt_ge): optimize flonum and
  on-heap float comparison.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57319 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
---
 insns.def | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)

(limited to 'insns.def')

diff --git a/insns.def b/insns.def
index c963b42ec0..4dc4975b6a 100644
--- a/insns.def
+++ b/insns.def
@@ -1645,17 +1645,11 @@ opt_lt
 	/* flonum is not NaN */
 	val = RFLOAT_VALUE(recv) < RFLOAT_VALUE(obj) ? Qtrue : Qfalse;
     }
-    else if (!SPECIAL_CONST_P(recv) && !SPECIAL_CONST_P(obj)) {
-	if (RBASIC_CLASS(recv) == rb_cFloat && RBASIC_CLASS(obj) == rb_cFloat  &&
-	    BASIC_OP_UNREDEFINED_P(BOP_LT, FLOAT_REDEFINED_OP_FLAG)) {
-	    val = double_cmp_lt(RFLOAT_VALUE(recv), RFLOAT_VALUE(obj));
-	}
-	else {
-	    goto INSN_LABEL(normal_dispatch);
-	}
+    else if (FLOAT_INSTANCE_P(recv) && FLOAT_INSTANCE_P(obj) &&
+	     BASIC_OP_UNREDEFINED_P(BOP_LT, FLOAT_REDEFINED_OP_FLAG)) {
+	val = double_cmp_lt(RFLOAT_VALUE(recv), RFLOAT_VALUE(obj));
     }
     else {
-      INSN_LABEL(normal_dispatch):
 	PUSH(recv);
 	PUSH(obj);
 	CALL_SIMPLE_METHOD(recv);
@@ -1689,6 +1683,10 @@ opt_le
 	/* flonum is not NaN */
 	val = RFLOAT_VALUE(recv) <= RFLOAT_VALUE(obj) ? Qtrue : Qfalse;
     }
+    else if (FLOAT_INSTANCE_P(recv) && FLOAT_INSTANCE_P(obj) &&
+	     BASIC_OP_UNREDEFINED_P(BOP_LT, FLOAT_REDEFINED_OP_FLAG)) {
+	val = double_cmp_le(RFLOAT_VALUE(recv), RFLOAT_VALUE(obj));
+    }
     else {
 	/* other */
 	PUSH(recv);
@@ -1724,17 +1722,11 @@ opt_gt
 	/* flonum is not NaN */
 	val = RFLOAT_VALUE(recv) > RFLOAT_VALUE(obj) ? Qtrue : Qfalse;
     }
-    else if (!SPECIAL_CONST_P(recv) && !SPECIAL_CONST_P(obj)) {
-	if (RBASIC_CLASS(recv) == rb_cFloat && RBASIC_CLASS(obj) == rb_cFloat  &&
-	    BASIC_OP_UNREDEFINED_P(BOP_GT, FLOAT_REDEFINED_OP_FLAG)) {
-	    val = double_cmp_gt(RFLOAT_VALUE(recv), RFLOAT_VALUE(obj));
-	}
-	else {
-	    goto INSN_LABEL(normal_dispatch);
-	}
+    else if (FLOAT_INSTANCE_P(recv) && FLOAT_INSTANCE_P(obj) &&
+	     BASIC_OP_UNREDEFINED_P(BOP_LT, FLOAT_REDEFINED_OP_FLAG)) {
+	val = double_cmp_gt(RFLOAT_VALUE(recv), RFLOAT_VALUE(obj));
     }
     else {
-      INSN_LABEL(normal_dispatch):
 	PUSH(recv);
 	PUSH(obj);
 	CALL_SIMPLE_METHOD(recv);
@@ -1768,6 +1760,10 @@ opt_ge
 	/* flonum is not NaN */
 	val = RFLOAT_VALUE(recv) >= RFLOAT_VALUE(obj) ? Qtrue : Qfalse;
     }
+    else if (FLOAT_INSTANCE_P(recv) && FLOAT_INSTANCE_P(obj) &&
+	     BASIC_OP_UNREDEFINED_P(BOP_LT, FLOAT_REDEFINED_OP_FLAG)) {
+	val = double_cmp_ge(RFLOAT_VALUE(recv), RFLOAT_VALUE(obj));
+    }
     else {
 	PUSH(recv);
 	PUSH(obj);
-- 
cgit v1.2.3

