I am looking for doing shl(mult(var1,var2),1) operation, where mult multiplies var1 and var2 (both are 16-bit signed integers) and shl shifts left arithmetically the multiplication result. Result must be saturated, i.e., int32 max or int32 min if overflow or underflow occurs and mult(-32768,-32768)=2147483647.
I need to make this op for multiple values in an efficient way for which I think using MMX/SSE instruction set. I though about making mult(sign_extesion(var1), shl(sign_extension(var2))) but I've just discovered no MMX mult() saturation version exists. Do you know any other way to get it?
I think the following should work for you. There is only one potential overflow case (
SHRT_MIN * SHRT_MIN) and it handles this explicitly: