shithub: orca

Download patch

ref: c577a4a25fbb4f4db4305adbc4ca89b340bb510e
parent: 3d3e8e3fb1421a28ce590ea4af1c408de463a45e
author: cancel <cancel@cancel.fm>
date: Sat Dec 1 08:55:23 EST 2018

Shorten definition of oper_has_neighboring bang, cleanup base macros

--- 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
 
--- a/sim.c
+++ b/sim.c
@@ -70,18 +70,21 @@
   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) {