Skip to content

Commit 0ee4022

Browse files
committed
GDALCopyWords(): perf improvements for some packed conversions
1 parent 9d7dc05 commit 0ee4022

File tree

3 files changed

+510
-150
lines changed

3 files changed

+510
-150
lines changed

autotest/cpp/testcopywords.cpp

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class TestCopyWords : public ::testing::Test
5555
protected:
5656
void SetUp() override
5757
{
58-
pIn = (GByte *)malloc(256);
59-
pOut = (GByte *)malloc(256);
58+
pIn = (GByte *)malloc(2048);
59+
pOut = (GByte *)malloc(2048);
6060
}
6161

6262
void TearDown() override
@@ -74,8 +74,8 @@ class TestCopyWords : public ::testing::Test
7474
GDALDataType outtype, ConstantType outval, ConstantType outvali,
7575
int numLine)
7676
{
77-
memset(pIn, 0xff, 128);
78-
memset(pOut, 0xff, 128);
77+
memset(pIn, 0xff, 1024);
78+
memset(pOut, 0xff, 1024);
7979

8080
*(InType *)(pIn) = (InType)inval;
8181
*(InType *)(pIn + 32) = (InType)inval;
@@ -89,14 +89,14 @@ class TestCopyWords : public ::testing::Test
8989
GDALCopyWords(pIn, intype, 32, pOut, outtype, 32, 2);
9090

9191
/* Test negative offsets */
92-
GDALCopyWords(pIn + 32, intype, -32, pOut + 128 - 16, outtype, -32, 2);
92+
GDALCopyWords(pIn + 32, intype, -32, pOut + 1024 - 16, outtype, -32, 2);
9393

9494
MY_EXPECT(intype, inval, outtype, outval, *(OutType *)(pOut));
9595
MY_EXPECT(intype, inval, outtype, outval, *(OutType *)(pOut + 32));
9696
MY_EXPECT(intype, inval, outtype, outval,
97-
*(OutType *)(pOut + 128 - 16));
97+
*(OutType *)(pOut + 1024 - 16));
9898
MY_EXPECT(intype, inval, outtype, outval,
99-
*(OutType *)(pOut + 128 - 16 - 32));
99+
*(OutType *)(pOut + 1024 - 16 - 32));
100100

101101
if (GDALDataTypeIsComplex(outtype))
102102
{
@@ -105,38 +105,29 @@ class TestCopyWords : public ::testing::Test
105105
((OutType *)(pOut + 32))[1]);
106106

107107
MY_EXPECT(intype, invali, outtype, outvali,
108-
((OutType *)(pOut + 128 - 16))[1]);
108+
((OutType *)(pOut + 1024 - 16))[1]);
109109
MY_EXPECT(intype, invali, outtype, outvali,
110-
((OutType *)(pOut + 128 - 16 - 32))[1]);
110+
((OutType *)(pOut + 1024 - 16 - 32))[1]);
111111
}
112112
else
113113
{
114-
*(InType *)(pIn + GDALGetDataTypeSizeBytes(intype)) = (InType)inval;
115-
/* Test packed offsets */
116-
GDALCopyWords(pIn, intype, GDALGetDataTypeSizeBytes(intype), pOut,
117-
outtype, GDALGetDataTypeSizeBytes(outtype), 2);
118-
119-
MY_EXPECT(intype, inval, outtype, outval, *(OutType *)(pOut));
120-
MY_EXPECT(intype, inval, outtype, outval,
121-
*(OutType *)(pOut + GDALGetDataTypeSizeBytes(outtype)));
114+
constexpr int N = 32 + 31;
115+
for (int i = 0; i < N; ++i)
116+
{
117+
*(InType *)(pIn + i * GDALGetDataTypeSizeBytes(intype)) =
118+
(InType)inval;
119+
}
122120

123-
*(InType *)(pIn + 2 * GDALGetDataTypeSizeBytes(intype)) =
124-
(InType)inval;
125-
*(InType *)(pIn + 3 * GDALGetDataTypeSizeBytes(intype)) =
126-
(InType)inval;
127121
/* Test packed offsets */
128122
GDALCopyWords(pIn, intype, GDALGetDataTypeSizeBytes(intype), pOut,
129-
outtype, GDALGetDataTypeSizeBytes(outtype), 4);
130-
131-
MY_EXPECT(intype, inval, outtype, outval, *(OutType *)(pOut));
132-
MY_EXPECT(intype, inval, outtype, outval,
133-
*(OutType *)(pOut + GDALGetDataTypeSizeBytes(outtype)));
134-
MY_EXPECT(
135-
intype, inval, outtype, outval,
136-
*(OutType *)(pOut + 2 * GDALGetDataTypeSizeBytes(outtype)));
137-
MY_EXPECT(
138-
intype, inval, outtype, outval,
139-
*(OutType *)(pOut + 3 * GDALGetDataTypeSizeBytes(outtype)));
123+
outtype, GDALGetDataTypeSizeBytes(outtype), N);
124+
125+
for (int i = 0; i < N; ++i)
126+
{
127+
MY_EXPECT(
128+
intype, inval, outtype, outval,
129+
*(OutType *)(pOut + i * GDALGetDataTypeSizeBytes(outtype)));
130+
}
140131
}
141132
}
142133

0 commit comments

Comments
 (0)