         up += ncols_u;
         cp += ncols;
         hp += ncols;
-        if (skip_type) xp += ncols_x;
-        if (pad_p) pad_p += batch;
+        xp = skip_type ? (xp + ncols_x) : NULL;
+        pad_p = mask_pad ? (pad_p + batch) : NULL;
     }
 }
 

        cp -= ncols;
        gup -= ncols_u;
        ghp -= ncols;
        if (skip_type) xp -= ncols_x;
        if (skip_type) gxp -= ncols_x;
        if (pad_p) pad_p -= batch;
    }

    //const int bias_idx = col % d;

                *gxp = gh_val*(1-g2);

            // gradient with respect to values in the second gate g2
            const auto gg2 = gh_val*(c_val*mask-x_val)*(g2*(1-g2));
            *(gup+2) = gg2;
            gbias2 += gg2;
            gwc2 += gg2*prev_c_val;
