[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[dotgnu-pnet-commits] pnet ChangeLog engine/jitc.c engine/jitc.h engi...
From: |
Klaus Treichel |
Subject: |
[dotgnu-pnet-commits] pnet ChangeLog engine/jitc.c engine/jitc.h engi... |
Date: |
Sat, 27 Dec 2008 15:55:40 +0000 |
CVSROOT: /cvsroot/dotgnu-pnet
Module name: pnet
Changes by: Klaus Treichel <ktreichel> 08/12/27 15:55:40
Modified files:
. : ChangeLog
engine : jitc.c jitc.h Makefile.am
Added files:
engine : jitc_string.c
Log message:
Add support for inlining System.String:get_Chars and
System.String::NewString
for the jit coder.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3596&r2=1.3597
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc.c?cvsroot=dotgnu-pnet&r1=1.88&r2=1.89
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc.h?cvsroot=dotgnu-pnet&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/Makefile.am?cvsroot=dotgnu-pnet&r1=1.97&r2=1.98
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc_string.c?cvsroot=dotgnu-pnet&rev=1.1
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3596
retrieving revision 1.3597
diff -u -b -r1.3596 -r1.3597
--- ChangeLog 25 Dec 2008 13:14:15 -0000 1.3596
+++ ChangeLog 27 Dec 2008 15:55:38 -0000 1.3597
@@ -1,3 +1,18 @@
+2008-12-27 Klaus Treichel <address@hidden>
+
+ * engine/jitc_string.c: Add support for inlining for String.get_Chars
+ and String.NewString.
+
+ * engine/jitc.c: Add the signature for the string allocator.
+ (ILJitInit): Define the signature for the string allocator.
+ (_ILJitSetMethodInfo): Set the method info for the new inlining
+ functions.
+ (ILJitTypeCreate): Mark the System.String class.
+
+ * engine/jitc.h: Add a new type kind for the System.String class.
+
+ * engine/Makefile.am: Add jitc_string.c to the jit coder sources.
+
2008-12-25 Klaus Treichel <address@hidden>
* codegen/cg_nodes.tc: Define the new nodetypes ILNode_Memcpy and
Index: engine/jitc.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/jitc.c,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -b -r1.88 -r1.89
--- engine/jitc.c 18 Nov 2008 20:06:05 -0000 1.88
+++ engine/jitc.c 27 Dec 2008 15:55:40 -0000 1.89
@@ -183,6 +183,12 @@
static ILJitType _ILJitSignature_ILJitSArrayAlloc = 0;
/*
+ * System_String *_ILJitStringAlloc(ILClass *stringClass,
+ *
ILUInt32 numChars)
+ */
+static ILJitType _ILJitSignature_ILJitStringAlloc = 0;
+
+/*
* System_Array *_ILJitGetExceptionStackTrace(ILExecThread *thread)
*/
static ILJitType _ILJitSignature_ILJitGetExceptionStackTrace = 0;
@@ -395,6 +401,7 @@
#include "jitc_except.c"
#include "jitc_alloc.c"
#include "jitc_array.c"
+#include "jitc_string.c"
#include "jitc_call.c"
#include "jitc_delegate.c"
#include "jitc_math.c"
@@ -2342,6 +2349,15 @@
}
args[0] = _IL_JIT_TYPE_VPTR;
+ args[1] = _IL_JIT_TYPE_UINT32;
+ returnType = _IL_JIT_TYPE_VPTR;
+ if(!(_ILJitSignature_ILJitStringAlloc =
+ jit_type_create_signature(IL_JIT_CALLCONV_CDECL, returnType,
args, 2, 1)))
+ {
+ return 0;
+ }
+
+ args[0] = _IL_JIT_TYPE_VPTR;
args[1] = _IL_JIT_TYPE_VPTR;
args[2] = _IL_JIT_TYPE_VPTR;
returnType = _IL_JIT_TYPE_INT32;
@@ -3895,6 +3911,25 @@
}
}
break;
+
+ case IL_JIT_TYPEKIND_SYSTEM_STRING:
+ {
+ ILType *signature = ILMethod_Signature(method);
+
+ if(ILMethod_IsStatic(method) &&
+ !strcmp(ILMethod_Name(method), "NewString")
&&
+ _ILLookupTypeMatch(signature,
"(i)oSystem.String;"))
+ {
+ inlineFunc =
_ILJitSystemStringNew;
+ }
+ else if(!ILMethod_IsStatic(method) &&
+ !strcmp(ILMethod_Name(method),
"get_Chars") &&
+ _ILLookupTypeMatch(signature,
"(Ti)c"))
+ {
+ inlineFunc =
_ILJitSystemStringChars;
+ }
+ }
+ break;
}
}
@@ -4597,6 +4632,10 @@
{
classPrivate->jitTypes.jitTypeKind = IL_JIT_TYPEKIND_SYSTEM_MATH;
}
+ else
if(!strcmp(ILClass_Name(classPrivate->classInfo), "String"))
+ {
+
classPrivate->jitTypes.jitTypeKind = IL_JIT_TYPEKIND_SYSTEM_STRING;
+ }
}
}
}
@@ -5029,6 +5068,7 @@
#include "jitc_inline.c"
#include "jitc_alloc.c"
#include "jitc_array.c"
+#include "jitc_string.c"
#include "jitc_except.c"
#include "jitc_call.c"
#include "jitc_delegate.c"
Index: engine/jitc.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/jitc.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- engine/jitc.h 21 Sep 2008 17:40:37 -0000 1.24
+++ engine/jitc.h 27 Dec 2008 15:55:40 -0000 1.25
@@ -124,6 +124,7 @@
#define IL_JIT_TYPEKIND_ARRAY 0x00000010
#define IL_JIT_TYPEKIND_SYSTEM_ARRAY 0x00000020
#define IL_JIT_TYPEKIND_SYSTEM_MATH 0x00000040
+#define IL_JIT_TYPEKIND_SYSTEM_STRING 0x00000080
/*
* Initialize a ILJitTypes structure
Index: engine/Makefile.am
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/Makefile.am,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -b -r1.97 -r1.98
--- engine/Makefile.am 10 Aug 2008 16:16:13 -0000 1.97
+++ engine/Makefile.am 27 Dec 2008 15:55:40 -0000 1.98
@@ -35,6 +35,7 @@
jitc_ptr.c \
jitc_setup.c \
jitc_stack.c \
+ jitc_string.c \
jitc_var.c
MD_ARM_INCLUDES = md_arm.h arm_codegen.h
Index: engine/jitc_string.c
===================================================================
RCS file: engine/jitc_string.c
diff -N engine/jitc_string.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ engine/jitc_string.c 27 Dec 2008 15:55:39 -0000 1.1
@@ -0,0 +1,267 @@
+/*
+ * jitc_string.c - Jit coder string handling routines.
+ *
+ * Copyright (C) 2008 Southern Storm Software, Pty Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifdef IL_JITC_DECLARATIONS
+
+/*
+ * The simple array header size.
+ */
+#define _IL_JIT_STRING_HEADERSIZE
((ILInt32)(ILNativeInt)StringToBuffer(0))
+
+/*
+ * Validate the string index.
+ */
+#define JITC_START_CHECK_STRING_INDEX(jitCoder, length, index) \
+ { \
+ jit_label_t __label = jit_label_undefined; \
+ jit_label_t __okLabel = jit_label_undefined; \
+ ILJitValue __length = (length); \
+ ILJitValue __index = (index); \
+ ILJitValue __temp; \
+ \
+ AdjustSign(jitCoder->jitFunction, &(__length), 1, 0); \
+ AdjustSign(jitCoder->jitFunction, &(__index), 1, 0); \
+ \
+ __temp = jit_insn_le(jitCoder->jitFunction, __length, __index);
\
+ jit_insn_branch_if(jitCoder->jitFunction, __temp, &__label);
+
+#define JITC_END_CHECK_STRING_INDEX(jitCoder) \
+ jit_insn_branch(jitCoder->jitFunction, &__okLabel); \
+ jit_insn_label(jitCoder->jitFunction, &__label); \
+ _ILJitThrowSystem(jitCoder->jitFunction,
_IL_JIT_INDEX_OUT_OF_RANGE); \
+ jit_insn_label(jitCoder->jitFunction, &__okLabel); \
+ }
+
+/*
+ * Allocate a string with the given length.
+ */
+static System_String *_ILJitStringAlloc(ILClass *stringClass,
+
ILUInt32 numChars);
+
+/*
+ * Get the pointer to the firct character in a string.
+ */
+static ILJitValue _ILJitStringGetStart(ILJitFunction jitFunction,
+
ILJitValue string);
+
+/*
+ * Get the ength of a string.
+ */
+static ILJitValue _ILJitStringGetLength(ILJitFunction jitFunction,
+
ILJitValue string);
+
+
+/*
+ * Inline function to create a new string with the given length
+ */
+static int _ILJitSystemStringNew(ILJITCoder *jitCoder,
+ ILMethod
*method,
+
ILCoderMethodInfo *methodInfo,
+ ILJitStackItem
*args,
+ ILInt32
numArgs);
+
+/*
+ * Inline function to get the character at the specified indexe in a
+ * string.
+ */
+static int _ILJitSystemStringChars(ILJITCoder *jitCoder,
+ ILMethod
*method,
+
ILCoderMethodInfo *methodInfo,
+
ILJitStackItem *args,
+ ILInt32
numArgs);
+
+#endif /* IL_JITC_DECLARATIONS */
+
+#ifdef IL_JITC_FUNCTIONS
+
+/*
+ * Allocate a string with the given length.
+ */
+static System_String *_ILJitStringAlloc(ILClass *stringClass,
+
ILUInt32 numChars)
+{
+ ILUInt64 totalSize;
+ ILInt32 roundLen;
+ System_String *ptr;
+
+ /* Add space for the 0 character and round to a multiple of 8 */
+ roundLen = ((numChars + 8) & ~7);
+ totalSize = (((ILUInt64)roundLen) * ((ILUInt64)sizeof(ILUInt16))) +
+ _IL_JIT_STRING_HEADERSIZE;
+ if(totalSize > (ILUInt64)IL_MAX_UINT32)
+ {
+ /* The array is too large. */
+ /* Throw an "OutOfMemoryException" */
+ ILRuntimeExceptionThrowOutOfMemory();
+ return (System_String *)0;
+ }
+ ptr = (System_String *)_ILJitAllocAtomic(stringClass,
(ILUInt32)totalSize);
+ ptr->capacity = roundLen - 1;
+ ptr->length = (ILInt32)numChars;
+ return ptr;
+}
+
+/*
+ * Get the pointer to the first character in a string.
+ */
+static ILJitValue _ILJitStringGetStart(ILJitFunction jitFunction,
+
ILJitValue string)
+{
+ return jit_insn_add_relative(jitFunction, string,
+
_IL_JIT_STRING_HEADERSIZE);
+}
+
+/*
+ * Get the length of a string.
+ */
+static ILJitValue _ILJitStringGetLength(ILJitFunction jitFunction,
+
ILJitValue string)
+{
+ ILJitValue len;
+
+ len = jit_insn_load_relative(jitFunction,
+ string,
+
offsetof(System_String, length),
+
_IL_JIT_TYPE_INT32);
+ return len;
+}
+
+/*
+ * Inline function to create a new string with the given length
+ */
+static int _ILJitSystemStringNew(ILJITCoder *jitCoder,
+ ILMethod
*method,
+
ILCoderMethodInfo *methodInfo,
+ ILJitStackItem
*args,
+ ILInt32
numArgs)
+{
+ ILJitFunction jitFunction = ILJitFunctionFromILMethod(method);
+ ILClass *stringClass = ILMethod_Owner(method);
+ ILJitValue newString;
+ ILJitValue callArgs[2];
+
+ if(!jitFunction)
+ {
+ /* We need to layout the class first. */
+ if(!_LayoutClass(ILExecThreadCurrent(), stringClass))
+ {
+ return 0;
+ }
+ if(!(jitFunction = ILJitFunctionFromILMethod(method)))
+ {
+ return 0;
+ }
+ }
+
+#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS) &&
defined(_IL_JIT_ENABLE_DEBUG)
+ if(jitCoder->flags & IL_CODER_FLAG_STATS)
+ {
+ ILMutexLock(globalTraceMutex);
+ fprintf(stdout, "Inline System.String::NewString\n");
+ ILMutexUnlock(globalTraceMutex);
+ }
+#endif
+
+ /* We call the alloc functions. */
+ /* They thow an out of memory exception so we don't need to care. */
+ callArgs[0] = jit_value_create_nint_constant(jitCoder->jitFunction,
+
_IL_JIT_TYPE_VPTR,
+
(jit_nint)stringClass);
+ if(!callArgs[0])
+ {
+ return 0;
+ }
+ callArgs[1] = _ILJitValueConvertImplicit(jitCoder->jitFunction,
+
_ILJitStackItemValue(args[0]),
+
_IL_JIT_TYPE_UINT32);
+ if(!callArgs[1])
+ {
+ return 0;
+ }
+ newString = jit_insn_call_native(jitCoder->jitFunction,
+
"_ILJitStringAlloc",
+
_ILJitStringAlloc,
+
_ILJitSignature_ILJitStringAlloc,
+
callArgs, 2, 0);
+ if(!newString)
+ {
+ return 0;
+ }
+
+ _ILJitStackPushValue(jitCoder, newString);
+ return 1;
+}
+
+/*
+ * Inline function to get the character at the specified indexe in a
+ * string.
+ */
+static int _ILJitSystemStringChars(ILJITCoder *jitCoder,
+ ILMethod
*method,
+
ILCoderMethodInfo *methodInfo,
+
ILJitStackItem *args,
+ ILInt32
numArgs)
+{
+ ILJitFunction jitFunction = ILJitFunctionFromILMethod(method);
+ ILClass *stringClass = ILMethod_Owner(method);
+ ILJitValue length;
+ ILJitValue stringBase;
+ ILJitValue returnValue;
+
+ if(!jitFunction)
+ {
+ /* We need to layout the class first. */
+ if(!_LayoutClass(ILExecThreadCurrent(), stringClass))
+ {
+ return 0;
+ }
+ if(!(jitFunction = ILJitFunctionFromILMethod(method)))
+ {
+ return 0;
+ }
+ }
+
+#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS) &&
defined(_IL_JIT_ENABLE_DEBUG)
+ if(jitCoder->flags & IL_CODER_FLAG_STATS)
+ {
+ ILMutexLock(globalTraceMutex);
+ fprintf(stdout, "Inline System.String::get_Chars\n");
+ ILMutexUnlock(globalTraceMutex);
+ }
+#endif
+
+ _ILJitStackItemCheckNull(jitCoder, args[0]);
+ length = _ILJitStringGetLength(jitCoder->jitFunction,
+
_ILJitStackItemValue(args[0]));
+ JITC_START_CHECK_STRING_INDEX(jitCoder, length,
_ILJitStackItemValue(args[1]))
+ stringBase = _ILJitStringGetStart(jitCoder->jitFunction,
+
_ILJitStackItemValue(args[0]));
+ returnValue = jit_insn_load_elem(jitCoder->jitFunction,
+
stringBase,
+
_ILJitStackItemValue(args[1]),
+
_IL_JIT_TYPE_CHAR);
+ JITC_END_CHECK_STRING_INDEX(jitCoder)
+
+ _ILJitStackPushValue(jitCoder, returnValue);
+ return 1;
+}
+
+#endif /* IL_JITC_FUNCTIONS */
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [dotgnu-pnet-commits] pnet ChangeLog engine/jitc.c engine/jitc.h engi...,
Klaus Treichel <=