anchor.diff:      Bit#(9) v = (extend(yuv0.u) + extend(yuv1.v)) >> 1;
       return Yuv422 { y1: yuv0.y, u: truncate(u), y2: yuv1.y, v: truncate(v) };
   endfunction
  -
  -
  -
  -// module mkRgb888ToYuv422(Rgb888ToYuv422);
  -//     FIFOF#(Yuv444) yuvFifo <- mkBypassFIFOF();
  -//     Reg#(Maybe#(Yuv444)) yuvReg1 <- mkReg(tagged Invalid);
  -
  -//     rule alternating if (yuvReg1 matches tagged Invalid);
  -//         yuvReg1 <= tagged Valid yuv0;
  -//     endrule
  -
  -//     method Action putRgb888(Rgb888 rgb888) if (yuvReg0 matches tagged Invalid);
  -//         yuvFifo.enq(rgbtoyub(rgb888));
  -//     endmethod
  -
  -//     method ActionValue#(Yuv422) getYuv422() if (yuvReg1 matches tagged Valid .yuv1);
  -//         let yuv0 = yuvFifo.first;
  -//         yuvFifo.deq;
  -//         let yuv1 = yuvReg1;
  -//         yuvReg1 <= tagged Invalid;
  -//         let yuv422 = yuv444toyuv422(yuv0, yuv1);
  -//         return yuv422;
  -//     endmethod
  -
  -// endmodule
  
positive.code: // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  // SOFTWARE.
  
  // little endian RGB
  typedef struct {
  
negative.code:     return Yuv444 { y: truncate(y>>8), u: truncate(u >> 8), v: truncate(v >> 8) };
  endfunction
  
  typedef Vector#(4, Vector#(3, Bit#(16))) Yuv444Intermediates;
  
  function Vector#(3, Bit#(n)) rgbToVector(Rgb888 rgb) provisos (Add#(a__, 8, n));
     Vector#(3, Bit#(n)) vec;
     vec[0] = zeroExtend(rgb.r);
     vec[1] = zeroExtend(rgb.g);
     vec[2] = zeroExtend(rgb.b);
     return vec;
  endfunction   
  function Yuv444 yuv444FromVector(Vector#(3, Bit#(n)) vec) provisos (Add#(a__, 8, n));
     return Yuv444 { y: truncate(vec[0]), u: truncate(vec[1]), v: truncate(vec[2]) };
  endfunction
  
  function Yuv444Intermediates rgbToYuvIntermediates(Rgb888 rgb);
     Vector#(3, Vector#(4, Bit#(16))) rgbv = replicate(append(rgbToVector(rgb), replicate(1)));
     Vector#(3, Vector#(4, Bit#(16))) coeffs = replicate(newVector());
     coeffs[0][0] =  77; coeffs[0][1] =  150; coeffs[0][2] =  29; coeffs[0][3] = 0;
     coeffs[1][0] =  43; coeffs[1][1] =  -85; coeffs[1][2] = 128; coeffs[1][3] = (128<<8);
     coeffs[2][0] = 128; coeffs[2][1] = -107; coeffs[2][2] = -21; coeffs[2][3] = (128<<8);
     return transpose(map(uncurry(vmul), zip(rgbv, coeffs)));
  endfunction
  
  function Yuv444 yuvIntermediatesToYuv444(Yuv444Intermediates w);
     Vector#(3, Bit#(16)) v0 = vadd(w[0], w[1]);
     Vector#(3, Bit#(16)) v1 = vadd(w[2], w[3]);
     return yuv444FromVector(vrshift(vadd(vadd(w[0], w[1]), vadd(w[2], w[3])), 8));
  endfunction
  
  function Yuv422 yuv444toyuv422(Yuv444 yuv0, Yuv444 yuv1);
  