Handmade Hero»Forums»Code
Jez
3 posts
Day 116: Changes for LLVM
Hi Casey,

Would it be possible to get you to make a couple of updates to your codebase for those of us using non-microsoft compilers? (LLVM for me)

In "handmade_platform.h":

1) #include <x86intrin.h>
2) #define END_TIMED_BLOCK_COUNTED(ID, Count)

It's nice to be able to drop in your code with my platform layer and compile straight off the bat.

Thanks, Jez
Mārtiņš Možeiko
2562 posts / 2 projects
Day 116: Changes for LLVM
Edited by Mārtiņš Možeiko on
I would prefer that BEGIN_TIMED_BLOCK, END_TIMED_BLOCK and END_TIMED_BLOCK_COUNTED macros would be compiler independent. Only compiler dependent macro should be "#define GET_CYCLE_COUNTER_VALUE __rdtsc".

And not very related to LLVM, but to latest changes - for those counter macros, change "#if _MSC_VER" to "#if COMPILER_MSVC" in handmade_platform.h. Otherwise, what's the point of COMPILER_MSVC define.
Matt Mascarenhas
135 posts / 1 project
Annotator, supper gatherer and slammer of thunderous high fives
Day 116: Changes for LLVM
Thank you for this thread, Jez! Perhaps the #include line was too obvious for the internet to mention. It had this beginner stumped, at least.

And mmozeiko, not sure how I should feel about making the macros compiler independent, so I've simply put Jez's lines in an #if COMPILER_LLVM.

Suppose I'd better actually figure out how to flip the Y-axis in xcb_handmade.cpp at some point, incidentally…
Mārtiņš Možeiko
2562 posts / 2 projects
Day 116: Changes for LLVM
Edited by Mārtiņš Možeiko on
You would do it like this:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#if COMPILER_MSVC
#define GET_CYCLE_COUNT __rdtsc
#elif COMPILER_LLVM
#define GET_CYCLE_COUNT __builtin_readcyclecounter
#else
#error How to get cycles?
#endif

#define BEGIN_TIMED_BLOCK(ID) uint64 StartCycleCount##ID = GET_CYCLE_COUNT();
#define END_TIMED_BLOCK(ID) DebugGlobalMemory->Counters[DebugCycleCounter_##ID].CycleCount += GET_CYCLE_COUNT() - StartCycleCount##ID; ++DebugGlobalMemory->Counters[DebugCycleCounter_##ID].HitCount;
#define END_TIMED_BLOCK_COUNTED(ID, Count) DebugGlobalMemory->Counters[DebugCycleCounter_##ID].CycleCount += GET_CYCLE_COUNT() - StartCycleCount##ID; DebugGlobalMemory->Counters[DebugCycleCounter_##ID].HitCount += (Count);


This way there's no need to repeat BEGIN_TIMED_BLOCK/END_TIMED_BLOCK macros for each compiler. It would be much better, because when Casey would modify it, they would be automatically up to date for all compilers/platforms.
Kim
Kim Jørgensen
64 posts
Day 116: Changes for LLVM
+1 for the #include <x86intrin.h> and support for BEGIN_TIMED_BLOCK on other compilers. It would be nice if GCC was supported too.

Is it necessary to discriminate between compilers regarding to intrinsics on the x86 platform? It seems that MSVC, LLVM and GCC all support the format defined by Intel including the __rdtsc operation.

@Miblo: Regarding flipping the Y-axis; I am using the SDL port and had the same problem. After getting annoyed by the slowdown of flipping the Y-axis in the platform layer, I realized that you can ask the game to do it for you. Just advance the memory pointer and negate the pitch:

1
2
3
game_offscreen_buffer Buffer = {};
Buffer.Memory = ((uint8*)GlobalBackbuffer.Memory) + (GlobalBackbuffer.Width * (GlobalBackbuffer.Height-1) * GlobalBackbuffer.BytesPerPixel);
Buffer.Pitch = -GlobalBackbuffer.Pitch;


It works for now, but not sure if Casey will keep this “feature” in the game layer.
Nuno
18 posts
Day 116: Changes for LLVM
+1 for these changes.

I've been using the command line version of Jeff's OSX Port and that's all I need as well:

Here the patch :)

http://pastebin.com/uiHBp0ty
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
Day 116: Changes for LLVM
Roger that guys - I'll try to remember this for Saturday's stream.

- Casey
Nuno
18 posts
Day 116: Changes for LLVM
Thank you :)