6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Sep 28, 2024 7:25 pm

All times are UTC




Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Wed Apr 06, 2016 10:27 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Would there be any harm in always setting the V flag for a ROL?
(An earlier query asked if C should be affected by INX, DEX and so on. The answer, I think, is no, because X or Y could be used to control a loop, and preserving C from one iteration to the next could be important. I'm not so sure that preserving V is important.)


Top
 Profile  
Reply with quote  
PostPosted: Wed Apr 06, 2016 3:11 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1948
Location: Sacramento, CA, USA
If by "setting" you mean "updating", then I'm on board with you. My 65m32 allows at least four different ways to do an INX (each a single machine instruction), and each of them have different flag effects, allowing the careful programmer some flexibility in that area.

Mike B.


Top
 Profile  
Reply with quote  
PostPosted: Wed Apr 06, 2016 3:40 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
[Updating is a much better choice of word!]


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 09, 2016 1:01 am 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
This is non-sequitor, I know, but thought I'd contribute for informational purposes.

BigEd wrote:
MichaelM wrote:
Similarly, the RISC-like 16-bit Inmos Transputer did not have a carry flag (or processor status register), and doing higher precision (32-bit or more) arithmetic was a bit difficult
Well, well - you are quite right. I hadn't realised that. The same is true of the modern RISC-V architecture, which comes in 32-bit and 64-bit flavours - multi-word arithmetic being less crucial on a wider machine. On an 8-bit machine it's essential.

(It turns out that the high level language Occam for the Transputer provided functions for wide arithmetic.)


Multi-precision arithmetic is still possible and with acceptable overhead as if you had an explicit carry bit (remember, these instructions are all single-cycle if you use an in-order, single-pipeline CPU, and faster on wider dispatching architectures):

Code:
    add x1, x2, x3       ; Add low half
    add x4, x5, x6       ; Add high half
    slt x7, x1, x2      ; X7 = 1 iff X1 < X2, else 0 (IOW, the carry bit)
    add x4, x4, x7      ; Accumulate the carry.


The reason the RISC-V lacks any CPU flags what-so-ever is that, frankly, flags are complicated in anything that isn't a single-issue, in-order CPU. They require every instruction to have an implicit register dependency (your flags) which takes a fair amount of logic to work around to get high performance.

I think one of the reasons why Intel CPUs beat the Motorola 68K series once superscalar architectures became a thing is because, if you look at x86 instruction semantics, not all instructions touch flags like Motorola's did. The POWER architecture works around this by having a "flags queue", where each instruction that is allowed to update flags will set CC0, thus bumping its former contents to CC1, CC2, etc. I think there are 8 CCs on a 32-bit architecture. If you need to branch on a CC, you must explicitly specify which CC you're interested in testing. (If you've read about the Mill CPU, this should sound familiar; Mill CPU does the same sort of thing to all intermediate computations, not just the flags.)


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 09, 2016 9:18 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Yikes, I didn't know POWER had that explicit queue of conditions!


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 09, 2016 5:15 pm 
Offline

Joined: Tue Sep 03, 2002 12:58 pm
Posts: 325
Don't be alarmed! POWER's CR register was not a queue. Integer arithmetic operations that modified flags (most didn't) wrote to CR0. Floating point wrote to CR1. Comparison instructions had a field saying which set of flags to write to, and the branch unit instructions (which included logical operations between flags) could work on any of them. Once written, flags stayed put.

Higher CR fields didn't get used much in practice, at least not in the code I saw. They would have been useful for complicated boolean expressions, but when everyone writes in C or C++ and uses the short-circuiting && and || operators, you never get the opportunity.

What stopped it being a bottleneck is that you never wrote just a single flag. All bits in your destination field got written at once. Treat CR as 8 independent 4-bit registers, and that makes it possible to use register renaming. The 6502's style, with every instruction writing to a different subset of bits, would still be possible but more of a headache.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 09, 2016 6:40 pm 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
John West wrote:
Don't be alarmed! POWER's CR register was not a queue. Integer arithmetic operations that modified flags (most didn't) wrote to CR0. Floating point wrote to CR1. Comparison instructions had a field saying which set of flags to write to, and the branch unit instructions (which included logical operations between flags) could work on any of them. Once written, flags stayed put.


Thanks for the clarification! I remember that that PowerPC 601 definitely had 8 CRs available for use, but I could have sworn that it bumped CRs when told to do so.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 24 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: