<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
</style>
</head>
<body class='hmmessage'>
<meta http-equiv="Content-Type" content="text/html; charset=unicode">
<meta name="Generator" content="Microsoft SafeHTML">
<style>
.hmmessage P
{margin:0px;padding:0px;}
body.hmmessage
{font-size:10pt;font-family:Verdana;}
</style>
I was playing around in x86 assembly the other day, looking at ways to optimize my cooperative multitasking system. Currently, it uses a 'timeout' counter that is decremented each time through a loop, letting me stop the loop and go to the next cooperative thread if the loop runs a little long.<br><br>The asm has two overlapping loops:<br><br>---<br>_main:<br> mov ecx, 1000000000<br>timeoutloop:<br> mov edx, 2000<br>loopto:<br> dec edx<br> jz timeoutloop<br> dec ecx<br> jnz loopto<br> mov eax, 0<br> ret<br>---<br><br>Which takes 1.0s on my machine.<br><br>To compare, I wanted to see what LLVM performance was like and if a similar technique would yield good performance. I cooked up this test in C:<br><br>---<br>#include <stdio.h><br><br>int main() {<br> int loop = 1000000000;<br> int timeout;<br><br>timeoutloop:<br> timeout = 2000;<br>loopto:<br> if (--timeout == 0) goto timeoutloop;<br> if (--loop != 0) goto loopto;<br><br> printf("Timeout: %i\n", timeout);<br><br> return 0;<br>}<br>---<br><br>With gcc -O3 4.2 and 4.4 we match 1.0s. The LLVM, after running it through opt -std-compile-opts, is around 1.7s. <br><br>Should I be looking at any particular optimization passes that aren't in -std-compile-opts to match the gcc speeds?<br><br>Thanks,<br><br>Jonathan<br><br /><hr />Windows Live™ Groups: Create an online spot for your favorite groups to meet. <a href='http://windowslive.com/online/groups?ocid=TXT_TAGLM_WL_groups_032009' target='_new'>Check it out.</a></body>
</html>