<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Fri, 15 Jul 1994 19:13:04 +0100
From   : jfid@... (James Fidell)
Subject: Re: Beeb Emulators

James Bonfield wrote:

> James Fidell wrote:
> 
> [ about P or SR]
> > I've gone for the single unsigned char per flag approach, giving
> > each the value of it's position in the SR when it's set. So it's
> > easy to reconstruct the SR for the instructions that require it,
> > just by ORing all of the flags together.
>
> This doesn't lead to efficient systems. I thought about this and
> rejected it.

Feel free to try to convince me -- I'm sure that there's stuff to be
learned from our efforts.

> 1) It requires (for maximum speed) many more registers to be
>    allocated.

Very true.  I'll bite the bullet and use real memory if I have to, then.

> 2) It disallows setting multiple flags simultaneously. This is
> sometimes useful from certain bits of code. My optimised reset_ZN(x)
> macro ended up looking like:
>
> #define reset_ZN(x) (P = P & ~(P_Z + P_N) | x & 0x80 | (!x)<<1)
>
> It's pretty quick, but still 25% slower than Stephen Quan's table
> lookup method. It's suprising though that they're so close.

It's true that you can't set multiple flags.  However, I compiled your
code to assembler, and I get the following :

       cmpb    $0,value
       jne     .L6
       movl    $1,%eax
.L7:
       leal    (,%eax,2),%eax
       movzbl  P,%edx
       andl    $ffffff7d,%edx
       movzbl  value,%ecx
       andl    $128,%ecx
       orl     %ecx,%edx
       orl     %eax,%edx
       movb    %dl,P

       EXIT

.L6:
       xorl    %eax,%eax
       jmp     .L7

"value" is "x" here, but there were already too many "x" characters.
I've removed a lot of the junk, but you get the idea.  My code for the
same operations reads :

       Z = x ? 0 : 2;
       N = x & 0x80;

And gives the following :

       testb   %ch,%ch
       je      .L8
       movb    $0,Z
.L9:
       movzbl  %ch,%eax
       andl    $128,%eax
       movb    %al,N

       EXIT

.L8:
       movb    $2,Z
       jmp     .L9


That's a lot less instructions.  Am I missing something blindingly
obvious to everyone else ?

> 3) PLP and PHP are more complex. (But they're not used that often
> anyway.)

Agreed, which warrants less worrying about how fast they are.  The other
time you have to regenerate the SR is on IRQs.

James.

-- 
 "Yield to temptation --             |
  it may not pass your way again"    |     jfid@...        
                                     |
        - Lazarus Long               |              James Fidell
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>