From 4f61d922907e98ac5601493cf00ed5f939709f7f Mon Sep 17 00:00:00 2001 From: Lu Date: Fri, 24 May 2024 15:52:40 +0800 Subject: [PATCH] use zf_int instead int in bitops word code --- src/atmega8/zfconf.h | 3 +++ src/linux/zfconf.h | 3 +++ src/zforth/zforth.c | 10 +++++----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/atmega8/zfconf.h b/src/atmega8/zfconf.h index 605c990..33e105d 100644 --- a/src/atmega8/zfconf.h +++ b/src/atmega8/zfconf.h @@ -40,6 +40,9 @@ typedef int32_t zf_cell; #define ZF_CELL_FMT "%ld" #define ZF_SCAN_FMT "%ld" +/* zf_int use for bitops, some arch int type width is less than register width, + it will cause sign fill, so we need manual specify it */ +typedef int zf_int; /* The type to use for pointers and adresses. 'unsigned int' is usually a good * choice for best performance and smallest code size */ diff --git a/src/linux/zfconf.h b/src/linux/zfconf.h index 4a06fc0..6b7f1ea 100644 --- a/src/linux/zfconf.h +++ b/src/linux/zfconf.h @@ -40,6 +40,9 @@ typedef float zf_cell; #define ZF_CELL_FMT "%.14g" #define ZF_SCAN_FMT "%f" +/* zf_int use for bitops, some arch int type width is less than register width, + it will cause sign fill, so we need manual specify it */ +typedef int zf_int; /* The type to use for pointers and adresses. 'unsigned int' is usually a good * choice for best performance and smallest code size */ diff --git a/src/zforth/zforth.c b/src/zforth/zforth.c index 42e2b20..32456d6 100644 --- a/src/zforth/zforth.c +++ b/src/zforth/zforth.c @@ -727,25 +727,25 @@ static void do_prim(zf_prim op, const char *input) break; case PRIM_AND: - zf_push((int)zf_pop() & (int)zf_pop()); + zf_push((zf_int)zf_pop() & (zf_int)zf_pop()); break; case PRIM_OR: - zf_push((int)zf_pop() | (int)zf_pop()); + zf_push((zf_int)zf_pop() | (zf_int)zf_pop()); break; case PRIM_XOR: - zf_push((int)zf_pop() ^ (int)zf_pop()); + zf_push((zf_int)zf_pop() ^ (zf_int)zf_pop()); break; case PRIM_SHL: d1 = zf_pop(); - zf_push((int)zf_pop() << (int)d1); + zf_push((zf_int)zf_pop() << (zf_int)d1); break; case PRIM_SHR: d1 = zf_pop(); - zf_push((int)zf_pop() >> (int)d1); + zf_push((zf_int)zf_pop() >> (zf_int)d1); break; default: