Skip to content

Commit

Permalink
Removed the FIXABLE_DBL() macro (all doubles are fixable now regardle…
Browse files Browse the repository at this point in the history
…ss of precision loss) and cleaned up compiler.cpp a little bit.

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/fp-optimized-experimental@1862 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
Patrick Thomson committed Jun 15, 2009
1 parent d51f0d1 commit 330f1d7
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 122 deletions.
179 changes: 66 additions & 113 deletions compiler.cpp
Expand Up @@ -171,13 +171,6 @@ RoxorCompiler::unbox_ruby_constant(Value *val, VALUE *rval)
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)
{
Expand Down Expand Up @@ -1629,7 +1622,7 @@ RoxorCompiler::precompile_floating_arith_node(SEL sel, double leftDouble, long r
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);
Expand Down Expand Up @@ -1661,6 +1654,65 @@ RoxorCompiler::precompile_floating_arith_node(SEL sel, double leftDouble, long r
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)
{
Expand Down Expand Up @@ -1798,31 +1850,7 @@ RoxorCompiler::compile_variable_and_integral_node(SEL sel, long fixedLong, Value
}
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);
}
Expand Down Expand Up @@ -1881,8 +1909,7 @@ RoxorCompiler::compile_variable_arith_node(SEL sel, Value *leftVal, Value *right
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);
Expand All @@ -1909,9 +1936,6 @@ RoxorCompiler::compile_variable_arith_node(SEL sel, Value *leftVal, Value *right
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);
Expand All @@ -1927,31 +1951,7 @@ RoxorCompiler::compile_variable_arith_node(SEL sel, Value *leftVal, Value *right
}
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);
}
Expand All @@ -1963,7 +1963,7 @@ RoxorCompiler::compile_variable_arith_node(SEL sel, Value *leftVal, Value *right
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);
Expand All @@ -1984,30 +1984,7 @@ RoxorCompiler::compile_variable_arith_node(SEL sel, Value *leftVal, Value *right
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);
}
Expand Down Expand Up @@ -2096,31 +2073,7 @@ RoxorCompiler::compile_variable_and_floating_node(SEL sel, double fixedDouble, V
}
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);
}
Expand Down
5 changes: 4 additions & 1 deletion compiler.h
Expand Up @@ -177,6 +177,10 @@ class RoxorCompiler {
: 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 *
Expand Down Expand Up @@ -275,7 +279,6 @@ class RoxorCompiler {
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);
Expand Down
1 change: 0 additions & 1 deletion include/ruby/ruby.h
Expand Up @@ -236,7 +236,6 @@ VALUE rb_ull2inum(unsigned LONG_LONG);

#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)

Expand Down
8 changes: 1 addition & 7 deletions numeric.c
Expand Up @@ -541,13 +541,7 @@ num_to_int(VALUE num, SEL sel)
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);
}

/*
Expand Down

0 comments on commit 330f1d7

Please sign in to comment.