The worst result a shader compiler should generate are two shifts and a select afterwards. This isn't that hard ;)