Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MSVC intrinsics for bit math functions #2266

Closed
DorpsGek opened this issue Sep 3, 2008 · 2 comments
Closed

Use MSVC intrinsics for bit math functions #2266

DorpsGek opened this issue Sep 3, 2008 · 2 comments
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) patch from FlySpray This issue is in fact a Patch, but imported from FlySrpay

Comments

@DorpsGek
Copy link
Member

DorpsGek commented Sep 3, 2008

michi_cc opened the ticket and wrote:

I've prepared a patch that makes MSVC use intrinsics for some bit operations to improve speed.
There are three changes:

  1. Use instrinsics for byte swapping, like it is already done for GCC and Apple.
    If it helps them, it helps MSVC as well.

  2. Use intrinsics for rotate left/right. At least with a variable rotate count MSVC
    will not use the rol/ror CPU instructions on its own. According to Agner Fog, all
    relevant Intel-compatible CPUs have a fast (one clock) implementation of these
    instructions. Measuring the speedup is quite hard as the main improvement is in
    the MD5 sum code (as seen by looking at the disassembly) which is not called
    repeatedly. Because of this, I can't provide hard numbers.

  3. FindFirstBit/FindLastBit: Intel CPUs also have instructions for this, but it is not
    clear if this is really an improvment. On modern CPUs, these instructions are
    reasonably fast, especially when compared with a cmp/jmp cascade that might lead
    to pipeline stalls.
    The problem here is that older CPUs like Pentium 1 or AMD K7 have quite slow bitscan
    instructions (c.f Agner Fog again). As I don't have any old computers around, I can't
    profile this. Because of this, I've also attached a patch without the bitscan part.

Attachments

Reported version: trunk
Operating system: Windows


This issue was imported from FlySpray: https://bugs.openttd.org/task/2266
@DorpsGek
Copy link
Member Author

DorpsGek commented Sep 3, 2008

michi_cc wrote:

Some test for FFB/FLB:
BitScanForward is only competitive on Core 2 CPUs, AMD and older Intel are slower.
BitScanReverse64 is competitive, but only available in 64-bit mode.


This comment was imported from FlySpray: https://bugs.openttd.org/task/2266#comment4685

@DorpsGek
Copy link
Member Author

Rubidium closed the ticket.

Reason for closing: Won't implement


This comment was imported from FlySpray: https://bugs.openttd.org/task/2266

@DorpsGek DorpsGek added Core flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) patch from FlySpray This issue is in fact a Patch, but imported from FlySrpay labels Apr 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) patch from FlySpray This issue is in fact a Patch, but imported from FlySrpay
Projects
None yet
Development

No branches or pull requests

1 participant