ref: 3d3e8e3fb1421a28ce590ea4af1c408de463a45e
parent: 30b7652c585aed25faa05f2e0b59dd9f9dca2c38
author: cancel <cancel@cancel.fm>
date: Sat Dec 1 07:35:43 EST 2018
Add specialized version of index_of No loop over array, but requires manual work to keep updated.
--- a/sim.c
+++ b/sim.c
@@ -12,14 +12,14 @@
enum { Glyphs_array_num = sizeof indexed_glyphs };
-static inline Glyph glyph_lowered(Glyph c) {
- return (c >= 'A' && c <= 'Z') ? (char)(c - ('a' - 'A')) : c;
-}
-
// Always returns 0 through (sizeof indexed_glyphs) - 1, and works on
// capitalized glyphs as well. The index of the lower-cased glyph is returned
// if the glyph is capitalized.
-static ORCA_FORCE_NO_INLINE Usz index_of(Glyph c) {
+#if 0
+static inline Glyph glyph_lowered(Glyph c) {
+ return (c >= 'A' && c <= 'Z') ? (char)(c - ('a' - 'A')) : c;
+}
+static ORCA_FORCE_NO_INLINE Usz index_of__reference(Glyph c) {
Glyph c0 = glyph_lowered(c);
if (c0 == '.')
return 0;
@@ -29,19 +29,42 @@
}
return 0;
}
+#endif
+static Usz index_of(Glyph c) {
+ if (c == '.')
+ return 0;
+ if (c >= '0' && c <= '9')
+ return (Usz)(c - '0');
+ if (c >= 'A' && c <= 'Z')
+ return (Usz)(c - 'A' + 10);
+ if (c >= 'a' && c <= 'z')
+ return (Usz)(c - 'a' + 10);
+ switch (c) {
+ case '*':
+ return 37;
+ case ':':
+ return 38;
+ case ';':
+ return 49;
+ case '#':
+ return 40;
+ }
+ return 0;
+}
+
static inline Glyph glyph_of(Usz index) {
assert(index < Glyphs_array_num);
return indexed_glyphs[index];
}
-static inline Glyph glyphs_add(Glyph a, Glyph b) {
+static Glyph glyphs_add(Glyph a, Glyph b) {
Usz ia = index_of(a);
Usz ib = index_of(b);
return indexed_glyphs[(ia + ib) % Glyphs_array_num];
}
-static inline Glyph glyphs_mod(Glyph a, Glyph b) {
+static Glyph glyphs_mod(Glyph a, Glyph b) {
Usz ia = index_of(a);
Usz ib = index_of(b);
return indexed_glyphs[ib == 0 ? 0 : (ia % ib)];