I use the same method as you, calculating the forward step. E.g. in Spartacus the board is 24 x 10, and side to move 32 (white) or 64 (black), so forward = 48 - stm + (48 - stm >> 1). This is a nice branchless way to calculate the forward step.
I don't use bitboards, though, so Pawn moves are not generated by shifting something.
Variable shifts are treated by i386 modulo word length, so they are by definition positive (0-31 or 0-63 bits). You can't shift the other way by taking a negative number.
In your case, however, I would use
Code: Select all
moves = (((board->piecelist[piece] << 8) >> 16*to_move) & ~(board->all_pieces));
Because Pawns are never on the 8th rank, you won't have to worry this loses bits. And I would probably change my encoding of to_move to {0, 16} rather than {0, 1}, to save me the 16*.