So, I ended up pre-expanding the alpha channel 4x, and then this simpler
blend function:
export void BlendSRGB(uniform int nPix, uniform float color[], uniform
uint8 glyph[], uniform uint8 dst[]) {
foreach (i = 0 ... nPix * 4) {
float alpha = glyph[i] / 255.0f;
dst[i] = ToSRGBCheap((1 - alpha) * FromSRGBCheap(dst[i]) + alpha * color[
programIndex]);
}
}
inline float FromSRGBCheap(uint8 v) {
float f = (float) v * (1.0f / 255.0f);
return f * f;
}
inline uint8 ToSRGBCheap(float v) {
return (uint8) (sqrt(v) * 255.0f);
}
and the resulting code looks reasonably good:
.LBB0_2: # %foreach_full_body
# =>This Inner Loop Header: Depth=1
movd (%rdx,%rsi), %xmm6 # xmm6 = mem[0],zero,zero,zero
punpcklbw %xmm1, %xmm6 # xmm6 =
xmm6[0],xmm1[0],xmm6[1],xmm1[1],xmm6[2],xmm1[2],xmm6[3],xmm1[3],xmm6[4],xmm1[4],xmm6[5],xmm1[5],xmm6[6],xmm1[6],xmm6[7],xmm1[7]
punpcklwd %xmm1, %xmm6 # xmm6 =
xmm6[0],xmm1[0],xmm6[1],xmm1[1],xmm6[2],xmm1[2],xmm6[3],xmm1[3]
cvtdq2ps %xmm6, %xmm6
mulps %xmm2, %xmm6
movaps %xmm8, %xmm7
subps %xmm6, %xmm7
movd (%rcx,%rsi), %xmm3 # xmm3 = mem[0],zero,zero,zero
punpcklbw %xmm1, %xmm3 # xmm3 =
xmm3[0],xmm1[0],xmm3[1],xmm1[1],xmm3[2],xmm1[2],xmm3[3],xmm1[3],xmm3[4],xmm1[4],xmm3[5],xmm1[5],xmm3[6],xmm1[6],xmm3[7],xmm1[7]
punpcklwd %xmm1, %xmm3 # xmm3 =
xmm3[0],xmm1[0],xmm3[1],xmm1[1],xmm3[2],xmm1[2],xmm3[3],xmm1[3]
cvtdq2ps %xmm3, %xmm3
mulps %xmm2, %xmm3
mulps %xmm3, %xmm3
mulps %xmm7, %xmm3
mulps %xmm0, %xmm6
addps %xmm3, %xmm6
sqrtps %xmm6, %xmm3
mulps %xmm4, %xmm3
cvttps2dq %xmm3, %xmm3
pand %xmm5, %xmm3
packuswb %xmm3, %xmm3
packuswb %xmm3, %xmm3
movd %xmm3, (%rcx,%rsi)
addq $4, %rsi
cmpq %rax, %rsi
jl .LBB0_2
Thanks for the help!
Ben
On Friday, 20 December 2019 16:48:30 UTC+2, Benjamin Legros wrote:
>
>
> The lookup table will cause ispc to emit gather instructions, because the
>> index of the lookup is varying *AND not contiguous*.
>>
>
> My bad.
>
--
You received this message because you are subscribed to the Google Groups
"Intel SPMD Program Compiler Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ispc-users/1add8bb0-2299-490c-ab0e-e82ca47b12e2%40googlegroups.com.