[前][次][番号順一覧][スレッド一覧]

ruby-changes:45246

From: nobu <ko1@a...>
Date: Fri, 13 Jan 2017 14:49:49 +0900 (JST)
Subject: [ruby-changes:45246] nobu:r57319 (trunk): insns.def: float comparison

nobu	2017-01-13 14:49:43 +0900 (Fri, 13 Jan 2017)

  New Revision: 57319

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57319

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

  Modified files:
    trunk/insns.def
    trunk/vm_insnhelper.h
Index: insns.def
===================================================================
--- insns.def	(revision 57318)
+++ insns.def	(revision 57319)
@@ -1645,17 +1645,11 @@ opt_lt https://github.com/ruby/ruby/blob/trunk/insns.def#L1645
 	/* 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 https://github.com/ruby/ruby/blob/trunk/insns.def#L1683
 	/* 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 https://github.com/ruby/ruby/blob/trunk/insns.def#L1722
 	/* 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 https://github.com/ruby/ruby/blob/trunk/insns.def#L1760
 	/* 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);
Index: vm_insnhelper.h
===================================================================
--- vm_insnhelper.h	(revision 57318)
+++ vm_insnhelper.h	(revision 57319)
@@ -166,6 +166,8 @@ enum vm_regan_acttype { https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.h#L166
 #else
 #define FLONUM_2_P(a, b) 0
 #endif
+#define FLOAT_HEAP_P(x) (!SPECIAL_CONST_P(x) && RBASIC_CLASS(x) == rb_cFloat)
+#define FLOAT_INSTANCE_P(x) (FLONUM_P(x) || FLOAT_HEAP_P(x))
 
 #ifndef USE_IC_FOR_SPECIALIZED_METHOD
 #define USE_IC_FOR_SPECIALIZED_METHOD 1

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]