flat assembler
Message board for the users of flat assembler.

 Index > Main > What is faster Div or SSE2 divss ?
Author
Roman

Joined: 21 Apr 2012
Posts: 562
Roman
What is faster Div or SSE2 divss ?
And how write asm code work like Div ?
And asm code faster than Div (asm comand)
09 Aug 2013, 09:42
tthsqe

Joined: 20 May 2009
Posts: 721
tthsqe
The timings of division instructions (integer, single, double) depend on the divisor. Why don't you run some tests on you own computer?
09 Aug 2013, 10:10
Roman

Joined: 21 Apr 2012
Posts: 562
Roman
tthsqe
ok !
PS: А так хотелось поговорить,пообщяться.
09 Aug 2013, 11:18
bitRAKE

Joined: 21 Jul 2003
Posts: 2829
Location: dank orb
bitRAKE
A) What is faster Div or SSE2 divss ?

They use the same execution units.

B) And how write asm code work like Div ?

a. Binary: Shift and subtract until zero.
b. Approximate and check/modify. (Newton's method)

C) And asm code faster than Div (asm comand)

Only possible for constant cases. At runtime it might be useful to calculate 1/x and multiply. Often algorithms can be setup in that fashion - to eliminate or reduce division use.

Easiest method:
Code:
```mul [_1dX] ; 2^32 / X
; EDX is integer, EAX is fraction    ```

Obviously, these also apply to remainder or modulus.
09 Aug 2013, 14:02

Joined: 25 Sep 2003
Posts: 2145
Location: Estonia
Your questions cannot be answered because DIV/IDIV work on integers, but DIVSS/DIVPS work on floating point numbers. They are generally equally fast, integer one taking 20-27 clocks while floating point taking 10-14 clock to execute (these are the latencies for Sandy Bridge CPU). While comparing DIVSS to FDIV you lose precision. FDIV takes 10-24 clocks. So you see they are competing in the same class, measured in "tens of clocks".

There are some tricks (with integer arithmetric):
For example I often find myself using (x*0x55555556) shr 32 instead of x/3
because in simple cases it works and is a lot faster. You can easily extend this
to division by 6, 12 etc by shifting. Useful in 24-bi / 32-bit RGB / RGBA conversions.
12 Aug 2013, 05:29
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsCompiler InternalsIDE DevelopmentOS ConstructionNon-x86 architecturesHigh Level LanguagesProgramming Language DesignProjects and IdeasExamples and Tutorials Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum