flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
ronware 26 Sep 2011, 18:12
Emil,
The problem is that there is always other activity in other processes and threads. The only way to get consistant results is to make your test last long enough (tens of seconds), and repeat it a number of times. |
|||
![]() |
|
emil 26 Sep 2011, 19:32
ok ronware.
so i put a long loop to get your idea , but.............. have the same problem & get negative results here is the code. Code: /*************************************** * Sphinx C-- * * * * TimerTest demo By Emil Halim * * 26 / 9 / 2011 * ***************************************/ #pragma option w32 //create Windows GUI EXE. #pragma option OBJ //create OBJ file #pragma option OS //speed optimization #pragma option J0 //no startup code. #include <Windows.h> #pragma option ia // allow inline asm #pragma option LST extern cdecl _printf(); #define printf _printf int strlen1(char* pStr) { EAX=0; while(byte *pStr !=0 ) { pStr++; EAX++; } } // *** SSE2 version from MASM forum*** int fastcall strlen4(EAX) { EBX = EAX ; LEA ECX, DSDWORD[EAX+16] EAX &= 0xFFFFFFF0; @shiftOK: XORPS XMM0, XMM0 @a1: PCMPEQB XMM0, DSQWORD[EAX] PMOVMSKB EDX, XMM0 EAX += 16; TEST EDX,EDX JE a1 if(ECX<=EAX) goto a2; ECX -= EAX; SHR EDX, CL SHL EDX, CL JE shiftOK @a2: BSF EDX, EDX SUB EAX, EBX LEA EAX, DSDWORD[EAX+EDX-16] } char* testStr = "SPHINX C-- is so easy (an intermediate position between Assembler and C)"; qword EAX_EDX_1; qword EAX_EDX_2; main() int i; int reslt1, reslt2; int count; { _start: count = 1000000; SetPriorityClass( GetCurrentProcess(), HIGH_PRIORITY_CLASS); rdtsc EAX_EDX_1 = EDX:EAX; for(i=0; i < count; i++) { strlen1( testStr ); } rdtsc EAX_EDX_1 = EDX:EAX - EAX_EDX_1; rdtsc EAX_EDX_2 = EDX:EAX; for(i=0; i < count; i++) { strlen4( testStr ); } rdtsc EAX_EDX_2 = EDX:EAX - EAX_EDX_2; SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS); ST(0) = EAX_EDX_1 / count; fistp reslt1 ST(0) = EAX_EDX_2 / count; fistp reslt2 printf("strlen1 is %d\nstrlen2 is %d", reslt1 , reslt2 ); MessageBox(0,"","",0); } |
|||
![]() |
|
ronware 27 Sep 2011, 07:22
emil wrote: ok ronware. Emil - What exactly are "negative results" in this context? Is it that the difference between them seems to vary up and down? Is the variance very large, or not so much? Please quantify (I cannot currently run the code so I can't see for myself) best regards Ron |
|||
![]() |
|
emil 27 Sep 2011, 16:03
well,
i will demonstrate that what the program did. first i used SetPriorityClass to reduce the effect of multitasking stuff to get most accurate resultes then call rdtsc to get the clock time and save it in EAX_EDX_1 variable. then i put a test loop to measure it's time , so after the loop finished i call rdtsc to get the new clock time then i subtract it from first value EAX_EDX_1 to get the actual time of our test. the differnt time we get is for entir loop , so to get the time pre one cycle i divid it by loop counter. the problem is that the last result is negative !!!!!!!!!! not well , the result of rdtsc in second call is greater than the result of first call , so the subtraction will always postive. |
|||
![]() |
|
emil 30 Sep 2011, 18:05
Ok ,
I get a good results if i change the int type of reslt1, reslt2 variables to double type , and change fistp to fstp instruction. So here is the correct code , hope it will be useful for someone. Code: /*************************************** * Sphinx C-- * * * * TimerTest demo By Emil Halim * * 30 / 9 / 2011 * ***************************************/ #pragma option w32 //create Windows GUI EXE. #pragma option OBJ //create OBJ file #pragma option OS //speed optimization #pragma option J0 //no startup code. #include <Windows.h> #pragma option ia // allow inline asm #pragma option LST extern cdecl _printf(); #define printf _printf int strlen1(char* pStr) { EAX=0; while(byte *pStr !=0 ) { pStr++; EAX++; } } // *** SSE2 version from MASM forum*** int fastcall strlen4(EAX) { EBX = EAX ; LEA ECX, DSDWORD[EAX+16] EAX &= 0xFFFFFFF0; @shiftOK: XORPS XMM0, XMM0 @a1: PCMPEQB XMM0, DSQWORD[EAX] PMOVMSKB EDX, XMM0 EAX += 16; TEST EDX,EDX JE a1 if(ECX<=EAX) goto a2; ECX -= EAX; SHR EDX, CL SHL EDX, CL JE shiftOK @a2: BSF EDX, EDX SUB EAX, EBX LEA EAX, DSDWORD[EAX+EDX-16] } char* testStr = "SPHINX C-- is so easy (an intermediate position between Assembler and C)"; qword EAX_EDX_1; qword EAX_EDX_2; main() int i; double reslt1, reslt2; int count; { _start: count = 1000000; SetPriorityClass( GetCurrentProcess(), HIGH_PRIORITY_CLASS); rdtsc EAX_EDX_1 = EDX:EAX; for(i=0; i < count; i++) { strlen1( testStr ); } rdtsc EAX_EDX_1 = EDX:EAX - EAX_EDX_1; rdtsc EAX_EDX_2 = EDX:EAX; for(i=0; i < count; i++) { strlen4( testStr ); } rdtsc EAX_EDX_2 = EDX:EAX - EAX_EDX_2; SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS); ST(0) = EAX_EDX_1 / count; fstp reslt1 ST(0) = EAX_EDX_2 / count; fstp reslt2 printf("strlen1 is %f\nstrlen2 is %f", reslt1 , reslt2 ); MessageBox(0,"","",0); } |
|||
![]() |
|
ronware 02 Oct 2011, 04:26
Good, Emil --
Sorry, I was unavailable for the past several days. Glad you were able to work it out! Best regards, Ron |
|||
![]() |
|
Matrix 04 Nov 2011, 16:23
sorry wrong thread, never written windows program
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.