dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dotgnu-pnet-commits] pnet ChangeLog codegen/cg_stmt.tc cscc/c/c_stmt...


From: Klaus Treichel
Subject: [dotgnu-pnet-commits] pnet ChangeLog codegen/cg_stmt.tc cscc/c/c_stmt...
Date: Sat, 28 Mar 2009 12:02:23 +0000

CVSROOT:        /cvsroot/dotgnu-pnet
Module name:    pnet
Changes by:     Klaus Treichel <ktreichel>      09/03/28 12:02:23

Modified files:
        .              : ChangeLog 
        codegen        : cg_stmt.tc 
        cscc/c         : c_stmt.tc 
        cscc/csharp    : cs_stmt.tc 

Log message:
        Determine how the code for a switch table is generated in one place now 
instead
        of having the same function multiple times and generate switch tables 
more
        often.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3610&r2=1.3611
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_stmt.tc?cvsroot=dotgnu-pnet&r1=1.48&r2=1.49
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/c/c_stmt.tc?cvsroot=dotgnu-pnet&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_stmt.tc?cvsroot=dotgnu-pnet&r1=1.46&r2=1.47

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3610
retrieving revision 1.3611
diff -u -b -r1.3610 -r1.3611
--- ChangeLog   25 Mar 2009 19:26:04 -0000      1.3610
+++ ChangeLog   28 Mar 2009 12:02:22 -0000      1.3611
@@ -1,3 +1,19 @@
+2009-03-28  Klaus Treichel  <address@hidden>
+
+       * codegen/cg_stmt.tc (CGSetSwitchTableType): Move the duplicate function
+       SwitchTableType from cscc/c/c_stmt.tc and cscc/csharp/cs_stmt.tc to 
here.
+       Generate simple ifs only for tables with less than 3 switchentries 
instead
+       of 4 and generate switch tables too if the range of the constant values
+       is less than 128.
+ 
+       cscc/c/c_stmt.tc (SwitchTableType): Move to codegen/cg_stmt.tc.
+       (ILNode_CSemAnalysis(ILNode_Switch)): Set the switch type in the node
+       and call CGSetSwitchTableType instead of SwitchTableType.
+
+       cscc/csharp/cs_stmt.tc (SwitchTableType): Move to codegen/cg_stmt.tc.
+       (ILNode_SemAnalysis(ILNode_Switch)): Call CGSetSwitchTableType instead
+       of SwitchTableType.
+
 2009-03-25  Klaus Treichel  <address@hidden>
 
        * dumpasm/dump_class.c (Dump_PropertyDef): Add output of the constant

Index: codegen/cg_stmt.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_stmt.tc,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -b -r1.48 -r1.49
--- codegen/cg_stmt.tc  25 Dec 2008 13:14:16 -0000      1.48
+++ codegen/cg_stmt.tc  28 Mar 2009 12:02:23 -0000      1.49
@@ -1917,6 +1917,106 @@
        }
 }
 
+void CGSetSwitchTableType(ILNode_Switch *switchNode)
+{
+       ILMachineType type;
+       ILSwitchValue *values;
+       unsigned long numValues;
+       unsigned long range;
+
+       values = switchNode->switchValues;
+       numValues = switchNode->numSwitchValues;
+       /*
+        * The switch statement has to substract the lowest value from the
+        * value to switch on for calculating the index in the switch table
+        * and check implicitely if the value is in the range lowest value
+        * and highest value by an unsinged comparision.
+        * So it makes sense to use a switch table only if a certain number of
+        * entries is available.
+        * So we are using simple "if" statements for 2 or less cases.
+        */
+       if(numValues <= 2)
+       {
+               switchNode->tableType = ILSwitchTableType_If;
+               return;
+       }
+
+       /*
+        * If the switch type can fit in a 32-bit integer, and the
+        * range is less that 128 or the cases fill up at least 80% of the
+        * range, then use an indexed table for the switch.
+        * But the calculation is prone to overflow, hence the upper limit
+        * check.
+        */
+       type = ILTypeToMachineType(switchNode->switchType);
+       switch(type)
+       {
+               case ILMachineType_Int8:
+               case ILMachineType_UInt8:
+               case ILMachineType_Int16:
+               case ILMachineType_UInt16:
+               case ILMachineType_Char:
+               case ILMachineType_Int32:
+               {
+                       range = (unsigned long)(values[numValues - 
1].value.un.i4Value -
+                                                                       
values[0].value.un.i4Value);
+                       if(range < 128)
+                       {
+                               switchNode->tableType = 
ILSwitchTableType_Indexed;
+                               return;
+                       }
+                       else if(((range * 4) / 5) <= numValues && range < 
0x1fffffff)
+                       {
+                               switchNode->tableType = 
ILSwitchTableType_Indexed;
+                               return;
+                       }
+                       else
+                       {
+                               switchNode->tableType = 
ILSwitchTableType_Lookup;
+                               return;
+                       }
+               }
+               /* Not reached */
+
+               case ILMachineType_UInt32:
+               {
+                       range = (unsigned long)
+                               (((ILUInt32)(values[numValues - 
1].value.un.i4Value)) -
+                                ((ILUInt32)(values[0].value.un.i4Value)));
+                       if(range < 128)
+                       {
+                               switchNode->tableType = 
ILSwitchTableType_Indexed;
+                               return;
+                       }
+                       else if(((range * 4) / 5) <= numValues && range < 
0x3fffffff)
+                       {
+                               switchNode->tableType = 
ILSwitchTableType_Indexed;
+                               return;
+                       }
+                       else
+                       {
+                               switchNode->tableType = 
ILSwitchTableType_Lookup;
+                               return;
+                       }
+               }
+               /* Not reached */
+
+               default: break;
+       }
+
+       /* If we get here, then we need to use a binary tree of if statements */
+       switchNode->tableType = ILSwitchTableType_BinaryIf;
+}
+
+%}
+
+%decls %end %{
+
+/*
+ * Determine the type of table to be used for the switch statement.
+ */
+void CGSetSwitchTableType(ILNode_Switch *switchNode);
+
 %}
 
 /*

Index: cscc/c/c_stmt.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_stmt.tc,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- cscc/c/c_stmt.tc    25 Dec 2008 13:14:16 -0000      1.15
+++ cscc/c/c_stmt.tc    28 Mar 2009 12:02:23 -0000      1.16
@@ -982,71 +982,6 @@
        return size;
 }
 
-/*
- * Determine the type of table to be used for a set of switch cases.
- */
-static ILSwitchTableType SwitchTableType(ILType *switchType,
-                                                                               
 ILSwitchValue *values,
-                                                                               
 unsigned long numValues)
-{
-       ILMachineType type;
-       unsigned long range;
-
-       /* Use simple "if" statements for 4 or less cases */
-       if(numValues <= 4)
-       {
-               return ILSwitchTableType_If;
-       }
-
-       /* If the switch type can fit in a 32-bit integer, and the
-          cases fill up at least 80% of the range, then use an
-          indexed table for the switch */
-       type = ILTypeToMachineType(switchType);
-       switch(type)
-       {
-               case ILMachineType_Int8:
-               case ILMachineType_UInt8:
-               case ILMachineType_Int16:
-               case ILMachineType_UInt16:
-               case ILMachineType_Char:
-               case ILMachineType_Int32:
-               {
-                       range = (unsigned long)(values[numValues - 
1].value.un.i4Value -
-                                                                       
values[0].value.un.i4Value);
-                       if(((range * 80) / 100) <= numValues)
-                       {
-                               return ILSwitchTableType_Indexed;
-                       }
-                       else
-                       {
-                               return ILSwitchTableType_Lookup;
-                       }
-               }
-               /* Not reached */
-
-               case ILMachineType_UInt32:
-               {
-                       range = (unsigned long)
-                               (((ILUInt32)(values[numValues - 
1].value.un.i4Value)) -
-                                ((ILUInt32)(values[0].value.un.i4Value)));
-                       if(((range * 80) / 100) <= numValues)
-                       {
-                               return ILSwitchTableType_Indexed;
-                       }
-                       else
-                       {
-                               return ILSwitchTableType_Lookup;
-                       }
-               }
-               /* Not reached */
-
-               default: break;
-       }
-
-       /* If we get here, then we need to use a binary tree of if statements */
-       return ILSwitchTableType_BinaryIf;
-}
-
 %}
 
 /*
@@ -1118,6 +1053,8 @@
        /* Coerce the expression to the governing type */
        CCoerceNode(info, node->expr, &(node->expr), value, governType);
 
+       node->switchType = governType;
+
        /* Enter the switch context */
        PushStmtContext(info, C_STMT_SWITCH);
 
@@ -1147,8 +1084,7 @@
                                                                                
          governType, node->switchValues);
 
        /* Determine the type of switch table to generate */
-       node->tableType = SwitchTableType(governType, node->switchValues,
-                                                                         
node->numSwitchValues);
+       CGSetSwitchTableType(node);
 
        /* Perform semantic analysis on the switch body */
        StmtSem(node->body, info, &(node->body), stmtLevel);

Index: cscc/csharp/cs_stmt.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_stmt.tc,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -b -r1.46 -r1.47
--- cscc/csharp/cs_stmt.tc      25 Dec 2008 13:14:16 -0000      1.46
+++ cscc/csharp/cs_stmt.tc      28 Mar 2009 12:02:23 -0000      1.47
@@ -908,72 +908,6 @@
        return size;
 }
 
-/*
- * Determine the type of table to be used for a set of switch cases.
- */
-static ILSwitchTableType SwitchTableType(ILType *switchType,
-                                                                               
 ILSwitchValue *values,
-                                                                               
 unsigned long numValues)
-{
-       ILMachineType type;
-       unsigned long range;
-
-       /* Use simple "if" statements for 4 or less cases */
-       if(numValues <= 4)
-       {
-               return ILSwitchTableType_If;
-       }
-
-       /* If the switch type can fit in a 32-bit integer, and the
-          cases fill up at least 80% of the range, then use an
-          indexed table for the switch. But the calculation is prone 
-          to overflow, hence the upper limit check. */
-       type = ILTypeToMachineType(switchType);
-       switch(type)
-       {
-               case ILMachineType_Int8:
-               case ILMachineType_UInt8:
-               case ILMachineType_Int16:
-               case ILMachineType_UInt16:
-               case ILMachineType_Char:
-               case ILMachineType_Int32:
-               {
-                       range = (unsigned long)(values[numValues - 
1].value.un.i4Value -
-                                                                       
values[0].value.un.i4Value);
-                       if(((range * 4) / 5) <= numValues && range < 0x1fffffff)
-                       {
-                               return ILSwitchTableType_Indexed;
-                       }
-                       else
-                       {
-                               return ILSwitchTableType_Lookup;
-                       }
-               }
-               /* Not reached */
-
-               case ILMachineType_UInt32:
-               {
-                       range = (unsigned long)
-                               (((ILUInt32)(values[numValues - 
1].value.un.i4Value)) -
-                                ((ILUInt32)(values[0].value.un.i4Value)));
-                       if(((range * 4) / 5) <= numValues && range < 0x3fffffff)
-                       {
-                               return ILSwitchTableType_Indexed;
-                       }
-                       else
-                       {
-                               return ILSwitchTableType_Lookup;
-                       }
-               }
-               /* Not reached */
-
-               default: break;
-       }
-
-       /* If we get here, then we need to use a binary tree of if statements */
-       return ILSwitchTableType_BinaryIf;
-}
-
 %}
 
 /*
@@ -1078,8 +1012,7 @@
                                                                                
          switchType, node->switchValues);
 
        /* Determine the type of switch table to generate */
-       node->tableType = SwitchTableType(switchType, node->switchValues,
-                                                                         
node->numSwitchValues);
+       CGSetSwitchTableType(node);
 
        info->currentSwitch=savedSwitch;
        /* Leave the switch context */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]