Again, if not constrained by sse2 its easy.
If you must use sse2, then something like the following (untested again, essentially the reverse of the above):
Code:
zero: dq 0
toint_func:
movq xmm1, [zero]
movq xmm0, packed_single_value
cvtps2dq xmm0, xmm0
packusdw xmm0, xmm1
packuswb xmm0, xmm1
You should then have the 32-bit packed value in the low 32 bits of xmm0. How you write that to display memory is up to you: most direct stores from sse registers will store at least 64 bits, so will overwrite the top 32 bits. If you are writing direct to the framebuffer from position 0 upwards then thats fine to do (repeated movqs). Otherwise, if you know the next pixel too, then put it into xmm1 above for the first pack instruction (and then zero for the second) and you'll have two 32-bit pixels in the low half of xmm0 which you can movq to screen even quicker. You can even optimise further and get 4 packed 32 bit pixels into xmm0 if you like (packusdw xmm0, xmm1; packusdw xmm2, xmm3; packusbw xmm0, xmm2). Otherwise if you want to be conservative, reserve some stack space, store 64 bits there, pop into rax and then do a 32-bit GPR move.
Regards,
John.