From cc405a60e96eda9cb5aa14c688f039951df00bb6 Mon Sep 17 00:00:00 2001 From: StarCells Date: Sat, 25 Jul 2026 18:59:15 +0800 Subject: [PATCH] Improved some macros with r8veritas --- asm/add.r8asm | 174 +++++++++++++++++++++++++++++++++++++++----------- asm/and.r8asm | 67 +++++++++++++++---- asm/or.r8asm | 66 +++++++++++++++---- asm/xor.r8asm | 61 ++++++++++++++---- 4 files changed, 293 insertions(+), 75 deletions(-) diff --git a/asm/add.r8asm b/asm/add.r8asm index ee0aa00..3a43bb8 100644 --- a/asm/add.r8asm +++ b/asm/add.r8asm @@ -1,66 +1,166 @@ %include asm/lib.r8asm -%include asm/and.r8asm -%include asm/or.r8asm -%include asm/xor.r8asm ; Macro bit_add -; %1: UnitBit A -; %2: UnitBit B -; %3: UnitBit Ci -; %4: CellBit S +; %1: CellBit A +; %2: CellBit B +; %3: CellBit Ci +; %4: UnitBit S ; %5: CellBit Co %macro bit_add 5 .anchor before_bit_add -.tp %1 -bit_copy_to_buffer %5 +.tp %4 stp .anchor bit_add_buf_1 -.tp %2 -bit_copy_to_buffer %5 -stp -.anchor bit_add_buf_2 -.tp %3 -stp -.anchor bit_add_buf_3 .tp %4 -set_0 +biz + flb +rnz + .tp %5 -set_0 +biz + flb +rnz -bit_unsafe_xor bit_add_buf_1 bit_add_buf_2 %5 .tp %3 -bit_copy_to_buffer %4 -bit_unsafe_and bit_add_buf_3 %5 %4 -.tp %1 -bit_copy_to_buffer bit_add_buf_3 -.tp %2 -bit_copy_to_buffer bit_add_buf_3 -bit_unsafe_and bit_add_buf_1 bit_add_buf_2 bit_add_buf_3 -bit_unsafe_or bit_add_buf_3 %4 %5 +biz + flb + .tp %1 + flb + .tp %2 + flb + .tp %4 + flb + .tp %3 +rnz .tp %1 -bit_copy_to_buffer %4 +biz + flb + .tp %3 + set_1 + .tp %5 + set_1 + .tp %1 +rnz + .tp %2 -bit_copy_to_buffer %4 -bit_unsafe_xor bit_add_buf_1 bit_add_buf_2 %4 +biz + flb + .tp %1 + set_1 + .tp %5 + set_1 + .tp %2 +rnz + +.tp %1 +biz + flb + .tp %2 + flb + .tp %5 + flb + .tp %1 +rnz + .tp %3 -bit_copy_to_buffer bit_add_buf_1 -bit_unsafe_xor %4 bit_add_buf_3 bit_add_buf_1 +biz + flb + .tp %1 + flb + .tp %5 + flb + .tp %3 +rnz + +.tp %4 +biz + flb + .tp %1 + flb + .tp %2 + flb + .tp %3 + flb + .tp %5 + flb + .tp %4 +rnz + +.tp %4 +biz + flb +rnz + .tp bit_add_buf_1 -bit_move_to %4 +biz + flb +rnz + +.tp %3 +biz + flb + .tp %1 + flb + .tp %2 + flb + .tp bit_add_buf_1 + flb + .tp %3 +rnz + +.tp %2 +biz + flb + .tp %1 + flb + .tp %3 + flb + .tp %4 + flb + .tp bit_add_buf_1 + flb + .tp %2 +rnz + +.tp %1 +biz + flb + .tp %2 + flb + .tp %3 + flb + .tp bit_add_buf_1 + flb + .tp %1 +rnz + +.tp bit_add_buf_1 +biz + flb + .tp %1 + flb + .tp %2 + flb + .tp %3 + flb + .tp %4 + flb + .tp bit_add_buf_1 +rnz .tp before_bit_add %endmacro ; Macro add -; %1: Unit A -; %2: Unit B +; %1: Cell A +; %2: Cell B ; %3: Unit Ci -; %4: Cell S -; %5: Unit Co +; %4: Unit S +; %5: Cell Co %macro add 5 .anchor before_add diff --git a/asm/and.r8asm b/asm/and.r8asm index 239df84..545bfe0 100644 --- a/asm/and.r8asm +++ b/asm/and.r8asm @@ -47,22 +47,63 @@ rnz - ; Macro bit_and ; %1: UnitBit arg1 ; %2: UnitBit arg2 ; %3: CellBit ans %macro bit_and 3 .anchor before_and + .tp %1 -bit_copy_to_buffer %3 stp .anchor bit_and_buf_1 .tp %2 -bit_copy_to_buffer %3 stp .anchor bit_and_buf_2 -bit_unsafe_and bit_and_buf_1 bit_and_buf_2 %3 + +.tp %3 +set_0 +.tp bit_and_buf_1 +set_0 +.tp bit_and_buf_2 +set_0 +.tp %1 +biz + .tp %3 + set_1 + .tp bit_and_buf_1 + set_1 + .tp %1 + flb +rnz +.tp %2 +biz + .tp %1 + set_1 + .tp %3 + set_1 + .tp %2 + flb +rnz +.tp %1 +biz + .tp %2 + flb + .tp %3 + flb + .tp %1 + flb +rnz +.tp bit_and_buf_1 +biz + .tp %1 + flb + .tp %3 + flb + .tp bit_and_buf_1 + flb +rnz + .tp before_and %endmacro @@ -75,14 +116,14 @@ bit_unsafe_and bit_and_buf_1 bit_and_buf_2 %3 %macro and 3 .anchor before_and -.tp %1 -copy_to_buffer %3 -stp -.anchor and_buf_1 -.tp %2 -copy_to_buffer %3 -stp -.anchor and_buf_2 -unsafe_and and_buf_1 and_buf_2 ans +%repeat _CELL_SIZE + bit_and %1 %2 %3 + .tp %1 + ror + .tp %2 + ror + .tp %3 + ror +%endrepeat .tp before_and %endmacro \ No newline at end of file diff --git a/asm/or.r8asm b/asm/or.r8asm index 2adab33..41a24ac 100644 --- a/asm/or.r8asm +++ b/asm/or.r8asm @@ -55,15 +55,57 @@ rnz ; %3: CellBit ans %macro bit_or 3 .anchor before_or + .tp %1 -bit_copy_to_buffer %3 stp .anchor bit_or_buf_1 .tp %2 -bit_copy_to_buffer %3 stp .anchor bit_or_buf_2 -bit_unsafe_or bit_or_buf_1 bit_or_buf_2 %3 + +.tp %3 +set_0 +.tp bit_or_buf_1 +set_0 +.tp bit_or_buf_2 +set_0 +.tp %1 +biz + .tp %3 + set_1 + .tp %1 + flb +rnz +.tp %3 +biz + .tp %1 + flb + .tp %2 + flb + .tp bit_or_buf_1 + flb + .tp %3 + flb +rnz +.tp %2 +biz + .tp %3 + flb + .tp bit_or_buf_1 + flb + .tp %2 + flb +rnz +.tp bit_or_buf_1 +biz + .tp %2 + set_1 + .tp %3 + set_1 + .tp bit_or_buf_1 + flb +rnz + .tp before_or %endmacro @@ -76,14 +118,14 @@ bit_unsafe_or bit_or_buf_1 bit_or_buf_2 %3 %macro or 3 .anchor before_or -.tp %1 -copy_to_buffer %3 -stp -.anchor or_buf_1 -.tp %2 -copy_to_buffer %3 -stp -.anchor or_buf_2 -unsafe_or or_buf_1 or_buf_2 ans +%repeat _CELL_SIZE + bit_or %1 %2 %3 + .tp %1 + ror + .tp %2 + ror + .tp %3 + ror +%endrepeat .tp before_or %endmacro \ No newline at end of file diff --git a/asm/xor.r8asm b/asm/xor.r8asm index dc95cd3..cfe9e5c 100644 --- a/asm/xor.r8asm +++ b/asm/xor.r8asm @@ -1,4 +1,5 @@ %include asm/lib.r8asm + ; Macro bit_unsafe_xor ; %1: CellBit arg1 ; %2: CellBit arg2 @@ -48,22 +49,56 @@ rnz - ; Macro bit_xor ; %1: UnitBit arg1 ; %2: UnitBit arg2 ; %3: CellBit ans %macro bit_xor 3 .anchor before_xor + .tp %1 -bit_copy_to_buffer %3 stp .anchor bit_xor_buf_1 .tp %2 -bit_copy_to_buffer %3 stp .anchor bit_xor_buf_2 -bit_unsafe_xor bit_xor_buf_1 bit_xor_buf_2 %3 + +.tp %3 +set_0 +.tp bit_xor_buf_1 +set_0 +.tp bit_xor_buf_2 +set_0 +.tp %1 +biz + .tp %2 + flb + .tp bit_xor_buf_1 + flb + .tp %1 + flb +rnz +.tp %2 +biz + .tp %1 + flb + .tp %3 + flb + .tp bit_xor_buf_1 + flb + .tp %2 + flb +rnz +.tp bit_xor_buf_1 +biz + .tp %1 + flb + .tp %2 + flb + .tp bit_xor_buf_1 + flb +rnz + .tp before_xor %endmacro @@ -76,14 +111,14 @@ bit_unsafe_xor bit_xor_buf_1 bit_xor_buf_2 %3 %macro xor 3 .anchor before_xor -.tp %1 -copy_to_buffer %3 -stp -.anchor xor_buf_1 -.tp %2 -copy_to_buffer %3 -stp -.anchor xor_buf_2 -unsafe_xor xor_buf_1 xor_buf_2 ans +%repeat _CELL_SIZE + bit_xor %1 %2 %3 + .tp %1 + ror + .tp %2 + ror + .tp %3 + ror +%endrepeat .tp before_xor %endmacro \ No newline at end of file