Skip to content
This repository has been archived by the owner on Nov 4, 2019. It is now read-only.

Commit

Permalink
eval: faster fwd and bck w/ wraparound (thanks @lamarqua)
Browse files Browse the repository at this point in the history
  • Loading branch information
hellerve committed Nov 18, 2018
1 parent fb8b051 commit a865aa2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/eval.c
Expand Up @@ -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();
Expand Down

0 comments on commit a865aa2

Please sign in to comment.