src/common/xed-util.c
/* arbitrary sign extension from a qty of "bits" length to 32b */
arbitrary sign extension from a qty of "bits" length to 32b
arbitrary sign extension from a qty of " bits " length to 32b
xed_int32_t xed_sign_extend_arbitrary_to_32(xed_uint32_t x, unsigned int bits) {
    xed_int32_t mask = 1<<(bits-1);
    xed_int32_t vmask, o=0;
    if (bits < 32) {
        vmask = (1<<bits)-1;
        o = ((x&vmask) ^ mask)- mask;
    }
    else if (bits == 32) 
        o=x;
    else 
        xed_assert(0);
    return o;
}
xed_int32_t xed_sign_extend_arbitrary_to_32 ( xed_uint32_t x , unsigned int bits ) { xed_int32_t mask = 1 << ( bits - 1 ) ; xed_int32_t vmask , o = 0 ; if ( bits < 32 ) { vmask = ( 1 << bits ) - 1 ; o = ( ( x & vmask ) ^ mask ) - mask ; } else if ( bits == 32 ) o = x ; else xed_assert ( 0 ) ; return o ; }
arbitrary sign extension from a qty of "bits" length to 32b
arbitrary sign extension from a qty of " bits " length to 32b