omarandlorraine / strop

Stochastically generates machine code
MIT License
95 stars 1 forks source link

Smaller randomize steps #23

Closed omarandlorraine closed 2 years ago

omarandlorraine commented 2 years ago

Strop generated this code:

    ldw x, #5
    incw x
    incw x
    mul x, a
    ld a, xl

to multiply the accumulator by 7. What it's doing is loading X with the constant five, and incrementing it twice, leaving seven. Then it does the multiplication, and then moves the result where it should be.

It's a bit stupid

But picking a random immediate value with any of the possible values picked with a uniform distribution makes it too unattractive to the search function, and it ends up trying to use shifts and things. This is because mutating a single instruction means randomizing all of the opcode and the source and destination operands. It's too great a step.

So we should experiment with some kind of "smaller step". So maybe the mutation here should take immediates and pick one of: increment, decrement, flip-a-bit, negate, etc. In the example above, this would mean offering successively closer values for x in the first instruction, which would reduce the probability of strop inserting these pointless incw instructions.

omarandlorraine commented 2 years ago

Implemented, but not tested