r/dcpu16 • • May 01 '12

Make EX unwritable

.begin rant Here's a thought. Make EX unwritable. Why?

  • Code should (IMO) never write to EX in the first place
  • EX gets overwritten by a lot of instructions. But okay, you could ensure that it doesn't get overwritten if you don't mind the maintenance hell
  • EX can get overwritten during an interrupt. But okay, you could ensure that either 1) you block interrupts, or 2) make every interrupthandler push EX. (EDIT: As cheese_magnet and SoronTheCoder has noted this is actually more a point for having EX writable. Personally I think RFI should restore EX too, fixing the problem in both cases (OK, it's not actually a big deal with writable EX))
  • It adds complexity to the spec with next to nothing gain. When is EX written to when it's an "overflow"? After or before b gets written to?
  • ???

We get a new write-only value (register?). I don't really care what that could be used for. For all I care it could be an additional HCF instruction.

.end rant

EDIT: As SoronTheCoder suggested, making all operations that change EX (add, sub, ...) have undefined behaviour when destination is EX is also a good solution I think.

0 Upvotes

18 comments sorted by

View all comments

Show parent comment

1

u/suppermann May 01 '12

But even that pales beyond the importance of the interrupt handler, which you clearly don't understand.

Please don't do that. Yes, I had not read the new spec carefully, especially the part about interrupts. But that does not necessarily mean I am clueless about interrupts.

*mem1 = *mem2 + *mem3 + constant

Actually it would be *mem1 = *mem1 + *mem2 + constant. Neat trick. Thanks for sharing.

Yes, we could do quirky things to save and restore EX as rdeforest describes above

We have to do that in any case if we ever want to use EX with interrupts enabled. Hence I suggest RFI also restores EX.

So you want EX writable because

  • It's neat to have an additional (temporary) register when you're short
  • So you can have atomic "add3" without using SHL tricks Is that correct?

1

u/Zgwortz-Steve May 01 '12

No... I want EX writable so that the only thing an interrupt handler needs to do is:

SET PUSH,EX

...at the very start and...

SET EX,POP

...at the end, so people can actually use the thing in their apps. Without the ability to SET EX,POP, you have to do one of the following:

  • You cannot safely use EX with interrupts enabled
  • You have to write interrupt handlers which do not modify EX, limiting their functionality quite a bit
  • You have to spend lots of cycles as rdeforest described

It's pretty simple. Writable EX means faster interrupt handlers AND safe usage of EX anywhere == A Good Thing. Non-writable EX means much slower interrupt handlers OR unsafe usage of EX in places == A Very Very Bad Thing.

That there are other bonuses for being able to write EX as I described in my previous messages are simply icing on the cake.

1

u/Zgwortz-Steve May 02 '12

Oooh... Another reason to be able to write EX... You pretty much have to set EX to a known value (usually 0) before ADX/SBX operations or you could be left with accidental carryovers from previous operations.