FreeBSD/sys/contrib/x86emu/x86emu.c
/*
 * REMARKS:
 * Implements the SAR instruction and side effects.
 */
Implements the SAR instruction and side effects.
Implements the SAR instruction and side effects .
static uint32_t 
sar_long(struct x86emu *emu, uint32_t d, uint8_t s)
{
	uint32_t cnt, res, cf, mask, sf;
	sf = d & 0x80000000;
	cnt = s % 32;
	res = d;
	if (cnt > 0 && cnt < 32) {
		mask = (1 << (32 - cnt)) - 1;
		cf = d & (1 << (cnt - 1));
		res = (d >> cnt) & mask;
		CONDITIONAL_SET_FLAG(cf, F_CF);
		if (sf) {
			res |= ~mask;
		}
		CONDITIONAL_SET_FLAG((res & 0xffffffff) == 0, F_ZF);
		CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF);
		CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF);
	} else if (cnt >= 32) {
		if (sf) {
			res = 0xffffffff;
			SET_FLAG(F_CF);
			CLEAR_FLAG(F_ZF);
			SET_FLAG(F_SF);
			SET_FLAG(F_PF);
		} else {
			res = 0;
			CLEAR_FLAG(F_CF);
			SET_FLAG(F_ZF);
			CLEAR_FLAG(F_SF);
			CLEAR_FLAG(F_PF);
		}
	}
	return res;
}
static uint32_t sar_long ( struct x86emu * emu , uint32_t d , uint8_t s ) { uint32_t cnt , res , cf , mask , sf ; sf = d & 0x80000000 ; cnt = s % 32 ; res = d ; if ( cnt > 0 && cnt < 32 ) { mask = ( 1 << ( 32 - cnt ) ) - 1 ; cf = d & ( 1 << ( cnt - 1 ) ) ; res = ( d >> cnt ) & mask ; CONDITIONAL_SET_FLAG ( cf , F_CF ) ; if ( sf ) { res |= ~ mask ; } CONDITIONAL_SET_FLAG ( ( res & 0xffffffff ) == 0 , F_ZF ) ; CONDITIONAL_SET_FLAG ( res & 0x80000000 , F_SF ) ; CONDITIONAL_SET_FLAG ( PARITY ( res & 0xff ) , F_PF ) ; } else if ( cnt >= 32 ) { if ( sf ) { res = 0xffffffff ; SET_FLAG ( F_CF ) ; CLEAR_FLAG ( F_ZF ) ; SET_FLAG ( F_SF ) ; SET_FLAG ( F_PF ) ; } else { res = 0 ; CLEAR_FLAG ( F_CF ) ; SET_FLAG ( F_ZF ) ; CLEAR_FLAG ( F_SF ) ; CLEAR_FLAG ( F_PF ) ; } } return res ; }
REMARKS:
 Implements the SAR instruction and side effects.
REMARKS : Implements the SAR instruction and side effects .