[dense] Re-enable SIMD to work with fixed-point

* src/dense/ftdense.c: Use integer SIMD functions for accumulation

* src/dense/ftdense.h: Change types of FT26D6, FT20D12 to better fit
their usage
This commit is contained in:
Anurag Thakur 2022-11-19 13:05:14 +05:30
parent 0aa7485b0d
commit eaf09d951f
2 changed files with 43 additions and 22 deletions

View File

@ -24,7 +24,7 @@
#if FT_SSE4_1
#include <tmmintrin.h>
#include <immintrin.h>
#endif
@ -384,26 +384,47 @@ dense_render_glyph( dense_worker* worker, const FT_Bitmap* target )
unsigned char* dest = target->buffer;
unsigned char* dest_end = target->buffer + worker->m_w * worker->m_h;
//#if FT_SSE4_1
#if FT_SSE4_1
// __m128 offset = _mm_setzero_ps();
// __m128i mask = _mm_set1_epi32(0x0c080400);
// __m128 sign_mask = _mm_set1_ps(-0.f);
// for (int i = 0; i < worker->m_h*worker->m_w; i += 4) {
// __m128 x = _mm_load_ps(&source[i]);
// x = _mm_add_ps(x, _mm_castsi128_ps(_mm_slli_si128(_mm_castps_si128(x), 4)));
// x = _mm_add_ps(x, _mm_shuffle_ps(_mm_setzero_ps(), x, 0x40));
// x = _mm_add_ps(x, offset);
// __m128 y = _mm_andnot_ps(sign_mask, x); // fabs(x)
// y = _mm_min_ps(y, _mm_set1_ps(1.0f));
// y = _mm_mul_ps(y, _mm_set1_ps(255.0f));
// __m128i z = _mm_cvtps_epi32(y);
// z = _mm_shuffle_epi8(z, mask);
// _mm_store_ss((float *)&dest[i], (__m128)z);
// offset = _mm_shuffle_ps(x, x, _MM_SHUFFLE(3, 3, 3, 3));
// }
__m128i offset = _mm_setzero_si128();
__m128i mask = _mm_set1_epi32( 0x0c080400 );
//#else /* FT_SSE4_1 */
for (int i = 0; i < worker->m_h*worker->m_w; i += 4)
{
// load 4 floats from source
__m128i x = _mm_load_si128( (__m128i*)&source[i] );
x = _mm_add_epi32( x, _mm_slli_si128( x, 4 ) );
x = _mm_add_epi32(
x, _mm_castps_si128( _mm_shuffle_ps( _mm_setzero_ps(),
_mm_castsi128_ps( x ), 0x40 ) ) );
// add the prefsum of previous 4 floats to all current floats
x = _mm_add_epi32( x, offset );
// take absolute value
__m128i y = _mm_abs_epi32( x ); // fabs(x)
// cap max value to 1
y = _mm_min_epi32( y, _mm_set1_epi32( 4080 ) );
// reduce to 255
y = _mm_srli_epi32( y, 4 );
// shuffle
y = _mm_shuffle_epi8( y, mask );
_mm_store_ss( (float*)&dest[i], (__m128)y );
// store the current prefix sum in offset
offset = _mm_castps_si128( _mm_shuffle_ps( _mm_castsi128_ps( x ),
_mm_castsi128_ps( x ),
_MM_SHUFFLE( 3, 3, 3, 3 ) ) );
}
#else /* FT_SSE4_1 */
FT20D12 value = 0;
@ -422,7 +443,7 @@ dense_render_glyph( dense_worker* worker, const FT_Bitmap* target )
dest++;
}
//#endif /* FT_SSE4_1 */
#endif /* FT_SSE4_1 */
free(worker->m_a);
return error;

View File

@ -20,8 +20,8 @@ extern "C"
#endif
typedef signed long long FT26D6; /* 26.6 fixed-point representation */
typedef signed long long FT20D12; /* 20.12 fixed-point representation */
typedef signed long FT26D6; /* 26.6 fixed-point representation */
typedef signed int FT20D12; /* 20.12 fixed-point representation */
typedef struct
{