Skip to content

Commit 1ce393b

Browse files
Minor tweaks
1 parent 9739271 commit 1ce393b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

test.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ union float4
6363
};
6464

6565
// -O3 -ffast-math -mfma4
66-
inline float4 normalize(float4 n)
66+
inline float4 normalize(float3 n)
6767
{
68-
const float4 sqr = {n.v * n.v};
69-
const float sum = sqr.x + sqr.y + sqr.z;// + sqr.w;
68+
const float4 sqr = {n.x * n.x, n.y * n.y , n.z * n.z, 0 };
69+
const float sum = sqr.x + sqr.y + sqr.z + sqr.w;
7070
const float invMag = 1.0F / std::sqrt(sum);
7171
return float4{ n.x * invMag, n.y * invMag, n.z * invMag, n.w * invMag } ;
7272
}
@@ -96,15 +96,15 @@ float3 octDecodeFloat2( float2 f )
9696
xy.y += ((xy.y < 0.0F) ? t : -t);
9797
#endif
9898
// xy += signNotZero(xy) * -t;
99-
return normalize( float4{ xy.x, xy.y, z, 0} ).xyz;
99+
return normalize(float3{ xy.x, xy.y, z }).xyz;
100100
}
101101

102102
float3 octDecodeVec( float2 f )
103103
{
104-
float z = 1.0F - std::abs(f.x) - std::abs(f.y);
104+
float z = 1.0F - std::abs(f.v[0]) - std::abs(f.v[1]);
105105
const float t = std::max(-z, 0.0F);
106-
v2sf quad = (f.v < 0.0F) ? t : -t;
107-
v4sf norm = normalize( v4sf{ f.v[0] + quad[0], f.v[1] + quad[1], z, 0} );
106+
f.v += ((f.v < 0.0F) ? t : -t);
107+
v4sf norm = normalize(v4sf{ f.v[0], f.v[1], z, 0 });
108108
return float3{ norm[0], norm[1], norm[2] };
109109
}
110110

@@ -194,9 +194,9 @@ static void BenchOctDecodeJCGT(benchmark::State& state) {
194194
}
195195
}
196196
// Register the function as a benchmark
197+
BENCHMARK(BenchOctDecodeVec)->MinTime(3);
197198
BENCHMARK(BenchOctDecodeJCGT)->MinTime(3);
198199
BENCHMARK(BenchOctDecodeFloat2)->MinTime(3);
199-
BENCHMARK(BenchOctDecodeVec)->MinTime(3);
200200

201201
TEST(MyTest, Benchmarks)
202202
{
@@ -273,9 +273,9 @@ TEST_P(DecodeVec, Correct)
273273
EXPECT_NEAR( res.z, encDec.dec.z, 0.001);
274274
}
275275

276+
INSTANTIATE_TEST_SUITE_P(Decodes, DecodeVec, testing::Range(size_t(0), std::size(encDecTests) ) );
276277
INSTANTIATE_TEST_SUITE_P(Decodes, DecodeJCGT, testing::Range(size_t(0), std::size(encDecTests) ) );
277278
INSTANTIATE_TEST_SUITE_P(Decodes, DecodeFloat2, testing::Range(size_t(0), std::size(encDecTests) ) );
278-
INSTANTIATE_TEST_SUITE_P(Decodes, DecodeVec, testing::Range(size_t(0), std::size(encDecTests) ) );
279279

280280
#endif //TEST_ENABLED
281281

0 commit comments

Comments
 (0)