flat assembler
Message board for the users of flat assembler.

Index > Heap > Why is division sooooooo slow

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
Furs



Joined: 04 Mar 2016
Posts: 1471
Furs
You guys ought to just compile the damn thing and disassemble it to see for yourselves, but yes revolution is correct. The compiler is required to do integer division. However it does it under-the-hood is left to it, so it could indeed convert to float and back, but for what point? I'm sure not a single compiler will be that dumb, since an integer division instruction exists. (well, I'm not aware of any, not even TCC which I use for semi-scripting purposes dealing with binary data, since I hate Python and most scripting languages can only handle text)

I use C a lot, it's my main high-level programming language, asm being low level. I don't count scripting languages here though. I also disassemble my own and others' stuff very often, I have a strange passion for that, just to see how it ends up in the executable (especially from a high level language).

As for whether DIV is made slow on purpose, that could actually be true by the way. Intel might not decide it's worth making the integer division very fast, considering it's not used very often, and use the transistors in other stuff. Floating point division is another matter (the reciprocal especially).
Post 22 Jul 2016, 17:37
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1412
Location: Toronto, Canada
AsmGuru62
The microcode for DIV is more complex than for MUL.
In x86 sheets you can see that difference is about your measured x5.
Post 22 Jul 2016, 19:53
View user's profile Send private message Send e-mail Reply with quote
l4m2



Joined: 15 Jan 2015
Posts: 648
l4m2
DimonSoft wrote:
In fact, it would be a compiler of some other language very similar to C.
That must be See language Very Happy
Furs wrote:
so it could indeed convert to float and back, but for what point? I'm sure not a single compiler will be that dumb, since an integer division instruction exists.
It makes sense if a 64/64 division is translated into
Code:
fild qword [ebp+8]
fidiv qword [ebp+16]
fist qword [ebp+8]    
instead of
Code:
mov eax, [ebp+16]
cdq
cmp edx, [ebp+20]
... (I won't finish the sub. Too long)    
Post 22 Jul 2016, 23:25
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
https://en.wikipedia.org/wiki/Division_algorithm#Newton.E2.80.93Raphson_division

Requires 3/4 steps to reach the needed precision, and each step requires a multiply. It's not the whole story, but it's a good place along one's path of discovery.

_________________
¯\(°_o)/¯ unlicense.org
Post 23 Jul 2016, 03:08
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.