• Subject: RE: stack vs. storage-to-storage
  • From: Leif Svalgaard <l.svalgaard@xxxxxxxxxxxxx>
  • Date: Wed, 24 Nov 1999 14:36:37 -0600



> -----Original Message-----
> From: Blair Wyman [SMTP:wyman@VNET.IBM.COM]
> Sent: Wednesday, November 24, 1999 12:41 PM
> To:   'MI400@midrange.com'
> Subject:      Re: stack vs. storage-to-storage
> 
> Excerpts from mi400: 23-Nov-99 stack vs. storage-to-storage Gene
> Gaunt@ibm.net (433) 
> 
> > Why is the stack virtual machine better than the storage-to-storage
> > virtual machine?  Is it faster? 
> 
> The key advantage to a stack-based virtual machine is in code
> optimization.  Consider this simple sequence of HLL code: 
        [Leif Svalgaard]    
        Although Blair does have a valid point, it should be moderated a
bit.
        Below I show the actual generated code for a C-program 

        void main(void)     
        {                   
        long a, b, c, x, y; 
        x = (a*a) + (b*b);  
        y = x + (c*c);      
        }                    

          LWA 12,0XFFE4(31)   
          LWA 10,0XFFE4(31)
          MULLD 9,10,12
          EXTSW 9,9
          LWA 8,0XFFE0(31)
          LWA 7,0XFFE0(31)
          MULLD 6,7,8
          EXTSW 6,6
          ADD 5,6,9
          EXTSW 5,5
          STW 5,0XFFEC(31)

          LWA 4,0XFFE8(31)   
          LWA 12,0XFFE8(31)
          MULLD 10,12,4
          EXTSW 10,10
          LWA 8,0XFFEC(31)
          ADD 7,8,10
          EXTSW 7,7
          STW 7,0XFFF0(31)

        And for the corresponding MI program:

        DCL DD A BIN(4);        
        DCL DD B BIN(4);        
        DCL DD C BIN(4);        
        DCL DD T1 BIN(4);       
        DCL DD T2 BIN(4);       
        DCL DD X BIN(4);        
        DCL DD Y BIN(4);        
        ENTRY * EXT;            
             MULT     T1, A, A; 
             MULT     T2, B, B; 
             ADDN     X, T1, T2;
             MULT     T1, C, C; 
             ADDN     Y, X , T1;
             RTX *;             

        To make a fair comparison I have removed some extra
        code that checked for overflow (which the C-program didn't)

          LWA 0,0X40(12)
          MULLD 2,0,0
          EXTSW 0,2
          STW 0,0X4C(12)
          LWA 2,0X44(12)
          MULLD 2,2,2
          EXTSW 0,2
          STW 0,0X50(12)
          LWA 0,0X50(12)
          LWA 2,0X4C(12)
          ADD 2,2,0
          EXTSW 0,2
          STW 0,0X54(12)

          LWA 0,0X48(12)
          MULLD 2,0,0
          EXTSW 0,2
          STW 0,0X4C(12)
          LWA 0,0X54(12)
          LWA 2,0X4C(12)
          ADD 0,2,0
          EXTSW 2,0
          STW 2,0X58(12)

        The difference is all that great although there ARE more
        storage references in the MI code.

        Part of the lack of dramatic difference is that the two
        compilers do different optimizations and not all that
        great ones, either.

        Let us play C-compiler and optimize a bit better:
         
          LWA 12,0XFFE4(31)   
          MULLD 9,12,12
          LWA 8,0XFFE0(31)
          MULLD 6,8,8
          ADD 5,6,9
          STW 5,0XFFEC(31)

          LWA 4,0XFFE8(31)   
          MULLD 10,4,4
          ADD 7,5,10
          STW 7,0XFFF0(31)

        We could also play MI-compiler and optimize a bit better:

          LWA 0,0X40(12)
          MULLD 0,0,0
          STW 0,0X4C(12) ..
          LWA 2,0X44(12)
          MULLD 2,2,2
          STW 2,0X50(12) ..
          ADD 2,2,0
          STW 2,0X54(12)

          LWA 0,0X48(12)
          MULLD 0,0,0
          STW 0,0X4C(12) ..
          ADD 0,2,0
          STW 0,0X58(12)

        Instructions marked with ... refer to operands that are not
        used again, so following Blair's suggestion the optimizer
        could omit these and we get:

          LWA 0,0X40(12)
          MULLD 0,0,0
          LWA 2,0X44(12)
          MULLD 2,2,2
          ADD 2,2,0
          STW 2,0X54(12)

          LWA 0,0X48(12)
          MULLD 0,0,0
          ADD 0,2,0
          STW 0,0X58(12)

        which is exactly the same as we got for the C-program,
        so it is NOT the underlying difference (stack based versus
        storage based) that makes the difference, but solely the
        optimizations made by the compilers (in both modes).
>  
> 
+---
| This is the MI Programmers Mailing List!
| To submit a new message, send your mail to MI400@midrange.com.
| To subscribe to this list send email to MI400-SUB@midrange.com.
| To unsubscribe from this list send email to MI400-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: dr2@cssas400.com
+---


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.