From ae95995747a521fe861a3644ff977f96a7427cd9 Mon Sep 17 00:00:00 2001 From: Neo_Chen Date: Wed, 2 Dec 2020 15:13:38 +0800 Subject: [PATCH] avoid branch --- libbrainfunk.c | 3 +-- libstdbfc.h | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/libbrainfunk.c b/libbrainfunk.c index 9672054..ae695e6 100644 --- a/libbrainfunk.c +++ b/libbrainfunk.c @@ -162,8 +162,7 @@ EXEC(a) EXEC(mul) { /* *(Current + offset) += Current * mul */ - if(cpu->mem[cpu->ptr] != 0) - cpu->mem[(cpu->ptr + cpu->code[cpu->pc].arg.dual.offset) % cpu->size.mem] += cpu->mem[cpu->ptr] * cpu->code[cpu->pc].arg.dual.mul; + cpu->mem[(cpu->ptr + cpu->code[cpu->pc].arg.dual.offset) % cpu->size.mem] += cpu->mem[cpu->ptr] * cpu->code[cpu->pc].arg.dual.mul; cpu->pc++; return _CONT; } diff --git a/libstdbfc.h b/libstdbfc.h index 087712a..099f6b2 100644 --- a/libstdbfc.h +++ b/libstdbfc.h @@ -45,7 +45,7 @@ pid_t p=0; typedef uint8_t memory_t; memory_t *memory; -int ptr=0; +unsigned int ptr=0; #define current (memory[ptr]) @@ -61,7 +61,7 @@ void panic(char *msg) #define a(x) \ current += x #define mul(mul, offset) \ - if(memory[ptr]) memory[ptr + offset] += current * mul + memory[(ptr + offset) % MEMSIZE] += current * mul #define s(x) \ current = x #define f(x) \