Skip to content

Commit 2c5e8ea

Browse files
authored
Fix SDBEGINS(Q) in Asm.fif (#1626)
1 parent f997d4a commit 2c5e8ea

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

crypto/fift/lib/Asm.fif

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ library TVM_Asm
22
// simple TVM Assembler
33
namespace Asm
44
Asm definitions
5-
"0.4.5" constant asm-fif-version
5+
"0.4.6" constant asm-fif-version
66

77
variable @atend
88
variable @was-split
@@ -750,26 +750,37 @@ x{D723} @Defop SDSKIPLAST
750750
x{D724} @Defop SDSUBSTR
751751
x{D726} @Defop SDBEGINSX
752752
x{D727} @Defop SDBEGINSXQ
753+
754+
/*
755+
if (rembits >= opcodebits) or (rembits <= 18)
756+
just write
757+
else
758+
PUSHSLICE SDBEGINSXQ
759+
760+
---
761+
18 - size of PUSHREFSLICE
762+
*/
763+
753764
{ tuck sbits tuck 5 + 3 >> swap x{D72A_} s, over 7 u, 3 roll s,
754765
-rot 3 << 3 + swap - @scomplete } : SDBEGINS:imm
755-
{ tuck sbitrefs abort"no references allowed in slice" dup 26 <=
756-
{ drop <b rot SDBEGINS:imm @addopb }
757-
{ @havebits
758-
{ swap SDBEGINS:imm }
759-
{ swap PUSHSLICE SDBEGINSX
760-
} cond
761-
} cond
766+
{ tuck sbitrefs abort"no references allowed in slice" // slice builder slicebits
767+
5 + 3 >> 8 * 3 + 21 + // slice builder opcodebits ((sbits + 5) // 8) * 8 + 3 + 21
768+
over brembits <= // total op bits <= remaining free bits in slice
769+
{ <b rot SDBEGINS:imm @addopb }
770+
{ swap PUSHSLICE SDBEGINSX }
771+
cond
762772
} : SDBEGINS
773+
763774
{ tuck sbits tuck 5 + 3 >> swap x{D72E_} s, over 7 u, 3 roll s,
764775
-rot 3 << 3 + swap - @scomplete } : SDBEGINSQ:imm
765-
{ tuck sbitrefs abort"no references allowed in slice" dup 26 <=
766-
{ drop <b rot SDBEGINSQ:imm @addopb }
767-
{ @havebits
768-
{ swap SDBEGINSQ:imm }
769-
{ swap PUSHSLICE SDBEGINSXQ
770-
} cond
771-
} cond
776+
{ tuck sbitrefs abort"no references allowed in slice" // slice builder slicebits
777+
5 + 3 >> 8 * 3 + 21 + // slice builder opcodebits
778+
over brembits <= // total op bits <= remaining free bits in slice
779+
{ <b rot SDBEGINSQ:imm @addopb }
780+
{ swap PUSHSLICE SDBEGINSXQ }
781+
cond
772782
} : SDBEGINSQ
783+
773784
x{D730} @Defop SCUTFIRST
774785
x{D731} @Defop SSKIPFIRST
775786
x{D732} @Defop SCUTLAST

0 commit comments

Comments
 (0)