RATools icon indicating copy to clipboard operation
RATools copied to clipboard

Optimize AndNext chain comparisons that span consecutive bytes

Open rzumer opened this issue 5 years ago • 1 comments

It seems like when AndNext chains are generated, no optimization is done to merge bytes into words and words into dwords. For example, the function shown below generates an AndNext chain where consecutive bytes are compared to their deltas 8 bits at a time. Since the final condition is a reset, I think these could be reduced to dwords.

function reset_on_same_skillset(slot) {
    trigger = always_true()

    for i in range(0, 127) {
        skills = byte(0x1234 + slot * 0x100 + 12 + i)
        trigger = trigger && skills == prev(skills)
    }

    return never(trigger)
}

rzumer avatar Feb 08 '20 07:02 rzumer

The optimizer explicitly does not merge adjacent bytes under the assumption that they could have separate notes, and combining the bytes would make future debugging harder.

See also https://github.com/Jamiras/RATools/issues/32#issuecomment-464241535

merge bits into lower/upper/byte: https://github.com/Jamiras/RATools/blob/master/Tests/Parser/AchievementBuilderTests.cs#L415

  • does not merge consecutive bytes to 16-bit or 32-bit - this is typically undesirable as bytes have separate code notes

It might be reasonable to combine bytes if they don't have separate code notes, or if the range is annotated with with a length (i.e. "[60 bytes] skill flags")

Jamiras avatar Feb 08 '20 13:02 Jamiras