From c577a4a25fbb4f4db4305adbc4ca89b340bb510e Mon Sep 17 00:00:00 2001 From: cancel Date: Sat, 1 Dec 2018 13:55:23 +0900 Subject: [PATCH] Shorten definition of oper_has_neighboring bang, cleanup base macros --- base.h | 18 ++++++------------ sim.c | 23 +++++++++++++---------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/base.h b/base.h index 2eced19..42725e0 100644 --- a/base.h +++ b/base.h @@ -11,32 +11,26 @@ #if defined(__GNUC__) || defined(__clang__) #define ORCA_FORCE_INLINE __attribute__((always_inline)) inline #define ORCA_FORCE_STATIC_INLINE __attribute__((always_inline)) static inline +#define ORCA_FORCE_NO_INLINE __attribute__((noinline)) #elif defined(_MSC_VER) #define ORCA_FORCE_INLINE __forceinline #define ORCA_FORCE_STATIC_INLINE __forceinline static +#define ORCA_FORCE_NO_INLINE __declspec(noinline) #else #define ORCA_FORCE_INLINE inline #define ORCA_FORCE_STATIC_INLINE inline static -#endif - -#if defined(__GNUC__) || defined(__clang__) -#define ORCA_FORCE_NO_INLINE __attribute__((noinline)) -#elif defined(_MSC_VER) -#define ORCA_FORCE_NO_INLINE __declspec(noinline) -#else #define ORCA_FORCE_NO_INLINE #endif + #if defined(__GNUC__) || defined(__clang__) #define ORCA_ASSUME_ALIGNED(_ptr, _alignment) \ __builtin_assume_aligned(_ptr, _alignment) -#else -#define ORCA_ASSUME_ALIGNED(_ptr, _alignment) (_ptr) -#endif - -#if defined(__GNUC__) || defined(__clang__) +#define ORCA_PURE __attribute__((pure)) #define ORCA_LIKELY(_x) __builtin_expect(_x, 1) #else +#define ORCA_ASSUME_ALIGNED(_ptr, _alignment) (_ptr) +#define ORCA_PURE #define ORCA_LIKELY(_x) (_x) #endif diff --git a/sim.c b/sim.c index 109f438..993c9b5 100644 --- a/sim.c +++ b/sim.c @@ -70,18 +70,21 @@ static Glyph glyphs_mod(Glyph a, Glyph b) { return indexed_glyphs[ib == 0 ? 0 : (ia % ib)]; } -// todo check if these inlines are actually being inlinded -- might be bad, -// should probably mark them not inlined - -static bool oper_has_neighboring_bang(Gbuffer gbuf, Usz h, Usz w, Usz y, - Usz x) { - return gbuffer_peek_relative(gbuf, h, w, y, x, 0, 1) == '*' || - gbuffer_peek_relative(gbuf, h, w, y, x, 0, -1) == '*' || - gbuffer_peek_relative(gbuf, h, w, y, x, 1, 0) == '*' || - gbuffer_peek_relative(gbuf, h, w, y, x, -1, 0) == '*'; +ORCA_PURE static bool oper_has_neighboring_bang(Glyph const* gbuf, Usz h, Usz w, + Usz y, Usz x) { + Glyph const* gp = gbuf + w * y + x; + if (x < w && gp[1] == '*') + return true; + if (x > 0 && gp[-1] == '*') + return true; + if (y < h && gp[w] == '*') + return true; + if (y > 0 && gp[-w] == '*') + return true; + return false; } -static ORCA_FORCE_NO_INLINE void +ORCA_FORCE_NO_INLINE static void oper_move_relative_or_explode(Gbuffer gbuf, Mbuffer mbuf, Usz height, Usz width, Glyph moved, Usz y, Usz x, Isz delta_y, Isz delta_x) {