[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-libjit] Problems with load and store on x86_64
From: |
Jan Wedekind |
Subject: |
[Dotgnu-libjit] Problems with load and store on x86_64 |
Date: |
Fri, 3 Oct 2008 21:38:43 +0100 (BST) |
Hi,
I am trying to use libjit for doing element-wise operations on arrays.
The program below fills an array with values 0, 1, 2, ... and then
adds 1 to it using libjit (i.e. the result should be 1, 2, 3, ...).
Under x86 it works so far. However on x86_64 it does not work for
combinations of 8-bit or 16-bit numbers with floating point numbers
(it returns large floating point numbers). I don't have any idea why
it doesn't work. Can anybody help?
Thanks in advance!
-------------------
// g++ -DNDEBUG -o jittest jittest.cc -ljit
#include <boost/shared_array.hpp>
#include <iostream>
#include <jit/jit.h>
#include <sys/time.h>
#define JIT
#define JITTYPE jit_float64
#define JITTYPET jit_type_float64
#define JITTYPE2 jit_sbyte
#define JITTYPET2 jit_type_sbyte
// #define JITTYPE jit_float32
// #define JITTYPET jit_type_float32
// #define JITTYPE2 jit_float32
// #define JITTYPET2 jit_type_float32
// #define JITTYPE jit_float32
// #define JITTYPET jit_type_float32
// #define JITTYPE2 jit_short
// #define JITTYPET2 jit_type_short
// #define JITTYPE jit_float64
// #define JITTYPET jit_type_float64
// #define JITTYPE2 jit_int
// #define JITTYPET2 jit_type_int
// #define JITTYPE jit_float32
// #define JITTYPET jit_type_float32
// #define JITTYPE2 jit_float64
// #define JITTYPET2 jit_type_float64
// #define JITTYPE jit_int
// #define JITTYPET jit_type_int
// #define JITTYPE2 jit_short
// #define JITTYPET2 jit_type_short
// #define JITTYPE jit_ubyte
// #define JITTYPET jit_type_ubyte
// #define JITTYPE2 jit_sbyte
// #define JITTYPET2 jit_type_sbyte
// AMD Athlon 64bit
// INT:
// G++: 0.00346661 s
// JIT: 0.00344854 s
// SHORT:
// G++: 0.00184178 s
// JIT: 0.00267739 s
// UBYTE:
// G++: 0.00154156 s
// JIT: 0.00222944 s
// http://lists.gnu.org/archive/html/dotgnu-libjit/2008-08/msg00004.html
#define SIZE 1000
#define PRINT 20
#define COUNT 1
#ifndef timersub
# define timersub(a, b, result) \
do { \
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
if ((result)->tv_usec < 0) { \
--(result)->tv_sec; \
(result)->tv_usec += 1000000; \
} \
} while (0)
#endif
using namespace std;
int main(void)
{
jit_context_t context = jit_context_create();
assert( context != NULL );
boost::shared_array< JITTYPE > arr( new JITTYPE[ SIZE ] );
for ( int i=0; i<SIZE; i++ )
arr[i] = i;
#ifdef JIT
jit_context_build_start( context );
jit_type_t params[3];
params[0] = jit_type_void_ptr;
params[1] = JITTYPET2;
params[2] = jit_type_void_ptr;
jit_type_t signature =
jit_type_create_signature( jit_abi_cdecl, jit_type_void_ptr,
params, 3, 1 );
jit_function_t function = jit_function_create( context, signature );
// jit_function_set_recompilable( function );
jit_value_t p, px, one, end, eq;
jit_label_t start = jit_label_undefined;
p = jit_value_get_param( function, 0 );
one = jit_value_get_param( function, 1 );
end = jit_value_get_param( function, 2 );
jit_insn_label( function, &start );
jit_value_t temp1 = jit_insn_load_relative( function, p, 0, JITTYPET );
jit_value_t temp2 = jit_insn_add( function, temp1, one );
jit_value_t temp3 = jit_insn_convert( function, temp2, JITTYPET, 0 );
jit_insn_store_relative( function, p, 0, temp3 );
jit_value_t temp4 = jit_insn_add_relative( function, p, sizeof(JITTYPE) );
jit_insn_store( function, p, temp4 );
eq = jit_insn_lt( function, p, end );
jit_insn_branch_if( function, eq, &start );
jit_insn_return( function, p );
jit_function_compile( function );
jit_context_build_end( context );
#endif
struct timeval time;
gettimeofday( &time, NULL );
#ifdef JIT
for ( int i=0; i<COUNT; i++ ) {
void *args[3];
jit_ptr arg1 = arr.get();
JITTYPE2 arg2 = 1;
jit_ptr arg3 = arr.get() + SIZE;
jit_ptr result;
args[0] = &arg1;
args[1] = &arg2;
args[2] = &arg3;
jit_function_apply( function, args, &result );
};
#else
for ( int i=0; i<COUNT; i++ ) {
JITTYPE *p = arr.get();
JITTYPE *end = arr.get() + SIZE;
for ( ; p != end; p++ )
*p += 1;
};
#endif
struct timeval time2;
gettimeofday( &time2, NULL );
struct timeval difference;
timersub( &time2, &time, &difference );
cout << ( ( difference.tv_sec + difference.tv_usec * 1.0E-6 ) / COUNT )
<< " s" << endl;
cout << "[ " << (int)arr[0];
for ( int i=1; i<PRINT; i++ )
cout << ", " << (int)arr[i];
cout << " ]" << endl;
jit_context_destroy( context );
return 0;
}
- [Dotgnu-libjit] Problems with load and store on x86_64,
Jan Wedekind <=