[Mono-devel-list] cmove patch

dietmar dietmar at ximian.com
Wed Jun 18 04:00:44 EDT 2003


Here is a first prototype of a cmove implementation. cmove needs a
register as destination (on x86 and afaik all other architectures).
Unfortunately there are very few registers on x86, so that case is
relatively seldom on x86:

stmt: OP_CMOV_EQ (OP_GROUP (OP_REGVAR, reg), cflags)

a common case is where the destination is a local variable:

stmt: OP_CMOV_EQ (OP_GROUP (base, reg), cflags)

We need to translate that into (see OP_CMOV_MEMBASE_EQ):

tmp = load (base)
tmp = cmove (reg)
store (base, tmp)

What I meassured so far this is slower than the original conditional
branch, so I guess we should not impl. that. Paolo pointed out that
there is no need for the load if we have code like:

if (cond) a = x; else a = y;

which could be translated into 2 conditional movex

cmove (cond, a, x)
cmove (!cond, a, y)

but x and y can be expression, so they can set the EFALGS. Sure, we can
avoid that if we first compute them, but IMO thats a bit clumsy.

any better ideas, suggestion?

I also attached 2 examples:

t.cs: you can meassure a speedup here (OP_CMOV_EQ)
t2.cs: you can see the slowdown caused by OP_CMOV_MEMBASE_EQ

- Dietmar


-------------- next part --------------
A non-text attachment was scrubbed...
Name: mono.diff
Type: text/x-patch
Size: 7343 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20030618/f9a710a5/attachment.bin 
-------------- next part --------------
using System;

public class Test
{
	public static int Main()
	{
		int a = 1;

		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 50000000; j++) {
		
				if (a == 1)
					a = 3;
				if (a == 5)
					a = 4;
				if (a == 6)
					a = 5;
				if (a == 7)
					a = 6;
			}
		}
		
		if (a != 3)
			return 1;

		return 0;
	}
}
-------------- next part --------------
using System;

public class Test
{
	public static int Main()
	{
		int b = 2;
		
		int a = 1;

		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 50000000; j++) {
		
				if (b == 2)
					a = 3;
				if (b == 5)
					a = 4;
				if (b == 6)
					a = 5;
				if (b == 7)
					a = 6;
			}
		}

		a += b;
		
		if (a != 5)
			return 1;

		return 0;
	}
}


More information about the Mono-devel-list mailing list