Implement constant folding for many transcendentals#3166
Implement constant folding for many transcendentals#3166s-perron merged 2 commits intoKhronosGroup:masterfrom zeux:master
Conversation
This change adds support for folding of sin/cos/tan/asin/acos/atan, exp/log/exp2/log2, sqrt, atan2 and pow. The mechanism allows to use any C function to implement folding in the future; for now I limited the actual additions to the most commonly used intrinsics in the shaders. Unary folder had to be tweaked to work with extended instructions - for extended instructions, constants.size() == 2 and constants[0] == nullptr. This adjustment is similar to the one binary folder already performs. Fixes #1390.
s-perron
left a comment
There was a problem hiding this comment.
Thanks. This looks great.
|
Apparently Android's standard library implementation used by the build doesn't have std::exp2 :-/ I think this is because it's using a (deprecated) libstdc++ library instead of libc++... I'm going to change exp2/log2 to use global (C99) versions. |
|
This didn't solve this completely :( The build looks like it's using r15c NDK and targets Android 15 ABI (4.1). I'm surprised this still targets the toolchain/ABI this old, but I could implement a shim that uses |
On old versions of Android NDK, we don't get std::exp2/std::log2 because of partial C++11 support. We do get ::exp2, but not ::log2 so we need to emulate that.
|
clang-debug build timed out during building so probably unrelated to this change; at least Android is green now 😅 |
|
macos builds passed earlier, so that is not an issue. I just want to take a little time to see if it is possible to avoid the if-def that was added in the middle of |
Sure, but it's a necessity. I don't know why the Android ABI that is used is so low - if the ABI can be bumped, we can use global exp2/log2 unconditionally. If the Android build stops using deprecated STL implementation and becomes C++11 compliant, we can use C++11 std::exp2/std::log2. Alternatively we can always use ::exp2 and log2 emulation but it seems wrong to do this because surely, eventually Android builds will migrate to modern versions of the toolchain. |
|
I'll fix this up later. I know we cannot remove the if-def completely. However, it could be moved somewhere out of the way. |
Roll third_party/glslang/ 19ec0d2..5e86b28 (3 commits) KhronosGroup/glslang@19ec0d2...5e86b28 $ git log 19ec0d2..5e86b28 --date=short --no-merges --format='%ad %ae %s' 2020-01-29 jbolz Use NOT ... VERSION_LESS instead of VERSION_GREATER_EQUAL 2020-01-28 jordan.l.justen standalone: Fix --help 2020-01-27 rharrison Use correct enum type in case statement Roll third_party/re2/ 85c014206..05faa8db3 (2 commits) google/re2@85c0142...05faa8d $ git log 85c014206..05faa8db3 --date=short --no-merges --format='%ad %ae %s' 2020-01-31 junyer Avoid using the forward DFA in "ANCHOR_END" cases. 2020-01-29 junyer Make the fuzzer use FuzzedDataProvider. Roll third_party/spirv-cross/ 68bf0f824..6b2add8e2 (4 commits) KhronosGroup/SPIRV-Cross@68bf0f8...6b2add8 $ git log 68bf0f824..6b2add8e2 --date=short --no-merges --format='%ad %ae %s' 2020-02-03 post Use GNUInstallDirs for include path as well. 2020-02-01 orbea cmake: Don't hardcode the pkg-config file. 2020-02-01 orbea cmake: Use GNUInstallDirs. 2020-02-01 post CMake: Avoid warning when parent project uses VERSION in project(). Roll third_party/spirv-tools/ 1b34410..ddcc117 (7 commits) KhronosGroup/SPIRV-Tools@1b34410...ddcc117 $ git log 1b34410..ddcc117 --date=short --no-merges --format='%ad %ae %s' 2020-02-03 stevenperron Update CHANGES 2020-02-03 arseny.kapoulkine Implement constant folding for many transcendentals (KhronosGroup#3166) 2020-01-30 afdx Fix typo in comment. (KhronosGroup#3163) 2020-01-30 afdx spirv-fuzz: Arbitrary variable facts (KhronosGroup#3165) 2020-01-29 afdx spirv-fuzz: Add outlining test (KhronosGroup#3164) 2020-01-29 afdx spirv-fuzz: Make functions "livesafe" during donation (KhronosGroup#3146) 2020-01-28 stevenperron Dead branch elim fix (KhronosGroup#3160) Created with: roll-dep third_party/effcee third_party/glslang third_party/googletest third_party/re2 third_party/spirv-cross third_party/spirv-headers third_party/spirv-tools
This change adds support for folding of sin/cos/tan/asin/acos/atan,
exp/log/exp2/log2, sqrt, atan2 and pow.
The mechanism allows to use any C function to implement folding in the
future; for now I limited the actual additions to the most commonly used
intrinsics in the shaders.
Unary folder had to be tweaked to work with extended instructions - for
extended instructions, constants.size() == 2 and constants[0] ==
nullptr. This adjustment is similar to the one binary folder already
performs.
Fixes #1390.