Get rid of level of indirection, noticed by VC++ 2017 bug
authorBruce Dawson <brucedawson@google.com>
Sun, 22 Jan 2017 20:43:53 +0000 (12:43 -0800)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Mon, 23 Jan 2017 15:26:28 +0000 (15:26 +0000)
When building Chrome with VC++ 2017 the QuickFDot6Inverse::table pointer
is initialized to zero. This is certainly a bug, and it has been
reported to the VC++ team. But, the table pointer appears to be
unnecessary. Changing the code to reference the array directly should
give identical or perhaps even better code.

The change to the array indexing code is as follows:

- return table[x];
+ gFDot6INVERSE[kInverseTableSize + x];

This looks like a step backwards, but it isn't. 'table' is a pointer.
So, by default the compiler will load this pointer and then load the
value from the array. gFDot6INVERSE is an array, not a pointer. This
means that the adding of kInverseTableSize is trivially done at
compile time, and there is no loading of a pointer - only one data
segment memory access is needed.

The compiler may have realized that this optimization was ready before,
but now it is more trivial. And, this works around the VC++ 2017 bug so
that Chrome with VC++ 2017 will launch.

https://connect.microsoft.com/VisualStudio/feedback/details/3119337
BUG=683729

Change-Id: Iad443b59a70af83b39260e244e3242e782fafdbb
Reviewed-on: https://skia-review.googlesource.com/7284
Reviewed-by: Yuqian Li <liyuqian@google.com>
Commit-Queue: Yuqian Li <liyuqian@google.com>

src/core/SkFDot6.h

index b9a5c2a..0046661 100644 (file)
@@ -78,12 +78,10 @@ inline SkFixed SkFDot6Div(SkFDot6 a, SkFDot6 b) {
 #include "SkFDot6Constants.h"
 
 class QuickFDot6Inverse {
-private:
-    static constexpr const SkFDot6* table = gFDot6INVERSE + kInverseTableSize;
 public:
     inline static SkFixed Lookup(SkFDot6 x) {
         SkASSERT(SkAbs32(x) < kInverseTableSize);
-        return table[x];
+        return gFDot6INVERSE[kInverseTableSize + x];
     }
 };