--- libjit-org/jit/jit-init.c	2004-05-01 01:30:12.000000000 +0200
+++ libjit/jit/jit-init.c	2004-06-07 22:32:15.000000000 +0200
@@ -20,6 +20,7 @@
 
 #include "jit-internal.h"
 #include "jit-rules.h"
+#include "jit-alloc.h"
 
 /*@
  * @deftypefun void jit_init (void)
@@ -40,6 +41,9 @@
 	/* Make sure that the thread subsystem is initialized */
 	_jit_thread_init();
 
+	/* Make sure allocation unit is initialized */
+	_jit_alloc_init();
+
 	/* Initialize the backend */
 	_jit_init_backend();
 }
--- libjit-org/jit/jit-alloc.c	2004-06-07 19:52:15.000000000 +0200
+++ libjit/jit/jit-alloc.c	2004-06-07 23:27:42.000000000 +0200
@@ -51,6 +51,107 @@
  * own versions.
 @*/
 
+#if defined(__i386) || defined(__i386__) || defined(_M_IX86)
+static jit_uint _x86_clflush_line_size = 0;
+
+#ifdef __GNUC__
+static int _x86_has_cpuid (void)
+{
+	jit_int ret;
+
+	asm volatile (
+					"\txor %%ecx,%%ecx\n"
+					"\tpushf\n"
+					"\tpop %%eax\n"
+					"\tmov %%eax,%%ebx\n"
+					"\txor $0x00200000,%%eax\n"
+					"\tpush %%eax\n"
+					"\tpopf\n"
+					"\tpushf\n"
+					"\tpop %%eax\n"
+					"\tcmp %%ebx,%%eax\n"
+					"\tjz  0f\n"
+					"\tnot %%ecx\n"
+					"0:"
+					"\tmov %%ecx,%0\n"
+					: "=g" (ret)
+					:
+					: "eax", "ebx", "ecx");
+
+	return !!ret;
+}
+
+
+/* NOTE: we need here 32 bit datatype */
+static void _x86_cpuid (jit_uint code, jit_uint *a, jit_uint *b, jit_uint *c, jit_uint *d)
+{
+	jit_uint eax, ebx, ecx, edx;
+
+	asm volatile (
+			"\tmov %4,%%eax\n"
+			"\tcpuid\n"
+			"\tmov %%eax,%0\n"
+			"\tmov %%ebx,%1\n"
+			"\tmov %%ecx,%2\n"
+			"\tmov %%edx,%3\n"
+			: "=g" (eax),
+			  "=g" (ebx),
+			  "=g" (ecx),
+			  "=g" (edx)
+			: "g" (code)
+			: "eax", "ebx", "ecx", "edx");
+
+	*a = eax;
+	*b = ebx;
+	*c = ecx;
+	*d = edx;
+}
+#else /* __GNUC__ */
+#define _x86_has_cpuid() (!!0)
+#define _x86_cpuid(a,b,c,d,e) do { *(b) = 0; *(c) = 0; *(d) = 0; *(e) = 0; } while (0)
+#endif /* __GNUC__ */
+
+
+static jit_uint _x86_get_clflush_line_size (void)
+{
+	jit_uint   eax, ebx, ecx, edx;
+	jit_uint   size;
+
+	_x86_cpuid (0, &eax, &ebx, &ecx, &edx);
+
+	/* is function 1 implemented ? */
+	if (eax < 1)
+		return 0;
+
+	_x86_cpuid (1, &eax, &ebx, &ecx, &edx);
+
+	/* is clflush present ? */
+	if (! (edx & (1 << 19)))
+		return 0;
+
+	/* second byte of ebx contains the number of quadwords in cacheline */
+	size = (8 * ((ebx >> 8) & 0xff));
+
+	return size;
+}
+#endif /* X86 */
+
+
+/*@
+ * @deftypefun {void} _jit_alloc_init (void)
+ * Does one time initialization
+ * Currently used determinet cache line size of the current platform
+ * @end deftypefun
+@*/
+void _jit_alloc_init (void)
+{
+#if defined(__i386) || defined(__i386__) || defined(_M_IX86)
+	if (_x86_has_cpuid ())
+		_x86_clflush_line_size = _x86_get_clflush_line_size ();
+#endif
+}
+
+
 /*@
  * @deftypefun {void *} jit_malloc ({unsigned int} size)
  * Allocate @code{size} bytes of memory from the heap.
@@ -158,8 +259,8 @@
 
 #define ROUND_BEG_PTR(p) \
 	((void *)((((jit_nuint)(p)) / CLSIZE) * CLSIZE))
-#define ROUND_END_PTR(p) \
-	((void *)(((((jit_nuint)(p)) + CLSIZE - 1)/CLSIZE)*CLSIZE))
+#define ROUND_END_PTR(p,s) \
+	((void *)(((((jit_nuint)(p)) + (s) + CLSIZE - 1)/CLSIZE)*CLSIZE))
 
 #if defined(__GNUC__)
 #if defined(PPC)
@@ -171,7 +272,7 @@
 
 	/* Flush the data out of the data cache */
 	p   = ROUND_BEG_PTR (ptr);
-	end = ROUND_END_PTR (p + size);
+	end = ROUND_END_PTR (ptr, size);
 	while (p < end)
 	{
 		__asm__ __volatile__ ("dcbst 0,%0" :: "r"(p));
@@ -194,7 +295,7 @@
 
 	/* Flush the CPU cache on sparc platforms */
 	register unsigned char *p   = ROUND_BEG_PTR (ptr);
-	register unsigned char *end = ROUND_END_PTR (p + size);
+	register unsigned char *end = ROUND_END_PTR (ptr, size);
 	__asm__ __volatile__ ("stbar");
 	while (p < end)
 	{
@@ -221,13 +322,29 @@
 #elif (defined(__ia64) || defined(__ia64__)) && defined(linux)
 #define CLSIZE 32
 	register unsigned char *p   = ROUND_BEG_PTR (ptr);
-	register unsigned char *end = ROUND_END_PTR (p + size);
+	register unsigned char *end = ROUND_END_PTR (ptr, size);
 	while(p < end)
 	{
 		asm volatile("fc %0" :: "r"(p));
 		p += CLSIZE;
 	}
 	asm volatile(";;sync.i;;srlz.i;;");
+#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
+#define CLSIZE _x86_clflush_line_size
+	if (_x86_clflush_line_size > 0)
+	{
+		register unsigned char *p   = ROUND_BEG_PTR (ptr);
+		register unsigned char *end = ROUND_END_PTR (ptr, size);
+		while (p < end)
+		{
+				asm volatile ("\tmov %0,%%eax\n"
+							  "\tclflush (%%eax)\n"
+							  : /* not outputs */
+							  : "g" (p)
+							  : "eax");
+				p += CLSIZE;
+		}
+	}
 #endif
 #endif	/* __GNUC__ */
 }
--- libjit-org/jit/jit-alloc.h	1970-01-01 01:00:00.000000000 +0100
+++ libjit/jit/jit-alloc.h	2004-06-07 22:31:17.000000000 +0200
@@ -0,0 +1,40 @@
+/*
+ * jit-alloc.h - Internal interface for memory allocation
+ *
+ * Copyright (C) 2004  Miroslaw Dobrzanski-Neumann
+ *
+ * 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
+ */
+
+
+#ifndef	_JIT_ALLOC_H
+#define _JIT_ALLOC_H
+
+#ifdef	__cplusplus
+extern	"C" {
+#endif
+
+
+/*
+ * Does onetime initializatiuon of the allocation unit
+ */
+void _jit_alloc_init (void);
+
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif
