Permalink
Browse files

eval: faster fwd and bck w/ wraparound (thanks @lamarqua)

  • Loading branch information...
hellerve committed Nov 18, 2018
1 parent fb8b051 commit a865aa2f63a3e0db18e5d16a8d414528742490a5
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/eval.c
@@ -43,8 +43,10 @@ do_dec: t[h]--; DISPATCH();
do_fwd: h++; DISPATCH();
do_bck: h--; DISPATCH();
#else
do_fwd: h = h+1 % TAPE_LEN; DISPATCH();
do_bck: h = h-1 % TAPE_LEN; DISPATCH();
// modulo would be prettier here, but slows the code down by A LOT; somehow
// the C compilers can’t optimize uncoditional modulos here
do_fwd: h = h > TAPE_LEN-1 ? 0 : h+1; DISPATCH();
do_bck: h = h == 0 ? TAPE_LEN-1 : h-1; DISPATCH();
#endif
do_prn: printf("%c", t[h]); DISPATCH();
do_read: scanf("%c", (char*)&t[h]); DISPATCH();

0 comments on commit a865aa2

Please sign in to comment.