Используя самый простой подход:
Код: Выделить всё
struct cdiv_t
{
// char
std::int8_t quot;
std::int8_t rem;
};
cdiv_t idiv(std::int8_t dividend, std::int8_t const divisor)
{
int8_t const quotient = dividend / divisor;
int8_t const remainder = dividend % divisor;
return cdiv_t{quotient, remainder};
}
Код: Выделить всё
IntelIntrinsics!idiv [x86instructions.cpp @ 4]:
3 {
0x7ff63f4d1740 movsx eax,cl
4 int8_t const quotient = dividend / divisor;
0x7ff63f4d1743 movsx ecx,dl
0x7ff63f4d1746 cdq
0x7ff63f4d1747 idiv eax,ecx
6 return cdiv_t{quotient, remainder};
0x7ff63f4d1749 movzx r8d,dl
0x7ff63f4d174d shl r8w,8
0x7ff63f4d1752 movzx eax,al
0x7ff63f4d1755 or ax,r8w
7 }
0x7ff63f4d1759 ret
Кто-нибудь знает способ явного вызова 8-битной [и 16-битной] версии idiv?>
Подробнее здесь: https://stackoverflow.com/questions/798 ... c-directly
Мобильная версия