Add SIMD
This commit is contained in:
parent
3d0e33d2aa
commit
0b682c5417
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -2,6 +2,7 @@
|
||||
"files.associations": {
|
||||
"ftoutln.h": "c",
|
||||
"svprop.h": "c",
|
||||
"ftdebug.h": "c"
|
||||
"ftdebug.h": "c",
|
||||
"tmmintrin.h": "c"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "ftdense.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <tmmintrin.h>
|
||||
#include "ftdenseerrs.h"
|
||||
|
||||
#define PIXEL_BITS 8
|
||||
@ -372,22 +373,40 @@ 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;
|
||||
float value = 0.0f;
|
||||
while ( dest < dest_end )
|
||||
{
|
||||
value += *source++;
|
||||
if ( value > 0.0f )
|
||||
{
|
||||
int n = (int)( fabs( value ) * 255.0f + 0.5f );
|
||||
if ( n > 255 )
|
||||
n = 255;
|
||||
*dest = (unsigned char)n;
|
||||
}
|
||||
else
|
||||
*dest = 0;
|
||||
dest++;
|
||||
|
||||
__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));
|
||||
}
|
||||
|
||||
// float value = 0.0f;
|
||||
// while ( dest < dest_end )
|
||||
// {
|
||||
// value += *source++;
|
||||
// if ( value > 0.0f )
|
||||
// {
|
||||
// int n = (int)( fabs( value ) * 255.0f + 0.5f );
|
||||
// if ( n > 255 )
|
||||
// n = 255;
|
||||
// *dest = (unsigned char)n;
|
||||
// }
|
||||
// else
|
||||
// *dest = 0;
|
||||
// dest++;
|
||||
// }
|
||||
|
||||
free(worker->m_a);
|
||||
return error;
|
||||
}
|
||||
|
@ -22,8 +22,9 @@ DENSE_DIR := $(SRC_DIR)/dense
|
||||
#
|
||||
DENSE_COMPILE := $(CC) $(ANSIFLAGS) \
|
||||
$I$(subst /,$(COMPILER_SEP),$(DENSE_DIR)) \
|
||||
$(INCLUDE_FLAGS) \
|
||||
$(FT_CFLAGS)
|
||||
$(INCLUDE_FLAGS) \
|
||||
$(FT_CFLAGS) \
|
||||
"-msse4.1"
|
||||
|
||||
|
||||
# DENSE driver sources (i.e., C files)
|
||||
|
Loading…
Reference in New Issue
Block a user