Why does JIT order affect performance?

Please note that I do not trust the “Suppress JIT optimization on module load” option, I spawn the process without debugging and attach my debugger after the JIT has run. In the version where single-line runs faster, this is Main: SingleLineTest(); 00000000 push ebp 00000001 mov ebp,esp 00000003 call dword ptr ds:[0019380Ch] MultiLineTest(); 00000009 call … Read more

Representing an Abstract Syntax Tree in C

You can make any of these work. I prefer the union layout, because then all nodes have “the same” layout. [You may find it useful to have a “child sublist” option, e.g., and arbitarily big, dynamic array of children, instead of having left- or right-leaning lists.] You are going to find that this issue isn’t … Read more

Which contemporary computer languages are LL(1)?

I think I’d be tempted to flag that Wikipedia quote with [citation needed]; the assumptions are, at least, questionable. For example, there are a large number of compiler-construction tools based on yacc which make it extremely easy, in practice, to construct a parser using the more powerful (and equally fast) LALR algorithm, and some also … Read more

Wanted: good definition of the term “lowering” in the context of compilers

Dr. Dobbs just published an article by Walter Bright (of dlang fame), where he mentions the term: Lowering One semantic technique that is obvious in hindsight (but took Andrei Alexandrescu to point out to me) is called “lowering.” It consists of, internally, rewriting more complex semantic constructs in terms of simpler ones. For example, while … Read more

JIT compiler vs offline compilers

Yes, there certainly are such scenarios. JIT compilation can use runtime profiling to optimize specific cases based on measurement of the characteristics of what the code is actually doing at the moment, and can recompile “hot” code as necessary. That’s not theoretical; Java’s HotSpot actually does this. JITters can optimize for the specific CPU and … Read more

How to compile x64 code with Visual Studio in command line?

You need to use a version of the cl.exe compiler which emits x64 code. Which one depends a bit on your setup. Let’s consider the case you’re on a 64 bit machine. For this you’ll need to use the compiler which lives at c:\Program Files (x86)\Microsoft visual Studio 10.0\VC\bin\amd64\cl.exe If you’re on a 32 bit … Read more

Do modern compilers optimize the x * 2 operation to x

Actually VS2008 optimizes this to x+x: 01391000 push ecx int x = 0; scanf(“%d”, &x); 01391001 lea eax,[esp] 01391004 push eax 01391005 push offset string “%d” (13920F4h) 0139100A mov dword ptr [esp+8],0 01391012 call dword ptr [__imp__scanf (13920A4h)] int y = x * 2; 01391018 mov ecx,dword ptr [esp+8] 0139101C lea edx,[ecx+ecx] In an x64 … Read more

Are constant C expressions evaluated at compile time or at runtime?

Macros are simply textual substitution, so in your example writing TIMER_100_MS in a program is a fancy way of writing 32768 / 10. Therefore, the question is when the compiler would evaluate 32768 / 10, which is a constant integral expression. I don’t think the standard requires any particular behavior here (since run-time and compile-time … Read more