2 ms·
> Those manual use/optimization of SIMD are done in C anyway. C seems to be used only for SSE intrinsics support. ~16 LoC of "C". This is all C in the whole p
by vardump 10y ago
> Those manual use/optimization of SIMD are done in C anyway.
C seems to be used only for SSE intrinsics support. ~16 LoC of "C".
This is all C in the whole project, if you really think you can call it as such:
https://github.com/google/font-rs/blob/master/src/accumulate.c https://github.com/google/font-rs/blob/master/src/accumulate...
void accumulate_sse(const float *in, uint8_t *out, uint32_t n) {
__m128 offset = _mm_setzero_ps();
__m128i mask = _mm_set1_epi32(0x0c080400);
__m128 sign_mask = _mm_set1_ps(-0.f);
for (int i = 0; i < n; i += 4) {
__m128 x = _mm_load_ps(&in[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 *)&out[i], (__m128)z);
offset = _mm_shuffle_ps(x, x, _MM_SHUFFLE(3, 3, 3, 3));
}
}
Also consider top level: https://github.com/google/font-rs/tree/master/src https://github.com/google/font-rs/tree/master/src
> What is the main benefit of using Rust?
Safety and performance.
From the article:
"With the SIMD speedup, font-rs is approximately 7.6x faster than FreeType in larger sizes (keep in mind that 42 pixels/em is the default for xxhdpi Android devices)."
- dman 10y agoAny reasons why the sse code wouldnt be written in rust itself?
- phpnode 10y agoNo SIMD intrinsics yet
- kibwen 10y agoOr rather, they're there, but only on nightly builds of Rust, though there's talk of stabilizing them with only minor changes.
- brohee 10y agoThe SIMD crate is still unstable so not usable with the stable compiler, that's the only reason. It should take very little time to convert it to Rust.