Jump to content
  • Advertisement

Archived

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

vbisme

Divide by 2, right shift

This topic is 6088 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Guest Anonymous Poster
shift to the high order

Share this post


Link to post
Share on other sites
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
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
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
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!