-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replace skiz
by if_then_call
#84
Conversation
Expressing
Program length: 8. Execution cycle count: 4 or 5. Note that the emulated The technical reason is that any one instruction may change at most one memory pointer. Since Of course, depending on
|
65ac892
to
640b991
Compare
skiz
by if_then_call
640b991
to
dc70b50
Compare
I thought about emulating if-then-else with
To verify the execution, see the following table:
|
Very elegant. This warrants a more thorough analysis of the costs of the two instructions |
6aa47c3
to
3ffbf9e
Compare
A variation of this if-then-else wrapper that I derived is like this:
I.e., start by pushing a 1 that will make the else-skiz trigger, and in the then-branch change that 1 to a 0. A limitation of |
I don't follow. Please elaborate. |
What I meant was just: The So if you want to leave a function entirely from within a
For nested conditionals where the inner branch leaves the function, applying this trick once for each nesting is necessary. |
There seems to be no immediate need to replace instruction |
As discussed in this issue, implementing a proper “if then else” is not currently very straightforward using Triton assembly. The new instruction
if_then_call
alleviates the problem.For instruction
if_then_call
, note the difference between the potential offsets added to instruction pointerip
and jump origino
. Specifically, if the top of the stacka
is 0, the instruction pointerip
is incremented by 2, skipping the instruction's argumentd
. However, if the top of the stacka
is not 0, the return address put on the jump stack isip+4
. This skips not only the instruction's argumentd
, but also the next two instructions whenreturn
ing. Together, this mechanic allows following instructionif_then_call
+d
with instructioncall
+e
to serve as the “else” branch. If no “else” branch is desired, instructionif_then_else
+d
can be followed with two instructionsnop
. Of course, instructionif_then_call
can be followed by any instruction. The appropriate care should be taken toreturn
only to where it makes sense.We might drop instruction
skiz
from the ISA, but the combination ofskiz recurse return
is beautiful.