Announcement

Collapse
No announcement yet.

[u]int64_t to TTInt conversion misbehaving with VoltDB's ttmath library.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • [u]int64_t to TTInt conversion misbehaving with VoltDB's ttmath library.

    Parent thread: https://forum.voltdb.com/showthread....power-platform

    This is in the context of parent thread, but is a different issue hence I am starting a new thread for this.

    I am seeing a difference in output produced by same code when built with VoltDB's ttmath lib and with fresh ttmath cloned from github. This is on power platform. I could trace the issue to int64_t cast to uint to TTInt in src/ee/common/NValue.cpp line 321, which is,

    if (TTInt((uint64_t)kMaxScaleFactor) <= fractional)

    The result of this comparison is wrong due to difference in type conversion.

    I wrote a simple code to mimic this condition as follows:

    std::cout << " test 1 -----------------------------------------" << std::endl;
    {
    TTInt my = 0;
    int64_t test = -1;
    my = TTInt ((uint64_t) test);
    std::cout << "my = " << my << " test (-1) = " << test << std::endl;
    }
    std::cout << " test 2 -----------------------------------------" << std::endl;
    {
    TTInt my = 0;
    int64_t test = 1;
    my = TTInt ((uint64_t) test);
    std::cout << "my = " << my << " test (1) = " << test << std::endl;
    }
    std::cout << " test 3 -----------------------------------------" << std::endl;
    {
    TTInt my = 0;
    int64_t test = 10000;
    my = TTInt ((uint64_t) test);
    std::cout << "my = " << my << " test (10000) = " << test << std::endl;
    }

    I built and tested this code using the voltdb build settings. The build command was:
    g++ -Wall -Woverloaded-virtual -Wpointer-arith -Wcast-qual -Wwrite-strings -Winit-self -Wno-sign-compare -Wno-unused-parameter -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DNOCLOCK -fno-omit-frame-pointer -fvisibility=default -DTTMATH_NOASM -DBOOST_SP_DISABLE_THREADS -DBOOST_DISABLE_THREADS -DBOOST_ALL_NO_LIB -pthread -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-unused-local-typedefs -Wno-ignored-qualifiers -fno-strict-aliasing -std=c++11 -g3 -O3 -m64 -mcpu=power8 -DTTMATH_NOASM -DNDEBUG -DVOLT_LOG_LEVEL=500 -Wno-attributes -Wcast-align -DLINUX -fpic -isystem /root/voltdb/third_party/cpp -I/root/voltdb/src/ee -I/root/voltdb/obj/release/3pty-install/include -I/root/voltdb/obj/release -MMD -MP -o test test.cpp

    The results were as follows:

    test 1 -----------------------------------------
    my = 4294967295 test (-1) = -1 <---- 0xFFFFFFFF
    test 2 -----------------------------------------
    my = 1 test (1) = 1
    test 3 -----------------------------------------
    my = 10000 test (10000) = 10000

    I cloned the ttmath code from the ttmath repository and built the same code. The build command was:
    g++ -Wall -o test -I ../ttmath -DTTMATH_NOASM -std=c++11 -m64 -mcpu=power8 -g3 -O2 test.cpp

    The output was:
    test 1 -----------------------------------------
    my = -1 test (-1) = -1
    test 2 -----------------------------------------
    my = 1 test (1) = 1
    test 3 -----------------------------------------
    my = 10000 test (10000) = 10000

    I am baffled by the difference in the behaviour. Also, ttmathuint.h file seems to be different in original ttmath code and voltdb's ttmath version. Any comments on why this might be happening?

    Thanks,
    Atul.
    Last edited by sowani; 01-16-2017, 01:16 AM.
Working...
X