Hello,

I created some basic vala bindings for orc. I've also attached a small
sample, on how to use those bindings. 
Maybe they can be included in orc and managed there. The bindings are
not yet 'stable' as some functions are missing.

Maybe they are of use to someone :)

Shall we include them in orc?

Greetings
- fabian
/*
 * valac --verbose --pkg orc-0.4 --vapidir=vapi/ --save-temps --Xcc=-O3 test3.vala
 */

using Orc;

const int N = 20000;

int16[] a;
int16[] b;
int16[] c;

void main(string[] args)
{
	Orc.init();

	a = new int16[ N ];
	b = new int16[ N ];
	c = new int16[ N ];

	for( int16 i = 0 ; i < N ; i++ )
	{
		a[i] = i+1;
		b[i] = 100;
	}

	Timer t = new Timer();
	t.start();
	for( int i = N ; i > 0 ; i-- )
	{
		add_inter(c,a,b);
	}
	debug("Without orc: %.4f", t.elapsed() );

	t.start();
	for( int i = N ; i > 0 ; i-- )
	{
		add_s16(c, a, b);
	}
	debug("With orc: %.4f", t.elapsed() );
}

Program p;
Executor e;
inline void add_s16(int16[] dst, int16[] src1, int16[] src2)
{
	if( p == null )
	{
		Debug.set_level(DebugLevel.INFO);
		p = new Program.dss(2,2,2);
		p.add_temporary(2, "t1");

		p.append_str("addw", "t1", "s1", "s2");
		p.append_str("mullw", "d1", "t1", "s2");

		CompileResult r = p.compile();
		assert( r == CompileResult.OK );
		
		e = new Executor(p);
		e.set_program(p);
	}
	
	e.set_n( dst.length );
	e.set_array_str("s1", src1);
	e.set_array_str("s2", src2);
	e.set_array_str("d1", dst);

	e.run();
}

inline void add_inter(int16[] dst, int16[] src1, int16[] src2)
{
	for( int i = 0 ; i < dst.length ; i++ )
	{
		dst[i] = (src1[i] + src2[i]) * src2[i];
	}
}
[CCode (lower_case_cprefix = "orc_", cheader_filename = "orc/orc.h")]
namespace Orc
{
/*	[Compact]
	[SimpleType]
	[CCode (cname = "uuid_t")]
	public struct UUID {
		[CCode (cname="uuid_generate_random", instance_pos = 0)]
		public UUID.generate_random();
		public void unparse(out string str);
	}*/
	
	[CCode (cname = "orc_init")]
	public void init();
	
	[CCode (cname = "OrcProgram", unref_function = "orc_program_free")]
	public class Program
	{
		[CCode (cname = "orc_program_new")]
		public Program();
		public Program.dss(int size1, int size2, int size3);
		
		public unowned string get_name();
		
		public void add_temporary(int size, owned string name);
		public void add_source(int size, owned string name);
		public void add_destination(int size, owned string name);
		public void add_constant(int size, owned string name);
		public void add_accumulator(int size, owned string name);
		public void add_parameter(int size, owned string name);
		
		public void append(string opcode, int arg0, int arg1, int arg2);
		public void append_str(string opcode, string arg0, string arg1, string arg2);
		public void append_ds(string opcode, int arg0, int arg1);
		public void append_ds_str(string opcode, string arg0, string arg1);
		
		public CompileResult compile();
		
		public string get_asm_code();
		public int find_var_by_name(string name);
		
		
		public void set_2d();
	}
	
	
	/* OrcCompiler */
	public class Compiler
	{
	}
	
	public enum CompileResult
	{
		OK = 0,
		UNKNOWN_COMPILE = 0x100,
		MISSING_RULE = 0x101,
		UNKNOWN_PARSE = 0x200,
		PARSE = 0x201,
		VARIABLE = 0x202;
		
		[CCode (cname = "ORC_COMPILE_RESULT_IS_SUCCESSFUL")]
		public bool is_successful();
		[CCode (cname = "ORC_COMPILE_RESULT_IS_FATAL")]
		public bool is_fatal();
	}
	
	/* OrcExecutor */
	[CCode (cname = "OrcExecutor", unref_function = "orc_executor_free")]
	public class Executor
	{
		[CCode (cname = "orc_executor_new")]
		public Executor(Program p);
		
		public void set_array(int _var, void* ptr);
		public void set_array_str(string _var, void* ptr);
		
		public void set_n(int n);
		
		public void emulate();
		public void run();
		
		public int get_accumulator(int n);
		public int get_accumulator_str(string name);
		public int set_param(int n, int val);
		public int set_param_str(string name, int val);
		
		public void set_program(Program p);
		
		public void set_2d();
		/* Width of a 2d-array */
		public void set_m(int n);
		public void set_stride(int _var, int stride);
	}
	
	[CCode (cprefix = "ORC_DEBUG_")]
	public enum DebugLevel
	{
		NONE = 0,
		ERROR,
		WARNING,
		INFO,
		DEBUG,
		LOG
	}
	
	namespace Debug
	{
		public void set_level(DebugLevel l);
	}
}

Attachment: smime.p7s
Description: S/MIME cryptographic signature

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

_______________________________________________
Schrodinger-devel mailing list
Schrodinger-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/schrodinger-devel

Reply via email to