[macruby-changes] [1862] MacRuby/branches/fp-optimized-experimental

source_changes at macosforge.org source_changes at macosforge.org
Mon Jun 15 15:47:13 PDT 2009


Revision: 1862
          http://trac.macosforge.org/projects/ruby/changeset/1862
Author:   pthomson at apple.com
Date:     2009-06-15 15:47:13 -0700 (Mon, 15 Jun 2009)
Log Message:
-----------
Removed the FIXABLE_DBL() macro (all doubles are fixable now regardless of precision loss) and cleaned up compiler.cpp a little bit.

Modified Paths:
--------------
    MacRuby/branches/fp-optimized-experimental/compiler.cpp
    MacRuby/branches/fp-optimized-experimental/compiler.h
    MacRuby/branches/fp-optimized-experimental/include/ruby/ruby.h
    MacRuby/branches/fp-optimized-experimental/numeric.c

Modified: MacRuby/branches/fp-optimized-experimental/compiler.cpp
===================================================================
--- MacRuby/branches/fp-optimized-experimental/compiler.cpp	2009-06-15 22:21:33 UTC (rev 1861)
+++ MacRuby/branches/fp-optimized-experimental/compiler.cpp	2009-06-15 22:47:13 UTC (rev 1862)
@@ -171,13 +171,6 @@
     return false;
 }
 
-inline ICmpInst *
-RoxorCompiler::is_value_a_fixnum(Value *val)
-{
-    Value *andOp = BinaryOperator::CreateAnd(val, oneVal, "", bb);
-    return new ICmpInst(ICmpInst::ICMP_EQ, andOp, oneVal, "", bb); 
-}
-
 Value *
 RoxorCompiler::compile_protected_call(Function *func, std::vector<Value *> &params)
 {
@@ -1629,7 +1622,7 @@
 			abort();		
 		}
 	}
-	if (!result_is_fixfloat || FIXABLE_DBL(res)) {
+	if (!result_is_fixfloat) {
 		Value *is_redefined_val = new LoadInst(is_redefined, "", bb);
 		Value *isOpRedefined = new ICmpInst(ICmpInst::ICMP_EQ, 
 											is_redefined_val, ConstantInt::getFalse(), "", bb);
@@ -1661,6 +1654,65 @@
 	return NULL; // loss of precision, call the dispatcher.
 }
 
+CmpInst::Predicate
+RoxorCompiler::integer_predicate_for_selector(SEL sel)
+{
+	CmpInst::Predicate predicate;
+	
+	if (sel == selLT) {
+	    predicate = ICmpInst::ICMP_SLT;
+	}
+	else if (sel == selLE) {
+	    predicate = ICmpInst::ICMP_SLE;
+	}
+	else if (sel == selGT) {
+	    predicate = ICmpInst::ICMP_SGT;
+	}
+	else if (sel == selGE) {
+	    predicate = ICmpInst::ICMP_SGE;
+	}
+	else if ((sel == selEq) || (sel == selEqq)) {
+	    predicate = ICmpInst::ICMP_EQ;
+	}
+	else if (sel == selNeq) {
+	    predicate = ICmpInst::ICMP_NE;
+	}
+	else {
+	    abort();
+	}	
+	return predicate;
+}
+
+CmpInst::Predicate
+RoxorCompiler::floating_point_predicate_for_selector(SEL sel)
+{
+	CmpInst::Predicate predicate;
+	
+	if (sel == selLT) {
+	    predicate = FCmpInst::FCMP_OLT;
+	}
+	else if (sel == selLE) {
+	    predicate = FCmpInst::FCMP_OLE;
+	}
+	else if (sel == selGT) {
+	    predicate = FCmpInst::FCMP_OGT;
+	}
+	else if (sel == selGE) {
+	    predicate = FCmpInst::FCMP_OGE;
+	}
+	else if ((sel == selEq) || (sel == selEqq)) {
+	    predicate = FCmpInst::FCMP_OEQ;
+	}
+	else if (sel == selNeq) {
+	    predicate = FCmpInst::FCMP_ONE;
+	}
+	else {
+	    abort();
+	}
+	
+	return predicate;
+}
+
 PHINode *
 RoxorCompiler::precompile_integral_arith_node(SEL sel, long leftLong, long rightLong, int argc, std::vector<Value *> &params)
 {
@@ -1798,31 +1850,7 @@
 	}
 	else {
 		result_is_fixnum = false;
-		
-		CmpInst::Predicate predicate;
-		
-		if (sel == selLT) {
-		    predicate = ICmpInst::ICMP_SLT;
-		}
-		else if (sel == selLE) {
-		    predicate = ICmpInst::ICMP_SLE;
-		}
-		else if (sel == selGT) {
-		    predicate = ICmpInst::ICMP_SGT;
-		}
-		else if (sel == selGE) {
-		    predicate = ICmpInst::ICMP_SGE;
-		}
-		else if ((sel == selEq) || (sel == selEqq)) {
-		    predicate = ICmpInst::ICMP_EQ;
-		}
-		else if (sel == selNeq) {
-		    predicate = ICmpInst::ICMP_NE;
-		}
-		else {
-		    abort();
-		}
-		
+		CmpInst::Predicate predicate = integer_predicate_for_selector(sel);
 		opVal = new ICmpInst(predicate, unboxedLeft, unboxedRight, "", bb);
 		opVal = SelectInst::Create(opVal, trueVal, falseVal, "", bb);
 	}
@@ -1881,8 +1909,7 @@
 	Function *f = bb->getParent();
 	
 	BasicBlock *redefBB = BasicBlock::Create("op_not_redefined", f);
-	BasicBlock *toDblBB = BasicBlock::Create("op_floating_cast", f);
-	BasicBlock *onDblBB = BasicBlock::Create("op_optimize_floating", f);
+	BasicBlock *toDblBB = BasicBlock::Create("op_optimize_floating", f);
 	BasicBlock *toIntBB = BasicBlock::Create("op_optimize_integral", f);
 	BasicBlock *elseBB  = BasicBlock::Create("op_dispatch", f);
 	BasicBlock *mergeBB = BasicBlock::Create("op_merge", f);
@@ -1909,9 +1936,6 @@
 	Value *unmaskedRight = BinaryOperator::CreateXor(rightVal, threeVal, "", bb);
 	leftAsDouble = new BitCastInst(unmaskedLeft, Type::DoubleTy, "", bb);
 	rightAsDouble = new BitCastInst(unmaskedRight, Type::DoubleTy, "", bb);
-	BranchInst::Create(onDblBB, toDblBB);
-	
-	bb = onDblBB;
 	bool result_is_bool = false;
 	if (sel == selPLUS) {
 		opVal = BinaryOperator::CreateAdd(leftAsDouble, rightAsDouble, "", bb);
@@ -1927,31 +1951,7 @@
 	}
 	else {
 		result_is_bool = true;
-		
-		CmpInst::Predicate predicate;
-		
-		if (sel == selLT) {
-		    predicate = FCmpInst::FCMP_OLT;
-		}
-		else if (sel == selLE) {
-		    predicate = FCmpInst::FCMP_OLE;
-		}
-		else if (sel == selGT) {
-		    predicate = FCmpInst::FCMP_OGT;
-		}
-		else if (sel == selGE) {
-		    predicate = FCmpInst::FCMP_OGE;
-		}
-		else if ((sel == selEq) || (sel == selEqq)) {
-		    predicate = FCmpInst::FCMP_OEQ;
-		}
-		else if (sel == selNeq) {
-		    predicate = FCmpInst::FCMP_ONE;
-		}
-		else {
-		    abort();
-		}
-		
+		CmpInst::Predicate predicate = floating_point_predicate_for_selector(sel);
 		opVal = new FCmpInst(predicate, leftAsDouble, rightAsDouble, "", bb);
 		opVal = SelectInst::Create(opVal, trueVal, falseVal, "", bb);
 	}
@@ -1963,7 +1963,7 @@
 		Value *castedResult = new BitCastInst(opVal, IntTy, "", bb);
 		dblReturnResult = BinaryOperator::CreateOr(castedResult, threeVal, "", bb);
 	}
-	BranchInst::Create(mergeBB, onDblBB);
+	BranchInst::Create(mergeBB, toDblBB);
 	
 	bb = toIntBB;
 	leftAsInt = BinaryOperator::CreateAShr(leftVal, twoVal, "", bb);
@@ -1984,30 +1984,7 @@
 	else {
 		result_is_bool = true;
 		
-		CmpInst::Predicate predicate;
-		
-		if (sel == selLT) {
-		    predicate = ICmpInst::ICMP_SLT;
-		}
-		else if (sel == selLE) {
-		    predicate = ICmpInst::ICMP_SLE;
-		}
-		else if (sel == selGT) {
-		    predicate = ICmpInst::ICMP_SGT;
-		}
-		else if (sel == selGE) {
-		    predicate = ICmpInst::ICMP_SGE;
-		}
-		else if ((sel == selEq) || (sel == selEqq)) {
-		    predicate = ICmpInst::ICMP_EQ;
-		}
-		else if (sel == selNeq) {
-		    predicate = ICmpInst::ICMP_NE;
-		}
-		else {
-		    abort();
-		}
-		
+		CmpInst::Predicate predicate = integer_predicate_for_selector(sel);
 		opVal = new ICmpInst(predicate, leftAsInt, rightAsInt, "", bb);
 		opVal = SelectInst::Create(opVal, trueVal, falseVal, "", bb);
 	}
@@ -2096,31 +2073,7 @@
 	}
 	else {
 		result_is_double = false;
-		
-		CmpInst::Predicate predicate;
-		
-		if (sel == selLT) {
-		    predicate = FCmpInst::FCMP_OLT;
-		}
-		else if (sel == selLE) {
-		    predicate = FCmpInst::FCMP_OLE;
-		}
-		else if (sel == selGT) {
-		    predicate = FCmpInst::FCMP_OGT;
-		}
-		else if (sel == selGE) {
-		    predicate = FCmpInst::FCMP_OGE;
-		}
-		else if ((sel == selEq) || (sel == selEqq)) {
-		    predicate = FCmpInst::FCMP_OEQ;
-		}
-		else if (sel == selNeq) {
-		    predicate = FCmpInst::FCMP_ONE;
-		}
-		else {
-		    abort();
-		}
-		
+		CmpInst::Predicate predicate = floating_point_predicate_for_selector(sel);
 		opVal = new FCmpInst(predicate, left, right, "", bb);
 		opVal = SelectInst::Create(opVal, trueVal, falseVal, "", bb);
 	}

Modified: MacRuby/branches/fp-optimized-experimental/compiler.h
===================================================================
--- MacRuby/branches/fp-optimized-experimental/compiler.h	2009-06-15 22:21:33 UTC (rev 1861)
+++ MacRuby/branches/fp-optimized-experimental/compiler.h	2009-06-15 22:47:13 UTC (rev 1862)
@@ -177,6 +177,10 @@
 		: new IntToPtrInst(ptrint, PtrPtrTy, "");
 	}
 	
+	CmpInst::Predicate integer_predicate_for_selector(SEL sel);
+	CmpInst::Predicate floating_point_predicate_for_selector(SEL sel);
+	
+	
 	PHINode *compile_negation_node(int argc, Value *val);
 	PHINode *compile_symbol_equality_node(SEL sel, VALUE leftRVal, VALUE rightRVal, int argc, std::vector<Value *> &params);
 	PHINode *
@@ -275,7 +279,6 @@
 	    return iter->second;
 	}
 
-	ICmpInst *is_value_a_fixnum(Value *val);
 	void compile_ivar_slots(Value *klass, BasicBlock::InstListType &list, 
 				BasicBlock::InstListType::iterator iter);
 	bool unbox_ruby_constant(Value *val, VALUE *rval);

Modified: MacRuby/branches/fp-optimized-experimental/include/ruby/ruby.h
===================================================================
--- MacRuby/branches/fp-optimized-experimental/include/ruby/ruby.h	2009-06-15 22:21:33 UTC (rev 1861)
+++ MacRuby/branches/fp-optimized-experimental/include/ruby/ruby.h	2009-06-15 22:47:13 UTC (rev 1862)
@@ -236,7 +236,6 @@
 
 #define VOODOO_DOUBLE(d) (*(VALUE*)(&d))
 #define DBL2FIXFLOAT(d) (VOODOO_DOUBLE(d) | FIXFLOAT_FLAG)
-#define FIXABLE_DBL(d) (!(VOODOO_DOUBLE(d) & FIXFLOAT_FLAG))
 #define FIXFLOAT_P(v)  (((VALUE)v & FIXFLOAT_FLAG) == FIXFLOAT_FLAG)
 #define FIXFLOAT2DBL(v) coerce_ptr_to_double((VALUE)v)
 

Modified: MacRuby/branches/fp-optimized-experimental/numeric.c
===================================================================
--- MacRuby/branches/fp-optimized-experimental/numeric.c	2009-06-15 22:21:33 UTC (rev 1861)
+++ MacRuby/branches/fp-optimized-experimental/numeric.c	2009-06-15 22:47:13 UTC (rev 1862)
@@ -541,13 +541,7 @@
 VALUE
 rb_float_new(double d)
 {
-	if (FIXABLE_DBL(d)) return DBL2FIXFLOAT(d);
-    NEWOBJ(flt, struct RFloat);
-    OBJSETUP(flt, rb_cFloat, T_FLOAT);
-
-    flt->float_value = d;
-
-    return (VALUE)flt;
+	return DBL2FIXFLOAT(d);
 }
 
 /*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090615/5a3851f5/attachment-0001.html>


More information about the macruby-changes mailing list