Archived

This topic is now archived and is closed to further replies.

vbisme

Divide by 2, right shift

Recommended Posts

DrKappa    122
quote:
Original post by Beer Hunter
I think it''s just:

shr eax, 1


As long as you are talking about unsigned numbers,
otherwise you should use sar.

Share this post


Link to post
Share on other sites
TerranFury    142
I don''t think you can divide just by using bitwise logic. But bit-shifting is pretty darn fast, so I don''t see why that wouldn''t be good enough. In fact, using multiple logical operations would undoubtedly be SLOWER!

Share this post


Link to post
Share on other sites
vbisme    100
I''m tested for algorithm on limited machine instructions. Like for left shift or multiply by two, you would simply ADD the number by itself. There is away to do right shift, which I don''t know.

Share this post


Link to post
Share on other sites
S1CA    1418
There are some tricks (although mainly adds and subs) you can do by mixing 1''s complement operations with 2''s complement ops - (NOT vs NEG etc) and there are a few things you can do with masking against a few constants, but as mentioned above it''ll be slower than just using a bitwise shift (or using the FPU divide with good pipelining to hide the overhead).

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites