Origen-SDK / o2

MIT License
4 stars 0 forks source link

Register model to support dirty/clean concept #77

Closed redxeth closed 4 years ago

redxeth commented 4 years ago

To support Pattern Atomization (Issue https://github.com/Origen-SDK/o2/issues/75), we will need the register model to be able to support having clean vs dirty data.

Clean or Freeze The original value in the register at the start of a 'pattern atom' (section of pattern that can be broken apart into partial patterns). Or the value that we want to eventually come back to, but want to temporarily modify for a section of a pattern (which can happen independent of the pattern atomization thing.

Dirty or Live The current value of the register. It may or may not match the 'clean' or 'frozen' value of the register.

Freezing The register model should automatically handle the dirty/clean concept. i.e. you would write to a register normally, then when you wanted to freeze it you would save the clean state:

reg.save_clean
reg.freeze           # alternate name

Then subsequent writes would 'dirty' the register:

reg.write(data) # doesn't matter if writing out to pattern or not,
                # the register has been dirtied in origen

Where you could check the dirty status:

reg.dirty?
reg.clean?

By definition all registers would be considered 'clean' until the first 'freeze' occured.

Then when you wanted to restore the 'clean' state you'd do:

reg.clean  # writes clean reg value back to register (only in origen model)
reg.clean! # writes clean reg value back to register (model and out to real pattern)

And this would restore clean register state again via a write operation of the original clean data.

If you had a dirty register and wanted to update the clean state again (or re-freeze), just run 'save_clean' again:

reg.save_clean
reg.freeze

If you wanted to clear the clean data back to reset state, without resetting the current state of the register (why don't know):

reg.reset_clean

Basically now every register has 2 bit collections associated with it-- a clean/save state and a currently active state.

Each bit collection has the same features as previous register model, i.e. :

reg.bit.store_clean
reg.bit.reset_clean
reg.bits.overlay_clean

Actually every bit field would have to have clean/dirty state on it and a backup value to store if dirtied.

I'm not set on the nomenclature, clean/dirty, freeze/thaw, save/load. Suggestions?

ginty commented 4 years ago

Definitely we should support this.

I would propose a more explicit API...

We should generally track whether a register has changed since its last reset, something like:

reg.data()                      # => 0
reg.is_modified_since_reset()   # => false
reg.is_in_reset_state()         # => true
reg.set_data(0x1234)
reg.is_modified_since_reset()   # => true
reg.is_in_reset_state()         # => false
reg.set_data(0)
reg.is_modified_since_reset()   # => true
reg.is_in_reset_state()         # => true
reg.reset()
reg.is_modified_since_reset()   # => false
reg.is_in_reset_state()         # => true

And then we should have another API to take snapshots and rollback:

reg.set_data(0x1234)
reg.snapshot("snap1")
reg.is_changed("snap1")   # => false
reg.set_data(0xFFFF)
reg.snapshot("snap2")
reg.is_changed("snap1")   # => true
reg.is_changed("snap2")   # => false
reg.rollback("snap1")
reg.data()                # => 0x1234
reg.is_changed("snap1")   # => false
reg.is_changed("snap2")   # => true

Though not shown here, the snapshot would apply to all bit attributes (read flag, overlay str, etc), not just the data.

This stuff is all going to be implemented at the bit level, so you will have this same API available on individual bit fields too.

Does the above cover your use case?

ginty commented 4 years ago

Thinking about the implementation some more, I think this will be implemented at the bit-field level and not at the individual bit level as noted above. So you will be able to do my_reg.snapshot or my_reg.my_bits.snapshot, but not on some arbitrary collection of bits - i.e. you won't be able to do this: my_reg[7:0].snapshot or my_reg.my_bits[2:0].snapshot.

I will assume that will be OK unless anyone says otherwise...

ginty commented 4 years ago

In the end, this API is available on any bit

ginty commented 4 years ago

This is now available in master, API as above.

redxeth commented 4 years ago

@ginty Cool! Let me give it a shot...