@@ -63,10 +63,10 @@ union float4
63
63
};
64
64
65
65
// -O3 -ffast-math -mfma4
66
- inline float4 normalize (float4 n)
66
+ inline float4 normalize (float3 n)
67
67
{
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 ;
70
70
const float invMag = 1 .0F / std::sqrt (sum);
71
71
return float4{ n.x * invMag, n.y * invMag, n.z * invMag, n.w * invMag } ;
72
72
}
@@ -96,15 +96,15 @@ float3 octDecodeFloat2( float2 f )
96
96
xy.y += ((xy.y < 0 .0F ) ? t : -t);
97
97
#endif
98
98
// 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 ;
100
100
}
101
101
102
102
float3 octDecodeVec ( float2 f )
103
103
{
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 ] );
105
105
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 } );
108
108
return float3{ norm[0 ], norm[1 ], norm[2 ] };
109
109
}
110
110
@@ -194,9 +194,9 @@ static void BenchOctDecodeJCGT(benchmark::State& state) {
194
194
}
195
195
}
196
196
// Register the function as a benchmark
197
+ BENCHMARK (BenchOctDecodeVec)->MinTime(3 );
197
198
BENCHMARK (BenchOctDecodeJCGT)->MinTime(3 );
198
199
BENCHMARK (BenchOctDecodeFloat2)->MinTime(3 );
199
- BENCHMARK (BenchOctDecodeVec)->MinTime(3 );
200
200
201
201
TEST (MyTest, Benchmarks)
202
202
{
@@ -273,9 +273,9 @@ TEST_P(DecodeVec, Correct)
273
273
EXPECT_NEAR ( res.z , encDec.dec .z , 0.001 );
274
274
}
275
275
276
+ INSTANTIATE_TEST_SUITE_P (Decodes, DecodeVec, testing::Range(size_t (0 ), std::size(encDecTests) ) );
276
277
INSTANTIATE_TEST_SUITE_P (Decodes, DecodeJCGT, testing::Range(size_t (0 ), std::size(encDecTests) ) );
277
278
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) ) );
279
279
280
280
#endif // TEST_ENABLED
281
281
0 commit comments