feat(vm): implement TIP-7939 CLZ opcode#6656
feat(vm): implement TIP-7939 CLZ opcode#6656yanghang8612 wants to merge 1 commit intotronprotocol:developfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| DataWord word = program.stackPop(); | ||
| int clz = numberOfLeadingZeros(word.getData()); | ||
| if (clz == 256) { | ||
| program.stackPush(new DataWord(256)); |
There was a problem hiding this comment.
Why not define 256 as a static constant, so that whenever word is 0, it is pushed directly onto the stack?
There was a problem hiding this comment.
Even if a 256 DataWord constant is defined, it still needs to be cloned when pushed onto the stack. The overhead involved is nearly equivalent to creating a new instance from scratch, so the constant approach was not adopted.
| if (clz == 256) { | ||
| program.stackPush(new DataWord(256)); | ||
| } else { | ||
| program.stackPush(DataWord.of((byte) clz)); |
There was a problem hiding this comment.
Nice work overall! One minor suggestion: since DataWord.of(byte num) directly assigns bb[31] = num, casting clz to (byte) when it's in [128, 255] introduces a subtle signed/unsigned ambiguity. Would it be worth simplifying both branches into one using new DataWord(int), which handles the full range cleanly?
Summary
Implement TIP-7939 CLZ opcode (
0x1e), gated behind the existingallowTvmOsakaflag.LOW_TIER, matching MUL)TRON_V1_5version withappendOsakaOperationsto support Osaka opcodesRelated: tronprotocol/tips#838