Commit 02a39536 by Antonio Maiorano

Subzero: replace globals with external memory for constant vectors

Nucleus::createConstantVector was implemented in terms of Subzero's globals API; however, once we generate multiple functions, these globals end up with incorrect addresses in the jitted code. For now, replacing this usage of globals with using externally provided (and allocated) memory via Routine::addConstantData. We can go back to using globals once we fix the problem (b/148086935). Also, this change fixes a problem with loading from a constant pointer, which Subzero interprets as a load with offset. We fix this by casting to a non-const variable when loading. Bug: b/145754674 Change-Id: I6e15385de134d385036eef3e9a255bf0738e4d44 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/40451Tested-by: 's avatarAntonio Maiorano <amaiorano@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com>
parent 370cba59
...@@ -2499,6 +2499,24 @@ TEST(ReactorUnitTests, FRem) ...@@ -2499,6 +2499,24 @@ TEST(ReactorUnitTests, FRem)
EXPECT_FLOAT_EQ(result.v[3], expected.v[3]); EXPECT_FLOAT_EQ(result.v[3], expected.v[3]);
} }
// Subzero's load instruction assumes that a Constant ptr value is an offset, rather than an absolute
// pointer, and would fail during codegen. This was fixed by casting the constant to a non-const
// variable, and loading from it instead. This test makes sure this works.
TEST(ReactorUnitTests, LoadFromConstantData)
{
const int value = 123;
FunctionT<int()> function;
{
auto p = Pointer<Int>{ ConstantData(&value, sizeof(value)) };
Int v = *p;
Return(v);
}
const int result = function("one")();
EXPECT_EQ(result, value);
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment