a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

intrinsics.h (1004B)


      1 // NOTE: __has_builtin is a clang-specific macro
      2 #ifndef __has_builtin
      3 #define __has_builtin(x) 0
      4 #endif
      5 
      6 static_assert(__has_builtin(__builtin_clz), "No builtin clz intrinsic");
      7 #define intr_clz(x) __builtin_clz((x))
      8 
      9 internal i32 intr_mod(i32 x, i32 y)
     10 {
     11     // NOTE(amin): There are multiple valid definitions of an operation that
     12     // gets the remainder of an integer division: `x / y`. Such an operation
     13     // must satisfy this equation:
     14     //
     15     //     x == (quotient * y) + remainder
     16     //
     17     // The value computed for `remainder` will differ (when x or y is negative)
     18     // based on the method of computing `quotient`.
     19     //
     20     // C's `%` operator is based on truncated integer division. This operation
     21     // is often called 'rem' in other languages.
     22     //
     23     // Python's `%` operator is based on floored integer division. This
     24     // operation is often called 'mod' in other languages.
     25     //
     26     // Here we implement 'mod'.
     27     i32 result = ((x % y) + y) % y;
     28     return result;
     29 }