Skip to content

Instantly share code, notes, and snippets.

@QuLogic
Last active October 15, 2017 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QuLogic/90fcf703b1974a22b4127d48cebdee83 to your computer and use it in GitHub Desktop.
Save QuLogic/90fcf703b1974a22b4127d48cebdee83 to your computer and use it in GitHub Desktop.
PPC Barbs problem

Fedora 26 x86 Output

$ g++ --version
g++ (GCC) 7.1.1 20170622 (Red Hat 7.1.1-3)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ g++ -O2 -fPIC -o test test.cpp && ./test
Trial 1: 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
		-> -347.36689814814809552 (expected: -347.36689814814809552)
Trial 2: 
	(296.30129417178909534,384.53203916154427588) 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)
Trial 3: 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)
$ g++ -m32 -O2 -fPIC -o test test.cpp && ./test
Trial 1: 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
		-> -347.36689814814809552 (expected: -347.36689814814809552)
Trial 2: 
	(296.30129417178909534,384.53203916154427588) 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)
Trial 3: 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)

Fedora 26 PPC64

This is on Fedora test machines, using mock for Fedora 26.

Big Endian

$ g++ --version
g++ (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
g++ -O2 -fPIC test.cpp -o test && ./test
Trial 1: 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
		-> -347.36689814814809552 (expected: -347.36689814814809552)
Trial 2: 
	(296.30129417178909534,384.53203916154427588) 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
		-> -1.1172633071198007275e-14 (expected: 0)
Trial 3: 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
	(310.73805762101443406,370.09527571231893717) 
		-> 2.0028264676141013257e-15 (expected: 0)
$ g++ -fPIC test.cpp -o test && ./test
Trial 1: 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
		-> -347.36689814814809552 (expected: -347.36689814814809552)
Trial 2: 
	(296.30129417178909534,384.53203916154427588) 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)
Trial 3: 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)
$ g++ -O2 test.cpp -o test && ./test
Trial 1: 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
		-> -347.36689814814809552 (expected: -347.36689814814809552)
Trial 2: 
	(296.30129417178909534,384.53203916154427588) 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)
Trial 3: 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)

Little Endian

$ g++ --version
g++ (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ g++ -O2 -fPIC test.cpp -o test && ./test
Trial 1: 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
		-> -347.36689814814809552 (expected: -347.36689814814809552)
Trial 2: 
	(296.30129417178909534,384.53203916154427588) 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
		-> -1.1172633071198007275e-14 (expected: 0)
Trial 3: 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
	(310.73805762101443406,370.09527571231893717) 
		-> 2.0028264676141013257e-15 (expected: 0)
$ g++ -fPIC test.cpp -o test && ./test
Trial 1: 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
		-> -347.36689814814809552 (expected: -347.36689814814809552)
Trial 2: 
	(296.30129417178909534,384.53203916154427588) 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)
Trial 3: 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)
$ g++ -O2 test.cpp -o test && ./test
Trial 1: 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
		-> -347.36689814814809552 (expected: -347.36689814814809552)
Trial 2: 
	(296.30129417178909534,384.53203916154427588) 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)
Trial 3: 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)

Fedora 25 PPC64

This is on Fedora test machines, so Fedora 25.

Big Endian

$ g++ --version
g++ (GCC) 6.4.1 20170727 (Red Hat 6.4.1-1)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ g++ -O2 -fPIC -o test test.cpp && ./test
Trial 1: 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
		-> -347.36689814814809552 (expected: -347.36689814814809552)
Trial 2: 
	(296.30129417178909534,384.53203916154427588) 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
		-> -1.1172633071198007275e-14 (expected: 0)
Trial 3: 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
	(310.73805762101443406,370.09527571231893717) 
		-> 2.0028264676141013257e-15 (expected: 0)
$ g++ -fPIC -o test /home/fedora/qulogic/test.cpp && ./test
Trial 1: 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
		-> -347.36689814814809552 (expected: -347.36689814814809552)
Trial 2: 
	(296.30129417178909534,384.53203916154427588) 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)
Trial 3: 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)
$ g++ -O2 -o test test.cpp && ./test
Trial 1: 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
		-> -347.36689814814809552 (expected: -347.36689814814809552)
Trial 2: 
	(296.30129417178909534,384.53203916154427588) 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)
Trial 3: 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)

Little Endian

$ g++ --version
g++ (GCC) 6.4.1 20170727 (Red Hat 6.4.1-1)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ g++ -O2 -fPIC test.cpp -o test && ./test
Trial 1: 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
		-> -347.36689814814809552 (expected: -347.36689814814809552)
Trial 2: 
	(296.30129417178909534,384.53203916154427588) 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
		-> -1.1172633071198007275e-14 (expected: 0)
Trial 3: 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
	(310.73805762101443406,370.09527571231893717) 
		-> 2.0028264676141013257e-15 (expected: 0)
$ g++ -fPIC test.cpp -o test && ./test
Trial 1: 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
		-> -347.36689814814809552 (expected: -347.36689814814809552)
Trial 2: 
	(296.30129417178909534,384.53203916154427588) 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)
Trial 3: 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)
$ g++ -O2 test.cpp -o test && ./test
Trial 1: 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
		-> -347.36689814814809552 (expected: -347.36689814814809552)
Trial 2: 
	(296.30129417178909534,384.53203916154427588) 
	(286.67678520563885058,394.15654812769452064) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)
Trial 3: 
	(310.73805762101443406,370.09527571231893717) 
	(320.96409839754903714,374.3059983850096728) 
	(310.73805762101443406,370.09527571231893717) 
		-> 0 (expected: 0)
#include <iostream>
#include <iomanip>
double cross_product(double x1, double y1,
double x2, double y2,
double x, double y)
{
return (x - x2) * (y2 - y1) - (y - y2) * (x2 - x1);
//return x * y2 - x * y1 - x2 * y2 + x2 * y1 - y * x2 + y * x1 + y2 * x2 - y2 * x1;
//return x * (y2 - y1) - y * (x2 - x1) + x2 * y1 - y2 * x1;
}
int main() {
double x1, y1, x2, y2, x, y, ret;
// Should work.
x1 = 0x1.1ead41cb94a2bp+8;
y1 = 0x1.8a281389c0b2bp+8;
x2 = 0x1.36bcf15820d21p+8;
y2 = 0x1.721863fd34835p+8;
x = 0x1.40f6cf270f996p+8;
y = 0x1.764e55e9003edp+8;
ret = -0x1.5b5ded097b425p+8;
std::cout << std::setprecision(20) << "Trial 1: "
"\n\t(" << x1 << "," << y1 << ") "
"\n\t(" << x2 << "," << y2 << ") "
"\n\t(" << x << "," << y << ") "
"\n\t\t-> " << cross_product(x1, y1, x2, y2, x, y) <<
" (expected: " << ret << ")" << std::endl;
// Lower than expected on PPC64.
x1 = 0x1.284d219d664f4p+8;
y1 = 0x1.808833b7ef062p+8;
x2 = 0x1.1ead41cb94a2bp+8;
y2 = 0x1.8a281389c0b2bp+8;
x = 0x1.36bcf15820d21p+8;
y = 0x1.721863fd34835p+8;
ret = 0x0p+0;
std::cout << std::setprecision(20) << "Trial 2: "
"\n\t(" << x1 << "," << y1 << ") "
"\n\t(" << x2 << "," << y2 << ") "
"\n\t(" << x << "," << y << ") "
"\n\t\t-> " << cross_product(x1, y1, x2, y2, x, y) <<
" (expected: " << ret << ")" << std::endl;
// Higher than expected on PPC64.
x1 = 0x1.36bcf15820d21p+8;
y1 = 0x1.721863fd34835p+8;
x2 = 0x1.40f6cf270f996p+8;
y2 = 0x1.764e55e9003edp+8;
x = 0x1.36bcf15820d21p+8;
y = 0x1.721863fd34835p+8;
ret = 0x0p+0;
std::cout << std::setprecision(20) << "Trial 3: "
"\n\t(" << x1 << "," << y1 << ") "
"\n\t(" << x2 << "," << y2 << ") "
"\n\t(" << x << "," << y << ") "
"\n\t\t-> " << cross_product(x1, y1, x2, y2, x, y) <<
" (expected: " << ret << ")" << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment