159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ------------------------------------------------------------------
259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Copyright (C) 1998-2009 PacketVideo
359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *
459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Licensed under the Apache License, Version 2.0 (the "License");
559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * you may not use this file except in compliance with the License.
659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * You may obtain a copy of the License at
759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *
859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *      http://www.apache.org/licenses/LICENSE-2.0
959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *
1059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Unless required by applicable law or agreed to in writing, software
1159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * distributed under the License is distributed on an "AS IS" BASIS,
1259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
1359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * express or implied.
1459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * See the License for the specific language governing permissions
1559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * and limitations under the License.
1659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * -------------------------------------------------------------------
1759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong */
1859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#include "mp4lib_int.h"
1959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#include "mp4enc_lib.h"
2059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
2159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong//const static Int roundtab4[] = {0,1,1,1};
2259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong//const static Int roundtab8[] = {0,0,1,1,1,1,1,2};
2359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong//const static Int roundtab12[] = {0,0,0,1,1,1,1,1,1,1,2,2};
2459f566c4ec3dfc097ad8163523e522280b27e5c3James Dongconst static Int roundtab16[] = {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
2559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
2659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define FORWARD_MODE    1
2759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define BACKWARD_MODE   2
2859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define BIDIRECTION_MODE    3
2959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define DIRECT_MODE         4
3059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
3159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifdef __cplusplus
3259f566c4ec3dfc097ad8163523e522280b27e5c3James Dongextern "C"
3359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
3459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif
3559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    /*Function Prototype */
3659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    /* no-edge padding */
3759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int EncGetPredOutside(Int xpos, Int ypos, UChar *c_prev, UChar *rec,
3859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int width, Int height, Int rnd1);
3959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
4059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    void Copy_MB_from_Vop(UChar *comp, Int yChan[][NCOEFF_BLOCK], Int width);
4159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    void Copy_B_from_Vop(UChar *comp, Int cChan[], Int width);
4259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    void Copy_MB_into_Vop(UChar *comp, Int yChan[][NCOEFF_BLOCK], Int width);
4359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    void Copy_B_into_Vop(UChar *comp, Int cChan[], Int width);
4459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    void get_MB(UChar *c_prev, UChar *c_prev_u  , UChar *c_prev_v,
4559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                Short mb[6][64], Int lx, Int lx_uv);
4659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
4759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int GetPredAdvBy0x0(
4859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        UChar *c_prev,      /* i */
4959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        UChar *pred_block,      /* i */
5059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        Int lx,     /* i */
5159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        Int rnd1 /* i */
5259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    );
5359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
5459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int GetPredAdvBy0x1(
5559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        UChar *c_prev,      /* i */
5659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        UChar *pred_block,      /* i */
5759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        Int lx,     /* i */
5859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        Int rnd1 /* i */
5959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    );
6059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
6159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int GetPredAdvBy1x0(
6259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        UChar *c_prev,      /* i */
6359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        UChar *pred_block,      /* i */
6459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        Int lx,     /* i */
6559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        Int rnd1 /* i */
6659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    );
6759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
6859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int GetPredAdvBy1x1(
6959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        UChar *c_prev,      /* i */
7059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        UChar *pred_block,      /* i */
7159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        Int lx,     /* i */
7259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        Int rnd1 /* i */
7359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    );
7459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
7559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    static Int(*const GetPredAdvBTable[2][2])(UChar*, UChar*, Int, Int) =
7659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
7759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {&GetPredAdvBy0x0, &GetPredAdvBy0x1},
7859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {&GetPredAdvBy1x0, &GetPredAdvBy1x1}
7959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    };
8059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
8159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
8259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifdef __cplusplus
8359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
8459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif
8559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
8659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
8759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */
8859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*  Function : getMotionCompensatedMB( )                                    */
8959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*  Date     : 4/17/2001                                                    */
9059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*  Purpose  : Get the motion compensate block into video->predictionMB     */
9159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*              and generate video->predictionErrorMB                       */
9259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*              modified from MBMotionComp() function in the decoder        */
9359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*  In/out   :                                                              */
9459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*  Return   :                                                              */
9559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*  Modified :                                                              */
9659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */
9759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
9859f566c4ec3dfc097ad8163523e522280b27e5c3James Dongvoid getMotionCompensatedMB(VideoEncData *video, Int ind_x, Int ind_y, Int offset)
9959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
10059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Vop *prevVop = video->forwardRefVop; //reference frame
10159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Vop *currVop = video->currVop;
10259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int mbnum = video->mbnum;       //mb index
10359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    MOT *mot = video->mot[mbnum];
10459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int ypos, xpos;
10559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *c_prev, *cu_prev, *cv_prev;
10659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *c_rec, *cu_rec, *cv_rec;
10759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int height, pitch, pitch_uv, height_uv;
10859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int mode = video->headerInfo.Mode[mbnum];  /* get mode */
10959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int dx, dy;
11059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int xpred, ypred;
11159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int xsum, ysum;
11259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int round1;
11359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
11459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    OSCL_UNUSED_ARG(offset);
11559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
11659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    round1 = (Int)(1 - video->currVop->roundingType);
11759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
11859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    pitch  = currVop->pitch;
11959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    height = currVop->height;
12059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    pitch_uv  = pitch >> 1;
12159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    height_uv = height >> 1;
12259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
12359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    ypos = ind_y << 4 ;
12459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    xpos = ind_x << 4 ;
12559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
12659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    c_rec = video->predictedMB;
12759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    cu_rec = video->predictedMB + 256;
12859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    cv_rec = video->predictedMB + 264;
12959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
13059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    if (mode == MODE_INTER || mode == MODE_INTER_Q)
13159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
13259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        /* Motion vector in x direction       */
13359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        dx = mot[0].x;
13459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        dy = mot[0].y;
13559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
13659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        c_prev  = prevVop->yChan;
13759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
13859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        xpred = (xpos << 1) + dx ;
13959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        ypred = (ypos << 1) + dy ;
14059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
14159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        /* Call function that performs luminance prediction */
14259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        EncPrediction_INTER(xpred, ypred, c_prev, c_rec,
14359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                            pitch, round1);
14459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
14559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if ((dx & 3) == 0)  dx = dx >> 1;
14659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        else        dx = (dx >> 1) | 1;
14759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
14859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if ((dy & 3) == 0)      dy = dy >> 1;
14959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        else        dy = (dy >> 1) | 1;
15059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
15159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        xpred = xpos + dx;
15259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        ypred = ypos + dy;
15359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
15459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        cu_prev = prevVop->uChan;
15559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        cv_prev = prevVop->vChan;
15659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
15759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        EncPrediction_Chrom(xpred, ypred, cu_prev, cv_prev, cu_rec, cv_rec,
15859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                            pitch_uv, (currVop->width) >> 1, height_uv, round1);
15959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
16059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifndef NO_INTER4V
16159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else if (mode == MODE_INTER4V)
16259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
16359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        c_prev  = prevVop->yChan;
16459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        cu_prev = prevVop->uChan;
16559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        cv_prev = prevVop->vChan;
16659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
16759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        EncPrediction_INTER4V(xpos, ypos, mot, c_prev, c_rec,
16859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                              pitch, round1);
16959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
17059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        xsum = mot[1].x + mot[2].x + mot[3].x + mot[4].x;
17159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        ysum = mot[1].y + mot[2].y + mot[3].y + mot[4].y;
17259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
17359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        dx = PV_SIGN(xsum) * (roundtab16[(PV_ABS(xsum)) & 0xF] +
17459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                              (((PV_ABS(xsum)) >> 4) << 1));
17559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        dy = PV_SIGN(ysum) * (roundtab16[(PV_ABS(ysum)) & 0xF] +
17659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                              (((PV_ABS(ysum)) >> 4) << 1));
17759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
17859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        ypred = ypos + dy;
17959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        xpred = xpos + dx;
18059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
18159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        EncPrediction_Chrom(xpred, ypred, cu_prev, cv_prev, cu_rec, cv_rec,
18259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                            pitch_uv, (currVop->width) >> 1, height_uv, round1);
18359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
18459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif
18559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else
18659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
18759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        ;//printf("Error, MODE_SKIPPED is not decided yet!\n");
18859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
18959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
19059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return ;
19159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
19259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
19359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/***************************************************************************
19459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Function:   EncPrediction_INTER
19559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Date:       04/17/2001
19659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Purpose:    Get predicted area for luminance and compensate with the residue.
19759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                Modified from luminance_pred_mode_inter() in decoder.
19859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong***************************************************************************/
19959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
20059f566c4ec3dfc097ad8163523e522280b27e5c3James Dongvoid EncPrediction_INTER(
20159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int xpred,          /* i */
20259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int ypred,          /* i */
20359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *c_prev,          /* i */
20459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *c_rec,       /* i */
20559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int lx,         /* i */
20659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int round1          /* i */
20759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong)
20859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
20959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    c_prev += (xpred >> 1) + ((ypred >> 1) * lx);
21059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
21159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    GetPredAdvBTable[ypred&1][xpred&1](c_prev, c_rec, lx, round1);
21259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
21359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    c_prev += B_SIZE;
21459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    c_rec += B_SIZE;
21559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
21659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    GetPredAdvBTable[ypred&1][xpred&1](c_prev, c_rec, lx, round1);
21759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
21859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    c_prev += (lx << 3) - B_SIZE;
21959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    c_rec += (16 << 3) - B_SIZE; /* padding */
22059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
22159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    GetPredAdvBTable[ypred&1][xpred&1](c_prev, c_rec, lx, round1);
22259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
22359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    c_prev += B_SIZE;
22459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    c_rec += B_SIZE;
22559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
22659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    GetPredAdvBTable[ypred&1][xpred&1](c_prev, c_rec, lx, round1);
22759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
22859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return;
22959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
23059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
23159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifndef NO_INTER4V
23259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/***************************************************************************
23359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Function:   EncPrediction_INTER4V
23459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Date:       04/17/2001
23559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Purpose:    Get predicted area for luminance and compensate with the residue.
23659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                Modified from luminance_pred_mode_inter4v() in decoder.
23759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong***************************************************************************/
23859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
23959f566c4ec3dfc097ad8163523e522280b27e5c3James Dongvoid EncPrediction_INTER4V(
24059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int xpos,           /* i */
24159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int ypos,           /* i */
24259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    MOT *mot,           /* i */
24359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *c_prev,          /* i */
24459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *c_rec,           /* i */
24559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int lx,         /* i */
24659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int round1          /* i */
24759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong)
24859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
24959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int ypred, xpred;
25059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
25159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    xpred = (Int)((xpos << 1) + mot[1].x);
25259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    ypred = (Int)((ypos << 1) + mot[1].y);
25359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
25459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*lx),
25559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                                       c_rec, lx, round1);
25659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
25759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    c_rec += B_SIZE;
25859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
25959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    xpred = (Int)(((xpos + B_SIZE) << 1) + mot[2].x);
26059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    ypred = (Int)((ypos << 1) + mot[2].y);
26159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
26259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*lx),
26359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                                       c_rec, lx, round1);
26459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
26559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    c_rec += (16 << 3) - B_SIZE; /* padding */
26659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
26759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    xpred = (Int)((xpos << 1) + mot[3].x);
26859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    ypred = (Int)(((ypos + B_SIZE) << 1) + mot[3].y);
26959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
27059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*lx),
27159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                                       c_rec, lx, round1);
27259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
27359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    c_rec += B_SIZE;
27459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
27559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    xpred = (Int)(((xpos + B_SIZE) << 1) + mot[4].x);
27659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    ypred = (Int)(((ypos + B_SIZE) << 1) + mot[4].y);
27759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
27859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*lx),
27959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                                       c_rec, lx, round1);
28059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
28159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return;
28259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
28359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif /* NO_INTER4V */
28459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
28559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/***************************************************************************
28659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Function:   EncPrediction_Chrom
28759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Date:       04/17/2001
28859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Purpose:    Get predicted area for chrominance and compensate with the residue.
28959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                Modified from chrominance_pred() in decoder.
29059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong***************************************************************************/
29159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
29259f566c4ec3dfc097ad8163523e522280b27e5c3James Dongvoid EncPrediction_Chrom(
29359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int xpred,          /* i */
29459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int ypred,          /* i */
29559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *cu_prev,         /* i */
29659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *cv_prev,         /* i */
29759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *cu_rec,
29859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *cv_rec,
29959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int lx,
30059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int width_uv,           /* i */
30159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int height_uv,          /* i */
30259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int round1          /* i */
30359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong)
30459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
30559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    /* check whether the MV points outside the frame */
30659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    /* Compute prediction for Chrominance b block (block[4]) */
30759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    if (xpred >= 0 && xpred <= ((width_uv << 1) - (2*B_SIZE)) && ypred >= 0 &&
30859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            ypred <= ((height_uv << 1) - (2*B_SIZE)))
30959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
31059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        /*****************************/
31159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        /* (x,y) is inside the frame */
31259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        /*****************************/
31359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
31459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        /* Compute prediction for Chrominance b (block[4]) */
31559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        GetPredAdvBTable[ypred&1][xpred&1](cu_prev + (xpred >> 1) + ((ypred >> 1)*lx),
31659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                                           cu_rec, lx, round1);
31759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
31859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        /* Compute prediction for Chrominance r (block[5]) */
31959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        GetPredAdvBTable[ypred&1][xpred&1](cv_prev + (xpred >> 1) + ((ypred >> 1)*lx),
32059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                                           cv_rec,  lx, round1);
32159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
32259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else
32359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
32459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        /******************************/
32559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        /* (x,y) is outside the frame */
32659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        /******************************/
32759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
32859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        /* Compute prediction for Chrominance b (block[4]) */
32959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        EncGetPredOutside(xpred, ypred,
33059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                          cu_prev, cu_rec,
33159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                          width_uv, height_uv, round1);
33259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
33359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        /* Compute prediction for Chrominance r (block[5]) */
33459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        EncGetPredOutside(xpred, ypred,
33559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                          cv_prev, cv_rec,
33659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                          width_uv, height_uv, round1);
33759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
33859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
33959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return;
34059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
34159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/***************************************************************************
34259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Function:   GetPredAdvancedB
34359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Date:       04/17/2001
34459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Purpose:    Get predicted area (block) and compensate with the residue.
34559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                - modified from GetPredAdvancedBAdd in decoder.
34659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Intput/Output:
34759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Modified:
34859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong***************************************************************************/
34959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
35059f566c4ec3dfc097ad8163523e522280b27e5c3James DongInt GetPredAdvBy0x0(
35159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *prev,        /* i */
35259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *rec,     /* i */
35359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int lx,     /* i */
35459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int rnd /* i */
35559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong)
35659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
35759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int i;      /* loop variable */
35859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    ULong  pred_word, word1, word2;
35959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int tmp;
36059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
36159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    OSCL_UNUSED_ARG(rnd);
36259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
36359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    /* initialize offset to adjust pixel counter */
36459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    /*    the next row; full-pel resolution      */
36559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
3662426d11f795a99de85999b3ff0a26cc070a99a59Ashok Bhat    tmp = (uintptr_t)prev & 0x3;
36759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
36859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    if (tmp == 0)  /* word-aligned */
36959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
37059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        rec -= 16; /* preset */
37159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        prev -= lx;
37259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
37359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        for (i = 8; i > 0; i--)
37459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
37559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            *((ULong*)(rec += 16)) = *((ULong*)(prev += lx));
37659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            *((ULong*)(rec + 4)) = *((ULong*)(prev + 4));
37759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
37859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        return 1;
37959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
38059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else if (tmp == 1) /* first position */
38159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
38259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        prev--; /* word-aligned */
38359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        rec -= 16; /* preset */
38459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        prev -= lx;
38559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
38659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        for (i = 8; i > 0; i--)
38759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
38859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            word1 = *((ULong*)(prev += lx)); /* read 4 bytes, b4 b3 b2 b1 */
38959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            word2 = *((ULong*)(prev + 4));  /* read 4 bytes, b8 b7 b6 b5 */
39059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            word1 >>= 8; /* 0 b4 b3 b2 */
39159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            pred_word = word1 | (word2 << 24);  /* b5 b4 b3 b2 */
39259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            *((ULong*)(rec += 16)) = pred_word;
39359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
39459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            word1 = *((ULong*)(prev + 8)); /* b12 b11 b10 b9 */
39559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            word2 >>= 8; /* 0 b8 b7 b6 */
39659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            pred_word = word2 | (word1 << 24); /* b9 b8 b7 b6 */
39759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            *((ULong*)(rec + 4)) = pred_word;
39859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
39959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
40059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        return 1;
40159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
40259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else if (tmp == 2) /* second position */
40359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
40459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        prev -= 2; /* word1-aligned */
40559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        rec -= 16; /* preset */
40659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        prev -= lx;
40759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
40859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        for (i = 8; i > 0; i--)
40959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
41059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            word1 = *((ULong*)(prev += lx)); /* read 4 bytes, b4 b3 b2 b1 */
41159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            word2 = *((ULong*)(prev + 4));  /* read 4 bytes, b8 b7 b6 b5 */
41259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            word1 >>= 16; /* 0 0 b4 b3 */
41359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            pred_word = word1 | (word2 << 16);  /* b6 b5 b4 b3 */
41459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            *((ULong*)(rec += 16)) = pred_word;
41559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
41659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            word1 = *((ULong*)(prev + 8)); /* b12 b11 b10 b9 */
41759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            word2 >>= 16; /* 0 0 b8 b7 */
41859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            pred_word = word2 | (word1 << 16); /* b10 b9 b8 b7 */
41959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            *((ULong*)(rec + 4)) = pred_word;
42059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
42159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
42259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        return 1;
42359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
42459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else /* third position */
42559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
42659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        prev -= 3; /* word1-aligned */
42759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        rec -= 16; /* preset */
42859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        prev -= lx;
42959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
43059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        for (i = 8; i > 0; i--)
43159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
43259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            word1 = *((ULong*)(prev += lx)); /* read 4 bytes, b4 b3 b2 b1 */
43359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            word2 = *((ULong*)(prev + 4));  /* read 4 bytes, b8 b7 b6 b5 */
43459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            word1 >>= 24; /* 0 0 0 b4 */
43559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            pred_word = word1 | (word2 << 8);   /* b7 b6 b5 b4 */
43659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            *((ULong*)(rec += 16)) = pred_word;
43759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
43859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            word1 = *((ULong*)(prev + 8)); /* b12 b11 b10 b9 */
43959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            word2 >>= 24; /* 0 0 0 b8 */
44059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            pred_word = word2 | (word1 << 8); /* b11 b10 b9 b8 */
44159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            *((ULong*)(rec + 4)) = pred_word;
44259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
44359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
44459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
44559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        return 1;
44659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
44759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
44859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/**************************************************************************/
44959f566c4ec3dfc097ad8163523e522280b27e5c3James DongInt GetPredAdvBy0x1(
45059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *prev,        /* i */
45159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *rec,     /* i */
45259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int lx,     /* i */
45359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int rnd1 /* i */
45459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong)
45559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
45659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int i;      /* loop variable */
45759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int offset;
45859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    ULong word1, word2, word3, word12;
45959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int tmp;
46059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    ULong mask;
46159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
46259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    /* initialize offset to adjust pixel counter */
46359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    /*    the next row; full-pel resolution      */
46459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    offset = lx - B_SIZE; /* offset for prev */
46559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
46659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    /* Branch based on pixel location (half-pel or full-pel) for x and y */
46759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    rec -= 12; /* preset */
46859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
4692426d11f795a99de85999b3ff0a26cc070a99a59Ashok Bhat    tmp = (uintptr_t)prev & 3;
47059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    mask = 254;
47159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    mask |= (mask << 8);
47259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    mask |= (mask << 16); /* 0xFEFEFEFE */
47359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
47459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    if (tmp == 0) /* word-aligned */
47559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
47659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if (rnd1 == 1)
47759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
47859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            for (i = B_SIZE; i > 0; i--)
47959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            {
48059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)prev); /* b4 b3 b2 b1 */
48159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev += 4)); /* b8 b7 b6 b5 */
48259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = (word1 >> 8); /* 0 b4 b3 b2 */
48359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 |= (word2 << 24); /* b5 b4 b3 b2 */
48459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12
48559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
48659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
48759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
48859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
48959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word12 >> 1);
49059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
49159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
49259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
49359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4)); /* b12 b11 b10 b9 */
49459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = (word2 >> 8); /* 0 b8 b7 b6 */
49559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 |= (word1 << 24); /* b9 b8 b7 b6 */
49659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word2 | word12;
49759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
49859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask);  /* 0x1010101, check last bit */
49959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
50059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 1;
50159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = word2 + (word12 >> 1);
50259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 += word3;
50359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
50459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
50559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                prev += offset;
50659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            }
50759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            return 1;
50859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
50959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        else /* rnd1 == 0 */
51059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
51159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            for (i = B_SIZE; i > 0; i--)
51259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            {
51359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)prev); /* b4 b3 b2 b1 */
51459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
51559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev += 4)); /* b8 b7 b6 b5 */
51659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = (word1 >> 8); /* 0 b4 b3 b2 */
51759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 |= (word2 << 24); /* b5 b4 b3 b2 */
51859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 & word12; // rnd1 = 1; otherwise word3 = word1&word12
51959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
52059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
52159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
52259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
52359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word12 >> 1);
52459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
52559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
52659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
52759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4)); /* b12 b11 b10 b9 */
52859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = (word2 >> 8); /* 0 b8 b7 b6 */
52959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 |= (word1 << 24); /* b9 b8 b7 b6 */
53059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word2 & word12;
53159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
53259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask);  /* 0x1010101, check last bit */
53359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
53459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 1;
53559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = word2 + (word12 >> 1);
53659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 += word3;
53759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
53859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
53959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                prev += offset;
54059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            }
54159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            return 1;
54259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        } /* rnd1 */
54359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
54459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else if (tmp == 1)
54559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
54659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        prev--; /* word-aligned */
54759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if (rnd1 == 1)
54859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
54959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            for (i = B_SIZE; i > 0; i--)
55059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            {
55159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)prev); /* b3 b2 b1 b0 */
55259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev += 4)); /* b7 b6 b5 b4 */
55359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = (word1 >> 8); /* 0 b3 b2 b1 */
55459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 16; /* 0 0 b3 b2 */
55559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 |= (word2 << 24); /* b4 b3 b2 b1 */
55659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 |= (word2 << 16); /* b5 b4 b3 b2 */
55759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12
55859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
55959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
56059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
56159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
56259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word12 >> 1);
56359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
56459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
56559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
56659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4)); /* b11 b10 b9 b8 */
56759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = (word2 >> 8); /* 0 b7 b6 b5 */
56859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 16; /* 0 0 b7 b6 */
56959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 |= (word1 << 24); /* b8 b7 b6 b5 */
57059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 |= (word1 << 16); /* b9 b8 b7 b6 */
57159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word2 | word12; // rnd1 = 1; otherwise word3 = word2&word12
57259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
57359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
57459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
57559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 1;
57659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = word2 + (word12 >> 1);
57759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 += word3;
57859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
57959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
58059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                prev += offset;
58159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            }
58259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            return 1;
58359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
58459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        else /* rnd1 = 0 */
58559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
58659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            for (i = B_SIZE; i > 0; i--)
58759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            {
58859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)prev); /* b3 b2 b1 b0 */
58959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
59059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev += 4)); /* b7 b6 b5 b4 */
59159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = (word1 >> 8); /* 0 b3 b2 b1 */
59259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 16; /* 0 0 b3 b2 */
59359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 |= (word2 << 24); /* b4 b3 b2 b1 */
59459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 |= (word2 << 16); /* b5 b4 b3 b2 */
59559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 & word12;
59659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
59759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
59859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
59959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
60059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word12 >> 1);
60159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
60259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
60359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
60459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4)); /* b11 b10 b9 b8 */
60559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = (word2 >> 8); /* 0 b7 b6 b5 */
60659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 16; /* 0 0 b7 b6 */
60759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 |= (word1 << 24); /* b8 b7 b6 b5 */
60859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 |= (word1 << 16); /* b9 b8 b7 b6 */
60959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word2 & word12;
61059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
61159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
61259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
61359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 1;
61459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = word2 + (word12 >> 1);
61559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 += word3;
61659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
61759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
61859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                prev += offset;
61959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            }
62059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            return 1;
62159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        } /* rnd1 */
62259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
62359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else if (tmp == 2)
62459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
62559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        prev -= 2; /* word-aligned */
62659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if (rnd1 == 1)
62759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
62859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            for (i = B_SIZE; i > 0; i--)
62959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            {
63059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)prev); /* b2 b1 b0 bN1 */
63159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev += 4)); /* b6 b5 b4 b3 */
63259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = (word1 >> 16); /* 0 0 b2 b1 */
63359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 24; /* 0 0 0 b2 */
63459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 |= (word2 << 16); /* b4 b3 b2 b1 */
63559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 |= (word2 << 8); /* b5 b4 b3 b2 */
63659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12
63759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
63859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
63959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
64059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
64159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word12 >> 1);
64259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
64359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
64459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
64559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4)); /* b10 b9 b8 b7 */
64659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = (word2 >> 16); /* 0 0 b6 b5 */
64759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 24; /* 0 0 0 b6 */
64859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 |= (word1 << 16); /* b8 b7 b6 b5 */
64959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 |= (word1 << 8); /* b9 b8 b7 b6 */
65059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word2 | word12; // rnd1 = 1; otherwise word3 = word1&word12
65159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
65259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
65359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
65459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 1;
65559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = word2 + (word12 >> 1);
65659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 += word3;
65759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
65859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                prev += offset;
65959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            }
66059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            return 1;
66159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
66259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        else /* rnd1 == 0 */
66359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
66459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            for (i = B_SIZE; i > 0; i--)
66559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            {
66659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)prev); /* b2 b1 b0 bN1 */
66759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev += 4)); /* b6 b5 b4 b3 */
66859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = (word1 >> 16); /* 0 0 b2 b1 */
66959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 24; /* 0 0 0 b2 */
67059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 |= (word2 << 16); /* b4 b3 b2 b1 */
67159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 |= (word2 << 8); /* b5 b4 b3 b2 */
67259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 & word12; // rnd1 = 1; otherwise word3 = word1&word12
67359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
67459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
67559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
67659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
67759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word12 >> 1);
67859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
67959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
68059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
68159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4)); /* b10 b9 b8 b7 */
68259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = (word2 >> 16); /* 0 0 b6 b5 */
68359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 24; /* 0 0 0 b6 */
68459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 |= (word1 << 16); /* b8 b7 b6 b5 */
68559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 |= (word1 << 8); /* b9 b8 b7 b6 */
68659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word2 & word12; // rnd1 = 1; otherwise word3 = word1&word12
68759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
68859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
68959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
69059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 1;
69159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = word2 + (word12 >> 1);
69259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 += word3;
69359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
69459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                prev += offset;
69559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            }
69659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            return 1;
69759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
69859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
69959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else /* tmp = 3 */
70059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
70159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        prev -= 3; /* word-aligned */
70259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if (rnd1 == 1)
70359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
70459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            for (i = B_SIZE; i > 0; i--)
70559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            {
70659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)prev); /* b1 b0 bN1 bN2 */
70759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev += 4)); /* b5 b4 b3 b2 */
70859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = (word1 >> 24); /* 0 0 0 b1 */
70959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 |= (word2 << 8); /* b4 b3 b2 b1 */
71059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word2;
71159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12
71259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
71359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
71459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
71559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
71659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word12 >> 1);
71759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
71859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
71959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
72059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4)); /* b9 b8 b7 b6 */
72159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = (word2 >> 24); /* 0 0 0 b5 */
72259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 |= (word1 << 8); /* b8 b7 b6 b5 */
72359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = word1; /* b9 b8 b7 b6 */
72459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word2 | word12; // rnd1 = 1; otherwise word3 = word1&word12
72559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
72659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
72759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
72859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 1;
72959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = word2 + (word12 >> 1);
73059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 += word3;
73159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
73259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                prev += offset;
73359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            }
73459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            return 1;
73559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
73659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        else
73759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
73859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            for (i = B_SIZE; i > 0; i--)
73959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            {
74059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)prev); /* b1 b0 bN1 bN2 */
74159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev += 4)); /* b5 b4 b3 b2 */
74259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = (word1 >> 24); /* 0 0 0 b1 */
74359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 |= (word2 << 8); /* b4 b3 b2 b1 */
74459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word2;
74559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 & word12; // rnd1 = 1; otherwise word3 = word1&word12
74659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
74759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
74859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
74959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
75059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word12 >> 1);
75159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
75259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
75359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
75459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4)); /* b9 b8 b7 b6 */
75559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = (word2 >> 24); /* 0 0 0 b5 */
75659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 |= (word1 << 8); /* b8 b7 b6 b5 */
75759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = word1; /* b9 b8 b7 b6 */
75859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word2 & word12; // rnd1 = 1; otherwise word3 = word1&word12
75959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
76059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
76159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
76259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 1;
76359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = word2 + (word12 >> 1);
76459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 += word3;
76559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
76659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                prev += offset;
76759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            }
76859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            return 1;
76959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
77059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
77159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
77259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
77359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/**************************************************************************/
77459f566c4ec3dfc097ad8163523e522280b27e5c3James DongInt GetPredAdvBy1x0(
77559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *prev,        /* i */
77659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *rec,     /* i */
77759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int lx,     /* i */
77859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int rnd1 /* i */
77959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong)
78059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
78159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int i;      /* loop variable */
78259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int offset;
78359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    ULong  word1, word2, word3, word12, word22;
78459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int tmp;
78559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    ULong mask;
78659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
78759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    /* initialize offset to adjust pixel counter */
78859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    /*    the next row; full-pel resolution      */
78959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    offset = lx - B_SIZE; /* offset for prev */
79059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
79159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    /* Branch based on pixel location (half-pel or full-pel) for x and y */
79259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    rec -= 12; /* preset */
79359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
7942426d11f795a99de85999b3ff0a26cc070a99a59Ashok Bhat    tmp = (uintptr_t)prev & 3;
79559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    mask = 254;
79659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    mask |= (mask << 8);
79759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    mask |= (mask << 16); /* 0xFEFEFEFE */
79859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
79959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    if (tmp == 0) /* word-aligned */
80059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
80159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        prev -= 4;
80259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if (rnd1 == 1)
80359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
80459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            for (i = B_SIZE; i > 0; i--)
80559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            {
80659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4));
80759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev + lx));
80859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 | word2; // rnd1 = 1; otherwise word3 = word1&word2
80959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
81059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
81159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
81259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
81359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word2 >> 1);
81459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
81559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 12)) = word1;
81659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4));
81759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev + lx));
81859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 | word2; // rnd1 = 1; otherwise word3 = word1&word2
81959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
82059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
82159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
82259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
82359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word2 >> 1);
82459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
82559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 4)) = word1;
82659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
82759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                prev += offset;
82859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            }
82959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            return 1;
83059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
83159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        else   /* rnd1 = 0 */
83259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
83359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            for (i = B_SIZE; i > 0; i--)
83459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            {
83559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4));
83659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev + lx));
83759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 & word2;  /* rnd1 = 0; */
83859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
83959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
84059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
84159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
84259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word2 >> 1);
84359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
84459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 12)) = word1;
84559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4));
84659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev + lx));
84759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 & word2;  /* rnd1 = 0; */
84859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
84959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
85059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
85159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
85259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word2 >> 1);
85359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
85459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 4)) = word1;
85559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
85659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                prev += offset;
85759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            }
85859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            return 1;
85959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
86059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
86159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else if (tmp == 1)
86259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
86359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        prev--; /* word-aligned */
86459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if (rnd1 == 1)
86559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
86659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            for (i = B_SIZE; i > 0; i--)
86759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            {
86859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
86959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = *((ULong*)(prev + lx));
87059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
87159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
87259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev + lx));
87359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 >>= 8; /* 0 b4 b3 b2 */
87459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 >>= 8;
87559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = word12 | (word1 << 24); /* b5 b4 b3 b2 */
87659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = word22 | (word2 << 24);
87759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word12 | word22;
87859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
87959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 &= mask;
88059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
88159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 >>= 1;
88259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = word12 + (word22 >> 1);
88359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 += word3;
88459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 12)) = word12;
88559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
88659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
88759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = *((ULong*)(prev + lx));
88859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 8; /* 0 b8 b7 b6 */
88959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 8;
89059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 | (word12 << 24); /* b9 b8 b7 b6 */
89159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = word2 | (word22 << 24);
89259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 | word2;
89359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
89459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
89559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
89659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
89759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word2 >> 1);
89859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
89959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 4)) = word1;
90059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                prev += offset;
90159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            }
90259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            return 1;
90359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
90459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        else /* rnd1 = 0 */
90559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
90659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            for (i = B_SIZE; i > 0; i--)
90759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            {
90859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
90959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = *((ULong*)(prev + lx));
91059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
91159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
91259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev + lx));
91359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 >>= 8; /* 0 b4 b3 b2 */
91459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 >>= 8;
91559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = word12 | (word1 << 24); /* b5 b4 b3 b2 */
91659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = word22 | (word2 << 24);
91759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word12 & word22;
91859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
91959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 &= mask;
92059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
92159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 >>= 1;
92259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = word12 + (word22 >> 1);
92359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 += word3;
92459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 12)) = word12;
92559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
92659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
92759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = *((ULong*)(prev + lx));
92859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 8; /* 0 b8 b7 b6 */
92959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 8;
93059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 | (word12 << 24); /* b9 b8 b7 b6 */
93159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = word2 | (word22 << 24);
93259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 & word2;
93359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
93459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
93559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
93659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
93759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word2 >> 1);
93859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
93959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 4)) = word1;
94059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                prev += offset;
94159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            }
94259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            return 1;
94359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
94459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
94559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else if (tmp == 2)
94659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
94759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        prev -= 2; /* word-aligned */
94859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if (rnd1 == 1)
94959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
95059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            for (i = B_SIZE; i > 0; i--)
95159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            {
95259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
95359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = *((ULong*)(prev + lx));
95459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
95559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
95659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev + lx));
95759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 >>= 16; /* 0 0 b4 b3 */
95859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 >>= 16;
95959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = word12 | (word1 << 16); /* b6 b5 b4 b3 */
96059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = word22 | (word2 << 16);
96159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word12 | word22;
96259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
96359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 &= mask;
96459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
96559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 >>= 1;
96659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = word12 + (word22 >> 1);
96759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 += word3;
96859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 12)) = word12;
96959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
97059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
97159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = *((ULong*)(prev + lx));
97259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 16; /* 0 0 b8 b7 */
97359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 16;
97459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 | (word12 << 16); /* b10 b9 b8 b7 */
97559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = word2 | (word22 << 16);
97659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 | word2;
97759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
97859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
97959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
98059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
98159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word2 >> 1);
98259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
98359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 4)) = word1;
98459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                prev += offset;
98559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            }
98659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            return 1;
98759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
98859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        else /* rnd1 = 0 */
98959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
99059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            for (i = B_SIZE; i > 0; i--)
99159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            {
99259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
99359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = *((ULong*)(prev + lx));
99459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
99559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
99659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev + lx));
99759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 >>= 16; /* 0 0 b4 b3 */
99859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 >>= 16;
99959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = word12 | (word1 << 16); /* b6 b5 b4 b3 */
100059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = word22 | (word2 << 16);
100159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word12 & word22;
100259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
100359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 &= mask;
100459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
100559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 >>= 1;
100659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = word12 + (word22 >> 1);
100759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 += word3;
100859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 12)) = word12;
100959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
101059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
101159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = *((ULong*)(prev + lx));
101259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 16; /* 0 0 b8 b7 */
101359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 16;
101459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 | (word12 << 16); /* b10 b9 b8 b7 */
101559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = word2 | (word22 << 16);
101659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 & word2;
101759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
101859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
101959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
102059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
102159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word2 >> 1);
102259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
102359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 4)) = word1;
102459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                prev += offset;
102559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            }
102659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
102759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            return 1;
102859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
102959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
103059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else /* tmp == 3 */
103159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
103259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        prev -= 3; /* word-aligned */
103359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if (rnd1 == 1)
103459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
103559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            for (i = B_SIZE; i > 0; i--)
103659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            {
103759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
103859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = *((ULong*)(prev + lx));
103959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
104059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
104159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev + lx));
104259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 >>= 24; /* 0 0 0 b4 */
104359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 >>= 24;
104459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = word12 | (word1 << 8); /* b7 b6 b5 b4 */
104559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = word22 | (word2 << 8);
104659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word12 | word22;
104759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
104859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 &= mask;
104959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
105059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 >>= 1;
105159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = word12 + (word22 >> 1);
105259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 += word3;
105359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 12)) = word12;
105459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
105559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
105659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = *((ULong*)(prev + lx));
105759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 24; /* 0 0 0 b8 */
105859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 24;
105959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 | (word12 << 8); /* b11 b10 b9 b8 */
106059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = word2 | (word22 << 8);
106159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 | word2;
106259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
106359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
106459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
106559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
106659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word2 >> 1);
106759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
106859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 4)) = word1;
106959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                prev += offset;
107059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            }
107159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            return 1;
107259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
107359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        else /* rnd1 = 0 */
107459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
107559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            for (i = B_SIZE; i > 0; i--)
107659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            {
107759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
107859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = *((ULong*)(prev + lx));
107959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
108059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
108159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = *((ULong*)(prev + lx));
108259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 >>= 24; /* 0 0 0 b4 */
108359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 >>= 24;
108459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = word12 | (word1 << 8); /* b7 b6 b5 b4 */
108559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = word22 | (word2 << 8);
108659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word12 & word22;
108759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 &= mask;
108859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 &= mask;
108959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
109059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 >>= 1;
109159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = word12 + (word22 >> 1);
109259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 += word3;
109359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 12)) = word12;
109459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
109559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
109659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word22 = *((ULong*)(prev + lx));
109759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 24; /* 0 0 0 b8 */
109859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 >>= 24;
109959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 | (word12 << 8); /* b11 b10 b9 b8 */
110059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 = word2 | (word22 << 8);
110159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 = word1 & word2;
110259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 &= mask;
110359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word2 &= mask;
110459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word3 &= (~mask); /* 0x1010101, check last bit */
110559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 >>= 1;
110659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 = word1 + (word2 >> 1);
110759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                word1 += word3;
110859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                *((ULong*)(rec += 4)) = word1;
110959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                prev += offset;
111059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            }
111159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            return 1;
111259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        } /* rnd */
111359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    } /* tmp */
111459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
111559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
111659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/**********************************************************************************/
111759f566c4ec3dfc097ad8163523e522280b27e5c3James DongInt GetPredAdvBy1x1(
111859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *prev,        /* i */
111959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    UChar *rec,     /* i */
112059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int lx,     /* i */
112159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int rnd1 /* i */
112259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong)
112359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
112459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int i;      /* loop variable */
112559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int offset;
112659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    ULong  x1, x2, x1m, x2m, y1, y2, y1m, y2m; /* new way */
112759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int tmp;
112859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    Int rnd2;
112959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    ULong mask;
113059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
113159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    /* initialize offset to adjust pixel counter */
113259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    /*    the next row; full-pel resolution      */
113359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    offset = lx - B_SIZE; /* offset for prev */
113459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
113559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    rnd2 = rnd1 + 1;
113659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    rnd2 |= (rnd2 << 8);
113759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    rnd2 |= (rnd2 << 16);
113859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
113959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    mask = 0x3F;
114059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    mask |= (mask << 8);
114159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    mask |= (mask << 16); /* 0x3f3f3f3f */
114259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
11432426d11f795a99de85999b3ff0a26cc070a99a59Ashok Bhat    tmp = (uintptr_t)prev & 3;
114459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
114559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    rec -= 4; /* preset */
114659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
114759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    if (tmp == 0) /* word-aligned */
114859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
114959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        for (i = B_SIZE; i > 0; i--)
115059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
115159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            x1 = *((ULong*)prev); /* load a3 a2 a1 a0 */
115259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            x2 = *((ULong*)(prev + lx)); /* load b3 b2 b1 b0, another line */
115359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            y1 = *((ULong*)(prev += 4)); /* a7 a6 a5 a4 */
115459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            y2 = *((ULong*)(prev + lx)); /* b7 b6 b5 b4 */
115559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
115659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            x1m = (x1 >> 2) & mask; /* zero out last 2 bits */
115759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            x2m = (x2 >> 2) & mask;
115859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            x1 = x1 ^(x1m << 2);
115959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            x2 = x2 ^(x2m << 2);
116059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            x1m += x2m;
116159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            x1 += x2;
116259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
116359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            /* x2m, x2 free */
116459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            y1m = (y1 >> 2) & mask; /* zero out last 2 bits */
116559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            y2m = (y2 >> 2) & mask;
116659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            y1 = y1 ^(y1m << 2);
116759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            y2 = y2 ^(y2m << 2);
116859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            y1m += y2m;
116959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            y1 += y2;
117059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
117159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            /* y2m, y2 free */
117259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            /* x2m, x2 free */
117359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            x2 = *((ULong*)(prev += 4)); /* a11 a10 a9 a8 */
117459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            y2 = *((ULong*)(prev + lx)); /* b11 b10 b9 b8 */
117559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            x2m = (x2 >> 2) & mask;
117659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            y2m = (y2 >> 2) & mask;
117759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            x2 = x2 ^(x2m << 2);
1178