From 9068de3b95edea91ab24fa9c38b52f6b4bdd823c Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Sat, 23 Nov 2024 22:06:18 +0100 Subject: [PATCH 01/13] opt: add peephole recipe for new normalized boolean The routine .code.__LEI16 already returns a normalized [0, 1] boolean. --- .../z80/peephole/opts/000_o1_lei16_bool.opt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/arch/z80/peephole/opts/000_o1_lei16_bool.opt diff --git a/src/arch/z80/peephole/opts/000_o1_lei16_bool.opt b/src/arch/z80/peephole/opts/000_o1_lei16_bool.opt new file mode 100644 index 000000000..d40127dfb --- /dev/null +++ b/src/arch/z80/peephole/opts/000_o1_lei16_bool.opt @@ -0,0 +1,20 @@ +;; core.LEI16 returns the bool result of Byte(a) <= Byte(b) +;; and is already normalized. The sequence +;; sub 1 +;; sbc a, a +;; inc a +;; can be removed + +OLEVEL: 1 +OFLAG: 14 + +REPLACE {{ + call .core.__LEI16 + sub 1 + sbc a, a + inc a +}} + +WITH {{ + call .core.__LEI16 +}} From 10f0bac6161c456e07b7f7b7b562e9de15b52b9b Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Sat, 23 Nov 2024 22:16:27 +0100 Subject: [PATCH 02/13] opt: improve norm bool sequence ;; The sequence: ;; sbc a, a ; A is either 0 or -1 ;; sub 1 ;; sbc a, a ;; inc a ;; can be replaced by ;; neg ; A is either 0 or 1 --- .../z80/peephole/opts/001_o1_norm_bool.opt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/arch/z80/peephole/opts/001_o1_norm_bool.opt diff --git a/src/arch/z80/peephole/opts/001_o1_norm_bool.opt b/src/arch/z80/peephole/opts/001_o1_norm_bool.opt new file mode 100644 index 000000000..346c69e1c --- /dev/null +++ b/src/arch/z80/peephole/opts/001_o1_norm_bool.opt @@ -0,0 +1,22 @@ +;; The sequence: +;; sbc a, a ; A is either 0 or -1 +;; sub 1 +;; sbc a, a +;; inc a +;; can be replaced by +;; neg ; A is either 0 or 1 + +OLEVEL: 1 +OFLAG: 15 + +REPLACE {{ + sbc a, a + sub 1 + sbc a, a + inc a +}} + +WITH {{ + sbc a, a + neg +}} From ebcc809a703e0a2f93ee94fae4b6c257ecd936b0 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Sat, 23 Nov 2024 22:31:56 +0100 Subject: [PATCH 03/13] opt: this recipe can also be applied for .core.GEF --- src/arch/z80/peephole/opts/000_o1_lei16_bool.opt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/arch/z80/peephole/opts/000_o1_lei16_bool.opt b/src/arch/z80/peephole/opts/000_o1_lei16_bool.opt index d40127dfb..2c3d20d84 100644 --- a/src/arch/z80/peephole/opts/000_o1_lei16_bool.opt +++ b/src/arch/z80/peephole/opts/000_o1_lei16_bool.opt @@ -1,4 +1,4 @@ -;; core.LEI16 returns the bool result of Byte(a) <= Byte(b) +;; core.LEI16 and .core.GEF return the bool result of Byte(a) <= Byte(b) ;; and is already normalized. The sequence ;; sub 1 ;; sbc a, a @@ -9,12 +9,14 @@ OLEVEL: 1 OFLAG: 14 REPLACE {{ - call .core.__LEI16 + $1 sub 1 sbc a, a inc a }} WITH {{ - call .core.__LEI16 + $1 }} + +IF {{ $1 == "call .core.GEF" || $1 == "call .core.LEI16"}} From 5777f144099c77c55ab14b39a46b6329e1e19bb9 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Sun, 24 Nov 2024 00:51:34 +0100 Subject: [PATCH 04/13] refact: no longer used. Dead code. --- src/lib/arch/zx48k/runtime/bool/and8.asm | 14 -------------- src/lib/arch/zxnext/runtime/bool/and8.asm | 14 -------------- 2 files changed, 28 deletions(-) delete mode 100644 src/lib/arch/zx48k/runtime/bool/and8.asm delete mode 100644 src/lib/arch/zxnext/runtime/bool/and8.asm diff --git a/src/lib/arch/zx48k/runtime/bool/and8.asm b/src/lib/arch/zx48k/runtime/bool/and8.asm deleted file mode 100644 index 1e6795eff..000000000 --- a/src/lib/arch/zx48k/runtime/bool/and8.asm +++ /dev/null @@ -1,14 +0,0 @@ -; FASTCALL boolean and 8 version. -; result in Accumulator (0 False, not 0 True) -; __FASTCALL__ version (operands: A, H) -; Performs 8bit and 8bit and returns the boolean - - push namespace core - -__AND8: - or a - ret z - ld a, h - ret - - pop namespace diff --git a/src/lib/arch/zxnext/runtime/bool/and8.asm b/src/lib/arch/zxnext/runtime/bool/and8.asm deleted file mode 100644 index 1e6795eff..000000000 --- a/src/lib/arch/zxnext/runtime/bool/and8.asm +++ /dev/null @@ -1,14 +0,0 @@ -; FASTCALL boolean and 8 version. -; result in Accumulator (0 False, not 0 True) -; __FASTCALL__ version (operands: A, H) -; Performs 8bit and 8bit and returns the boolean - - push namespace core - -__AND8: - or a - ret z - ld a, h - ret - - pop namespace From 545250f334e5bfffc57680cad729333b666a2373 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Sun, 24 Nov 2024 01:00:31 +0100 Subject: [PATCH 05/13] opt: this recipe can also be applied for others cmps concretely for core.__LEI8, core.__LTI8, core.__NOT32 Others like AND16 could be converted (saves memory, but reduces speed). In the future there would be a recipe for that. --- src/arch/z80/peephole/opts/000_o1_lei16_bool.opt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/arch/z80/peephole/opts/000_o1_lei16_bool.opt b/src/arch/z80/peephole/opts/000_o1_lei16_bool.opt index 2c3d20d84..3331f83f9 100644 --- a/src/arch/z80/peephole/opts/000_o1_lei16_bool.opt +++ b/src/arch/z80/peephole/opts/000_o1_lei16_bool.opt @@ -19,4 +19,7 @@ WITH {{ $1 }} -IF {{ $1 == "call .core.GEF" || $1 == "call .core.LEI16"}} +IF {{ + $1 == "call .core.GEF" || $1 == "call .core.LEI16" || $1 == "call .core.__NOT32" || + $1 == "call .core.__LEI8" || $1 == "call .core.__LTI8" +}} From 7bef7fa419b7fbf9ebdd8627bf68960bbbacebd5 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Sun, 24 Nov 2024 11:06:24 +0100 Subject: [PATCH 06/13] feat: implement normalized boolan only when necessary --- src/api/config.py | 25 ++++- src/api/errmsg.py | 2 +- src/api/options.py | 9 +- src/api/symboltable/symboltable.py | 3 + src/arch/z80/backend/_8bit.py | 3 +- src/arch/z80/backend/common.py | 99 ++++++++++++++++--- src/arch/z80/backend/generic.py | 7 +- src/arch/z80/backend/main.py | 15 --- .../z80/peephole/opts/000_o1_lei16_bool.opt | 25 ----- .../peephole/opts/020_o1_bool_norm_empty.opt | 29 ++++++ ...norm_bool.opt => 021_o1_bool_norm_neg.opt} | 11 ++- src/lib/arch/zx48k/runtime/strictbool.asm | 7 +- src/lib/arch/zxnext/runtime/strictbool.asm | 7 +- src/symbols/binary.py | 10 +- src/symbols/type_.py | 8 +- src/symbols/typecast.py | 5 +- src/symbols/unary.py | 2 +- src/zxbc/args_config.py | 21 +++- src/zxbc/args_parser.py | 14 ++- src/zxbc/zxbparser.py | 6 +- tests/arch/zx48k/optimizer/common.py | 14 +++ .../arch/zx48k/optimizer/test_o1_optimizer.py | 29 ++++++ tests/arch/zx48k/optimizer/test_optimizer.py | 15 +-- tests/functional/arch/zx48k/25.asm | 5 +- tests/functional/arch/zx48k/and16.asm | 13 ++- tests/functional/arch/zx48k/and32.asm | 15 ++- tests/functional/arch/zx48k/and8.asm | 9 ++ tests/functional/arch/zx48k/gef16.asm | 16 +-- tests/functional/arch/zx48k/gei32.asm | 17 ++-- tests/functional/arch/zx48k/gei8.asm | 40 ++++++-- tests/functional/arch/zx48k/gei8.bas | 12 ++- tests/functional/arch/zx48k/geu16.asm | 5 + tests/functional/arch/zx48k/geu32.asm | 13 ++- tests/functional/arch/zx48k/geu8.asm | 5 + tests/functional/arch/zx48k/gtf16.asm | 16 +-- tests/functional/arch/zx48k/gti32.asm | 17 ++-- tests/functional/arch/zx48k/gtu16.asm | 5 + tests/functional/arch/zx48k/gtu32.asm | 9 +- tests/functional/arch/zx48k/leu16.asm | 5 + tests/functional/arch/zx48k/leu32.asm | 9 +- tests/functional/arch/zx48k/leu8.asm | 5 + tests/functional/arch/zx48k/ltu16.asm | 5 + tests/functional/arch/zx48k/ltu32.asm | 9 +- tests/functional/arch/zx48k/ltu8.asm | 5 + tests/functional/arch/zx48k/not32.asm | 3 +- tests/functional/arch/zxnext/gef16.asm | 12 ++- tests/functional/arch/zxnext/gei32.asm | 13 ++- tests/functional/arch/zxnext/geu16.asm | 5 + tests/functional/arch/zxnext/geu32.asm | 9 +- tests/functional/arch/zxnext/geu8.asm | 5 + tests/functional/arch/zxnext/gtf16.asm | 12 ++- tests/functional/arch/zxnext/gti32.asm | 13 ++- tests/functional/arch/zxnext/gtu16.asm | 5 + tests/functional/arch/zxnext/gtu32.asm | 7 +- 54 files changed, 501 insertions(+), 184 deletions(-) delete mode 100644 src/arch/z80/peephole/opts/000_o1_lei16_bool.opt create mode 100644 src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt rename src/arch/z80/peephole/opts/{001_o1_norm_bool.opt => 021_o1_bool_norm_neg.opt} (72%) create mode 100644 tests/arch/zx48k/optimizer/common.py create mode 100644 tests/arch/zx48k/optimizer/test_o1_optimizer.py diff --git a/src/api/config.py b/src/api/config.py index c60832464..66361b27d 100644 --- a/src/api/config.py +++ b/src/api/config.py @@ -12,7 +12,7 @@ import os import sys from collections.abc import Callable -from enum import Enum +from enum import StrEnum from src.api import errmsg, global_, options, python_version_check from src.api.options import ANYTYPE, Action @@ -24,14 +24,21 @@ # Common setup and configuration for all tools # ------------------------------------------------------ @enum.unique -class ConfigSections(str, Enum): +class ConfigSections(StrEnum): ZXBC = "zxbc" ZXBASM = "zxbasm" ZXBPP = "zxbpp" @enum.unique -class OPTION(str, Enum): +class OptimizationStrategy(StrEnum): + Size = "size" + Speed = "speed" + Auto = "auto" + + +@enum.unique +class OPTION(StrEnum): OUTPUT_FILENAME = "output_filename" INPUT_FILENAME = "input_filename" STDERR_FILENAME = "stderr_filename" @@ -76,6 +83,9 @@ class OPTION(str, Enum): ASM_ZXNEXT = "zxnext" FORCE_ASM_BRACKET = "force_asm_brackets" + # Optimization Preferences + OPT_STRATEGY = "opt_strategy" + OPTIONS = options.Options() OPTIONS_NOT_SAVED = { @@ -226,6 +236,15 @@ def init() -> None: # Whether to show WXXX warning codes or not OPTIONS(Action.ADD, name=OPTION.HIDE_WARNING_CODES, type=bool, default=False, ignore_none=True) + # Optimization preferences + OPTIONS( + Action.ADD, + name=OPTION.OPT_STRATEGY, + type=OptimizationStrategy, + default=OptimizationStrategy.Auto, + ignore_none=True, + ) + OPTIONS( Action.ADD, name=OPTION.PROJECT_FILENAME, diff --git a/src/api/errmsg.py b/src/api/errmsg.py index 1c2bf295a..17c88afd4 100644 --- a/src/api/errmsg.py +++ b/src/api/errmsg.py @@ -106,7 +106,7 @@ def warning_command_line_flag_deprecation(flag: str) -> None: """Warning signaling command line flag is deprecated. This is a special warning that can't be silenced, and needs no line number nor filename. """ - # msg_output(f"WARNING: deprecated flag {flag}") # TODO: To be enabled upon 1.18+ + msg_output(f"WARNING: deprecated flag {flag}") # TODO: To be enabled upon 1.18+ # region [Warnings] diff --git a/src/api/options.py b/src/api/options.py index c6508f70d..9b2b207d1 100644 --- a/src/api/options.py +++ b/src/api/options.py @@ -9,11 +9,12 @@ import enum import json -from typing import Any +from enum import StrEnum +from typing import Any, Final from src.api.exception import Error -__all__ = ["Option", "Options", "ANYTYPE", "Action"] +__all__: Final[tuple[str, ...]] = "Option", "Options", "ANYTYPE", "Action" class ANYTYPE: @@ -51,7 +52,7 @@ def __str__(self): return "Cannot pop option '%s'. Option stack is empty" % self.option -class InvalidValueError(Error): +class InvalidValueError(ValueError, Error): def __init__(self, option_name, _type, value): self.option = option_name self.value = value @@ -159,7 +160,7 @@ def pop(self) -> Any: # Options commands # ---------------------------------------------------------------------- @enum.unique -class Action(str, enum.Enum): +class Action(StrEnum): ADD = "add" ADD_IF_NOT_DEFINED = "add_if_not_defined" CLEAR = "clear" diff --git a/src/api/symboltable/symboltable.py b/src/api/symboltable/symboltable.py index d5a9e0eb6..5fb0c9043 100644 --- a/src/api/symboltable/symboltable.py +++ b/src/api/symboltable/symboltable.py @@ -360,6 +360,9 @@ def access_id( # The entry was already declared. If it's type is auto and the default type is not None, # update its type. if default_type is not None and result.type_ == self.basic_types[TYPE.unknown]: + if default_type == self.basic_types[TYPE.boolean]: + default_type = self.basic_types[TYPE.ubyte] + result.type_ = default_type warning_implicit_type(lineno, id_, default_type.name) diff --git a/src/arch/z80/backend/_8bit.py b/src/arch/z80/backend/_8bit.py index 6028c9036..f0b1a7d41 100644 --- a/src/arch/z80/backend/_8bit.py +++ b/src/arch/z80/backend/_8bit.py @@ -745,14 +745,13 @@ def and8(cls, ins: Quad) -> list[str]: return output output = cls.get_oper(op1, op2) - # output.append('call __AND8') + lbl = tmp_label() output.append("or a") output.append("jr z, %s" % lbl) output.append("ld a, h") output.append("%s:" % lbl) output.append("push af") - # REQUIRES.add('and8.asm') return output diff --git a/src/arch/z80/backend/common.py b/src/arch/z80/backend/common.py index b04895d2d..933b12b08 100644 --- a/src/arch/z80/backend/common.py +++ b/src/arch/z80/backend/common.py @@ -5,6 +5,7 @@ from typing import Final from src.api import global_, tmp_labels +from src.api.config import OPTIONS, OptimizationStrategy from src.api.exception import TempAlreadyFreedError from .runtime import LABEL_REQUIRED_MODULES, NAMESPACE, RUNTIME_LABELS @@ -296,12 +297,52 @@ def get_bytes_size(elements: list[str]) -> int: return len(get_bytes(elements)) +def to_bool(stype: DataType) -> list[str]: + """Returns the instruction sequence for converting the number given number (in the stack) + to boolean (just 0 (False) or non-zero (True)).""" + + if stype in (U8_t, I8_t): + return [] + + if stype in (U16_t, I16_t): + return [ + "ld a, h" "or l", + ] + + if stype in (U32_t, I32_t, F16_t): + return ["ld a, h" "or l" "or d", "or e,"] + + if stype == F_t: + return [ + "or b", + "or c", + "or d", + "or e", + ] + + raise NotImplementedError(f"type conversion from {stype} to bool is undefined") + + +def normalize_boolean() -> list[str]: + if OPTIONS.opt_strategy == OptimizationStrategy.Size: + return [runtime_call(RuntimeLabel.NORMALIZE_BOOLEAN)] + + return [ + "sub 1", # Carry if A = 0 + "sbc a, a", # 0xFF if A was 0, 0 otherwise + "inc a", # 0 if A was 0, 1 otherwise + ] + + def to_byte(stype: DataType) -> list[str]: """Returns the instruction sequence for converting from the given type to byte. """ output = [] + if stype == BOOL_t: + return normalize_boolean() + if stype in (I8_t, U8_t): return [] @@ -322,7 +363,10 @@ def to_word(stype: DataType) -> list[str]: """ output = [] # List of instructions - if stype == U8_t: # Byte to word + if stype == BOOL_t: + output.extend(normalize_boolean()) + + if stype in (BOOL_t, U8_t): # Byte to word output.append("ld l, a") output.append("ld h, 0") @@ -347,6 +391,18 @@ def to_long(stype: DataType) -> list[str]: """ output = [] # List of instructions + if stype == BOOL_t: + output = normalize_boolean() + output.extend( + [ + "ld l, a", + "ld h, 0", + "ld e, h", + "ld d, h", + ] + ) + return output + if stype in {I8_t, U8_t, F16_t}: # Byte to word output = to_word(stype) @@ -354,18 +410,20 @@ def to_long(stype: DataType) -> list[str]: output.append("ld e, h") output.append("ld d, h") - if stype in (I16_t, F16_t): # Signed byte or fixed to word + elif stype in (I16_t, F16_t): # Signed byte or fixed to word output.append("ld a, h") output.append("add a, a") output.append("sbc a, a") output.append("ld e, a") output.append("ld d, a") - elif stype == "u16": + elif stype == U16_t: output.append("ld de, 0") elif stype == F_t: output.append(runtime_call(RuntimeLabel.FTOU32REG)) + else: + raise NotImplementedError(f"type conversion from {stype} to long is undefined") return output @@ -374,16 +432,30 @@ def to_fixed(stype: DataType) -> list[str]: """Returns the instruction sequence for converting the given type stored in DE,HL to fixed DE,HL. """ - output = [] # List of instructions + if stype == BOOL_t: + output = to_word(stype) + output.extend( + [ + "ex de, hl", + "ld hl, 0", # 'Truncate' the fixed point + ] + ) + return output if is_int_type(stype): output = to_word(stype) - output.append("ex de, hl") - output.append("ld hl, 0") # 'Truncate' the fixed point - elif stype == F_t: - output.append(runtime_call(RuntimeLabel.FTOF16REG)) + output.extend( + [ + "ex de, hl", + "ld hl, 0", # 'Truncate' the fixed point + ] + ) + return output - return output + if stype == F_t: + return [runtime_call(RuntimeLabel.FTOF16REG)] + + raise NotImplementedError(f"type conversion from {stype} to fixed") def to_float(stype: DataType) -> list[str]: @@ -399,17 +471,22 @@ def to_float(stype: DataType) -> list[str]: output.append(runtime_call(RuntimeLabel.F16TOFREG)) return output + if stype == BOOL_t: + output.extend(normalize_boolean()) + # If we reach this point, it's an integer type - if stype == U8_t: + if stype in (BOOL_t, U8_t): # The ZX Spectrum ROM FP-Calc already returns 0 or 1 for Booleans output.append(runtime_call(RuntimeLabel.U8TOFREG)) elif stype == I8_t: output.append(runtime_call(RuntimeLabel.I8TOFREG)) - else: + elif stype in {I16_t, I32_t, U16_t, U32_t}: output = to_long(stype) if stype in (I16_t, I32_t): output.append(runtime_call(RuntimeLabel.I32TOFREG)) else: output.append(runtime_call(RuntimeLabel.U32TOFREG)) + else: + raise NotImplementedError(f"type conversion from {stype} to float is undefined") return output diff --git a/src/arch/z80/backend/generic.py b/src/arch/z80/backend/generic.py index d0f5a91d2..882e49739 100644 --- a/src/arch/z80/backend/generic.py +++ b/src/arch/z80/backend/generic.py @@ -24,6 +24,7 @@ get_bytes_size, new_ASMID, runtime_call, + to_bool, to_byte, to_fixed, to_float, @@ -341,7 +342,7 @@ def _cast(ins: Quad): xsB = sB = YY_TYPES[tB] # Type sizes output = [] - if tA in ("u8", "i8"): + if tA in ("u8", "i8", "bool"): output.extend(Bits8.get_oper(ins[4])) elif tA in ("u16", "i16"): output.extend(Bits16.get_oper(ins[4])) @@ -364,6 +365,10 @@ def _cast(ins: Quad): output.extend(to_fixed(tA)) elif tB == "f": output.extend(to_float(tA)) + elif tB == "bool": + output.extend(to_bool(tA)) + else: + raise exception.GenericError("Internal error: invalid typecast from %s to %s" % (tA, tB)) xsB += sB % 2 # make it even (round up) diff --git a/src/arch/z80/backend/main.py b/src/arch/z80/backend/main.py index 79d8d487f..6b10983b0 100644 --- a/src/arch/z80/backend/main.py +++ b/src/arch/z80/backend/main.py @@ -100,7 +100,6 @@ # String comparison functions # String arithmetic functions from ._str import String -from .common import runtime_call from .generic import ( _call, _cast, @@ -130,7 +129,6 @@ from .icinstruction import ICInstruction from .quad import Quad from .runtime import NAMESPACE -from .runtime import Labels as RuntimeLabel __all__ = ("Backend",) @@ -677,16 +675,6 @@ def emit_prologue() -> list[str]: return output - @staticmethod - def emit_cast_to_bool(): - """Convert a byte value to boolean (0 or 1) if - the global flag strictBool is True - """ - if not OPTIONS.strict_bool: - return [] - - return ["pop af", runtime_call(RuntimeLabel.NORMALIZE_BOOLEAN), "push af"] - @staticmethod def emit_epilogue() -> list[str]: """This special ending autoinitializes required inits @@ -780,9 +768,6 @@ def emit(self, *, optimize: bool = True) -> list[str]: output: list[str] = [] for quad in self.MEMORY: self._output_join(output, self._QUAD_TABLE[quad.instr].func(quad), optimize=optimize) - # If it is a boolean operation convert it to 0/1 if the STRICT_BOOL flag is True - if common.RE_BOOL.match(quad.instr): - self._output_join(output, self.emit_cast_to_bool(), optimize=optimize) if optimize and OPTIONS.optimization_level > 1: self.remove_unused_labels(output) diff --git a/src/arch/z80/peephole/opts/000_o1_lei16_bool.opt b/src/arch/z80/peephole/opts/000_o1_lei16_bool.opt deleted file mode 100644 index 3331f83f9..000000000 --- a/src/arch/z80/peephole/opts/000_o1_lei16_bool.opt +++ /dev/null @@ -1,25 +0,0 @@ -;; core.LEI16 and .core.GEF return the bool result of Byte(a) <= Byte(b) -;; and is already normalized. The sequence -;; sub 1 -;; sbc a, a -;; inc a -;; can be removed - -OLEVEL: 1 -OFLAG: 14 - -REPLACE {{ - $1 - sub 1 - sbc a, a - inc a -}} - -WITH {{ - $1 -}} - -IF {{ - $1 == "call .core.GEF" || $1 == "call .core.LEI16" || $1 == "call .core.__NOT32" || - $1 == "call .core.__LEI8" || $1 == "call .core.__LTI8" -}} diff --git a/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt b/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt new file mode 100644 index 000000000..0b7980695 --- /dev/null +++ b/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt @@ -0,0 +1,29 @@ +;; Remove the boolean normalization if it's done after calling +;; certain routines that return the bool result already normalized. + +;; The sequence +;; sub 1 +;; sbc a, a +;; inc a +;; can be removed + +OLEVEL: 1 +OFLAG: 20 + +REPLACE {{ + $1 + sub 1 + sbc a, a + inc a +}} + +WITH {{ + $1 +}} + +IF {{ + $1 IN ("xor a", "ld a, 0", + "call .core.__GEF", "call .core.__LEI16", "call .core.__LEI8", "call .core.__LTI8", + "call .core.__ANDF", "call .core.__EQF", "call .core.__GTF", "call .core.__LTI16", + "call .core.__LEF", "call .core.__LEI32", "call .core.__LTF", "call .core.__LTI32") +}} diff --git a/src/arch/z80/peephole/opts/001_o1_norm_bool.opt b/src/arch/z80/peephole/opts/021_o1_bool_norm_neg.opt similarity index 72% rename from src/arch/z80/peephole/opts/001_o1_norm_bool.opt rename to src/arch/z80/peephole/opts/021_o1_bool_norm_neg.opt index 346c69e1c..ac02d3044 100644 --- a/src/arch/z80/peephole/opts/001_o1_norm_bool.opt +++ b/src/arch/z80/peephole/opts/021_o1_bool_norm_neg.opt @@ -7,16 +7,21 @@ ;; neg ; A is either 0 or 1 OLEVEL: 1 -OFLAG: 15 +OFLAG: 21 REPLACE {{ - sbc a, a + $1 sub 1 sbc a, a inc a }} WITH {{ - sbc a, a + $1 neg }} + +IF {{ + $1 == "sbc a, a" || + $1 == "call .core.__NOT32" +}} diff --git a/src/lib/arch/zx48k/runtime/strictbool.asm b/src/lib/arch/zx48k/runtime/strictbool.asm index 0461b1a55..80a7460a4 100644 --- a/src/lib/arch/zx48k/runtime/strictbool.asm +++ b/src/lib/arch/zx48k/runtime/strictbool.asm @@ -4,10 +4,9 @@ push namespace core __NORMALIZE_BOOLEAN: - or a - ret z - ld a, 1 + sub 1 + sbc a, a + inc a ret pop namespace - diff --git a/src/lib/arch/zxnext/runtime/strictbool.asm b/src/lib/arch/zxnext/runtime/strictbool.asm index 0461b1a55..80a7460a4 100644 --- a/src/lib/arch/zxnext/runtime/strictbool.asm +++ b/src/lib/arch/zxnext/runtime/strictbool.asm @@ -4,10 +4,9 @@ push namespace core __NORMALIZE_BOOLEAN: - or a - ret z - ld a, 1 + sub 1 + sbc a, a + inc a ret pop namespace - diff --git a/src/symbols/binary.py b/src/symbols/binary.py index ab89d3a2a..34f1c1b44 100644 --- a/src/symbols/binary.py +++ b/src/symbols/binary.py @@ -1,10 +1,8 @@ -# vim: ts=4:et:sw=4: - # ---------------------------------------------------------------------- -# Copyleft (K), Jose M. Rodriguez-Rosa (a.k.a. Boriel) +# Copyleft, Jose M. Rodriguez-Rosa (a.k.a. Boriel) # # This program is Free Software and is released under the terms of -# the GNU General License +# the Affero GNU General License v3 # ---------------------------------------------------------------------- from src.api import check, errmsg @@ -21,7 +19,7 @@ class SymbolBINARY(Symbol): Only the operator (e.g. 'PLUS') is stored. """ - def __init__(self, operator, left, right, lineno, type_=None, func=None): + def __init__(self, operator: str, left: Symbol, right: Symbol, lineno: int, type_=None, func=None): super().__init__(left, right) self.lineno = lineno self.operator = operator @@ -132,7 +130,7 @@ def make_node(cls, operator, left, right, lineno, func=None, type_=None): if type_ is None: if operator in ("LT", "GT", "EQ", "LE", "GE", "NE", "AND", "OR", "XOR", "NOT"): - type_ = TYPE.ubyte # Boolean type + type_ = TYPE.boolean else: type_ = c_type diff --git a/src/symbols/type_.py b/src/symbols/type_.py index 2f94682c2..02fbb49fc 100644 --- a/src/symbols/type_.py +++ b/src/symbols/type_.py @@ -26,7 +26,7 @@ def __init__(self, name: str, lineno: int, *children): self.name = name # typename self.lineno = lineno # The line the type was defined. Line 0 = basic type self.final = self # self.final always return the original aliased type (if this type is an alias) - self.caseins = OPTIONS.case_insensitive # Whether this ID is case insensitive or not + self.caseins = OPTIONS.case_insensitive # Whether this ID is case-insensitive or not self.class_ = CLASS.type self.accessed = False # Whether this type has been used or not @@ -113,7 +113,7 @@ class SymbolBASICTYPE(SymbolTYPE): If name is None or '', default typename from TYPES.to_string will be used. """ - def __init__(self, type_, name: str = None): + def __init__(self, type_: TYPE, name: str = None): """type_ = Internal representation (e.g. TYPE.ubyte)""" assert TYPE.is_valid(type_) if not name: @@ -146,7 +146,7 @@ def is_dynamic(self): return self.type_ == TYPE.string def __hash__(self): - return self.type_ + return hash(self.type_) def __eq__(self, other): if self is not self.final: @@ -316,7 +316,7 @@ def to_signed(cls, t: SymbolTYPE): assert t.is_basic if cls.is_unsigned(t): # FIXME - return {cls.ubyte: cls.byte_, cls.uinteger: cls.integer, cls.ulong: cls.long_}[t] # type:ignore[index] + return {cls.boolean: cls.byte_, cls.ubyte: cls.byte_, cls.uinteger: cls.integer, cls.ulong: cls.long_}[t] # type:ignore[index] if cls.is_signed(t) or cls.is_decimal(t): return t return cls.unknown diff --git a/src/symbols/typecast.py b/src/symbols/typecast.py index b81af8832..db0a98a46 100644 --- a/src/symbols/typecast.py +++ b/src/symbols/typecast.py @@ -87,7 +87,10 @@ def make_node(cls, new_type: SymbolTYPE, node: Symbol, lineno: int): if check.is_const(node): node = SymbolNUMBER(node.value, node.lineno, node.type_) - if new_type.is_basic and not TYPE.is_integral(new_type): # not an integer + if new_type == TYPE.boolean: + node.value = int(bool(node.value)) + new_type = TYPE.ubyte # For the moment we'll use UByte externally + elif new_type.is_basic and not TYPE.is_integral(new_type): # not an integer node.value = float(node.value) else: # It's an integer new_val = int(node.value) & ((1 << (8 * new_type.size)) - 1) # Mask it diff --git a/src/symbols/unary.py b/src/symbols/unary.py index 5649b43c0..5021c9d43 100644 --- a/src/symbols/unary.py +++ b/src/symbols/unary.py @@ -80,6 +80,6 @@ def make_node(cls, lineno, operator, operand, func=None, type_=None): type_ = type_.to_signed() operand = SymbolTYPECAST.make_node(type_, operand, lineno) elif operator == "NOT": - type_ = TYPE.ubyte + type_ = TYPE.boolean return cls(operator, operand, lineno, type_) diff --git a/src/zxbc/args_config.py b/src/zxbc/args_config.py index 64d9e70dc..918fe666a 100644 --- a/src/zxbc/args_config.py +++ b/src/zxbc/args_config.py @@ -50,6 +50,7 @@ def parse_options(args: list[str] | None = None) -> Namespace: OPTIONS.zxnext = options.zxnext OPTIONS.expected_warnings = gl.EXPECTED_WARNINGS = options.expect_warnings OPTIONS.hide_warning_codes = options.hide_warning_codes + OPTIONS.opt_strategy = options.opt_strategy if options.arch not in arch.AVAILABLE_ARCHITECTURES: parser.error(f"Invalid architecture '{options.arch}'") @@ -101,16 +102,28 @@ def parse_options(args: list[str] | None = None) -> Namespace: OPTIONS.output_file_type = options.output_format elif options.tzx: OPTIONS.output_file_type = FileType.TZX - warning_command_line_flag_deprecation(f"--tzx (use --output-format={FileType.TZX} instead)") + warning_command_line_flag_deprecation( + f"--tzx (use -f {FileType.TZX} or --output-format={FileType.TZX} instead)" + ) elif options.tap: OPTIONS.output_file_type = FileType.TAP - warning_command_line_flag_deprecation(f"--tap (use --output-format={FileType.TAP} instead)") + warning_command_line_flag_deprecation( + f"--tap (use -f {FileType.TAP} or --output-format={FileType.TAP} instead)" + ) elif options.asm: OPTIONS.output_file_type = FileType.ASM - warning_command_line_flag_deprecation(f"--asm (use --output-format={FileType.ASM} instead)") + warning_command_line_flag_deprecation( + f"--asm (use -f {FileType.ASM} or --output-format={FileType.ASM} instead)" + ) elif options.emit_backend: OPTIONS.output_file_type = FileType.IR - warning_command_line_flag_deprecation(f"--emit-backend (use --output-format={FileType.IR} instead)") + warning_command_line_flag_deprecation( + f"--emit-backend (use -f {FileType.IR} or --output-format={FileType.IR} instead)" + ) + + if OPTIONS.strict_bool: + OPTIONS.strict_bool = False + warning_command_line_flag_deprecation("--strict-bool is deprecated (no longer needed)") if OPTIONS.output_file_type == FileType.IR: OPTIONS.emit_backend = True diff --git a/src/zxbc/args_parser.py b/src/zxbc/args_parser.py index bbd1f66ac..ecbabbb5f 100644 --- a/src/zxbc/args_parser.py +++ b/src/zxbc/args_parser.py @@ -5,7 +5,7 @@ from src import arch from src.api import errmsg -from src.api.config import OPTIONS +from src.api.config import OPTIONS, OptimizationStrategy from .version import VERSION @@ -73,7 +73,7 @@ def parser() -> argparse.ArgumentParser: action="store_true", help="Sets output format to .asm. DEPRECATED. Use -f", ) - parser_.add_argument( + output_file_type_group.add_argument( "-E", "--emit-backend", action="store_true", @@ -125,7 +125,9 @@ def parser() -> argparse.ArgumentParser: parser_.add_argument("--heap-address", type=str, default=None, help="Sets the heap address.") parser_.add_argument("--debug-memory", action="store_true", default=None, help="Enables out-of-memory debug") parser_.add_argument("--debug-array", action="store_true", default=None, help="Enables array boundary checking") - parser_.add_argument("--strict-bool", action="store_true", default=None, help="Enforce boolean values to be 0 or 1") + parser_.add_argument( + "--strict-bool", action="store_true", default=None, help="Enforce boolean values to be 0 or 1 (Deprecated)" + ) parser_.add_argument("--enable-break", action="store_true", help="Enables program execution BREAK detection") parser_.add_argument( @@ -202,5 +204,11 @@ def parser() -> argparse.ArgumentParser: "-F", "--config-file", type=str, default=OPTIONS.project_filename, help="Loads config from config file" ) parser_.add_argument("--save-config", type=str, help="Save options into a config file") + parser_.add_argument( + "--opt-strategy", + choices=[str(x) for x in OptimizationStrategy], + default=OptimizationStrategy.Auto, + help=f"Optimization strategy (optimize for speed or size). Default: {OptimizationStrategy.Auto}", + ) return parser_ diff --git a/src/zxbc/zxbparser.py b/src/zxbc/zxbparser.py index c89be4963..3abc576a3 100755 --- a/src/zxbc/zxbparser.py +++ b/src/zxbc/zxbparser.py @@ -199,7 +199,7 @@ def make_number(value, lineno: int, type_=None): return sym.NUMBER(value, type_=type_, lineno=lineno) -def make_typecast(type_: sym.TYPE, node: sym.SYMBOL | None, lineno: int): +def make_typecast(type_: sym.TYPE, node: sym.SYMBOL | None, lineno: int) -> sym.TYPECAST | None: """Wrapper: returns a Typecast node""" if node is None or node.type_ is None: return None # syntax / semantic error @@ -208,12 +208,12 @@ def make_typecast(type_: sym.TYPE, node: sym.SYMBOL | None, lineno: int): return sym.TYPECAST.make_node(type_, node, lineno) -def make_binary(lineno, operator, left, right, func=None, type_=None): +def make_binary(lineno: int, operator, left, right, func=None, type_=None): """Wrapper: returns a Binary node""" return sym.BINARY.make_node(operator, left, right, lineno, func, type_) -def make_unary(lineno, operator, operand, func=None, type_=None): +def make_unary(lineno: int, operator, operand, func=None, type_=None): """Wrapper: returns a Unary node""" if operand is None: # syntax / semantic error return None diff --git a/tests/arch/zx48k/optimizer/common.py b/tests/arch/zx48k/optimizer/common.py new file mode 100644 index 000000000..3c604c471 --- /dev/null +++ b/tests/arch/zx48k/optimizer/common.py @@ -0,0 +1,14 @@ +from contextlib import contextmanager + +from src.api.config import OPTIONS + + +@contextmanager +def mock_options_level(level: int): + initial_level = OPTIONS.optimization_level + + try: + OPTIONS.optimization_level = level + yield + finally: + OPTIONS.optimization_level = initial_level diff --git a/tests/arch/zx48k/optimizer/test_o1_optimizer.py b/tests/arch/zx48k/optimizer/test_o1_optimizer.py new file mode 100644 index 000000000..c16bf8712 --- /dev/null +++ b/tests/arch/zx48k/optimizer/test_o1_optimizer.py @@ -0,0 +1,29 @@ +from src.arch.z80.backend import Backend +from tests.arch.zx48k.optimizer.common import mock_options_level + + +class TestO1Optimizer: + @staticmethod + def _asm_code(asm: str) -> list[str]: + return [x.strip() for x in asm.split("\n") if x.strip()] + + def setup_method(self) -> None: + self.backend = Backend() + + def test_call_match(self): + code_src = """ + call .core.__LEI8 + sub 1 + sbc a, a + inc a + """ + code = self._asm_code(code_src) + with mock_options_level(1): + output = [] + self.backend._output_join(output, code, optimize=True) + assert output == [ + "call .core.__LEI8", + "sub 1", + "sbc a, a", + "inc a", + ] diff --git a/tests/arch/zx48k/optimizer/test_optimizer.py b/tests/arch/zx48k/optimizer/test_optimizer.py index 3a5225921..3db7f24a7 100644 --- a/tests/arch/zx48k/optimizer/test_optimizer.py +++ b/tests/arch/zx48k/optimizer/test_optimizer.py @@ -1,19 +1,6 @@ -from contextlib import contextmanager - -from src.api.config import OPTIONS from src.arch.z80 import optimizer from src.arch.z80.peephole import engine - - -@contextmanager -def mock_options_level(level: int): - initial_level = OPTIONS.optimization_level - - try: - OPTIONS.optimization_level = level - yield - finally: - OPTIONS.optimization_level = initial_level +from tests.arch.zx48k.optimizer.common import mock_options_level class TestOptimizer: diff --git a/tests/functional/arch/zx48k/25.asm b/tests/functional/arch/zx48k/25.asm index 3db1b7fe2..2a1d38399 100644 --- a/tests/functional/arch/zx48k/25.asm +++ b/tests/functional/arch/zx48k/25.asm @@ -31,6 +31,7 @@ _c: ld hl, (_a) ld de, (_a + 2) call .core.__NOT32 + neg ld (_c), a ld hl, 0 ld b, h @@ -47,7 +48,7 @@ _c: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/not32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bool/not32.asm" ; ------------------------------------------------------------- ; 32 bit logical NOT ; ------------------------------------------------------------- @@ -61,5 +62,5 @@ __NOT32: ; A = ¬A sbc a, a; Gives 0 if not carry, FF otherwise ret pop namespace -#line 25 "25.bas" +#line 26 "arch/zx48k/25.bas" END diff --git a/tests/functional/arch/zx48k/and16.asm b/tests/functional/arch/zx48k/and16.asm index 255835297..9af2a346c 100644 --- a/tests/functional/arch/zx48k/and16.asm +++ b/tests/functional/arch/zx48k/and16.asm @@ -30,6 +30,9 @@ _b: ld hl, (_a) ld a, h or l + sub 1 + sbc a, a + inc a ld (_b), a ld hl, (_a) xor a @@ -37,10 +40,16 @@ _b: ld hl, (_a) ld a, h or l + sub 1 + sbc a, a + inc a ld (_b), a ld de, (_a) ld hl, (_a) call .core.__AND16 + sub 1 + sbc a, a + inc a ld (_b), a ld hl, 0 ld b, h @@ -57,7 +66,7 @@ _b: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/and16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bool/and16.asm" ; FASTCALL boolean and 16 version. ; result in Accumulator (0 False, not 0 True) ; __FASTCALL__ version (operands: DE, HL) @@ -71,5 +80,5 @@ __AND16: or e ret pop namespace -#line 35 "and16.bas" +#line 44 "arch/zx48k/and16.bas" END diff --git a/tests/functional/arch/zx48k/and32.asm b/tests/functional/arch/zx48k/and32.asm index bcf511206..9492290cd 100644 --- a/tests/functional/arch/zx48k/and32.asm +++ b/tests/functional/arch/zx48k/and32.asm @@ -33,6 +33,9 @@ _b: ld de, 0 ld hl, 1 call .core.__AND32 + sub 1 + sbc a, a + inc a ld (_b), a xor a ld (_b), a @@ -43,6 +46,9 @@ _b: ld de, 0 ld hl, 1 call .core.__AND32 + sub 1 + sbc a, a + inc a ld (_b), a ld hl, (_a + 2) push hl @@ -51,6 +57,9 @@ _b: ld hl, (_a) ld de, (_a + 2) call .core.__AND32 + sub 1 + sbc a, a + inc a ld (_b), a ld hl, 0 ld b, h @@ -67,7 +76,7 @@ _b: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/and32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bool/and32.asm" ; FASTCALL boolean and 32 version. ; Performs 32bit and 32bit and returns the boolean ; result in Accumulator (0 False, not 0 True) @@ -86,8 +95,8 @@ __AND32: or e or h or l -#line 28 "/zxbasic/src/arch/zx48k/library-asm/and32.asm" +#line 28 "/zxbasic/src/lib/arch/zx48k/runtime/bool/and32.asm" ret pop namespace -#line 45 "and32.bas" +#line 54 "arch/zx48k/and32.bas" END diff --git a/tests/functional/arch/zx48k/and8.asm b/tests/functional/arch/zx48k/and8.asm index f0707296e..5c22c95b6 100644 --- a/tests/functional/arch/zx48k/and8.asm +++ b/tests/functional/arch/zx48k/and8.asm @@ -28,11 +28,17 @@ _b: xor a ld (_b), a ld a, (_a) + sub 1 + sbc a, a + inc a ld (_b), a ld a, (_a) xor a ld (_b), a ld a, (_a) + sub 1 + sbc a, a + inc a ld (_b), a ld hl, (_a - 1) ld a, (_a) @@ -40,6 +46,9 @@ _b: jr z, .LABEL.__LABEL0 ld a, h .LABEL.__LABEL0: + sub 1 + sbc a, a + inc a ld (_b), a ld hl, 0 ld b, h diff --git a/tests/functional/arch/zx48k/gef16.asm b/tests/functional/arch/zx48k/gef16.asm index 8940308de..14054c701 100644 --- a/tests/functional/arch/zx48k/gef16.asm +++ b/tests/functional/arch/zx48k/gef16.asm @@ -42,6 +42,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ex de, hl @@ -57,6 +58,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ex de, hl @@ -72,6 +74,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ex de, hl @@ -87,6 +90,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ex de, hl @@ -108,8 +112,8 @@ _l: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/lti32.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/sub32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/lti32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/sub32.asm" ; SUB32 ; Perform TOP of the stack - DEHL ; Pops operand out of the stack (CALLEE) @@ -135,7 +139,7 @@ __SUB32: exx ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/lti32.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/lti32.asm" push namespace core __LTI32: ; Test 32 bit values in Top of the stack < HLDE PROC @@ -157,8 +161,8 @@ checkParity: ret ENDP pop namespace -#line 78 "gef16.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/swap32.asm" +#line 82 "arch/zx48k/gef16.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/swap32.asm" ; Exchanges current DE HL with the ; ones in the stack push namespace core @@ -175,5 +179,5 @@ __SWAP32: push bc ret pop namespace -#line 79 "gef16.bas" +#line 83 "arch/zx48k/gef16.bas" END diff --git a/tests/functional/arch/zx48k/gei32.asm b/tests/functional/arch/zx48k/gei32.asm index bc71ec1c5..872433a0a 100644 --- a/tests/functional/arch/zx48k/gei32.asm +++ b/tests/functional/arch/zx48k/gei32.asm @@ -42,6 +42,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -57,6 +58,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -72,6 +74,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -87,6 +90,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -102,6 +106,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -123,8 +128,8 @@ _l: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/lti32.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/sub32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/lti32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/sub32.asm" ; SUB32 ; Perform TOP of the stack - DEHL ; Pops operand out of the stack (CALLEE) @@ -150,7 +155,7 @@ __SUB32: exx ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/lti32.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/lti32.asm" push namespace core __LTI32: ; Test 32 bit values in Top of the stack < HLDE PROC @@ -172,8 +177,8 @@ checkParity: ret ENDP pop namespace -#line 93 "gei32.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/swap32.asm" +#line 98 "arch/zx48k/gei32.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/swap32.asm" ; Exchanges current DE HL with the ; ones in the stack push namespace core @@ -190,5 +195,5 @@ __SWAP32: push bc ret pop namespace -#line 94 "gei32.bas" +#line 99 "arch/zx48k/gei32.bas" END diff --git a/tests/functional/arch/zx48k/gei8.asm b/tests/functional/arch/zx48k/gei8.asm index ab79fda54..123e5077f 100644 --- a/tests/functional/arch/zx48k/gei8.asm +++ b/tests/functional/arch/zx48k/gei8.asm @@ -18,18 +18,38 @@ .core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA .core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN .core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA -_a: +_level: + DEFB 00h +_le: + DEFB 01h +_l: DEFB 00 .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: - ld a, 5 - ld hl, (_a - 1) + ld a, (_level) + ld hl, (_le - 1) call .core.__LEI8 - or a - jp z, .LABEL.__LABEL1 - ld a, 255 - ld (16384), a -.LABEL.__LABEL1: + ld (_l), a + ld a, (_level) + ld hl, (_le - 1) + call .core.__LEI8 + ld (_l), a + ld a, (_le) + push af + ld a, (_level) + pop hl + call .core.__LEI8 + ld (_l), a + ld a, (_le) + push af + ld a, (_level) + pop hl + call .core.__LEI8 + ld (_l), a + ld a, (_level) + ld h, 1 + call .core.__LEI8 + ld (_l), a ld hl, 0 ld b, h ld c, l @@ -45,7 +65,7 @@ _a: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/lei8.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/lei8.asm" push namespace core __LEI8: ; Signed <= comparison for 8bit int ; A <= H (registers) @@ -67,5 +87,5 @@ checkParity: ret ENDP pop namespace -#line 25 "gei8.bas" +#line 41 "arch/zx48k/gei8.bas" END diff --git a/tests/functional/arch/zx48k/gei8.bas b/tests/functional/arch/zx48k/gei8.bas index a71b5632e..d249df894 100644 --- a/tests/functional/arch/zx48k/gei8.bas +++ b/tests/functional/arch/zx48k/gei8.bas @@ -1,5 +1,9 @@ -DIM a as Byte +dim level as Byte = 0 +dim le as Byte = 1 +dim l as Byte -IF a >= 5 THEN - POKE 16384, 255 -END IF +l = le >= (level + 0) +l = le >= level +l = (le + 0) >= level +l = (le + 0) >= (level + 0) +l = 1 >= (level + 0) diff --git a/tests/functional/arch/zx48k/geu16.asm b/tests/functional/arch/zx48k/geu16.asm index 3afc03750..526643996 100644 --- a/tests/functional/arch/zx48k/geu16.asm +++ b/tests/functional/arch/zx48k/geu16.asm @@ -35,6 +35,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -44,6 +45,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -55,6 +57,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -67,6 +70,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -77,6 +81,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld (_l), hl diff --git a/tests/functional/arch/zx48k/geu32.asm b/tests/functional/arch/zx48k/geu32.asm index 67bffa174..72a185b5c 100644 --- a/tests/functional/arch/zx48k/geu32.asm +++ b/tests/functional/arch/zx48k/geu32.asm @@ -42,6 +42,7 @@ _l: call .core.__SUB32 ccf sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -57,6 +58,7 @@ _l: call .core.__SUB32 ccf sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -72,6 +74,7 @@ _l: call .core.__SUB32 ccf sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -87,6 +90,7 @@ _l: call .core.__SUB32 ccf sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -102,6 +106,7 @@ _l: call .core.__SUB32 ccf sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -123,7 +128,7 @@ _l: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/sub32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/sub32.asm" ; SUB32 ; Perform TOP of the stack - DEHL ; Pops operand out of the stack (CALLEE) @@ -149,8 +154,8 @@ __SUB32: exx ret pop namespace -#line 93 "geu32.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/swap32.asm" +#line 98 "arch/zx48k/geu32.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/swap32.asm" ; Exchanges current DE HL with the ; ones in the stack push namespace core @@ -167,5 +172,5 @@ __SWAP32: push bc ret pop namespace -#line 94 "geu32.bas" +#line 99 "arch/zx48k/geu32.bas" END diff --git a/tests/functional/arch/zx48k/geu8.asm b/tests/functional/arch/zx48k/geu8.asm index 123596b58..8a7fa2d0f 100644 --- a/tests/functional/arch/zx48k/geu8.asm +++ b/tests/functional/arch/zx48k/geu8.asm @@ -32,12 +32,14 @@ _l: sub h ccf sbc a, a + neg ld (_l), a ld hl, (_level - 1) ld a, (_le) sub h ccf sbc a, a + neg ld (_l), a ld a, (_le) push af @@ -46,12 +48,14 @@ _l: sub h ccf sbc a, a + neg ld (_l), a ld a, (_le) ld hl, (_level - 1) sub h ccf sbc a, a + neg ld (_l), a ld a, (_level) ld h, a @@ -59,6 +63,7 @@ _l: sub h ccf sbc a, a + neg ld (_l), a ld hl, 0 ld b, h diff --git a/tests/functional/arch/zx48k/gtf16.asm b/tests/functional/arch/zx48k/gtf16.asm index 3187481c0..349ada602 100644 --- a/tests/functional/arch/zx48k/gtf16.asm +++ b/tests/functional/arch/zx48k/gtf16.asm @@ -42,6 +42,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ex de, hl @@ -57,6 +58,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ex de, hl @@ -72,6 +74,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ex de, hl @@ -87,6 +90,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ex de, hl @@ -108,8 +112,8 @@ _l: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/lei32.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/sub32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/lei32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/sub32.asm" ; SUB32 ; Perform TOP of the stack - DEHL ; Pops operand out of the stack (CALLEE) @@ -135,7 +139,7 @@ __SUB32: exx ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/lei32.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/lei32.asm" push namespace core __LEI32: ; Test 32 bit values Top of the stack <= HL,DE PROC @@ -165,8 +169,8 @@ checkParity: ret ENDP pop namespace -#line 78 "gtf16.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/swap32.asm" +#line 82 "arch/zx48k/gtf16.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/swap32.asm" ; Exchanges current DE HL with the ; ones in the stack push namespace core @@ -183,5 +187,5 @@ __SWAP32: push bc ret pop namespace -#line 79 "gtf16.bas" +#line 83 "arch/zx48k/gtf16.bas" END diff --git a/tests/functional/arch/zx48k/gti32.asm b/tests/functional/arch/zx48k/gti32.asm index 634b8a437..c5f1c778c 100644 --- a/tests/functional/arch/zx48k/gti32.asm +++ b/tests/functional/arch/zx48k/gti32.asm @@ -42,6 +42,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -57,6 +58,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -72,6 +74,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -87,6 +90,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -102,6 +106,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -123,8 +128,8 @@ _l: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/lei32.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/sub32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/lei32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/sub32.asm" ; SUB32 ; Perform TOP of the stack - DEHL ; Pops operand out of the stack (CALLEE) @@ -150,7 +155,7 @@ __SUB32: exx ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/lei32.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/lei32.asm" push namespace core __LEI32: ; Test 32 bit values Top of the stack <= HL,DE PROC @@ -180,8 +185,8 @@ checkParity: ret ENDP pop namespace -#line 93 "gti32.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/swap32.asm" +#line 98 "arch/zx48k/gti32.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/swap32.asm" ; Exchanges current DE HL with the ; ones in the stack push namespace core @@ -198,5 +203,5 @@ __SWAP32: push bc ret pop namespace -#line 94 "gti32.bas" +#line 99 "arch/zx48k/gti32.bas" END diff --git a/tests/functional/arch/zx48k/gtu16.asm b/tests/functional/arch/zx48k/gtu16.asm index 51bae3d52..5b5f880a9 100644 --- a/tests/functional/arch/zx48k/gtu16.asm +++ b/tests/functional/arch/zx48k/gtu16.asm @@ -33,6 +33,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -41,6 +42,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -49,6 +51,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -57,6 +60,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -65,6 +69,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl diff --git a/tests/functional/arch/zx48k/gtu32.asm b/tests/functional/arch/zx48k/gtu32.asm index 44ad44503..fc852db7a 100644 --- a/tests/functional/arch/zx48k/gtu32.asm +++ b/tests/functional/arch/zx48k/gtu32.asm @@ -46,6 +46,7 @@ _l: pop de sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -65,6 +66,7 @@ _l: pop de sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -84,6 +86,7 @@ _l: pop de sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -103,6 +106,7 @@ _l: pop de sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -120,6 +124,7 @@ _l: pop de sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -141,7 +146,7 @@ _l: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/swap32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/swap32.asm" ; Exchanges current DE HL with the ; ones in the stack push namespace core @@ -158,5 +163,5 @@ __SWAP32: push bc ret pop namespace -#line 111 "gtu32.bas" +#line 116 "arch/zx48k/gtu32.bas" END diff --git a/tests/functional/arch/zx48k/leu16.asm b/tests/functional/arch/zx48k/leu16.asm index 199187de8..a2f7bad97 100644 --- a/tests/functional/arch/zx48k/leu16.asm +++ b/tests/functional/arch/zx48k/leu16.asm @@ -34,6 +34,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -43,6 +44,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -52,6 +54,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -61,6 +64,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -70,6 +74,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld (_l), hl diff --git a/tests/functional/arch/zx48k/leu32.asm b/tests/functional/arch/zx48k/leu32.asm index 5a6377e0f..eca79b558 100644 --- a/tests/functional/arch/zx48k/leu32.asm +++ b/tests/functional/arch/zx48k/leu32.asm @@ -47,6 +47,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -67,6 +68,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -87,6 +89,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -107,6 +110,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -125,6 +129,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -146,7 +151,7 @@ _l: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/swap32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/swap32.asm" ; Exchanges current DE HL with the ; ones in the stack push namespace core @@ -163,5 +168,5 @@ __SWAP32: push bc ret pop namespace -#line 116 "leu32.bas" +#line 121 "arch/zx48k/leu32.bas" END diff --git a/tests/functional/arch/zx48k/leu8.asm b/tests/functional/arch/zx48k/leu8.asm index ec5714265..317e38b49 100644 --- a/tests/functional/arch/zx48k/leu8.asm +++ b/tests/functional/arch/zx48k/leu8.asm @@ -31,12 +31,14 @@ _l: sub h ccf sbc a, a + neg ld (_l), a ld a, (_level) ld hl, (_le - 1) sub h ccf sbc a, a + neg ld (_l), a ld a, (_le) push af @@ -45,6 +47,7 @@ _l: sub h ccf sbc a, a + neg ld (_l), a ld a, (_le) push af @@ -53,11 +56,13 @@ _l: sub h ccf sbc a, a + neg ld (_l), a ld a, (_level) or a ccf sbc a, a + neg ld (_l), a ld hl, 0 ld b, h diff --git a/tests/functional/arch/zx48k/ltu16.asm b/tests/functional/arch/zx48k/ltu16.asm index 729952651..f2ab53404 100644 --- a/tests/functional/arch/zx48k/ltu16.asm +++ b/tests/functional/arch/zx48k/ltu16.asm @@ -34,6 +34,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -42,6 +43,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -52,6 +54,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -63,6 +66,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -72,6 +76,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl diff --git a/tests/functional/arch/zx48k/ltu32.asm b/tests/functional/arch/zx48k/ltu32.asm index eddd3364c..88116f19b 100644 --- a/tests/functional/arch/zx48k/ltu32.asm +++ b/tests/functional/arch/zx48k/ltu32.asm @@ -41,6 +41,7 @@ _l: call .core.__SWAP32 call .core.__SUB32 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -55,6 +56,7 @@ _l: ld de, (_level + 2) call .core.__SUB32 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -69,6 +71,7 @@ _l: ld de, (_level + 2) call .core.__SUB32 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -83,6 +86,7 @@ _l: ld de, (_level + 2) call .core.__SUB32 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -97,6 +101,7 @@ _l: push bc call .core.__SUB32 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -144,7 +149,7 @@ __SUB32: exx ret pop namespace -#line 88 "arch/zx48k/ltu32.bas" +#line 93 "arch/zx48k/ltu32.bas" #line 1 "/zxbasic/src/lib/arch/zx48k/runtime/swap32.asm" ; Exchanges current DE HL with the ; ones in the stack @@ -162,5 +167,5 @@ __SWAP32: push bc ret pop namespace -#line 89 "arch/zx48k/ltu32.bas" +#line 94 "arch/zx48k/ltu32.bas" END diff --git a/tests/functional/arch/zx48k/ltu8.asm b/tests/functional/arch/zx48k/ltu8.asm index 75e5e65a6..48d1266cf 100644 --- a/tests/functional/arch/zx48k/ltu8.asm +++ b/tests/functional/arch/zx48k/ltu8.asm @@ -31,11 +31,13 @@ _l: ld a, (_le) cp h sbc a, a + neg ld (_l), a ld hl, (_level - 1) ld a, (_le) cp h sbc a, a + neg ld (_l), a ld a, (_le) push af @@ -43,17 +45,20 @@ _l: pop af cp h sbc a, a + neg ld (_l), a ld a, (_le) ld hl, (_level - 1) cp h sbc a, a + neg ld (_l), a ld a, (_level) ld h, a xor a cp h sbc a, a + neg ld (_l), a ld hl, 0 ld b, h diff --git a/tests/functional/arch/zx48k/not32.asm b/tests/functional/arch/zx48k/not32.asm index 829a128b7..3b1c355e5 100644 --- a/tests/functional/arch/zx48k/not32.asm +++ b/tests/functional/arch/zx48k/not32.asm @@ -31,6 +31,7 @@ _b: ld hl, (_a) ld de, (_a + 2) call .core.__NOT32 + neg ld (_b), a ld hl, 0 ld b, h @@ -61,5 +62,5 @@ __NOT32: ; A = ¬A sbc a, a; Gives 0 if not carry, FF otherwise ret pop namespace -#line 25 "arch/zx48k/not32.bas" +#line 26 "arch/zx48k/not32.bas" END diff --git a/tests/functional/arch/zxnext/gef16.asm b/tests/functional/arch/zxnext/gef16.asm index 01c953e58..ddebc2790 100644 --- a/tests/functional/arch/zxnext/gef16.asm +++ b/tests/functional/arch/zxnext/gef16.asm @@ -39,6 +39,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ex de, hl @@ -54,6 +55,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ex de, hl @@ -69,6 +71,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ex de, hl @@ -84,6 +87,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ex de, hl @@ -101,7 +105,7 @@ _l: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/lti32.asm" +#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/cmp/lti32.asm" #line 1 "/zxbasic/src/lib/arch/zxnext/runtime/arith/sub32.asm" ; SUB32 ; Perform TOP of the stack - DEHL @@ -128,7 +132,7 @@ __SUB32: exx ret pop namespace -#line 3 "/zxbasic/src/lib/arch/zxnext/runtime/lti32.asm" +#line 3 "/zxbasic/src/lib/arch/zxnext/runtime/cmp/lti32.asm" push namespace core __LTI32: ; Test 32 bit values in Top of the stack < HLDE PROC @@ -150,7 +154,7 @@ checkParity: ret ENDP pop namespace -#line 74 "arch/zxnext/gef16.bas" +#line 78 "arch/zxnext/gef16.bas" #line 1 "/zxbasic/src/lib/arch/zxnext/runtime/swap32.asm" ; Exchanges current DE HL with the ; ones in the stack @@ -168,5 +172,5 @@ __SWAP32: push bc ret pop namespace -#line 75 "arch/zxnext/gef16.bas" +#line 79 "arch/zxnext/gef16.bas" END diff --git a/tests/functional/arch/zxnext/gei32.asm b/tests/functional/arch/zxnext/gei32.asm index 547971c08..6b8d9bb0b 100644 --- a/tests/functional/arch/zxnext/gei32.asm +++ b/tests/functional/arch/zxnext/gei32.asm @@ -39,6 +39,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -54,6 +55,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -69,6 +71,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -84,6 +87,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -99,6 +103,7 @@ _l: call .core.__LTI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -116,7 +121,7 @@ _l: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/lti32.asm" +#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/cmp/lti32.asm" #line 1 "/zxbasic/src/lib/arch/zxnext/runtime/arith/sub32.asm" ; SUB32 ; Perform TOP of the stack - DEHL @@ -143,7 +148,7 @@ __SUB32: exx ret pop namespace -#line 3 "/zxbasic/src/lib/arch/zxnext/runtime/lti32.asm" +#line 3 "/zxbasic/src/lib/arch/zxnext/runtime/cmp/lti32.asm" push namespace core __LTI32: ; Test 32 bit values in Top of the stack < HLDE PROC @@ -165,7 +170,7 @@ checkParity: ret ENDP pop namespace -#line 89 "arch/zxnext/gei32.bas" +#line 94 "arch/zxnext/gei32.bas" #line 1 "/zxbasic/src/lib/arch/zxnext/runtime/swap32.asm" ; Exchanges current DE HL with the ; ones in the stack @@ -183,5 +188,5 @@ __SWAP32: push bc ret pop namespace -#line 90 "arch/zxnext/gei32.bas" +#line 95 "arch/zxnext/gei32.bas" END diff --git a/tests/functional/arch/zxnext/geu16.asm b/tests/functional/arch/zxnext/geu16.asm index a5f4d06c6..5395c35b6 100644 --- a/tests/functional/arch/zxnext/geu16.asm +++ b/tests/functional/arch/zxnext/geu16.asm @@ -32,6 +32,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -41,6 +42,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -52,6 +54,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -64,6 +67,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -74,6 +78,7 @@ _l: sbc hl, de ccf sbc a, a + neg ld l, a ld h, 0 ld (_l), hl diff --git a/tests/functional/arch/zxnext/geu32.asm b/tests/functional/arch/zxnext/geu32.asm index b55a443ec..8fdc17539 100644 --- a/tests/functional/arch/zxnext/geu32.asm +++ b/tests/functional/arch/zxnext/geu32.asm @@ -39,6 +39,7 @@ _l: call .core.__SUB32 ccf sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -54,6 +55,7 @@ _l: call .core.__SUB32 ccf sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -69,6 +71,7 @@ _l: call .core.__SUB32 ccf sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -84,6 +87,7 @@ _l: call .core.__SUB32 ccf sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -99,6 +103,7 @@ _l: call .core.__SUB32 ccf sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -142,7 +147,7 @@ __SUB32: exx ret pop namespace -#line 89 "arch/zxnext/geu32.bas" +#line 94 "arch/zxnext/geu32.bas" #line 1 "/zxbasic/src/lib/arch/zxnext/runtime/swap32.asm" ; Exchanges current DE HL with the ; ones in the stack @@ -160,5 +165,5 @@ __SWAP32: push bc ret pop namespace -#line 90 "arch/zxnext/geu32.bas" +#line 95 "arch/zxnext/geu32.bas" END diff --git a/tests/functional/arch/zxnext/geu8.asm b/tests/functional/arch/zxnext/geu8.asm index 68fcdcdab..9ecf7b623 100644 --- a/tests/functional/arch/zxnext/geu8.asm +++ b/tests/functional/arch/zxnext/geu8.asm @@ -29,12 +29,14 @@ _l: sub h ccf sbc a, a + neg ld (_l), a ld hl, (_level - 1) ld a, (_le) sub h ccf sbc a, a + neg ld (_l), a ld a, (_le) push af @@ -43,12 +45,14 @@ _l: sub h ccf sbc a, a + neg ld (_l), a ld a, (_le) ld hl, (_level - 1) sub h ccf sbc a, a + neg ld (_l), a ld a, (_level) ld h, a @@ -56,6 +60,7 @@ _l: sub h ccf sbc a, a + neg ld (_l), a ld hl, 0 ld b, h diff --git a/tests/functional/arch/zxnext/gtf16.asm b/tests/functional/arch/zxnext/gtf16.asm index bfda0fdde..bea145f4e 100644 --- a/tests/functional/arch/zxnext/gtf16.asm +++ b/tests/functional/arch/zxnext/gtf16.asm @@ -39,6 +39,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ex de, hl @@ -54,6 +55,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ex de, hl @@ -69,6 +71,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ex de, hl @@ -84,6 +87,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ex de, hl @@ -101,7 +105,7 @@ _l: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/lei32.asm" +#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/cmp/lei32.asm" #line 1 "/zxbasic/src/lib/arch/zxnext/runtime/arith/sub32.asm" ; SUB32 ; Perform TOP of the stack - DEHL @@ -128,7 +132,7 @@ __SUB32: exx ret pop namespace -#line 3 "/zxbasic/src/lib/arch/zxnext/runtime/lei32.asm" +#line 3 "/zxbasic/src/lib/arch/zxnext/runtime/cmp/lei32.asm" push namespace core __LEI32: ; Test 32 bit values Top of the stack <= HL,DE PROC @@ -158,7 +162,7 @@ checkParity: ret ENDP pop namespace -#line 74 "arch/zxnext/gtf16.bas" +#line 78 "arch/zxnext/gtf16.bas" #line 1 "/zxbasic/src/lib/arch/zxnext/runtime/swap32.asm" ; Exchanges current DE HL with the ; ones in the stack @@ -176,5 +180,5 @@ __SWAP32: push bc ret pop namespace -#line 75 "arch/zxnext/gtf16.bas" +#line 79 "arch/zxnext/gtf16.bas" END diff --git a/tests/functional/arch/zxnext/gti32.asm b/tests/functional/arch/zxnext/gti32.asm index 3b8686ef0..c5c11c0c6 100644 --- a/tests/functional/arch/zxnext/gti32.asm +++ b/tests/functional/arch/zxnext/gti32.asm @@ -39,6 +39,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -54,6 +55,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -69,6 +71,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -84,6 +87,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -99,6 +103,7 @@ _l: call .core.__LEI32 sub 1 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -116,7 +121,7 @@ _l: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/lei32.asm" +#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/cmp/lei32.asm" #line 1 "/zxbasic/src/lib/arch/zxnext/runtime/arith/sub32.asm" ; SUB32 ; Perform TOP of the stack - DEHL @@ -143,7 +148,7 @@ __SUB32: exx ret pop namespace -#line 3 "/zxbasic/src/lib/arch/zxnext/runtime/lei32.asm" +#line 3 "/zxbasic/src/lib/arch/zxnext/runtime/cmp/lei32.asm" push namespace core __LEI32: ; Test 32 bit values Top of the stack <= HL,DE PROC @@ -173,7 +178,7 @@ checkParity: ret ENDP pop namespace -#line 89 "arch/zxnext/gti32.bas" +#line 94 "arch/zxnext/gti32.bas" #line 1 "/zxbasic/src/lib/arch/zxnext/runtime/swap32.asm" ; Exchanges current DE HL with the ; ones in the stack @@ -191,5 +196,5 @@ __SWAP32: push bc ret pop namespace -#line 90 "arch/zxnext/gti32.bas" +#line 95 "arch/zxnext/gti32.bas" END diff --git a/tests/functional/arch/zxnext/gtu16.asm b/tests/functional/arch/zxnext/gtu16.asm index df9fe49f5..b723f52c5 100644 --- a/tests/functional/arch/zxnext/gtu16.asm +++ b/tests/functional/arch/zxnext/gtu16.asm @@ -30,6 +30,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -38,6 +39,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -46,6 +48,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -54,6 +57,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -62,6 +66,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl diff --git a/tests/functional/arch/zxnext/gtu32.asm b/tests/functional/arch/zxnext/gtu32.asm index 20cc9e923..cb6a257fc 100644 --- a/tests/functional/arch/zxnext/gtu32.asm +++ b/tests/functional/arch/zxnext/gtu32.asm @@ -43,6 +43,7 @@ _l: pop de sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -62,6 +63,7 @@ _l: pop de sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -81,6 +83,7 @@ _l: pop de sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -100,6 +103,7 @@ _l: pop de sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -117,6 +121,7 @@ _l: pop de sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -151,5 +156,5 @@ __SWAP32: push bc ret pop namespace -#line 107 "arch/zxnext/gtu32.bas" +#line 112 "arch/zxnext/gtu32.bas" END From d58b7716c72a6477785b9db69d2adb5a32fb0c6d Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Mon, 25 Nov 2024 23:52:55 +0100 Subject: [PATCH 07/13] feat: update NE operator to be bool normalized --- src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt | 3 ++- tests/functional/arch/zx48k/nef16.asm | 3 ++- tests/functional/arch/zx48k/nei16.asm | 3 +++ tests/functional/arch/zx48k/nei32.asm | 3 ++- tests/functional/arch/zx48k/nei8.asm | 3 +++ tests/functional/arch/zx48k/neu16.asm | 3 +++ tests/functional/arch/zx48k/neu32.asm | 3 ++- tests/functional/arch/zx48k/neu8.asm | 3 +++ 8 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt b/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt index 0b7980695..f2659b218 100644 --- a/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt +++ b/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt @@ -25,5 +25,6 @@ IF {{ $1 IN ("xor a", "ld a, 0", "call .core.__GEF", "call .core.__LEI16", "call .core.__LEI8", "call .core.__LTI8", "call .core.__ANDF", "call .core.__EQF", "call .core.__GTF", "call .core.__LTI16", - "call .core.__LEF", "call .core.__LEI32", "call .core.__LTF", "call .core.__LTI32") + "call .core.__LEF", "call .core.__LEI32", "call .core.__LTF", "call .core.__LTI32", + "call .core.__NEF") }} diff --git a/tests/functional/arch/zx48k/nef16.asm b/tests/functional/arch/zx48k/nef16.asm index b117170ea..63cc38bcb 100644 --- a/tests/functional/arch/zx48k/nef16.asm +++ b/tests/functional/arch/zx48k/nef16.asm @@ -31,6 +31,7 @@ _t: call .core.__EQ32 sub 1 sbc a, a + neg ld (0), a ld hl, 0 ld b, h @@ -72,5 +73,5 @@ __EQ32: ; Test if 32bit value HLDE equals top of the stack xor a ret pop namespace -#line 27 "arch/zx48k/nef16.bas" +#line 28 "arch/zx48k/nef16.bas" END diff --git a/tests/functional/arch/zx48k/nei16.asm b/tests/functional/arch/zx48k/nei16.asm index 5db465ffe..c421dcd60 100644 --- a/tests/functional/arch/zx48k/nei16.asm +++ b/tests/functional/arch/zx48k/nei16.asm @@ -28,6 +28,9 @@ _t: sbc hl, de ld a, h or l + sub 1 + sbc a, a + inc a ld (0), a ld hl, 0 ld b, h diff --git a/tests/functional/arch/zx48k/nei32.asm b/tests/functional/arch/zx48k/nei32.asm index b410b751b..d216efe91 100644 --- a/tests/functional/arch/zx48k/nei32.asm +++ b/tests/functional/arch/zx48k/nei32.asm @@ -31,6 +31,7 @@ _t: call .core.__EQ32 sub 1 sbc a, a + neg ld (0), a ld hl, 0 ld b, h @@ -72,5 +73,5 @@ __EQ32: ; Test if 32bit value HLDE equals top of the stack xor a ret pop namespace -#line 27 "arch/zx48k/nei32.bas" +#line 28 "arch/zx48k/nei32.bas" END diff --git a/tests/functional/arch/zx48k/nei8.asm b/tests/functional/arch/zx48k/nei8.asm index 273704d71..0cf4df17c 100644 --- a/tests/functional/arch/zx48k/nei8.asm +++ b/tests/functional/arch/zx48k/nei8.asm @@ -23,6 +23,9 @@ _t: .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld a, (_t) + sub 1 + sbc a, a + inc a ld (0), a ld hl, 0 ld b, h diff --git a/tests/functional/arch/zx48k/neu16.asm b/tests/functional/arch/zx48k/neu16.asm index 5db465ffe..c421dcd60 100644 --- a/tests/functional/arch/zx48k/neu16.asm +++ b/tests/functional/arch/zx48k/neu16.asm @@ -28,6 +28,9 @@ _t: sbc hl, de ld a, h or l + sub 1 + sbc a, a + inc a ld (0), a ld hl, 0 ld b, h diff --git a/tests/functional/arch/zx48k/neu32.asm b/tests/functional/arch/zx48k/neu32.asm index dcdf70832..e759843d9 100644 --- a/tests/functional/arch/zx48k/neu32.asm +++ b/tests/functional/arch/zx48k/neu32.asm @@ -31,6 +31,7 @@ _t: call .core.__EQ32 sub 1 sbc a, a + neg ld (0), a ld hl, 0 ld b, h @@ -72,5 +73,5 @@ __EQ32: ; Test if 32bit value HLDE equals top of the stack xor a ret pop namespace -#line 27 "arch/zx48k/neu32.bas" +#line 28 "arch/zx48k/neu32.bas" END diff --git a/tests/functional/arch/zx48k/neu8.asm b/tests/functional/arch/zx48k/neu8.asm index 273704d71..0cf4df17c 100644 --- a/tests/functional/arch/zx48k/neu8.asm +++ b/tests/functional/arch/zx48k/neu8.asm @@ -23,6 +23,9 @@ _t: .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld a, (_t) + sub 1 + sbc a, a + inc a ld (0), a ld hl, 0 ld b, h From a4ab332d7b79079ca67609230b3b2a31264640be Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Mon, 25 Nov 2024 23:54:21 +0100 Subject: [PATCH 08/13] feat: make NOT operant to be bool normalized --- src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt | 2 +- tests/functional/arch/zx48k/not16.asm | 1 + tests/functional/arch/zx48k/not8.asm | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt b/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt index f2659b218..4584b8e13 100644 --- a/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt +++ b/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt @@ -26,5 +26,5 @@ IF {{ "call .core.__GEF", "call .core.__LEI16", "call .core.__LEI8", "call .core.__LTI8", "call .core.__ANDF", "call .core.__EQF", "call .core.__GTF", "call .core.__LTI16", "call .core.__LEF", "call .core.__LEI32", "call .core.__LTF", "call .core.__LTI32", - "call .core.__NEF") + "call .core.__NEF", "call .core.__NOTF") }} diff --git a/tests/functional/arch/zx48k/not16.asm b/tests/functional/arch/zx48k/not16.asm index 53ad82071..a8ce1bb36 100644 --- a/tests/functional/arch/zx48k/not16.asm +++ b/tests/functional/arch/zx48k/not16.asm @@ -33,6 +33,7 @@ _b: or l sub 1 sbc a, a + neg ld (_b), a ld hl, 0 ld b, h diff --git a/tests/functional/arch/zx48k/not8.asm b/tests/functional/arch/zx48k/not8.asm index 57c273ce6..d210a9448 100644 --- a/tests/functional/arch/zx48k/not8.asm +++ b/tests/functional/arch/zx48k/not8.asm @@ -31,6 +31,7 @@ _b: ld a, (_a) sub 1 sbc a, a + neg ld (_b), a ld hl, 0 ld b, h From 7ce2707ddf989f86a25d6666fb76e6ddb52299f4 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Mon, 25 Nov 2024 23:59:10 +0100 Subject: [PATCH 09/13] feat: make OR operand bool normalized --- .../peephole/opts/020_o1_bool_norm_empty.opt | 2 +- tests/functional/arch/zx48k/or16.asm | 15 +++++++++++++ tests/functional/arch/zx48k/or32.asm | 21 ++++++++++++++++--- tests/functional/arch/zx48k/or8.asm | 15 +++++++++++++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt b/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt index 4584b8e13..c8825bbe3 100644 --- a/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt +++ b/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt @@ -26,5 +26,5 @@ IF {{ "call .core.__GEF", "call .core.__LEI16", "call .core.__LEI8", "call .core.__LTI8", "call .core.__ANDF", "call .core.__EQF", "call .core.__GTF", "call .core.__LTI16", "call .core.__LEF", "call .core.__LEI32", "call .core.__LTF", "call .core.__LTI32", - "call .core.__NEF", "call .core.__NOTF") + "call .core.__NEF", "call .core.__NOTF", "call .core.__ORF") }} diff --git a/tests/functional/arch/zx48k/or16.asm b/tests/functional/arch/zx48k/or16.asm index 8745f81b0..87d920547 100644 --- a/tests/functional/arch/zx48k/or16.asm +++ b/tests/functional/arch/zx48k/or16.asm @@ -27,16 +27,28 @@ _b: ld hl, (_a) ld a, h or l + sub 1 + sbc a, a + inc a ld (_b), a ld hl, (_a) ld a, 0FFh + sub 1 + sbc a, a + inc a ld (_b), a ld hl, (_a) ld a, h or l + sub 1 + sbc a, a + inc a ld (_b), a ld hl, (_a) ld a, 0FFh + sub 1 + sbc a, a + inc a ld (_b), a ld de, (_a) ld hl, (_a) @@ -44,6 +56,9 @@ _b: or l or d or e + sub 1 + sbc a, a + inc a ld (_b), a ld hl, 0 ld b, h diff --git a/tests/functional/arch/zx48k/or32.asm b/tests/functional/arch/zx48k/or32.asm index ab8527a96..e80338794 100644 --- a/tests/functional/arch/zx48k/or32.asm +++ b/tests/functional/arch/zx48k/or32.asm @@ -31,6 +31,9 @@ _b: ld de, 0 ld hl, 0 call .core.__OR32 + sub 1 + sbc a, a + inc a ld (_b), a ld hl, (_a + 2) push hl @@ -39,6 +42,9 @@ _b: ld de, 0 ld hl, 1 call .core.__OR32 + sub 1 + sbc a, a + inc a ld (_b), a ld hl, (_a) ld de, (_a + 2) @@ -47,6 +53,9 @@ _b: ld bc, 0 push bc call .core.__OR32 + sub 1 + sbc a, a + inc a ld (_b), a ld hl, (_a) ld de, (_a + 2) @@ -55,6 +64,9 @@ _b: ld bc, 1 push bc call .core.__OR32 + sub 1 + sbc a, a + inc a ld (_b), a ld hl, (_a + 2) push hl @@ -63,6 +75,9 @@ _b: ld hl, (_a) ld de, (_a + 2) call .core.__OR32 + sub 1 + sbc a, a + inc a ld (_b), a ld hl, 0 ld b, h @@ -79,7 +94,7 @@ _b: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/or32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bool/or32.asm" push namespace core __OR32: ; Performs logical operation A AND B ; between DEHL and TOP of the stack. @@ -95,8 +110,8 @@ __OR32: ; Performs logical operation A AND B or e or h or l -#line 26 "/zxbasic/src/arch/zx48k/library-asm/or32.asm" +#line 26 "/zxbasic/src/lib/arch/zx48k/runtime/bool/or32.asm" ret pop namespace -#line 57 "or32.bas" +#line 72 "arch/zx48k/or32.bas" END diff --git a/tests/functional/arch/zx48k/or8.asm b/tests/functional/arch/zx48k/or8.asm index 666849d5a..e7c92e3da 100644 --- a/tests/functional/arch/zx48k/or8.asm +++ b/tests/functional/arch/zx48k/or8.asm @@ -25,18 +25,33 @@ _b: .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld a, (_a) + sub 1 + sbc a, a + inc a ld (_b), a ld a, (_a) ld a, 1 + sub 1 + sbc a, a + inc a ld (_b), a ld a, (_a) + sub 1 + sbc a, a + inc a ld (_b), a ld a, (_a) ld a, 1 + sub 1 + sbc a, a + inc a ld (_b), a ld hl, (_a - 1) ld a, (_a) or h + sub 1 + sbc a, a + inc a ld (_b), a ld hl, 0 ld b, h From 2d1dbaefe041a86b58ca948b648536e756ebb2f5 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Tue, 26 Nov 2024 00:14:12 +0100 Subject: [PATCH 10/13] feat: make XOR bool normalized --- .../peephole/opts/020_o1_bool_norm_empty.opt | 2 +- .../z80/peephole/opts/021_o1_bool_norm_neg.opt | 3 +-- tests/functional/arch/zx48k/xor16.asm | 17 +++++++++++++---- tests/functional/arch/zx48k/xor32.asm | 13 +++++++++---- tests/functional/arch/zx48k/xor8.asm | 13 +++++++++++-- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt b/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt index c8825bbe3..63679e28c 100644 --- a/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt +++ b/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt @@ -26,5 +26,5 @@ IF {{ "call .core.__GEF", "call .core.__LEI16", "call .core.__LEI8", "call .core.__LTI8", "call .core.__ANDF", "call .core.__EQF", "call .core.__GTF", "call .core.__LTI16", "call .core.__LEF", "call .core.__LEI32", "call .core.__LTF", "call .core.__LTI32", - "call .core.__NEF", "call .core.__NOTF", "call .core.__ORF") + "call .core.__NEF", "call .core.__NOTF", "call .core.__ORF", "call .core.__XORF") }} diff --git a/src/arch/z80/peephole/opts/021_o1_bool_norm_neg.opt b/src/arch/z80/peephole/opts/021_o1_bool_norm_neg.opt index ac02d3044..dc7f71d37 100644 --- a/src/arch/z80/peephole/opts/021_o1_bool_norm_neg.opt +++ b/src/arch/z80/peephole/opts/021_o1_bool_norm_neg.opt @@ -22,6 +22,5 @@ WITH {{ }} IF {{ - $1 == "sbc a, a" || - $1 == "call .core.__NOT32" + $1 IN ("sbc a, a", "call .core.__NOT32", "call .core.__XOR8", "call .core.__XOR16", "call .core.__XOR32") }} diff --git a/tests/functional/arch/zx48k/xor16.asm b/tests/functional/arch/zx48k/xor16.asm index 90c96b860..32701f831 100644 --- a/tests/functional/arch/zx48k/xor16.asm +++ b/tests/functional/arch/zx48k/xor16.asm @@ -27,26 +27,35 @@ _b: ld hl, (_a) ld a, h or l + sub 1 + sbc a, a + inc a ld (_b), a ld hl, (_a) ld a, h or l sub 1 sbc a, a + neg ld (_b), a ld hl, (_a) ld a, h or l + sub 1 + sbc a, a + inc a ld (_b), a ld hl, (_a) ld a, h or l sub 1 sbc a, a + neg ld (_b), a ld de, (_a) ld hl, (_a) call .core.__XOR16 + neg ld (_b), a ld hl, 0 ld b, h @@ -63,9 +72,9 @@ _b: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/xor16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bool/xor16.asm" ; XOR16 implemented in XOR8.ASM file -#line 1 "/zxbasic/src/arch/zx48k/library-asm/xor8.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bool/xor8.asm" ; vim:ts=4:et: ; FASTCALL boolean xor 8 version. ; result in Accumulator (0 False, not 0 True) @@ -88,6 +97,6 @@ __XOR8: xor l ret pop namespace -#line 4 "/zxbasic/src/arch/zx48k/library-asm/xor16.asm" -#line 41 "xor16.bas" +#line 4 "/zxbasic/src/lib/arch/zx48k/runtime/bool/xor16.asm" +#line 50 "arch/zx48k/xor16.bas" END diff --git a/tests/functional/arch/zx48k/xor32.asm b/tests/functional/arch/zx48k/xor32.asm index 6bd0d98f7..ae23a362d 100644 --- a/tests/functional/arch/zx48k/xor32.asm +++ b/tests/functional/arch/zx48k/xor32.asm @@ -31,6 +31,7 @@ _b: ld de, 0 ld hl, 0 call .core.__XOR32 + neg ld (_b), a ld hl, (_a + 2) push hl @@ -39,6 +40,7 @@ _b: ld de, 0 ld hl, 1 call .core.__XOR32 + neg ld (_b), a ld hl, (_a) ld de, (_a + 2) @@ -47,6 +49,7 @@ _b: ld bc, 0 push bc call .core.__XOR32 + neg ld (_b), a ld hl, (_a) ld de, (_a + 2) @@ -55,6 +58,7 @@ _b: ld bc, 1 push bc call .core.__XOR32 + neg ld (_b), a ld hl, (_a + 2) push hl @@ -63,6 +67,7 @@ _b: ld hl, (_a) ld de, (_a + 2) call .core.__XOR32 + neg ld (_b), a ld hl, 0 ld b, h @@ -79,12 +84,12 @@ _b: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/xor32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bool/xor32.asm" ; FASTCALL boolean xor 8 version. ; result in Accumulator (0 False, not 0 True) ; __FASTCALL__ version (operands: A, H) ; Performs 32bit xor 32bit and returns the boolean -#line 1 "/zxbasic/src/arch/zx48k/library-asm/xor8.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bool/xor8.asm" ; vim:ts=4:et: ; FASTCALL boolean xor 8 version. ; result in Accumulator (0 False, not 0 True) @@ -107,7 +112,7 @@ __XOR8: xor l ret pop namespace -#line 7 "/zxbasic/src/arch/zx48k/library-asm/xor32.asm" +#line 7 "/zxbasic/src/lib/arch/zx48k/runtime/bool/xor32.asm" push namespace core __XOR32: ld a, h @@ -125,5 +130,5 @@ __XOR32: ld h, c jp __XOR8 pop namespace -#line 57 "xor32.bas" +#line 62 "arch/zx48k/xor32.bas" END diff --git a/tests/functional/arch/zx48k/xor8.asm b/tests/functional/arch/zx48k/xor8.asm index 6fe10b2ef..1cf54ce1b 100644 --- a/tests/functional/arch/zx48k/xor8.asm +++ b/tests/functional/arch/zx48k/xor8.asm @@ -25,20 +25,29 @@ _b: .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld a, (_a) + sub 1 + sbc a, a + inc a ld (_b), a ld a, (_a) sub 1 sbc a, a + neg ld (_b), a ld a, (_a) + sub 1 + sbc a, a + inc a ld (_b), a ld a, (_a) sub 1 sbc a, a + neg ld (_b), a ld hl, (_a - 1) ld a, (_a) call .core.__XOR8 + neg ld (_b), a ld hl, 0 ld b, h @@ -55,7 +64,7 @@ _b: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/xor8.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bool/xor8.asm" ; vim:ts=4:et: ; FASTCALL boolean xor 8 version. ; result in Accumulator (0 False, not 0 True) @@ -78,5 +87,5 @@ __XOR8: xor l ret pop namespace -#line 33 "xor8.bas" +#line 42 "arch/zx48k/xor8.bas" END From 8c30906d48bc8a00525f8c7a026ecd4d117c695a Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Tue, 26 Nov 2024 00:16:25 +0100 Subject: [PATCH 11/13] test: update zxnext tests --- tests/functional/arch/zxnext/leu8.asm | 5 +++++ tests/functional/arch/zxnext/ltu16.asm | 5 +++++ tests/functional/arch/zxnext/ltu32.asm | 9 +++++++-- tests/functional/arch/zxnext/ltu8.asm | 5 +++++ tests/functional/arch/zxnext/nef16.asm | 3 ++- tests/functional/arch/zxnext/nei16.asm | 3 +++ tests/functional/arch/zxnext/nei32.asm | 3 ++- tests/functional/arch/zxnext/nei8.asm | 3 +++ tests/functional/arch/zxnext/neu16.asm | 3 +++ tests/functional/arch/zxnext/neu32.asm | 3 ++- tests/functional/arch/zxnext/neu8.asm | 3 +++ 11 files changed, 40 insertions(+), 5 deletions(-) diff --git a/tests/functional/arch/zxnext/leu8.asm b/tests/functional/arch/zxnext/leu8.asm index 45c3dcdfa..f4c9678a8 100644 --- a/tests/functional/arch/zxnext/leu8.asm +++ b/tests/functional/arch/zxnext/leu8.asm @@ -28,12 +28,14 @@ _l: sub h ccf sbc a, a + neg ld (_l), a ld a, (_level) ld hl, (_le - 1) sub h ccf sbc a, a + neg ld (_l), a ld a, (_le) push af @@ -42,6 +44,7 @@ _l: sub h ccf sbc a, a + neg ld (_l), a ld a, (_le) push af @@ -50,11 +53,13 @@ _l: sub h ccf sbc a, a + neg ld (_l), a ld a, (_level) or a ccf sbc a, a + neg ld (_l), a ld hl, 0 ld b, h diff --git a/tests/functional/arch/zxnext/ltu16.asm b/tests/functional/arch/zxnext/ltu16.asm index b13bfbe21..323aece6d 100644 --- a/tests/functional/arch/zxnext/ltu16.asm +++ b/tests/functional/arch/zxnext/ltu16.asm @@ -31,6 +31,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -39,6 +40,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -49,6 +51,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -60,6 +63,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl @@ -69,6 +73,7 @@ _l: or a sbc hl, de sbc a, a + neg ld l, a ld h, 0 ld (_l), hl diff --git a/tests/functional/arch/zxnext/ltu32.asm b/tests/functional/arch/zxnext/ltu32.asm index 485667aa2..0ce158060 100644 --- a/tests/functional/arch/zxnext/ltu32.asm +++ b/tests/functional/arch/zxnext/ltu32.asm @@ -38,6 +38,7 @@ _l: call .core.__SWAP32 call .core.__SUB32 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -52,6 +53,7 @@ _l: ld de, (_level + 2) call .core.__SUB32 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -66,6 +68,7 @@ _l: ld de, (_level + 2) call .core.__SUB32 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -80,6 +83,7 @@ _l: ld de, (_level + 2) call .core.__SUB32 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -94,6 +98,7 @@ _l: push bc call .core.__SUB32 sbc a, a + neg ld l, a ld h, 0 ld e, h @@ -137,7 +142,7 @@ __SUB32: exx ret pop namespace -#line 84 "arch/zxnext/ltu32.bas" +#line 89 "arch/zxnext/ltu32.bas" #line 1 "/zxbasic/src/lib/arch/zxnext/runtime/swap32.asm" ; Exchanges current DE HL with the ; ones in the stack @@ -155,5 +160,5 @@ __SWAP32: push bc ret pop namespace -#line 85 "arch/zxnext/ltu32.bas" +#line 90 "arch/zxnext/ltu32.bas" END diff --git a/tests/functional/arch/zxnext/ltu8.asm b/tests/functional/arch/zxnext/ltu8.asm index e2fa7ddb8..86f2eb562 100644 --- a/tests/functional/arch/zxnext/ltu8.asm +++ b/tests/functional/arch/zxnext/ltu8.asm @@ -28,11 +28,13 @@ _l: ld a, (_le) cp h sbc a, a + neg ld (_l), a ld hl, (_level - 1) ld a, (_le) cp h sbc a, a + neg ld (_l), a ld a, (_le) push af @@ -40,17 +42,20 @@ _l: pop af cp h sbc a, a + neg ld (_l), a ld a, (_le) ld hl, (_level - 1) cp h sbc a, a + neg ld (_l), a ld a, (_level) ld h, a xor a cp h sbc a, a + neg ld (_l), a ld hl, 0 ld b, h diff --git a/tests/functional/arch/zxnext/nef16.asm b/tests/functional/arch/zxnext/nef16.asm index 42ca9bc2a..e7db86298 100644 --- a/tests/functional/arch/zxnext/nef16.asm +++ b/tests/functional/arch/zxnext/nef16.asm @@ -28,6 +28,7 @@ _t: call .core.__EQ32 sub 1 sbc a, a + neg ld (0), a ld hl, 0 ld b, h @@ -65,5 +66,5 @@ __EQ32: ; Test if 32bit value HLDE equals top of the stack xor a ret pop namespace -#line 23 "arch/zxnext/nef16.bas" +#line 24 "arch/zxnext/nef16.bas" END diff --git a/tests/functional/arch/zxnext/nei16.asm b/tests/functional/arch/zxnext/nei16.asm index 5a8db79f6..e4d62f530 100644 --- a/tests/functional/arch/zxnext/nei16.asm +++ b/tests/functional/arch/zxnext/nei16.asm @@ -25,6 +25,9 @@ _t: sbc hl, de ld a, h or l + sub 1 + sbc a, a + inc a ld (0), a ld hl, 0 ld b, h diff --git a/tests/functional/arch/zxnext/nei32.asm b/tests/functional/arch/zxnext/nei32.asm index aa77d53c6..1b5c36f1c 100644 --- a/tests/functional/arch/zxnext/nei32.asm +++ b/tests/functional/arch/zxnext/nei32.asm @@ -28,6 +28,7 @@ _t: call .core.__EQ32 sub 1 sbc a, a + neg ld (0), a ld hl, 0 ld b, h @@ -65,5 +66,5 @@ __EQ32: ; Test if 32bit value HLDE equals top of the stack xor a ret pop namespace -#line 23 "arch/zxnext/nei32.bas" +#line 24 "arch/zxnext/nei32.bas" END diff --git a/tests/functional/arch/zxnext/nei8.asm b/tests/functional/arch/zxnext/nei8.asm index 022116094..1d2ca4656 100644 --- a/tests/functional/arch/zxnext/nei8.asm +++ b/tests/functional/arch/zxnext/nei8.asm @@ -20,6 +20,9 @@ _t: .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld a, (_t) + sub 1 + sbc a, a + inc a ld (0), a ld hl, 0 ld b, h diff --git a/tests/functional/arch/zxnext/neu16.asm b/tests/functional/arch/zxnext/neu16.asm index 5a8db79f6..e4d62f530 100644 --- a/tests/functional/arch/zxnext/neu16.asm +++ b/tests/functional/arch/zxnext/neu16.asm @@ -25,6 +25,9 @@ _t: sbc hl, de ld a, h or l + sub 1 + sbc a, a + inc a ld (0), a ld hl, 0 ld b, h diff --git a/tests/functional/arch/zxnext/neu32.asm b/tests/functional/arch/zxnext/neu32.asm index 68eedbb96..4b9de524b 100644 --- a/tests/functional/arch/zxnext/neu32.asm +++ b/tests/functional/arch/zxnext/neu32.asm @@ -28,6 +28,7 @@ _t: call .core.__EQ32 sub 1 sbc a, a + neg ld (0), a ld hl, 0 ld b, h @@ -65,5 +66,5 @@ __EQ32: ; Test if 32bit value HLDE equals top of the stack xor a ret pop namespace -#line 23 "arch/zxnext/neu32.bas" +#line 24 "arch/zxnext/neu32.bas" END diff --git a/tests/functional/arch/zxnext/neu8.asm b/tests/functional/arch/zxnext/neu8.asm index 022116094..1d2ca4656 100644 --- a/tests/functional/arch/zxnext/neu8.asm +++ b/tests/functional/arch/zxnext/neu8.asm @@ -20,6 +20,9 @@ _t: .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld a, (_t) + sub 1 + sbc a, a + inc a ld (0), a ld hl, 0 ld b, h From 2f5702868778bc26f8a508062d7f60c3c88fc240 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Tue, 26 Nov 2024 23:13:03 +0100 Subject: [PATCH 12/13] feat: make STRING operators bool normalized --- .../peephole/opts/020_o1_bool_norm_empty.opt | 4 +- src/lib/arch/zx48k/runtime/string.asm | 16 +++++--- tests/functional/arch/zx48k/streq00.asm | 16 +++++--- tests/functional/arch/zx48k/strge00.asm | 16 +++++--- tests/functional/arch/zx48k/strgt00.asm | 16 +++++--- tests/functional/arch/zx48k/strict_bool.asm | 40 +++++++------------ tests/functional/arch/zx48k/strle00.asm | 16 +++++--- tests/functional/arch/zx48k/strlt00.asm | 16 +++++--- tests/functional/arch/zx48k/strne00.asm | 16 +++++--- 9 files changed, 87 insertions(+), 69 deletions(-) diff --git a/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt b/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt index 63679e28c..07acaf1ae 100644 --- a/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt +++ b/src/arch/z80/peephole/opts/020_o1_bool_norm_empty.opt @@ -26,5 +26,7 @@ IF {{ "call .core.__GEF", "call .core.__LEI16", "call .core.__LEI8", "call .core.__LTI8", "call .core.__ANDF", "call .core.__EQF", "call .core.__GTF", "call .core.__LTI16", "call .core.__LEF", "call .core.__LEI32", "call .core.__LTF", "call .core.__LTI32", - "call .core.__NEF", "call .core.__NOTF", "call .core.__ORF", "call .core.__XORF") + "call .core.__NEF", "call .core.__NOTF", "call .core.__ORF", "call .core.__XORF", + "call .core.__STREQ", "call .core.__STRNE", "call .core.__STRLT", "call .core.__STRLE", + "call .core.__STRGT", "call .core.__STRGE") }} diff --git a/src/lib/arch/zx48k/runtime/string.asm b/src/lib/arch/zx48k/runtime/string.asm index 0631c2a85..31321ea7b 100644 --- a/src/lib/arch/zx48k/runtime/string.asm +++ b/src/lib/arch/zx48k/runtime/string.asm @@ -126,11 +126,11 @@ __STREQ: ; Compares a$ == b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 pop de pop hl sub 1 - sbc a, a + sbc a, a ; 0 if A register was 0, 0xFF if A was 1 or -1 jp __FREE_STR -__STRNE: ; Compares a$ != b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRNE: ; Compares a$ != b$ (HL = ptr a$, DE = ptr b$). Returns 1 (True) or 0 (False) push hl push de call __STRCMP @@ -139,7 +139,7 @@ __STRNE: ; Compares a$ != b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 jp __FREE_STR -__STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FE (True) or 0 (False) push hl push de call __STRCMP @@ -152,7 +152,7 @@ __STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 ( jp __FREE_STR -__STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF or FE (True) or 0 (False) push hl push de call __STRCMP @@ -163,7 +163,7 @@ __STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 jp __FREE_STR -__STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns 2 (True) or 0 (False) push hl push de call __STRCMP @@ -176,7 +176,7 @@ __STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 ( jp __FREE_STR -__STRGE: ; Compares a$ >= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRGE: ; Compares a$ >= b$ (HL = ptr a$, DE = ptr b$). Returns 1 or 2 (True) or 0 (False) push hl push de call __STRCMP @@ -193,6 +193,10 @@ __FREE_STR: ; This exit point will test A' for bits 0 and 1 LOCAL __FREE_STR2 LOCAL __FREE_END + ;; normalize boolean + sub 1 + sbc a, a + inc a ex af, af' bit 0, a diff --git a/tests/functional/arch/zx48k/streq00.asm b/tests/functional/arch/zx48k/streq00.asm index e5a29e5a0..b2e962c67 100644 --- a/tests/functional/arch/zx48k/streq00.asm +++ b/tests/functional/arch/zx48k/streq00.asm @@ -1020,16 +1020,16 @@ __STREQ: ; Compares a$ == b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 pop de pop hl sub 1 - sbc a, a + sbc a, a ; 0 if A register was 0, 0xFF if A was 1 or -1 jp __FREE_STR -__STRNE: ; Compares a$ != b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRNE: ; Compares a$ != b$ (HL = ptr a$, DE = ptr b$). Returns 1 (True) or 0 (False) push hl push de call __STRCMP pop de pop hl jp __FREE_STR -__STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FE (True) or 0 (False) push hl push de call __STRCMP @@ -1039,7 +1039,7 @@ __STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 ( jp z, __FREE_STR ; Returns 0 if A == B dec a ; Returns 0 if A == 1 => a$ > b$ jp __FREE_STR -__STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF or FE (True) or 0 (False) push hl push de call __STRCMP @@ -1047,7 +1047,7 @@ __STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 pop hl dec a ; Returns 0 if A == 1 => a$ < b$ jp __FREE_STR -__STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns 2 (True) or 0 (False) push hl push de call __STRCMP @@ -1057,7 +1057,7 @@ __STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 ( jp z, __FREE_STR ; Returns 0 if A == B inc a ; Returns 0 if A == -1 => a$ < b$ jp __FREE_STR -__STRGE: ; Compares a$ >= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRGE: ; Compares a$ >= b$ (HL = ptr a$, DE = ptr b$). Returns 1 or 2 (True) or 0 (False) push hl push de call __STRCMP @@ -1071,6 +1071,10 @@ __FREE_STR: ; This exit point will test A' for bits 0 and 1 PROC LOCAL __FREE_STR2 LOCAL __FREE_END + ;; normalize boolean + sub 1 + sbc a, a + inc a ex af, af' bit 0, a jr z, __FREE_STR2 diff --git a/tests/functional/arch/zx48k/strge00.asm b/tests/functional/arch/zx48k/strge00.asm index 9b37c9679..13eaebc85 100644 --- a/tests/functional/arch/zx48k/strge00.asm +++ b/tests/functional/arch/zx48k/strge00.asm @@ -1020,16 +1020,16 @@ __STREQ: ; Compares a$ == b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 pop de pop hl sub 1 - sbc a, a + sbc a, a ; 0 if A register was 0, 0xFF if A was 1 or -1 jp __FREE_STR -__STRNE: ; Compares a$ != b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRNE: ; Compares a$ != b$ (HL = ptr a$, DE = ptr b$). Returns 1 (True) or 0 (False) push hl push de call __STRCMP pop de pop hl jp __FREE_STR -__STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FE (True) or 0 (False) push hl push de call __STRCMP @@ -1039,7 +1039,7 @@ __STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 ( jp z, __FREE_STR ; Returns 0 if A == B dec a ; Returns 0 if A == 1 => a$ > b$ jp __FREE_STR -__STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF or FE (True) or 0 (False) push hl push de call __STRCMP @@ -1047,7 +1047,7 @@ __STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 pop hl dec a ; Returns 0 if A == 1 => a$ < b$ jp __FREE_STR -__STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns 2 (True) or 0 (False) push hl push de call __STRCMP @@ -1057,7 +1057,7 @@ __STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 ( jp z, __FREE_STR ; Returns 0 if A == B inc a ; Returns 0 if A == -1 => a$ < b$ jp __FREE_STR -__STRGE: ; Compares a$ >= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRGE: ; Compares a$ >= b$ (HL = ptr a$, DE = ptr b$). Returns 1 or 2 (True) or 0 (False) push hl push de call __STRCMP @@ -1071,6 +1071,10 @@ __FREE_STR: ; This exit point will test A' for bits 0 and 1 PROC LOCAL __FREE_STR2 LOCAL __FREE_END + ;; normalize boolean + sub 1 + sbc a, a + inc a ex af, af' bit 0, a jr z, __FREE_STR2 diff --git a/tests/functional/arch/zx48k/strgt00.asm b/tests/functional/arch/zx48k/strgt00.asm index 11573c746..c73282dcc 100644 --- a/tests/functional/arch/zx48k/strgt00.asm +++ b/tests/functional/arch/zx48k/strgt00.asm @@ -1020,16 +1020,16 @@ __STREQ: ; Compares a$ == b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 pop de pop hl sub 1 - sbc a, a + sbc a, a ; 0 if A register was 0, 0xFF if A was 1 or -1 jp __FREE_STR -__STRNE: ; Compares a$ != b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRNE: ; Compares a$ != b$ (HL = ptr a$, DE = ptr b$). Returns 1 (True) or 0 (False) push hl push de call __STRCMP pop de pop hl jp __FREE_STR -__STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FE (True) or 0 (False) push hl push de call __STRCMP @@ -1039,7 +1039,7 @@ __STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 ( jp z, __FREE_STR ; Returns 0 if A == B dec a ; Returns 0 if A == 1 => a$ > b$ jp __FREE_STR -__STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF or FE (True) or 0 (False) push hl push de call __STRCMP @@ -1047,7 +1047,7 @@ __STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 pop hl dec a ; Returns 0 if A == 1 => a$ < b$ jp __FREE_STR -__STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns 2 (True) or 0 (False) push hl push de call __STRCMP @@ -1057,7 +1057,7 @@ __STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 ( jp z, __FREE_STR ; Returns 0 if A == B inc a ; Returns 0 if A == -1 => a$ < b$ jp __FREE_STR -__STRGE: ; Compares a$ >= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRGE: ; Compares a$ >= b$ (HL = ptr a$, DE = ptr b$). Returns 1 or 2 (True) or 0 (False) push hl push de call __STRCMP @@ -1071,6 +1071,10 @@ __FREE_STR: ; This exit point will test A' for bits 0 and 1 PROC LOCAL __FREE_STR2 LOCAL __FREE_END + ;; normalize boolean + sub 1 + sbc a, a + inc a ex af, af' bit 0, a jr z, __FREE_STR2 diff --git a/tests/functional/arch/zx48k/strict_bool.asm b/tests/functional/arch/zx48k/strict_bool.asm index 5014400ff..ba1df01c5 100644 --- a/tests/functional/arch/zx48k/strict_bool.asm +++ b/tests/functional/arch/zx48k/strict_bool.asm @@ -28,7 +28,6 @@ _a: ld de, 00020h ld bc, 00000h call .core.__LTF - call .core.__NORMALIZE_BOOLEAN call .core.__U8TOFREG ld hl, _a call .core.__STOREF @@ -47,9 +46,9 @@ _a: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/ltf.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/u32tofreg.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/neg32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/ltf.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/u32tofreg.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/neg32.asm" push namespace core __ABS32: bit 7, d @@ -74,7 +73,7 @@ __NEG32: ; Negates DEHL (Two's complement) inc de ret pop namespace -#line 2 "/zxbasic/src/arch/zx48k/library-asm/u32tofreg.asm" +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/u32tofreg.asm" push namespace core __I8TOFREG: ld l, a @@ -144,8 +143,8 @@ __U32TOFREG_END: ret ENDP pop namespace -#line 2 "/zxbasic/src/arch/zx48k/library-asm/ltf.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/ftou32reg.asm" +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/ltf.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/ftou32reg.asm" push namespace core __FTOU32REG: ; Converts a Float to (un)signed 32 bit integer (NOTE: It's ALWAYS 32 bit signed) ; Input FP number in A EDCB (A exponent, EDCB mantissa) @@ -217,8 +216,8 @@ __FTOU8: ; Converts float in C ED LH to Unsigned byte in A ld a, l ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/ltf.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/stackf.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/ltf.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/stackf.asm" ; ------------------------------------------------------------- ; Functions to manage FP-Stack of the ZX Spectrum ROM CALC ; ------------------------------------------------------------- @@ -257,7 +256,7 @@ __FPSTACK_I16: ; Pushes 16 bits integer in HL into the FP ROM STACK ld b, a jp __FPSTACK_PUSH pop namespace -#line 4 "/zxbasic/src/arch/zx48k/library-asm/ltf.asm" +#line 4 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/ltf.asm" ; ------------------------------------------------------------- ; Floating point library using the FP ROM Calculator (ZX 48K) ; All of them uses A EDCB registers as 1st paramter. @@ -277,8 +276,8 @@ __LTF: ; A < B call __FPSTACK_POP jp __FTOU8 ; Convert to 8 bits pop namespace -#line 27 "strict_bool.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/pushf.asm" +#line 26 "arch/zx48k/strict_bool.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/pushf.asm" ; Routine to push Float pointed by HL ; Into the stack. Notice that the hl points to the last ; byte of the FP number. @@ -305,8 +304,8 @@ __FP_PUSH_REV: exx ret pop namespace -#line 28 "strict_bool.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/storef.asm" +#line 27 "arch/zx48k/strict_bool.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storef.asm" push namespace core __PISTOREF: ; Indect Stores a float (A, E, D, C, B) at location stored in memory, pointed by (IX + HL) push de @@ -334,16 +333,5 @@ __STOREF: ; Stores the given FP number in A EDCB at address HL ld (hl), b ret pop namespace -#line 29 "strict_bool.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/strictbool.asm" - ; This routine is called if --strict-boolean was set at the command line. - ; It will make any boolean result to be always 0 or 1 - push namespace core -__NORMALIZE_BOOLEAN: - or a - ret z - ld a, 1 - ret - pop namespace -#line 30 "strict_bool.bas" +#line 28 "arch/zx48k/strict_bool.bas" END diff --git a/tests/functional/arch/zx48k/strle00.asm b/tests/functional/arch/zx48k/strle00.asm index 94b047476..a3b4bb994 100644 --- a/tests/functional/arch/zx48k/strle00.asm +++ b/tests/functional/arch/zx48k/strle00.asm @@ -1020,16 +1020,16 @@ __STREQ: ; Compares a$ == b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 pop de pop hl sub 1 - sbc a, a + sbc a, a ; 0 if A register was 0, 0xFF if A was 1 or -1 jp __FREE_STR -__STRNE: ; Compares a$ != b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRNE: ; Compares a$ != b$ (HL = ptr a$, DE = ptr b$). Returns 1 (True) or 0 (False) push hl push de call __STRCMP pop de pop hl jp __FREE_STR -__STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FE (True) or 0 (False) push hl push de call __STRCMP @@ -1039,7 +1039,7 @@ __STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 ( jp z, __FREE_STR ; Returns 0 if A == B dec a ; Returns 0 if A == 1 => a$ > b$ jp __FREE_STR -__STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF or FE (True) or 0 (False) push hl push de call __STRCMP @@ -1047,7 +1047,7 @@ __STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 pop hl dec a ; Returns 0 if A == 1 => a$ < b$ jp __FREE_STR -__STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns 2 (True) or 0 (False) push hl push de call __STRCMP @@ -1057,7 +1057,7 @@ __STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 ( jp z, __FREE_STR ; Returns 0 if A == B inc a ; Returns 0 if A == -1 => a$ < b$ jp __FREE_STR -__STRGE: ; Compares a$ >= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRGE: ; Compares a$ >= b$ (HL = ptr a$, DE = ptr b$). Returns 1 or 2 (True) or 0 (False) push hl push de call __STRCMP @@ -1071,6 +1071,10 @@ __FREE_STR: ; This exit point will test A' for bits 0 and 1 PROC LOCAL __FREE_STR2 LOCAL __FREE_END + ;; normalize boolean + sub 1 + sbc a, a + inc a ex af, af' bit 0, a jr z, __FREE_STR2 diff --git a/tests/functional/arch/zx48k/strlt00.asm b/tests/functional/arch/zx48k/strlt00.asm index 7f2ead39f..276662b03 100644 --- a/tests/functional/arch/zx48k/strlt00.asm +++ b/tests/functional/arch/zx48k/strlt00.asm @@ -1020,16 +1020,16 @@ __STREQ: ; Compares a$ == b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 pop de pop hl sub 1 - sbc a, a + sbc a, a ; 0 if A register was 0, 0xFF if A was 1 or -1 jp __FREE_STR -__STRNE: ; Compares a$ != b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRNE: ; Compares a$ != b$ (HL = ptr a$, DE = ptr b$). Returns 1 (True) or 0 (False) push hl push de call __STRCMP pop de pop hl jp __FREE_STR -__STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FE (True) or 0 (False) push hl push de call __STRCMP @@ -1039,7 +1039,7 @@ __STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 ( jp z, __FREE_STR ; Returns 0 if A == B dec a ; Returns 0 if A == 1 => a$ > b$ jp __FREE_STR -__STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF or FE (True) or 0 (False) push hl push de call __STRCMP @@ -1047,7 +1047,7 @@ __STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 pop hl dec a ; Returns 0 if A == 1 => a$ < b$ jp __FREE_STR -__STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns 2 (True) or 0 (False) push hl push de call __STRCMP @@ -1057,7 +1057,7 @@ __STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 ( jp z, __FREE_STR ; Returns 0 if A == B inc a ; Returns 0 if A == -1 => a$ < b$ jp __FREE_STR -__STRGE: ; Compares a$ >= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRGE: ; Compares a$ >= b$ (HL = ptr a$, DE = ptr b$). Returns 1 or 2 (True) or 0 (False) push hl push de call __STRCMP @@ -1071,6 +1071,10 @@ __FREE_STR: ; This exit point will test A' for bits 0 and 1 PROC LOCAL __FREE_STR2 LOCAL __FREE_END + ;; normalize boolean + sub 1 + sbc a, a + inc a ex af, af' bit 0, a jr z, __FREE_STR2 diff --git a/tests/functional/arch/zx48k/strne00.asm b/tests/functional/arch/zx48k/strne00.asm index 5736ca2f7..cb6c13891 100644 --- a/tests/functional/arch/zx48k/strne00.asm +++ b/tests/functional/arch/zx48k/strne00.asm @@ -1020,16 +1020,16 @@ __STREQ: ; Compares a$ == b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 pop de pop hl sub 1 - sbc a, a + sbc a, a ; 0 if A register was 0, 0xFF if A was 1 or -1 jp __FREE_STR -__STRNE: ; Compares a$ != b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRNE: ; Compares a$ != b$ (HL = ptr a$, DE = ptr b$). Returns 1 (True) or 0 (False) push hl push de call __STRCMP pop de pop hl jp __FREE_STR -__STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FE (True) or 0 (False) push hl push de call __STRCMP @@ -1039,7 +1039,7 @@ __STRLT: ; Compares a$ < b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 ( jp z, __FREE_STR ; Returns 0 if A == B dec a ; Returns 0 if A == 1 => a$ > b$ jp __FREE_STR -__STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF or FE (True) or 0 (False) push hl push de call __STRCMP @@ -1047,7 +1047,7 @@ __STRLE: ; Compares a$ <= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 pop hl dec a ; Returns 0 if A == 1 => a$ < b$ jp __FREE_STR -__STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns 2 (True) or 0 (False) push hl push de call __STRCMP @@ -1057,7 +1057,7 @@ __STRGT: ; Compares a$ > b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 ( jp z, __FREE_STR ; Returns 0 if A == B inc a ; Returns 0 if A == -1 => a$ < b$ jp __FREE_STR -__STRGE: ; Compares a$ >= b$ (HL = ptr a$, DE = ptr b$). Returns FF (True) or 0 (False) +__STRGE: ; Compares a$ >= b$ (HL = ptr a$, DE = ptr b$). Returns 1 or 2 (True) or 0 (False) push hl push de call __STRCMP @@ -1071,6 +1071,10 @@ __FREE_STR: ; This exit point will test A' for bits 0 and 1 PROC LOCAL __FREE_STR2 LOCAL __FREE_END + ;; normalize boolean + sub 1 + sbc a, a + inc a ex af, af' bit 0, a jr z, __FREE_STR2 From 45d51740aae44e592dc5f6d7f1ae3ab04469d650 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Wed, 27 Nov 2024 23:48:31 +0100 Subject: [PATCH 13/13] test: update tests --- src/zxbc/args_config.py | 1 - tests/api/test_config.py | 75 +++++++++---------- .../arch/zx48k/optimizer/test_o1_optimizer.py | 3 - tests/functional/cmdline/test_cmdline.txt | 7 +- 4 files changed, 41 insertions(+), 45 deletions(-) diff --git a/src/zxbc/args_config.py b/src/zxbc/args_config.py index 918fe666a..1b607f746 100644 --- a/src/zxbc/args_config.py +++ b/src/zxbc/args_config.py @@ -91,7 +91,6 @@ def parse_options(args: list[str] | None = None) -> Namespace: if OPTIONS.sinclair: OPTIONS.array_base = 1 OPTIONS.string_base = 1 - OPTIONS.strict_bool = True OPTIONS.case_insensitive = True OPTIONS.case_insensitive = options.ignore_case diff --git a/tests/api/test_config.py b/tests/api/test_config.py index 5308575c6..891eb86bb 100644 --- a/tests/api/test_config.py +++ b/tests/api/test_config.py @@ -38,6 +38,7 @@ def test_init(self): self.assertEqual(config.OPTIONS.emit_backend, False) self.assertIsNone(config.OPTIONS.architecture) self.assertEqual(config.OPTIONS.expected_warnings, 0) + self.assertEqual(config.OPTIONS.opt_strategy, "auto") # private options that cannot be accessed with #pragma self.assertEqual(config.OPTIONS["__DEFINES"].value, {}) @@ -46,44 +47,42 @@ def test_init(self): self.assertEqual(config.OPTIONS.strict, False) def test_initted_values(self): - self.assertEqual( - sorted(config.OPTIONS._options.keys()), - [ - "__DEFINES", - config.OPTION.ARCH, - config.OPTION.ARRAY_BASE, - config.OPTION.CHECK_ARRAYS, - config.OPTION.AUTORUN, - config.OPTION.CASE_INS, - config.OPTION.DEBUG, - config.OPTION.DEFAULT_BYREF, - config.OPTION.EMIT_BACKEND, - config.OPTION.ENABLE_BREAK, - config.OPTION.EXPECTED_WARNINGS, - config.OPTION.EXPLICIT, - config.OPTION.FORCE_ASM_BRACKET, - config.OPTION.HIDE_WARNING_CODES, - config.OPTION.INCLUDE_PATH, - config.OPTION.INPUT_FILENAME, - config.OPTION.MAX_SYN_ERRORS, - config.OPTION.CHECK_MEMORY, - config.OPTION.MEMORY_MAP, - config.OPTION.O_LEVEL, - config.OPTION.OUTPUT_FILE_TYPE, - config.OPTION.OUTPUT_FILENAME, - "project_filename", - "sinclair", - config.OPTION.STDERR, - config.OPTION.STDERR_FILENAME, - config.OPTION.STDIN, - config.OPTION.STDOUT, - config.OPTION.STRICT, - config.OPTION.STRICT_BOOL, - config.OPTION.STR_BASE, - config.OPTION.USE_BASIC_LOADER, - config.OPTION.ASM_ZXNEXT, - ], - ) + assert sorted(config.OPTIONS._options.keys()) == [ + "__DEFINES", + config.OPTION.ARCH, + config.OPTION.ARRAY_BASE, + config.OPTION.CHECK_ARRAYS, + config.OPTION.AUTORUN, + config.OPTION.CASE_INS, + config.OPTION.DEBUG, + config.OPTION.DEFAULT_BYREF, + config.OPTION.EMIT_BACKEND, + config.OPTION.ENABLE_BREAK, + config.OPTION.EXPECTED_WARNINGS, + config.OPTION.EXPLICIT, + config.OPTION.FORCE_ASM_BRACKET, + config.OPTION.HIDE_WARNING_CODES, + config.OPTION.INCLUDE_PATH, + config.OPTION.INPUT_FILENAME, + config.OPTION.MAX_SYN_ERRORS, + config.OPTION.CHECK_MEMORY, + config.OPTION.MEMORY_MAP, + config.OPTION.OPT_STRATEGY, + config.OPTION.O_LEVEL, + config.OPTION.OUTPUT_FILE_TYPE, + config.OPTION.OUTPUT_FILENAME, + "project_filename", + "sinclair", + config.OPTION.STDERR, + config.OPTION.STDERR_FILENAME, + config.OPTION.STDIN, + config.OPTION.STDOUT, + config.OPTION.STRICT, + config.OPTION.STRICT_BOOL, + config.OPTION.STR_BASE, + config.OPTION.USE_BASIC_LOADER, + config.OPTION.ASM_ZXNEXT, + ] def test_loader_ignore_none(self): """Some settings must ignore "None" assignments, since diff --git a/tests/arch/zx48k/optimizer/test_o1_optimizer.py b/tests/arch/zx48k/optimizer/test_o1_optimizer.py index c16bf8712..931081681 100644 --- a/tests/arch/zx48k/optimizer/test_o1_optimizer.py +++ b/tests/arch/zx48k/optimizer/test_o1_optimizer.py @@ -23,7 +23,4 @@ def test_call_match(self): self.backend._output_join(output, code, optimize=True) assert output == [ "call .core.__LEI8", - "sub 1", - "sbc a, a", - "inc a", ] diff --git a/tests/functional/cmdline/test_cmdline.txt b/tests/functional/cmdline/test_cmdline.txt index 15fb86fcd..3933a993d 100644 --- a/tests/functional/cmdline/test_cmdline.txt +++ b/tests/functional/cmdline/test_cmdline.txt @@ -3,9 +3,9 @@ >>> os.environ['COLUMNS'] = '80' >>> process_file('arch/zx48k/arrbase1.bas', ['-q', '-S', '-O --mmap arrbase1.map']) -usage: zxbc.py [-h] [-d] [-O OPTIMIZE] [-o OUTPUT_FILE] [-T] [-t] [-A] [-E] - [--parse-only] [-f {asm,bin,ir,sna,tap,tzx,z80}] [-B] [-a] - [-S ORG] [-e STDERR] [--array-base ARRAY_BASE] +usage: zxbc.py [-h] [-d] [-O OPTIMIZE] [-o OUTPUT_FILE] + [-T | -t | -A | -E | --parse-only | -f {asm,bin,ir,sna,tap,tzx,z80}] + [-B] [-a] [-S ORG] [-e STDERR] [--array-base ARRAY_BASE] [--string-base STRING_BASE] [-Z] [-H HEAP_SIZE] [--heap-address HEAP_ADDRESS] [--debug-memory] [--debug-array] [--strict-bool] [--enable-break] [--explicit] [-D DEFINES] @@ -15,6 +15,7 @@ usage: zxbc.py [-h] [-d] [-O OPTIMIZE] [-o OUTPUT_FILE] [-T] [-t] [-A] [-E] [--arch ARCH] [--expect-warnings EXPECT_WARNINGS] [-W DISABLE_WARNING] [+W ENABLE_WARNING] [--hide-warning-codes] [-F CONFIG_FILE] [--save-config SAVE_CONFIG] + [--opt-strategy {size,speed,auto}] PROGRAM zxbc.py: error: Option --asm and --mmap cannot be used together