Coder Social home page Coder Social logo

Comments (3)

DigitalInBlue avatar DigitalInBlue commented on August 17, 2024

Can you demonstrate this bug on a POD or STL type such that it can be duplicated?

DoNotOptimizeAway takes a reference. In this case, it should take a reference to the result of the "u+v" operation and should not at all change the results or the way "u+v" is computed.

from celero.

xuyuan avatar xuyuan commented on August 17, 2024

I think STL is too complicated for compiler, but for POD, compiler can do great job. I created a small example:

#include <celero/Celero.h>
#include <eigen3/Eigen/Eigen>

CELERO_MAIN;

Eigen::Vector3f u, v;
struct Vec {
  float x, y, z;
};
Vec a, b;

Vec add(const Vec& a, const Vec& b) {
  Vec c;
  c.x = a.x + b.x;
  c.y = a.y + b.y;
  c.z = a.z + b.z;
  return c;
}

BASELINE(DemoSimple, Baseline, 0, 7100000)
{
  asm("# test eigen begin");
  celero::DoNotOptimizeAway(Eigen::Vector3f(u + v));
  asm("# test eigen end");

  asm("# test POD begin");
  celero::DoNotOptimizeAway(add(a, b));
  asm("# test POD end");
}

The assembler I got from gcc 4.7 is

# 22 "/home/xu/projects/Celero/examples/bug_report.cpp" 1
    # test eigen begin
# 0 "" 2
#NO_APP
    movss   u(%rip), %xmm0
    addss   v(%rip), %xmm0
    movss   %xmm0, (%rsp)
    call    getpid
    cmpl    $1, %eax
    je  .L68
.L65:
#APP
# 24 "/home/xu/projects/Celero/examples/bug_report.cpp" 1
    # test eigen end
# 0 "" 2
# 26 "/home/xu/projects/Celero/examples/bug_report.cpp" 1
    # test POD begin
# 0 "" 2
#NO_APP
    movss   a(%rip), %xmm0
    addss   b(%rip), %xmm0
    movss   %xmm0, 16(%rsp)
    call    getpid
    cmpl    $1, %eax
    je  .L69
.L66:
#APP
# 28 "/home/xu/projects/Celero/examples/bug_report.cpp" 1
    # test POD end

With bugfix, the result is follow, so you can see the difference.

# 22 "/home/xu/projects/Celero/examples/bug_report.cpp" 1
    # test eigen begin
# 0 "" 2
#NO_APP
    movss   u(%rip), %xmm0
    addss   v(%rip), %xmm0
    movss   %xmm0, (%rsp)
    movss   u+4(%rip), %xmm0
    addss   v+4(%rip), %xmm0
    movss   %xmm0, 4(%rsp)
    movss   u+8(%rip), %xmm0
    addss   v+8(%rip), %xmm0
    movss   %xmm0, 8(%rsp)
    call    getpid
    cmpl    $1, %eax
    je  .L65
.L68:
#APP
# 24 "/home/xu/projects/Celero/examples/bug_report.cpp" 1
    # test eigen end
# 0 "" 2
# 26 "/home/xu/projects/Celero/examples/bug_report.cpp" 1
    # test POD begin
# 0 "" 2
#NO_APP
    movss   a+4(%rip), %xmm1
    movss   a+8(%rip), %xmm0
    addss   b+4(%rip), %xmm1
    movss   a(%rip), %xmm2
    addss   b+8(%rip), %xmm0
    addss   b(%rip), %xmm2
    movss   %xmm1, 20(%rsp)
    movss   %xmm0, 24(%rsp)
    movss   %xmm2, 16(%rsp)
    call    getpid
    cmpl    $1, %eax
    je  .L71
.L67:
#APP
# 28 "/home/xu/projects/Celero/examples/bug_report.cpp" 1
    # test POD end

from celero.

DigitalInBlue avatar DigitalInBlue commented on August 17, 2024

Acknowledged. I see there is a problem here. I am checking in a fix. The fix for Visual Studio is not as nice as for gcc & clang, but I believe it addresses this issue. Thanks for the bug report!

from celero.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.