[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnet/codegen cg_arith.tc,1.13,1.14
From: |
Gopal.V <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnet/codegen cg_arith.tc,1.13,1.14 |
Date: |
Thu, 21 Nov 2002 04:52:28 -0500 |
Update of /cvsroot/dotgnu-pnet/pnet/codegen
In directory subversions:/tmp/cvs-serv32307/codegen
Modified Files:
cg_arith.tc
Log Message:
move arithmetic optimisations into codegen
Index: cg_arith.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_arith.tc,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** cg_arith.tc 19 Nov 2002 06:12:28 -0000 1.13
--- cg_arith.tc 21 Nov 2002 09:52:26 -0000 1.14
***************
*** 23,26 ****
--- 23,170 ----
#include <codegen/cg_nodes.h>
+
+ /*
+ * Bit count stuff to get the correct power of 2 for stuff
+ */
+ static int IsPowOfTwo(ILEvalValue evalValue)
+ {
+ int bitpos=-1;
+ int bitcount=0;
+ ILUInt32 word;
+ if(evalValue.un.i4Value < 0)
+ {
+ switch(evalValue.valueType)
+ {
+ case ILMachineType_UInt8:
+ case ILMachineType_UInt16:
+ case ILMachineType_UInt32:
+ case ILMachineType_UInt64:
+ break;
+ default:
+ return -1; /* negative nums cannot do this */
+ }
+ }
+ for(word=evalValue.un.i4Value;word!=0;word=word>>1)
+ {
+ if(word & 0x01)bitcount++;
+ bitpos++;
+ }
+ if(bitcount==1)return bitpos;
+ return -1;
+ }
+
+ /*
+ * Reduce operator strength for arithmetic operators
+ */
+ static int ReduceOperator(ILGenInfo *info, ILNode *node,
+ ILNode** parent,ILMachineType commonType)
+ {
+ ILEvalValue evalValue;
+ ILNode_BinaryExpression *expr;
+ int bitpos;
+ if(info->overflowInsns || !(info->optimizeFlag))
+ {
+ return 0;
+ }
+ if(!yyisa(node,ILNode_BinaryExpression))
+ {
+ return 0;
+ }
+ switch(commonType)
+ {
+ case ILMachineType_Int8:
+ case ILMachineType_UInt8:
+ case ILMachineType_Int16:
+ case ILMachineType_UInt16:
+ case ILMachineType_Int32:
+ case ILMachineType_UInt32:
+ case ILMachineType_Int64:
+ case ILMachineType_UInt64:
+ break;
+ default:
+ return 0; // not integer
+ }
+
+ expr=(ILNode_BinaryExpression*)(node);
+
+ if(ILNode_EvalConst(expr->expr1,info,&evalValue))
+ {
+ if((bitpos=IsPowOfTwo(evalValue))>0)
+ {
+ if(yyisa(node,ILNode_Mul))
+ {
+ *parent=ILNode_Shl_create(expr->expr2,
+
ILNode_Int32_create(bitpos,0,0));
+ return 1;
+ }
+ }
+ else if(evalValue.un.i4Value==1)
+ {
+ if(yyisa(node,ILNode_Mul))
+ {
+ *parent=expr->expr2; // 1 * x = x;
+ return 1;
+ }
+ }
+ else if(evalValue.un.i4Value==0)
+ {
+ if(yyisa(node,ILNode_Mul) || yyisa(node,ILNode_Div))
+ {
+ *parent=ILNode_Int32_create(0,0,0); // 0 * x
=0; 0/x = 0;
+ return 1;
+ }
+ else if(yyisa(node,ILNode_Add))
+ {
+ *parent=expr->expr2; // 0 + x = x
+ return 1;
+ }
+ else if(yyisa(node,ILNode_Sub))
+ {
+ *parent=ILNode_Neg_create(expr->expr2); // 0 -
x = -x
+ return 1;
+ }
+ }
+ }
+ else if(ILNode_EvalConst(expr->expr2,info,&evalValue))
+ {
+ if((bitpos=IsPowOfTwo(evalValue))>0)
+ {
+ if(yyisa(node,ILNode_Mul))
+ {
+ *parent=ILNode_Shl_create(expr->expr1,
+
ILNode_Int32_create(bitpos,0,0));
+ return 1;
+ }
+ else if(yyisa(node,ILNode_Div))
+ {
+ *parent=ILNode_Shr_create(expr->expr1,
+
ILNode_Int32_create(bitpos,0,0));
+ return 1;
+ }
+ }
+ else if(evalValue.un.i4Value==1)
+ {
+ if(yyisa(node,ILNode_Mul) || yyisa(node,ILNode_Div))
+ {
+ *parent=expr->expr1; // x * 1 = x; x/1 = x;
+ return 1;
+ }
+ }
+ else if(evalValue.un.i4Value==0)
+ {
+ if(yyisa(node,ILNode_Mul))
+ {
+ *parent=ILNode_Int32_create(0,0,0); // x * 0 =0;
+ return 1;
+ }
+ else if(yyisa(node,ILNode_Add) ||
yyisa(node,ILNode_Sub))
+ {
+ *parent=expr->expr1; // x + 0 = x ; x-0=x;
+ return 1;
+ }
+ }
+ }
+ return 0;
+ }
%}
***************
*** 225,228 ****
--- 369,377 ----
/* Determine the common type */
commonType = ILCommonType(info, type1, type2, 0);
+
+ if(ReduceOperator(info,(ILNode*)node,(ILNode**)(&node),commonType))
+ {
+ return ILNode_GenValue(node,info);
+ }
/* Evaluate the sub-expressions and cast to the common type */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnet/codegen cg_arith.tc,1.13,1.14,
Gopal.V <address@hidden> <=
- Prev by Date:
[Dotgnu-pnet-commits] CVS: cscctest/csharp/class indexer1.il,1.1,1.2 indexer1.jl,1.1,1.2 interface1.il,1.5,1.6 interface1.jl,1.5,1.6
- Next by Date:
[Dotgnu-pnet-commits] CVS: pnet ChangeLog,1.1875,1.1876
- Previous by thread:
[Dotgnu-pnet-commits] CVS: cscctest/csharp/class indexer1.il,1.1,1.2 indexer1.jl,1.1,1.2 interface1.il,1.5,1.6 interface1.jl,1.5,1.6
- Next by thread:
[Dotgnu-pnet-commits] CVS: pnet ChangeLog,1.1875,1.1876
- Index(es):