On 7/9/17, Bob Friesenhahn <bfrie...@simple.dallas.tx.us> wrote: > On Sat, 8 Jul 2017, Richard Hipp wrote: >> >> gcc-5.4: 491585 bytes, 1,124 million CPU cycles. >> icc-17.0: 536596 bytes, 1,274 million CPU cycles > > Sqlite3 has been cycle-optimized for GCC. You now have 29-days to > also cycle-optimize it for ICC.
I've spent some time investigating this, and I think the answer is that GCC simply generates better code. Here is one simple example. The source code at https://www.sqlite.org/src/artifact/a7ca64?ln=58-60 shows a function that takes two parameters. If the second parameter is not NULL, then invoke another function, otherwise return WRC_Continue (which happens to be zero). ICC generates the following code for that function: sqlite3WalkExpr: pushq %rsi testq %rsi, %rsi je ..B1210.4 call walkExpr jmp ..B1210.5 ..B1210.4: xorl %eax, %eax ..B1210.5: popq %rci ret GCC uses tail recursion on the walkExpr() call, which is faster, since "jmp" does not have to push the return address onto the stack and is thus faster than "call". GCC also avoids saving the second parameter on the stack (which is pointless - why does ICC even do that?) and thereby avoids a push and a pop. The GCC code is as follows: sqlite3WalkExpr: testq %rsi, %rsi je .L2706 jmp walkExpr .L2706: xorl %eax, %eax ret Thus the GCC implementation is both smaller and about twice as fast as the ICC implementation. I don't know of anything I can do at the source-code level to help ICC generate better code here. The above is just one example. I looked at many others. As far as I can see, GCC is simply a better compiler than ICC when targeting x64. The assembly code examples above were generated using -Os optimization. The performance results are similar (GCC is faster than ICC) when I use -O3, but there is a lot more code movement and so the examples are more difficult to follow. -- D. Richard Hipp d...@sqlite.org _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users