• Welcome to Jose's Read Only Forum 2023.
 

CPU registers working in parallel

Started by Charles Pegge, January 28, 2008, 11:28:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Charles Pegge

Some interesting results showing what can be done in a loop without costing extra clock cycles. This code shows a number of experiments and the timing for each one. These results are highly CPU dependent of course.


#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN () AS LONG
    #REGISTER NONE
    DIM t AS SINGLE
    t=TIMER
        ! mov ecx,1000000000 ' 1e9 cycles
    mdo:

        ' AMD64Dual @2GHz (no other apps running)
        ' This loop keeps 1 core 100% busy (almost)
        ' with a variability of about 2%
       
        '----------------------------------------------
        ' RESULTS                 Seconds  Description
        '----------------------------------------------
                                ' 1.56      empty loop

      ' ! mov eax,ecx           ' 1.56      1 register
      '------------------------------------------------
      ' ! mov eax,ecx           '
      ' ! mov edx,ecx           ' 1.56      2 registers
      '------------------------------------------------
      ' ! mov eax,ecx           '
      ' ! mov edx,ecx           '
      ' ! mov ebx,ecx           ' 1.56      3 registers
      '------------------------------------------------
      ' ! mov eax,ecx           '
      ' ! mov edx,ecx           '
      ' ! mov ebx,ecx           '
      ' ! mov esi,ecx           ' 1.56      4 registers
      '------------------------------------------------
      ' ! mov eax,ecx           '
      ' ! mov edx,ecx           '
      ' ! mov ebx,ecx           '
      ' ! mov esi,ecx           '
      ' ! mov edi,ecx           ' 1.56      5 registers
      '------------------------------------------------
      ' ! mov eax,&h10001000    ' 1.56      1 register immediate
      ' ! mov edx,&h10001000    ' 1.57      2 registers immediate
      ' ! mov ebx,&h10001000    ' 2.06      3 registers immediate
      ' ! mov esi,&h10001000    ' 2.06      4 registers immediate
      ' ! mov edi,&h10001000    ' 2.06      5 registers immediate
      '------------------------------------------------
      ' ! add eax,ecx           '
      ' ! add edx,ecx           '
      ' ! add ebx,ecx           '
      ' ! add esi,ecx           '
      ' ! add edi,ecx           ' 1.56      5 registers independent operations
      '------------------------------------------------
      ' ! add eax,ecx           '
      ' ! add ebx,eax           '
      ' ! add edx,ebx           '
      ' ! add esi,edx           '
      ' ! add edi,esi           ' 1.56      5 registers serially dependent operations
      '------------------------------------------------

      '================================================
      ' ! mul esi               ' 1.56      1 multiply
      '------------------------------------------------
      ' ! add ebx,ecx           '
      ' ! mul esi               ' 1.56      independent add and multiply
      '------------------------------------------------
        ! add eax,ecx           '
        ! mul esi               ' 2.06      dependent add and multiply
                                '           (eax is the other operand)
      '------------------------------------------------

        ! dec ecx
        ! jg mdo
       
    MSGBOX STR$(TIMER-t)
END FUNCTION