11fun builder.store_u32(mutate self, value: int): self {
22 return self.storeUint(value, 32);
33}
4+ fun builder.storeMessageOp(mutate self, op: int): self
5+ asm(op self) "32 STU";
6+ fun builder.storeMessageQueryId(mutate self, queryId: int): self
7+ asm(queryId self) "64 STU";
48
59fun slice.load_u32(mutate self): int {
610 return self.loadUint(32);
@@ -77,7 +81,8 @@ fun test5(): [int,int] {
7781
7882@method_id(106)
7983fun test6() {
80- return beginCell().storeUint(1, 32).storeUint(2, 32).storeUint(3, 32);
84+ var st = beginCell().storeUint(1, 32).storeUint(2, 32).storeUint(3, 32).endCell().beginParse();
85+ return st.loadUint(96) == ((1 << 64) + (2 << 32) + 3);
8186}
8287
8388@method_id(107)
@@ -194,7 +199,6 @@ fun test111() {
194199 var q2 = s.loadMessageQueryId();
195200 s.skipBits(64);
196201 s.assertEnd();
197- assert(isMessageBounced(0x001) && !isMessageBounced(0x002)) throw 444;
198202 return (op1, q1, op2, q2);
199203}
200204
@@ -229,6 +233,96 @@ fun test16() {
229233}
230234
231235
236+ @method_id(117)
237+ fun test17() {
238+ var b = beginCell().storeUint(1, 4).storeCoins(0).storeInt(123, 8);
239+ var s = b.endCell().beginParse();
240+ return (s.loadUint(4), s.loadCoins(), s.loadUint(8));
241+ }
242+
243+ @method_id(118)
244+ fun test18() {
245+ var x = 0;
246+ var b = beginCell();
247+ b = b.storeUint(x, 14);
248+ x += 12;
249+ if (10 > 3) { x += x; }
250+ if (true) {
251+ b.storeInt(x + 2, 8).storeUint(x = match (x) { 24 => 5, else => 0 }, 4);
252+ }
253+ var s = b.endCell().beginParse();
254+ return (s.loadUint(14), s.loadInt(8), s.loadUint(4));
255+ }
256+
257+ fun test19() {
258+ // numbers with potential overflow for STU are not joined, check via codegen
259+ var b = beginCell();
260+ b.storeInt(123, 4).storeUint(0xFF, 8).storeUint(0xFF, 8).storeInt(-1, 8);
261+ return b;
262+ }
263+
264+ @method_id(120)
265+ fun test20() {
266+ var x = false;
267+ var n = 4;
268+ var b = true ? beginCell() : null;
269+ b.storeBool(true).storeBool(x);
270+ b = b.storeBool(true).storeUint(0, n *= 2).storeBool(!!true).storeCoins(0);
271+ var s = b.endCell().beginParse();
272+ return (s.loadBool(), s.loadBool(), s.loadBool(), s.loadUint(8), s.loadBool(), s.loadCoins());
273+ }
274+
275+ fun test21(s: slice) {
276+ // successive skipBits are also joined
277+ var x = 8;
278+ s.skipBits(x);
279+ x -= 4;
280+ s = s.skipBits(x).skipBits(2);
281+ x *= 0;
282+ s = s.skipBits(x);
283+ return s;
284+ }
285+
286+ @method_id(122)
287+ fun test22() {
288+ // different builders aren't mixed, store inside them are joined independently
289+ var (b1, b2) = (beginCell(), beginCell());
290+ b1.storeUint(8, 16).storeUint(8, 8);
291+ b2.storeUint(8, 32).storeUint(1<<88, 100);
292+ return (
293+ b1.endCell().beginParse().remainingBitsCount(),
294+ b2.endCell().beginParse().skipBits(32).loadUint(100),
295+ );
296+ }
297+
298+ @method_id(123)
299+ fun test23(uns: bool) {
300+ // corner values, signed/unsigned 255/256
301+ var b = beginCell();
302+ if (uns) {
303+ b.storeUint(1, 100).storeUint(2, 100).storeInt(3, 55).storeInt(0, 1);
304+ b.storeUint(8, 256);
305+ } else {
306+ b.storeInt(1, 10).storeUint(2, 190).storeInt(3, 54).storeUint(1, 1);
307+ }
308+ return b.bitsCount();
309+ }
310+
311+ @method_id(124)
312+ fun test24(uns: bool) {
313+ // doesn't fit into a single STI/STU instruction, is splitted
314+ var b = beginCell();
315+ if (uns) {
316+ b.storeUint(1, 100).storeUint(2, 100)
317+ .storeInt(3, 100).storeInt(8, 19);
318+ return b.endCell().beginParse().skipBits(200+100).loadInt(19);
319+ } else {
320+ b.storeInt(1, 20).storeUint(2, 200).storeInt(3, 35)
321+ .storeUint(1, 1).storeUint(5, 5).storeUint(10, 10);
322+ return b.endCell().beginParse().skipBits(255+6).loadUint(10);
323+ }
324+ }
325+
232326fun main(): int {
233327 return 0;
234328}
@@ -239,6 +333,7 @@ fun main(): int {
239333@testcase | 103 | 103 | 103
240334@testcase | 104 | | [ 1 3 ]
241335@testcase | 105 | | [ 210 1 ]
336+ @testcase | 106 | | -1
242337@testcase | 107 | | 72 40 72
243338@testcase | 108 | | 0 40 32
244339@testcase | 110 | | 64 3 0 0 -1 0 100 -1
@@ -249,20 +344,102 @@ fun main(): int {
249344@testcase | 114 | 0 | 0 0 0
250345@testcase | 115 | | 123 456 123 456
251346@testcase | 116 | | BC{00140008000000ff00000008}
347+ @testcase | 117 | | 1 0 123
348+ @testcase | 118 | | 0 26 5
349+ @testcase | 120 | | -1 0 -1 0 -1 0
350+ @testcase | 122 | | 24 309485009821345068724781056
351+ @testcase | 123 | -1 | 512
352+ @testcase | 123 | 0 | 255
353+ @testcase | 124 | -1 | 8
354+ @testcase | 124 | 0 | 10
355+
356+ We test that consequtive storeInt/storeUint with constants are joined into a single number
252357
253- Note, that since 'compute-asm-ltr' became on be default, chaining methods codegen is not quite optimal.
254358@fif_codegen
255359"""
256360 test6 PROC:<{
257- 1 PUSHINT // '0=1
258- NEWC // '0=1 '1
259- 32 STU // '1
260- 2 PUSHINT // '1 '4=2
261- SWAP // '4=2 '1
262- 32 STU // '1
263- 3 PUSHINT // '1 '7=3
264- SWAP // '7=3 '1
265- 32 STU // '1
361+ 18446744082299486211 PUSHINT
362+ NEWC
363+ 96 STU // '2
364+ ENDC // '11
365+ """
366+
367+ @fif_codegen
368+ """
369+ test17 PROC:<{
370+ 4219 PUSHINT
371+ NEWC
372+ 16 STU
373+ """
374+
375+ @fif_codegen
376+ """
377+ test18 PROC:<{
378+ 421 PUSHINT
379+ NEWC
380+ 26 STU
381+ """
382+
383+ @fif_codegen
384+ """
385+ test19 PROC:<{
386+ NEWC
387+ 123 PUSHINT
388+ SWAP
389+ 4 STI
390+ 16 PUSHPOW2DEC
391+ 16 STUR
392+ -1 PUSHINT
393+ SWAP
394+ 8 STI
266395 }>
267396"""
397+
398+ @fif_codegen
399+ """
400+ test20 PROC:<{
401+ 40976 PUSHINT
402+ NEWC
403+ 16 STU
404+ """
405+
406+ @fif_codegen
407+ """
408+ test21 PROC:<{
409+ 14 PUSHINT
410+ SDSKIPFIRST
411+ }>
412+ """
413+
414+ @fif_codegen
415+ """
416+ test22 PROC:<{
417+ NEWC // '2
418+ NEWC // b1 b2
419+ SWAP // b2 b1
420+ 2056 PUSHINT
421+ 24 STUR // b2 b1
422+ SWAP // b1 b2
423+ 10141514286835656557042350424064 PUSHINTX
424+ 132 STUR // b1 b2
425+ """
426+
427+ @fif_codegen
428+ """
429+ test23 PROC:<{
430+ NEWC
431+ SWAP
432+ IF:<{
433+ 91343852333181432387730302044911803916571639814 PUSHINT
434+ 256 STUR
435+ 8 PUSHINT
436+ 256 STUR
437+ }>ELSE<{
438+ 56539106072908298546665520023773392506479484700019806659963456035401760775 PUSHINT
439+ 255 STIR
440+ }>
441+ BBITS
442+ }>
443+ """
444+
268445 */
0 commit comments