PTX bit field extract flips sign

Calling

bfe.s32 %r7, 2, 1, 1;
results in -1 being stored in the register
but
bfe.s32 %r7, 2, 1, 2;
stores 1
why does the first instruction flip the value sign?

You’re getting a sign-extended result, which is explained here, due to your choice of using s32.

In your case the sign bit is set to the msb of the extracted field. In the first case, the msb of the extracted field is 1. In the second case it is zero.

1 Like