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

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

[dotgnu-pnet-commits] [SCM] DotGNU Portable.NET engine, compilers and to


From: Klaus Treichel
Subject: [dotgnu-pnet-commits] [SCM] DotGNU Portable.NET engine, compilers and tools (pnet) branch, master, updated. 0b2736ee5dc7e5e470e8a974a5f4826aea5e44a7
Date: Tue, 04 Jan 2011 15:05:59 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "DotGNU Portable.NET engine, compilers and tools (pnet)".

The branch, master has been updated
       via  0b2736ee5dc7e5e470e8a974a5f4826aea5e44a7 (commit)
      from  8fc04a6d420138c4f3ce52910780db091e152230 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/pnet.git/commit/?id=0b2736ee5dc7e5e470e8a974a5f4826aea5e44a7

commit 0b2736ee5dc7e5e470e8a974a5f4826aea5e44a7
Author: Klaus Treichel <address@hidden>
Date:   Tue Jan 4 16:05:00 2011 +0100

    Do some optimizations in the cvm interpreter for x86.

diff --git a/ChangeLog b/ChangeLog
index 69f09ef..8ae249a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2011-01-04  Klaus Treichel  <address@hidden>
+
+       * engine/cvm.c: Make the interpreter loop variables volatile again
+       on x86.
+       Mark the consditions that lead to exceptions most probably not true.
+       (Interpreter): Move the exceptions to cvm_except.c in the throw opcode.
+
+       * cvm_call.c: Mark the consditions that lead to exceptions most
+       probably not true.
+
+       * cvm_config.h: Add IL_EXPECT macro for __builtin_expect for gcc >= 3.
+       Add optimizations for x86.
+
+       * cvm_except.c (CVM_PREFIX_OP_THROW): Move the exceptions from cvm.c
+       to here.
+
 2011-01-02  Klaus Treichel  <address@hidden>
 
        * engine/call.c (_ILCallMethod): Don't copy the currentException back
diff --git a/engine/cvm.c b/engine/cvm.c
index 9aa2484..f466dfe 100644
--- a/engine/cvm.c
+++ b/engine/cvm.c
@@ -147,14 +147,14 @@ extern    "C" {
  */
 #if defined(__GNUC__) && !defined(IL_VMCASE_BARRIER)
 #if (__GNUC__ == 4) && defined(CVM_X86)
-#define IL_PC_VOLATILE
-#define IL_STACKTOP_VOLATILE
-#define IL_FRAME_VOLATILE
-#define IL_STACKMAX_VOLATILE
-#define IL_METHOD_VOLATILE
-#define IL_METHODTOCALL_VOLATILE
-#define IL_CALLFRAME_VOLATILE
-#define IL_TEMPPTR_VOLATILE
+#define IL_PC_VOLATILE volatile
+#define IL_STACKTOP_VOLATILE volatile
+#define IL_FRAME_VOLATILE volatile
+#define IL_STACKMAX_VOLATILE volatile
+#define IL_METHOD_VOLATILE volatile
+#define IL_METHODTOCALL_VOLATILE volatile
+#define IL_CALLFRAME_VOLATILE volatile
+#define IL_TEMPPTR_VOLATILE volatile
 #endif
 #if (__GNUC__ == 4) && defined(CVM_X86_64)
 #define IL_PC_VOLATILE
@@ -276,7 +276,7 @@ extern      "C" {
        #define END_NULL_CHECK()
 #else
        #define BEGIN_NULL_CHECK(x) \
-               if ((x) == 0) goto throwNullReferenceException; \
+               if (IL_EXPECT((x) == 0, 0)) goto throwNullReferenceException; \
                {
 
        #define BEGIN_NULL_CHECK_STMT(x) BEGIN_NULL_CHECK(x)
@@ -290,7 +290,7 @@ extern      "C" {
        #define END_INT_ZERO_DIV_CHECK()
 #else
        #define BEGIN_INT_ZERO_DIV_CHECK(x) \
-               if ((x) != 0) \
+               if (IL_EXPECT((x) != 0, 1)) \
                {
 
        #define END_INT_ZERO_DIV_CHECK() \
@@ -309,7 +309,7 @@ extern      "C" {
        #define END_INT_OVERFLOW_CHECK()
 #else
        #define BEGIN_INT_OVERFLOW_CHECK(x) \
-               if (x) \
+               if (IL_EXPECT((x), 1)) \
                {
 
        #define END_INT_OVERFLOW_CHECK() \
@@ -958,82 +958,6 @@ static int Interpreter(ILExecThread *thread)
 
        /* We should never get here, but keep the compiler happy */
        return 0;
-
-       /*
-        * Jump target to throw a NullReferenceException
-        */
-throwNullReferenceException:
-       COPY_STATE_TO_THREAD();
-       tempptr = _ILSystemException(thread, "System.NullReferenceException");
-       goto throwException;
-
-       /*
-        * Jump target to throw an ArithmeticException
-        */
-throwArithmeticException:
-       COPY_STATE_TO_THREAD();
-       tempptr = _ILSystemException(thread, "System.ArithmeticException");
-       goto throwException;
-
-       /*
-        * Jump target to throw an OverflowException
-        */
-throwOverflowException:
-       COPY_STATE_TO_THREAD();
-       tempptr = _ILSystemException(thread, "System.OverflowException");
-       goto throwException;
-
-       /*
-        * Jump target to throw a DivideByZeroException
-        */
-throwDivideByZeroException:
-       COPY_STATE_TO_THREAD();
-       tempptr = _ILSystemException(thread, "System.DivideByZeroException");
-       goto throwException;
-
-       /*
-        * Jump target to throw a StackOverflowException
-        */
-throwStackOverflowException:
-       COPY_STATE_TO_THREAD();
-       tempptr = _ILSystemException(thread, "System.StackOverflowException");
-       goto throwException;
-
-       /*
-        * Jump target to throw a MissingMethodException
-        */
-throwMissingMethodException:
-       COPY_STATE_TO_THREAD();
-       tempptr = _ILSystemException(thread, "System.MissingMethodException");
-       goto throwException;
-
-       /*
-        * Jump target to throw an InvalidCastException
-        */
-throwInvalidCastException:
-       COPY_STATE_TO_THREAD();
-       tempptr = _ILSystemException(thread, "System.InvalidCastException");
-       goto throwException;
-
-       /*
-        * Jump target to throw an IndexOutOfRangeException
-        */
-throwIndexOutOfRangeException:
-       COPY_STATE_TO_THREAD();
-       tempptr = _ILSystemException(thread, "System.IndexOutOfRangeException");
-       goto throwException;
-       /*
-        * Label that we jump to when the engine throws an exception.
-        * The exception thrown is expected to be in tempptr.
-        */
-throwException:
-       /* Pop the exception object from the stack and store it to the thread. 
*/
-       thread->thrownException = tempptr;
-#ifdef IL_DUMP_CVM
-       fputs("Throw ", IL_DUMP_CVM_STREAM);
-       DUMP_STACK();
-#endif
-       return _CVM_EXIT_THROW;
 }
 
 /*
diff --git a/engine/cvm_call.c b/engine/cvm_call.c
index 2a31747..961ad9b 100644
--- a/engine/cvm_call.c
+++ b/engine/cvm_call.c
@@ -97,18 +97,13 @@ ILCallFrame *_ILAllocCallFrame(ILExecThread *thread)
 
 
 #define CHECK_MANAGED_BARRIER()        \
-       if (thread->managedSafePointFlags)      \
+       if (IL_EXPECT(thread->managedSafePointFlags, 0))        \
        {       \
                if  ((thread->managedSafePointFlags & 
_IL_MANAGED_SAFEPOINT_THREAD_ABORT) && ILThreadIsAbortRequested()) \
                { \
                        if (_ILExecThreadSelfAborting(thread) == 0) \
                        { \
-                               
ILInterlockedAndU4(&(thread->managedSafePointFlags), \
-                                                                  
~_IL_MANAGED_SAFEPOINT_THREAD_ABORT); \
-                               tempptr = thread->thrownException; \
-                               thread->thrownException = 0; \
-                               COPY_STATE_TO_THREAD(); \
-                               goto throwException; \
+                               goto throwThreadAbortException; \
                        } \
                } \
                else if (thread->managedSafePointFlags & 
_IL_MANAGED_SAFEPOINT_THREAD_SUSPEND) \
@@ -187,7 +182,7 @@ ILCallFrame *_ILAllocCallFrame(ILExecThread *thread)
                                stacktop = thread->stackTop; \
                                frame = thread->frame; \
                                stackmax = thread->stackLimit; \
-                               if(thread->thrownException != 0) \
+                               if(IL_EXPECT(thread->thrownException != 0, 0)) \
                                { \
                                        /* An exception occurred, which we now 
must handle */ \
                                        tempptr = thread->thrownException; \
diff --git a/engine/cvm_config.h b/engine/cvm_config.h
index 074d2de..03af4de 100644
--- a/engine/cvm_config.h
+++ b/engine/cvm_config.h
@@ -265,8 +265,32 @@ extern int _ILCVMInsnCount[];
        #define CVM_REGISTER_ASM_STACK(x)               register x asm ("edi")
        #define CVM_REGISTER_ASM_FRAME(x)               register x asm ("ebx")
 #if defined(IL_CVM_DIRECT_UNROLLED)
+       /*
+        * This is the barrier needed to make the interpreter work.
+        *
        #define CVM_VMBREAK_BARRIER()   \
-               __asm__ __volatile__ ("" : : : "eax", "ecx", "edx", "memory")
+               __asm__ __volatile__ ("" : : : "ecx", "edx")
+        *
+        * The extended barrier makes gcc (version 4.4) build faster code.
+        * (Tested on an intel atom cpu box)
+        * As of gcc 4.4 the interpreter segfaults if built with -O3 on x86
+        */
+       #define CVM_VMBREAK_BARRIER()   \
+       __asm__ __volatile__ ("" : : : "ecx", "edx", "memory")
+       /*
+        * Define arch specific replacements for the cvm interpreter switch
+        * , case and break statements.
+        * For these x86 specific versions all variables with a *VOLATILE* macro
+        * that are not kept in a register (see CVM_REGISTER* macros) MUST be 
defined
+        * volatile.
+        *
+        * NOTE: The goto statement in the macro is just for the compiler.
+        */
+       #define X86_CGOTO(pc) do { __asm__ __volatile__ ("jmp *(%0)" : : "r" 
(pc)); \
+                                                          goto ** ((void 
**)(pc)); } while(0)
+       #define VM_CGOTO_PREFIXSWITCH(val) X86_CGOTO(pc)
+       #define VM_CGOTO_BREAK(val) X86_CGOTO(pc)
+       #define VM_CGOTO_BREAKNOEND(val) X86_CGOTO(pc)
 #endif
 #elif defined(CVM_X86_64) && defined(__GNUC__) && !defined(IL_NO_ASM)
 
@@ -345,6 +369,17 @@ extern int _ILCVMInsnCount[];
 #endif
 #endif
 
+/*
+ * predict the outcome of an expression to allow the compiler to
+ * optimize better.
+ * The result must be a compile time constant. Usually either 0 or 1.
+ */
+#if (__GNUC__ >= 3)
+#define IL_EXPECT(expr, result) __builtin_expect((expr), (result))
+#else
+#define IL_EXPECT(expr, result) (expr)
+#endif
+
 #ifdef __cplusplus
 };
 #endif
diff --git a/engine/cvm_except.c b/engine/cvm_except.c
index 141dab6..eb45566 100644
--- a/engine/cvm_except.c
+++ b/engine/cvm_except.c
@@ -172,6 +172,93 @@ VMCASE(COP_PREFIX_THROW):
        --stacktop;
        tempptr = stacktop[0].ptrValue;
        COPY_STATE_TO_THREAD();
+       /*
+        * Label that we jump to when the engine throws an exception.
+        * The exception thrown is expected to be in tempptr.
+        */
+throwException:
+       /* Pop the exception object from the stack and store it to the thread. 
*/
+       thread->thrownException = tempptr;
+#ifdef IL_DUMP_CVM
+       fputs("Throw ", IL_DUMP_CVM_STREAM);
+       DUMP_STACK();
+#endif
+       return _CVM_EXIT_THROW;
+
+       /*
+        * Jump target to throw a ThreadAbortException from the
+        * managed barrier.
+        */
+throwThreadAbortException:
+       ILInterlockedAndU4(&(thread->managedSafePointFlags),
+                                          ~_IL_MANAGED_SAFEPOINT_THREAD_ABORT);
+       tempptr = thread->thrownException;
+       thread->thrownException = 0;
+       COPY_STATE_TO_THREAD();
+       goto throwException;
+
+       /*
+        * Jump target to throw a NullReferenceException
+        */
+throwNullReferenceException:
+       COPY_STATE_TO_THREAD();
+       tempptr = _ILSystemException(thread, "System.NullReferenceException");
+       goto throwException;
+
+       /*
+        * Jump target to throw an ArithmeticException
+        */
+throwArithmeticException:
+       COPY_STATE_TO_THREAD();
+       tempptr = _ILSystemException(thread, "System.ArithmeticException");
+       goto throwException;
+
+       /*
+        * Jump target to throw an OverflowException
+        */
+throwOverflowException:
+       COPY_STATE_TO_THREAD();
+       tempptr = _ILSystemException(thread, "System.OverflowException");
+       goto throwException;
+
+       /*
+        * Jump target to throw a DivideByZeroException
+        */
+throwDivideByZeroException:
+       COPY_STATE_TO_THREAD();
+       tempptr = _ILSystemException(thread, "System.DivideByZeroException");
+       goto throwException;
+
+       /*
+        * Jump target to throw a StackOverflowException
+        */
+throwStackOverflowException:
+       COPY_STATE_TO_THREAD();
+       tempptr = _ILSystemException(thread, "System.StackOverflowException");
+       goto throwException;
+
+       /*
+        * Jump target to throw a MissingMethodException
+        */
+throwMissingMethodException:
+       COPY_STATE_TO_THREAD();
+       tempptr = _ILSystemException(thread, "System.MissingMethodException");
+       goto throwException;
+
+       /*
+        * Jump target to throw an InvalidCastException
+        */
+throwInvalidCastException:
+       COPY_STATE_TO_THREAD();
+       tempptr = _ILSystemException(thread, "System.InvalidCastException");
+       goto throwException;
+
+       /*
+        * Jump target to throw an IndexOutOfRangeException
+        */
+throwIndexOutOfRangeException:
+       COPY_STATE_TO_THREAD();
+       tempptr = _ILSystemException(thread, "System.IndexOutOfRangeException");
        goto throwException;
 }
 VMBREAK(COP_PREFIX_THROW);

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog           |   16 ++++++++
 engine/cvm.c        |   98 ++++++---------------------------------------------
 engine/cvm_call.c   |   11 ++----
 engine/cvm_config.h |   37 +++++++++++++++++++-
 engine/cvm_except.c |   87 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 153 insertions(+), 96 deletions(-)


hooks/post-receive
-- 
DotGNU Portable.NET engine, compilers and tools (pnet)



reply via email to

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