BBC BASIC for Windows
« SIMD signum function »

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: SIMD signum function  (Read 552 times)
rtr2
Guest
xx SIMD signum function
« Thread started on: Dec 29th, 2014, 11:06pm »

Raymond Chen is continuing his series of Monday articles on SSE2 integer arithmetic. This week he is dealing with the signum function, i.e. SGN in BASIC. Here is a corrected version of his code for returning the signum of eight 16-bit integers in parallel:

Code:
      INSTALL @lib$+"ASMLIB2"
      DIM P% 100, L% -1, memory% 31
      memory% = (memory% + 15) AND -16

      ON ERROR LOCAL [OPT FN_asmext : ]
      [OPT 10
      .signum
      movdqu  xmm0, [memory%] ; input in xmm0
      pxor    xmm1, xmm1
      pxor    xmm2, xmm2
      pcmpgtw xmm1, xmm0 ; xmm1 = pcmpgt(0, x)
      pcmpgtw xmm0, xmm2 ; xmm0 = pcmpgt(x, 0)
      psubw   xmm1, xmm0 ; xmm1 = signum
      movdqu  [memory%], xmm1 ; output in xmm1
      ret
      ]
      RESTORE ERROR 

This can be converted to perform 16 8-bit signums or 4 32-bit signums by changing pcmpgtw and psubw to pcmpgtb and psubb or pcmpgtd and psubd respectively.

You can also adapt it to use the 64-bit MMX registers (hence working on half the number of values); in that case no library is required of course:

Code:
      DIM P% 100, L% -1, memory% 15
      memory% = (memory% + 7) AND -8

      [OPT 10
      .signum
      movq    mm0, [memory%] ; input in mm0
      pxor    mm1, mm1
      pxor    mm2, mm2
      pcmpgtw mm1, mm0 ; mm1 = pcmpgt(0, x)
      pcmpgtw mm0, mm2 ; mm0 = pcmpgt(x, 0)
      psubw   mm1, mm0 ; mm1 = signum
      movq    [memory%], mm1 ; output in mm1
      ret
      ] 

Richard.
« Last Edit: Dec 30th, 2014, 09:09am by rtr2 » 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