Skip to content
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

Simplify sbb ternary pattern #5688

Open
plafosse opened this issue Jul 4, 2024 · 1 comment
Open

Simplify sbb ternary pattern #5688

plafosse opened this issue Jul 4, 2024 · 1 comment
Labels
Component: Core Issue needs changes to the core Core: HLIL Issue involves High Level IL Effort: Trivial Issue should take < 1 day IL Optimization Issue involving optimization of representation (not correctness) Impact: Medium Issue is impactful with a bad, or no, workaround Type: Enhancement Issue is a small enhancement to existing functionality

Comments

@plafosse
Copy link
Member

plafosse commented Jul 4, 2024

The following pattern:

a = sbb(x, x, y != 0) & -4

Can be simplified down to:

if (y != 0)
  a = -4
else
  a = 0

Example: sparkle giraffe juggling toaster.zip @ 1c00013a0

Seen @ 1c00013a0 as

a = (sbb(x, x, y != 0) & -4) + 5

notice the additional + 5 at the end. Most likely we'd need to take that into account too and do the whole simplification in one step. So the output becomes

if (y != 0)
  a = 1
else
  a = 5

Compare with other tools here: https://dogbolt.org/?id=eed48ff1-8c4b-4a5d-8fc8-abc82a21b1fe#BinaryNinja=215&Hex-Rays=523

@plafosse plafosse added Type: Enhancement Issue is a small enhancement to existing functionality Component: Core Issue needs changes to the core Core: HLIL Issue involves High Level IL IL Optimization Issue involving optimization of representation (not correctness) Impact: Medium Issue is impactful with a bad, or no, workaround Effort: Trivial Issue should take < 1 day labels Jul 4, 2024
@xusheng6
Copy link
Member

xusheng6 commented Jul 9, 2024

There are many more such assembly riddles like this: https://www.xorpd.net/pages/xchg_rax/snip_00.html. Solutions can be found https://github.com/0xdea/xorpd-solutions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Core Issue needs changes to the core Core: HLIL Issue involves High Level IL Effort: Trivial Issue should take < 1 day IL Optimization Issue involving optimization of representation (not correctness) Impact: Medium Issue is impactful with a bad, or no, workaround Type: Enhancement Issue is a small enhancement to existing functionality
Projects
None yet
Development

No branches or pull requests

2 participants