Post by Thomas KoenigPost by MarcusCorrect. MRISC32 currently does not have a short-hand solution for
dealing with carry, but relies on the standard 4-instruction sequence
that is generated by GCC, for instance.
add s3,s1,s3
sltu s1,s3,s1
add s2,s2,s4
sub s2,s2,s1
I will probably look into more optimal ways of implementing carry.
The My66000 solution is interesting. Another possibility would be
to use some sort of 3-source ADD instruction, which could reduce
the sequence to three instructions instead of four.
A few weeks ago, a suggestion that registers could have extra bits,
or that you could have per-register status bits, was discussed here.
A carry bit for each register, with an extra "add with carry"
instruction, would cut this down to two.
Yes, I followed that discussion from a distance.
Post by Thomas KoenigThis could also be implemented as an extra 32-bit condition register
(this would probably be easier to model in gcc).
Of course, if you go down that route, you might also do the same
for signed overflow, another 32-bit register.
All of that only makes sense if you expect a lot of 64-bit
or arithmetic on your architecture. So, choices, choices...
One of the things that influences my ISA choices is that I want all
instructions to have the same behavior for vector registers as for
scalar registers (excluding branches that are purely scalar
operations).
That is one reason why MRISC32 does not have a flags register - it's
simply a bad match for vector operations. It's also the reason for
having the compare-instructions return 0 for FALSE and -1 (i.e.
all bits set) for TRUE: it works well for masks in vector operations,
e.g. in combination with the "SEL" instruction that does bitwise
selection, which can be used for implementing conditional selection
in scalar operations, vector operations and even packed operations,
e.g:
SLT.B V3,V1,V2 ; Byte-wise "set if less than", "V3 = V1 < V2"
SEL V3,V4,V5 ; Bit-wise select V4 (if true) or V5 (if false)
...which will select a byte from V4 or V5 depending on if the
corresponding (signed) byte in V1 is less than V2 or not.
Obviously you can do the same thing for regular scalar word-size
(unpacked) integers too:
SLT S3,S1,S2
SEL S3,S4,S5
I have still not decided on what carry mechanism to use (the current
state of affairs is that it already works - but with a slight
overhead compared to the optimal two-instruction sequence). As you
said it depends on how frequent 64-bit operations are. Actually, as
I aim to one day create a 64-bit version of the ISA ("MRISC64"),
this is one of the things that I do not want to over-optimize for
32-bit ALU operations ATM.
/Marcus