Stories
Slash Boxes
Comments

SoylentNews is people

posted by martyb on Saturday September 10 2016, @01:13PM   Printer-friendly
from the some-assembly-required dept.

Dan Luu demonstrates that even when optimizing, compilers often produce very slow code as compared to very basic source that is easily accessible to every assembly code programmer: Hand coded assembly beats intrinsics in speed and simplicity:

Every once in a while, I hear how intrinsics have improved enough that it's safe to use them for high performance code. That would be nice. The promise of intrinsics is that you can write optimized code by calling out to functions (intrinsics) that correspond to particular assembly instructions. Since intrinsics act like normal functions, they can be cross platform. And since your compiler has access to more computational power than your brain, as well as a detailed model of every CPU, the compiler should be able to do a better job of micro-optimizations. Despite decade old claims that intrinsics can make your life easier, it never seems to work out.

The last time I tried intrinsics was around 2007; for more on why they were hopeless then (see this exploration by the author of VirtualDub). I gave them another shot recently, and while they've improved, they're still not worth the effort. The problem is that intrinsics are so unreliable that you have to manually check the result on every platform and every compiler you expect your code to be run on, and then tweak the intrinsics until you get a reasonable result. That's more work than just writing the assembly by hand. If you don't check the results by hand, it's easy to get bad results.

For example, as of this writing, the first two Google hits for popcnt benchmark (and 2 out of the top 3 bing hits) claim that Intel's hardware popcnt instruction is slower than a software implementation that counts the number of bits set in a buffer, via a table lookup using the SSSE3 pshufb instruction. This turns out to be untrue, but it must not be obvious, or this claim wouldn't be so persistent. Let's see why someone might have come to the conclusion that the popcnt instruction is slow if they coded up a solution using intrinsics.

In my own experience, I have yet to find an optimizing compiler that generates code as fast or as compact as I am able to with hand-optimized code.

Dan Luu's entire website is a treasure trove of education for experienced and novice coders alike. I look forward to studying the whole thing. His refreshingly simple HTML 1.0 design is obviously intended to educate, and is an example of my assertion that the true experts all have austere websites.


Original Submission

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: -1, Offtopic) by Anonymous Coward on Saturday September 10 2016, @01:36PM

    by Anonymous Coward on Saturday September 10 2016, @01:36PM (#399977)
    >refreshingly simple HTML 1.0 design
    >the true experts all have austere websites

    .. and kissing spying ass
    <script async src='//www.google-analytics.com/analytics.js'></script>
    Starting Score:    0  points
    Moderation   -1  
       Offtopic=1, Total=1
    Extra 'Offtopic' Modifier   0  

    Total Score:   -1  
  • (Score: 1, Offtopic) by number6 on Saturday September 10 2016, @02:27PM

    by number6 (1831) on Saturday September 10 2016, @02:27PM (#399991) Journal
    -----------------------------------------------------------------------------
    <https://addons.mozilla.org/en-US/firefox/addon/requestpolicy/>

    ##   RequestPolicy
    ##   by Justin Samuel

    Works with Firefox 4.0 - 31.0

    Be in control of which cross-site requests are allowed. Improve the privacy
    of your browsing by not letting other sites know your browsing habits.
    Secure yourself from Cross-Site Request Forgery (CSRF) and other attacks.

    About this Add-on:
    RequestPolicy's new version is under development as RequestPolicy Continued..
       <https://addons.mozilla.org/en-US/firefox/addon/requestpolicy-continued/>
    Ultimately, I'd like RequestPolicy Continued to replace RequestPolicy.
    RequestPolicy development has been slow because I am working on ServerPilot,
       a cPanel alternative for DigitalOcean servers. Thankfully, some great
       community members are taking over development of RequestPolicy.

    Versions:
    * Version 0.5.28.1-signed.1-signed
        Released July 30, 2013
        Works with Firefox 4.0 and later, SeaMonkey 2.1 and later
    * [...]
    * Version 0.5.8
        Released June 5, 2009
        Works with Firefox 3.0 - 3.6b1pre, Mobile 0.1 - 1.0.*,
          SeaMonkey 2.0a - 2.1a1pre

    -----------------------------------------------------------------------------
    <https://addons.mozilla.org/en-US/firefox/addon/requestpolicy-continued/>

    ##   RequestPolicy Continued
    ##   by Martin Kimmerle

    Works with Firefox 24.0 - 50.0a1

    Be in control of which cross-site requests are allowed. Improve the privacy
    of your browsing by not letting other sites know your browsing habits.
    Secure yourself from Cross-Site Request Forgery (CSRF) and other attacks.

    About this Add-on:
    This add-on is the continuation of RequestPolicy by Justin Samuel.
    If you have've got problems, please visit our GitHub repository..
       <https://github.com/RequestPolicyContinued/requestpolicy>
    RequestPolicy is not a replacement for "NoScript" (addon); each focuses on
       different important issues. For the best security, we recommend using
       both RequestPolicy and NoScript. More information on the difference
       between the two is available here..
       <https://requestpolicycontinued.github.io/#faq-noscript>

    Versions:
    * Version 1.0.beta12.3.1531.r1d2cd54.pre
        Released August 15, 2016
        Works with Firefox 24.0 and later, SeaMonkey 2.21 and later
    * [...]
    * Version 1.0.beta11
        Released February 2, 2016
        Works with Firefox 24.0 and later, SeaMonkey 2.21 and later

    -----------------------------------------------------------------------------
  • (Score: 2) by Kilo110 on Saturday September 10 2016, @08:58PM

    by Kilo110 (2853) Subscriber Badge on Saturday September 10 2016, @08:58PM (#400097)

    I don't think there's anything nefarious about analytics by themselves. I think of it as a glorified site hit counter. He probably likes to see where his users are coming from, what pages generates the most activity, etc. It's all great info to have.