BBC BASIC for Windows
« Counting array elements »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:57pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Counting array elements  (Read 471 times)
rtr2
Guest
xx Counting array elements
« Thread started on: Dec 1st, 2014, 10:02pm »

Fans of Raymond Chen's blog will have probably been pleased to see, as I was, that today he made one of his rare forays into assembly language programming (albeit via compiler intrinsics rather than a conventional assembler):

http://blogs.msdn.com/b/oldnewthing/archive/2014/12/01/10576992.aspx

I thought it might be of interest to list a BBC BASIC equivalent of the code he discusses:

Code:
      INSTALL @lib$+"ASMLIB2"

      DIM xarray% 10000*4 + 15
      xarray% = (xarray% + 15) AND -16 : REM align
      FOR I% = 0 TO 9999
        xarray%!(I%*4) = I%
      NEXT

      xboundary% = 4999

      DIM P% 150, L% -1
      ON ERROR LOCAL [OPT FN_asmext : ]
      [OPT 10
      .countthem
      pxor     xmm5,xmm5
      pxor     xmm6,xmm6
      movd     xmm7,[^xboundary%]
      pshufd   xmm7,xmm7,%00000000

      mov      ecx,9980
      .loop
      movdqu   xmm0,xarray%[ecx*4]    ; REM GETVALUE(0)
      movdqu   xmm1,xarray%[ecx*4+16] ; REM GETVALUE(1)
      movdqu   xmm2,xarray%[ecx*4+32] ; REM GETVALUE(2)
      movdqu   xmm3,xarray%[ecx*4+48] ; REM GETVALUE(3)
      movdqu   xmm4,xarray%[ecx*4+64] ; REM GETVALUE(4)

      pcmpgtd  xmm0,xmm7              ; REM GETTEST(0)
      pcmpgtd  xmm1,xmm7              ; REM GETTEST(1)
      pcmpgtd  xmm2,xmm7              ; REM GETTEST(2)
      pcmpgtd  xmm3,xmm7              ; REM GETTEST(3)
      pcmpgtd  xmm4,xmm7              ; REM GETTEST(4)

      psubd    xmm5,xmm0              ; REM GETCOUNT(0)
      psubd    xmm6,xmm1              ; REM GETCOUNT(1)
      psubd    xmm5,xmm2              ; REM GETCOUNT(2)
      psubd    xmm6,xmm3              ; REM GETCOUNT(3)
      psubd    xmm5,xmm4              ; REM GETCOUNT(4)

      sub      ecx,20
      jns      loop

      paddd    xmm5,xmm6
      pshufd   xmm6,xmm5,%10001110
      paddd    xmm5,xmm6
      pshufd   xmm6,xmm5,%10110001
      paddd    xmm5,xmm6
      movd     eax,xmm5
      ret
      ]
      RESTORE ERROR

      PRINT "There were "; 10000-USR(countthem) ;
      PRINT " values less than or equal to " ; xboundary% 

To borrow Raymond's own phrase, the code above is a 'small program' and small programs don't bother with error checking or niceties such as moving code into procedures and functions. Also, the special requirements of ASMLIB (to allow the program to be compiled) have not been addressed.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls