Archived issue #0029825
Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method
Description
gcc (of some old versions, like gcc 4.7, 4.8, 7.2.0) has known issue with xyz() method returning a reference to vector of smaller size like this:
The problem is that gcc considers method as "dereferencing type-punned pointer will break strict aliasing", and following strict aliasing rules it might remove essential code lines.
//! @return XYZ-components modifiable vector
NCollection_Vec3<Element_t>& xyz()
{
return *((NCollection_Vec3<Element_t>* )&v[0]);
The problem is that gcc considers method as "dereferencing type-punned pointer will break strict aliasing", and following strict aliasing rules it might remove essential code lines.
Steps to reproduce
NCollection_Mat4<float> aMatrix;
aMatrix.Translate (NCollection_Vec3<float> (4.0f, 3.0f, 1.0f));
NCollection_Vec4<float> aPoints1[8];
for (int aX = 0; aX < 2; ++aX)
{
for (int aY = 0; aY < 2; ++aY)
{
for (int aZ = 0; aZ < 2; ++aZ)
{
aPoints1[aX * 2 * 2 + aY * 2 + aZ] =
NCollection_Vec4<float> (-1.0f + 2.0f * float(aX),
-1.0f + 2.0f * float(aY),
-1.0f + 2.0f * float(aZ),
1.0f);
}
}
}
NCollection_Vec3<float> aPoints2[8];
for (int aPntIdx = 0; aPntIdx < 8; ++aPntIdx)
{
// bug, the evaluation of line below can be dropped by optimizer
// while retrieving xyz() value the line after
aPoints1[aPntIdx] = aMatrix * aPoints1[aPntIdx];
aPoints2[aPntIdx] = aPoints1[aPntIdx].xyz() / aPoints1[aPntIdx].w();
//aPoints2[aPntIdx] = NCollection_Vec3<float> (aPoints1[aPntIdx].x(),
aPoints1[aPntIdx].y(),
aPoints1[aPntIdx].z())
/ aPoints1[aPntIdx].w();
}
Public activity
25 archived notes
Participants are labeled by their role within this record.
Branch [archived branch] has been created by Author.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Wed May 30 13:54:02 2018 +0300
0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method
[revision removed]
Detailed log of new commits:
Author: Author
Date: Wed May 30 13:54:02 2018 +0300
0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method
Branch [archived branch] has been updated forcibly by Author.
[revision removed]
[revision removed]
Branch [archived branch] has been updated by Author.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Wed May 30 21:01:26 2018 +0300
Define proxy structures NCollection_Vec2Ref/NCollection_Vec3Ref
for returning modifiable entities from methods like NCollection_Vec4::xyz().
[revision removed]
Detailed log of new commits:
Author: Author
Date: Wed May 30 21:01:26 2018 +0300
Define proxy structures NCollection_Vec2Ref/NCollection_Vec3Ref
for returning modifiable entities from methods like NCollection_Vec4::xyz().
Branch [archived branch] has been updated forcibly by Author.
[revision removed]
[revision removed]
Branch [archived branch] has been updated forcibly by Author.
[revision removed]
[revision removed]
Branch [archived branch] has been updated forcibly by Author.
[revision removed]
[revision removed]
Branch [archived branch] has been updated forcibly by Author.
[revision removed]
[revision removed]
Branch [archived branch] has been updated forcibly by Author.
[revision removed]
[revision removed]
Branch [archived branch] has been updated forcibly by Author.
[revision removed]
[revision removed]
Branch [archived branch] has been updated by Author.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Thu May 31 13:04:29 2018 +0300
# workaround crash of SWIG prepocessor
[revision removed]
Detailed log of new commits:
Author: Author
Date: Thu May 31 13:04:29 2018 +0300
# workaround crash of SWIG prepocessor
Branch [archived branch] has been updated by Author.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Thu May 31 13:18:55 2018 +0300
# extend description of proxy classes
[revision removed]
Detailed log of new commits:
Author: Author
Date: Thu May 31 13:18:55 2018 +0300
# extend description of proxy classes
Branch [archived branch] has been created by Author.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Sat Jun 2 16:05:11 2018 +0300
Eliminate NCollection_Vec4::xyz() returning a reference to NCollection_Vec3
Author: Author
Date: Wed May 30 18:59:12 2018 +0300
0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method
[revision removed]
Detailed log of new commits:
Author: Author
Date: Sat Jun 2 16:05:11 2018 +0300
Eliminate NCollection_Vec4::xyz() returning a reference to NCollection_Vec3
Author: Author
Date: Wed May 30 18:59:12 2018 +0300
0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method
Branch [archived branch] has been created by Participant.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Wed May 30 18:59:12 2018 +0300
0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method
Methods of NCollection_Vec3 and NCollection_Vec3 that returned reference to internal buffer as vector of lower dimension (non-const xy(), xyz() etc.) are eliminated.
Use of these methods could led to generation of incorrect binary code by GCC.
Instead added new method SetValues() accepting vector of lower dimension and additional value.
DRAW test command QANColTestVec4 reproducing one situation where the bug occurs is added, along with a test case.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Wed May 30 18:59:12 2018 +0300
0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method
Methods of NCollection_Vec3 and NCollection_Vec3 that returned reference to internal buffer as vector of lower dimension (non-const xy(), xyz() etc.) are eliminated.
Use of these methods could led to generation of incorrect binary code by GCC.
Instead added new method SetValues() accepting vector of lower dimension and additional value.
DRAW test command QANColTestVec4 reproducing one situation where the bug occurs is added, along with a test case.
Reviewed with amendments and tested, see branch CR29825_2 and Jenkins job CR29825-master-KGV
Combination -
OCCT branch : [archived branch] SHA - [revision removed]
Products branch : [archived branch] SHA - [revision removed]
was compiled on Linux, MacOS and Windows platforms and tested in optimize mode.
Number of compiler warnings:
No new/fixed warnings
Regressions/Differences/Improvements:
No regressions/differences
CPU differences:
Debian70-64:
OCCT
Total CPU difference: 17047.97000000008 / 17011.039999999866 [+0.22%]
Products
Total CPU difference: 7454.750000000047 / 7518.500000000041 [-0.85%]
Windows-64-VC10:
OCCT
Total CPU difference: 16828.4986742986 / 16821.806231398525 [+0.04%]
Products
Total CPU difference: 8237.14920189988 / 8177.369618699882 [+0.73%]
Image differences :
No differences that require special attention
Memory differences :
No differences that require special attention
OCCT branch : [archived branch] SHA - [revision removed]
Products branch : [archived branch] SHA - [revision removed]
was compiled on Linux, MacOS and Windows platforms and tested in optimize mode.
Number of compiler warnings:
No new/fixed warnings
Regressions/Differences/Improvements:
No regressions/differences
CPU differences:
Debian70-64:
OCCT
Total CPU difference: 17047.97000000008 / 17011.039999999866 [+0.22%]
Products
Total CPU difference: 7454.750000000047 / 7518.500000000041 [-0.85%]
Windows-64-VC10:
OCCT
Total CPU difference: 16828.4986742986 / 16821.806231398525 [+0.04%]
Products
Total CPU difference: 8237.14920189988 / 8177.369618699882 [+0.73%]
Image differences :
No differences that require special attention
Memory differences :
No differences that require special attention
Branch [archived branch] has been deleted by Author.
[revision removed]
[revision removed]
Branch [archived branch] has been deleted by Author.
[revision removed]
[revision removed]
Branch [archived branch] has been deleted by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been created by Author.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Wed Jun 6 22:42:11 2018 +0300
0029847: Visualization, Image_Diff - Tolerance is not effective for 24/32bit image formats
Image_Color - removed semibroken summ/difference operators.
Image_Diff now uses signed integer for computing differnce between ubyte3 components.
Author: Author
Date: Thu May 31 13:18:55 2018 +0300
# extend description of proxy classes
Author: Author
Date: Thu May 31 13:04:29 2018 +0300
# workaround crash of SWIG prepocessor
Author: Author
Date: Thu May 31 00:58:06 2018 +0300
Define proxy structures NCollection_Vec2Ref/NCollection_Vec3Ref
for returning modifiable entities from methods like NCollection_Vec4::xyz().
Author: Author
Date: Wed May 30 18:59:12 2018 +0300
0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method
[revision removed]
Detailed log of new commits:
Author: Author
Date: Wed Jun 6 22:42:11 2018 +0300
0029847: Visualization, Image_Diff - Tolerance is not effective for 24/32bit image formats
Image_Color - removed semibroken summ/difference operators.
Image_Diff now uses signed integer for computing differnce between ubyte3 components.
Author: Author
Date: Thu May 31 13:18:55 2018 +0300
# extend description of proxy classes
Author: Author
Date: Thu May 31 13:04:29 2018 +0300
# workaround crash of SWIG prepocessor
Author: Author
Date: Thu May 31 00:58:06 2018 +0300
Define proxy structures NCollection_Vec2Ref/NCollection_Vec3Ref
for returning modifiable entities from methods like NCollection_Vec4::xyz().
Author: Author
Date: Wed May 30 18:59:12 2018 +0300
0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method
Branch [archived branch] has been deleted by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been created by Author.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Wed Jun 6 22:42:11 2018 +0300
0029847: Visualization, Image_Diff - Tolerance is not effective for 24/32bit image formats
Image_Color - removed semibroken summ/difference operators.
Image_Diff now uses signed integer for computing differnce between ubyte3 components.
Author: Author
Date: Thu May 31 13:18:55 2018 +0300
# extend description of proxy classes
Author: Author
Date: Thu May 31 13:04:29 2018 +0300
# workaround crash of SWIG prepocessor
Author: Author
Date: Thu May 31 00:58:06 2018 +0300
Define proxy structures NCollection_Vec2Ref/NCollection_Vec3Ref
for returning modifiable entities from methods like NCollection_Vec4::xyz().
Author: Author
Date: Wed May 30 18:59:12 2018 +0300
0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method
[revision removed]
Detailed log of new commits:
Author: Author
Date: Wed Jun 6 22:42:11 2018 +0300
0029847: Visualization, Image_Diff - Tolerance is not effective for 24/32bit image formats
Image_Color - removed semibroken summ/difference operators.
Image_Diff now uses signed integer for computing differnce between ubyte3 components.
Author: Author
Date: Thu May 31 13:18:55 2018 +0300
# extend description of proxy classes
Author: Author
Date: Thu May 31 13:04:29 2018 +0300
# workaround crash of SWIG prepocessor
Author: Author
Date: Thu May 31 00:58:06 2018 +0300
Define proxy structures NCollection_Vec2Ref/NCollection_Vec3Ref
for returning modifiable entities from methods like NCollection_Vec4::xyz().
Author: Author
Date: Wed May 30 18:59:12 2018 +0300
0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method
Branch [archived branch] has been deleted by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been created by Author.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Wed Jun 6 22:42:11 2018 +0300
0029847: Visualization, Image_Diff - Tolerance is not effective for 24/32bit image formats
Image_Color - removed semibroken summ/difference operators.
Image_Diff now uses signed integer for computing differnce between ubyte3 components.
Author: Author
Date: Thu May 31 13:18:55 2018 +0300
# extend description of proxy classes
Author: Author
Date: Thu May 31 13:04:29 2018 +0300
# workaround crash of SWIG prepocessor
Author: Author
Date: Thu May 31 00:58:06 2018 +0300
Define proxy structures NCollection_Vec2Ref/NCollection_Vec3Ref
for returning modifiable entities from methods like NCollection_Vec4::xyz().
Author: Author
Date: Wed May 30 18:59:12 2018 +0300
0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method
[revision removed]
Detailed log of new commits:
Author: Author
Date: Wed Jun 6 22:42:11 2018 +0300
0029847: Visualization, Image_Diff - Tolerance is not effective for 24/32bit image formats
Image_Color - removed semibroken summ/difference operators.
Image_Diff now uses signed integer for computing differnce between ubyte3 components.
Author: Author
Date: Thu May 31 13:18:55 2018 +0300
# extend description of proxy classes
Author: Author
Date: Thu May 31 13:04:29 2018 +0300
# workaround crash of SWIG prepocessor
Author: Author
Date: Thu May 31 00:58:06 2018 +0300
Define proxy structures NCollection_Vec2Ref/NCollection_Vec3Ref
for returning modifiable entities from methods like NCollection_Vec4::xyz().
Author: Author
Date: Wed May 30 18:59:12 2018 +0300
0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method
Branch [archived branch] has been deleted by Participant.
[revision removed]
[revision removed]
Related records