News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

different compares clock cycle test ???

Started by daydreamer, February 11, 2025, 04:23:36 AM

Previous topic - Next topic

daydreamer

Hi
what speed difference are there between test,cmp,fpu compare,SSE UCOMISS,SSE2 UCOMISD ?
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

Villuy

Count for each:

.486p
.model flat, stdcall
option casemap:none

include C:\masm32\include\kernel32.inc
includelib C:\masm32\lib\kernel32.lib

.data?

PerformanceFrequency dword ?
dword ?
PerformanceCount1 dword ?
dword ?
PerformanceCount2 dword ?
dword ?

TimeSpent dword ?

.code

Start:

invoke QueryPerformanceFrequency, offset PerformanceFrequency ; Ticks per second frequency
invoke QueryPerformanceCounter, offset PerformanceCount1 ; Execution start time
mov ecx, 1000000000

CountTime:

test eax, 5
loop CountTime

invoke QueryPerformanceCounter, offset PerformanceCount2 ; Execution end time
mov eax, PerformanceCount2
sub eax, PerformanceCount1 ; Number of ticks elapsed
mov edx, 1000000 ; Converting ticks to microseconds
mul edx
div PerformanceFrequency
mov TimeSpent, eax ; Execution time in microseconds

invoke ExitProcess, 0

end Start

NoCforMe

I think the OP was asking for timings of these instructions, not code to measure them.
Assembly language programming should be fun. That's why I do it.

zedd151

Quote from: NoCforMe on February 11, 2025, 08:53:52 AMI think the OP was asking for timings of these instructions, not code to measure them.
I think that was a hint for daydreamer to time them for himself. I think...  :cool:
I, of course, could be mistaken. That's happened once before.  :tongue:
¯\_(ツ)_/¯

NoCforMe

Why should you have to write a program to find these timings when they're probably published somewhere already? It's not like they're some kind of Top Sekrit info.
Assembly language programming should be fun. That's why I do it.

zedd151

Quote from: NoCforMe on February 11, 2025, 09:11:54 AMWhy should you have to write a program to find these timings when they're probably published somewhere already? It's not like they're some kind of Top Sekrit info.
Because timings can differ wildly from one processor to another, and definitely between AMD vs. Intel for some instructions. Same holds true for cycle counts as well, judging by some of the threads in this very board (The Laboratory).
¯\_(ツ)_/¯

sinsi

Have a look at masm32\macros\timers.asm
You can count clock cycles and execution time with the macros.
They aren't in the MASM64 package though, but I think MichaelW ported them to 64-bit somewhere.

NoCforMe

Macros, schmacros.
The code given above by Villuy shows how simple this is:

  • Call QueryPerformanceCounter(), stash the start time
  • Run the operation you want to time
  • Call QueryPerformanceCounter() again, subtract the start time from this time
  • Scale the result using the value returned by QueryPerformanceFrequency(), display the result
Assembly language programming should be fun. That's why I do it.

sinsi

counter_begin 100000,HIGH_PRIORITY_CLASS
;your code here
counter_end
;EAX has cycle count
:rolleyes:

NoCforMe

To answer the OP's question without writing code, you might want to check this document of Agner Fog's, which gives the following info for each instruction for many different processors:

  • Ops ("Number of macro-operations issued from instruction decoder to schedulers")
  • Latency: ("This is the delay that the instruction generates in a dependency chain. The numbers are minimum values. Cache misses, misalignment, and exceptions may increase the clock counts considerably.")
  • Reciprocal throughput ("This is also called issue latency. This value indicates the average number of clock cycles from the execution of an instruction begins to a subsequent independent instruction of the same kind can begin to execute.")

As you can see, determining execution time for instructions is no simple thing. However, these tables at least offer the chance to compare instructions to see which ones may be relatively faster.
Of course, as they say, YMMV.
Assembly language programming should be fun. That's why I do it.

Villuy

In fact, if instruction is needed in this place, then it is needed. No point in thinking about its price. But in broad sense, optimization is so complex and unknowable that there is nothing to rely on except empirical method for each concrete case.

daydreamer

Real4 compares that can be done with integer 32 bit cmp is +inf ,-inf and zero 0.0 = zero 0
Real8 compares similar but with 64 bit integer cmp
Are these faster ?
Ucomiss faster than fpu compare ?
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

NoCforMe

Quote from: daydreamer on February 12, 2025, 06:15:21 AMReal4 compares that can be done with integer 32 bit cmp is +inf ,-inf and zero 0.0 = zero 0
Real8 compares similar but with 64 bit integer cmp
Are these faster ?
Ucomiss faster than fpu compare ?

Look them up in that document I linked in my reply above.
They're all there. See for yourself.
Assembly language programming should be fun. That's why I do it.

daydreamer

What's happened to this forum ?,nobody wants to test run code anymore ? :(
I have a comparison that might not been tested yet :
A loop with many scalar compares with conditional jumps vs packed compares ???
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

NoCforMe

Well, go ahead and test it then.
You have access to all the tools you need, including macros if you want to go that route.
Report back to us with your results.
Assembly language programming should be fun. That's why I do it.