medfall

A super great game engine
Log | Files | Refs

platform_alignment.h (525B)


      1 #pragma once
      2 
      3 #include "platform.h"
      4 
      5 #if COMPILER_MSVC
      6 #define ALIGNOF( x ) __alignof( x )
      7 #define ALIGNTO( n ) __declspec( align( n ) )
      8 #elif COMPILER_GCCORCLANG
      9 #define ALIGNOF( x ) __alignof__( x )
     10 #define ALIGNTO( n ) __attribute__(( aligned( n ) ))
     11 #else
     12 #error new compiler
     13 #endif
     14 
     15 #define CACHE_LINE_SIZE 64
     16 #define ALIGNTO_CACHE ALIGNTO( CACHE_LINE_SIZE )
     17 #define ALIGNTO_SSE ALIGNTO( 16 )
     18 
     19 template< typename T >
     20 inline bool is_aligned( const T * ptr ) {
     21 	return checked_cast< size_t >( ptr ) % ALIGNOF( T ) == 0;
     22 }