Okay so this is something that I came up with while working on my own engine, but I am not sure if anyone has ever tried. Basically I am using a separate set of magic hashed longs to store pieces and their pinners. So far as I can think this should work. I have a rudimentary implementation and I still need to test it, so I can think through on ways to potentially break it.
The idea only works if we already know that we are not under check. Basically, we use the king's position and all pieces covered by a regular rook or bishop mask to do the magic hash lookup. This returns us a bitboard with the pieces sitting closest to the king in any direction and the piece that next comes after it. So in every direction we have exactly two set bits. If one of them is an opposite coloured rook/bishop we can be certain it's behind the other piece (because we're not in check).
Now all we need to check is if the other piece belongs to us. In case it's our piece we know that it's a pinned piece. Now we can determine if it's a kind of piece that is partially pinned or a kind that gets fully pinned. I do hope that I haven't overlooked anything. Is this not an original idea, or is it? How do you guys think this will perform? Do you see something I am overlooking?
Here is a link to my commit with my rudimentary implementation. (It's a Java based engine so it's not exactly gold standard, also it's a work in progress. I am still at move generation).