Added helpers for 64-bit count leading zeroes/ones.

This commit is contained in:
Vas Crabb 2021-06-12 03:00:21 +10:00 committed by Vas Crabb
parent 27b93b2348
commit 73d97b7dc4
43 changed files with 457 additions and 122 deletions

View File

@ -233,6 +233,7 @@ project ("ocore_" .. _OPTIONS["osd"])
MAME_DIR .. "src/osd/eigccppc.h", MAME_DIR .. "src/osd/eigccppc.h",
MAME_DIR .. "src/osd/eigccx86.h", MAME_DIR .. "src/osd/eigccx86.h",
MAME_DIR .. "src/osd/eivc.h", MAME_DIR .. "src/osd/eivc.h",
MAME_DIR .. "src/osd/eivcarm.h",
MAME_DIR .. "src/osd/eivcx86.h", MAME_DIR .. "src/osd/eivcx86.h",
MAME_DIR .. "src/osd/eminline.h", MAME_DIR .. "src/osd/eminline.h",
MAME_DIR .. "src/osd/osdcomm.h", MAME_DIR .. "src/osd/osdcomm.h",

View File

@ -30,7 +30,7 @@ public:
assert(!(decode_limit & base)); assert(!(decode_limit & base));
for (offs_t remain = length, start = 0U; remain && (decode_limit >= start); ) for (offs_t remain = length, start = 0U; remain && (decode_limit >= start); )
{ {
unsigned const msb(31 - count_leading_zeros(u32(remain))); unsigned const msb(31 - count_leading_zeros_32(u32(remain)));
offs_t const chunk(offs_t(1) << msb); offs_t const chunk(offs_t(1) << msb);
offs_t range((chunk - 1) & decode_limit); offs_t range((chunk - 1) & decode_limit);
offs_t mirror(decode_limit & ~decode_mask & ~range); offs_t mirror(decode_limit & ~decode_mask & ~range);

View File

@ -28,7 +28,7 @@ void o2_rom_device::device_start()
void o2_rom_device::cart_init() void o2_rom_device::cart_init()
{ {
m_cart_mask = (1 << (31 - count_leading_zeros(m_rom_size))) - 1; m_cart_mask = (1 << (31 - count_leading_zeros_32(m_rom_size))) - 1;
} }

View File

@ -1396,7 +1396,7 @@ void am29000_cpu_device::CLZ()
{ {
uint32_t b = INST_M_BIT ? I8: GET_RB_VAL; uint32_t b = INST_M_BIT ? I8: GET_RB_VAL;
m_r[RC] = count_leading_zeros(b); m_r[RC] = count_leading_zeros_32(b);
} }
void am29000_cpu_device::SETIP() void am29000_cpu_device::SETIP()

View File

@ -1697,7 +1697,7 @@ void arm7_cpu_device::arm7ops_0123(uint32_t insn)
uint32_t rm = insn&0xf; uint32_t rm = insn&0xf;
uint32_t rd = (insn>>12)&0xf; uint32_t rd = (insn>>12)&0xf;
SetRegister(rd, count_leading_zeros(GetRegister(rm))); SetRegister(rd, count_leading_zeros_32(GetRegister(rm)));
R15 += 4; R15 += 4;
} }

View File

@ -1062,11 +1062,11 @@ int drcbe_c::execute(code_handle &entry)
break; break;
case MAKE_OPCODE_SHORT(OP_LZCNT, 4, 0): // LZCNT dst,src case MAKE_OPCODE_SHORT(OP_LZCNT, 4, 0): // LZCNT dst,src
PARAM0 = count_leading_zeros(PARAM1); PARAM0 = count_leading_zeros_32(PARAM1);
break; break;
case MAKE_OPCODE_SHORT(OP_LZCNT, 4, 1): case MAKE_OPCODE_SHORT(OP_LZCNT, 4, 1):
temp32 = count_leading_zeros(PARAM1); temp32 = count_leading_zeros_32(PARAM1);
flags = FLAGS32_NZ(temp32); flags = FLAGS32_NZ(temp32);
PARAM0 = temp32; PARAM0 = temp32;
break; break;
@ -1675,17 +1675,11 @@ int drcbe_c::execute(code_handle &entry)
break; break;
case MAKE_OPCODE_SHORT(OP_LZCNT, 8, 0): // DLZCNT dst,src case MAKE_OPCODE_SHORT(OP_LZCNT, 8, 0): // DLZCNT dst,src
if ((uint32_t)(DPARAM1 >> 32) != 0) DPARAM0 = count_leading_zeros_64(DPARAM1);
DPARAM0 = count_leading_zeros(DPARAM1 >> 32);
else
DPARAM0 = 32 + count_leading_zeros(DPARAM1);
break; break;
case MAKE_OPCODE_SHORT(OP_LZCNT, 8, 1): case MAKE_OPCODE_SHORT(OP_LZCNT, 8, 1):
if ((uint32_t)(DPARAM1 >> 32) != 0) temp64 = count_leading_zeros_64(DPARAM1);
temp64 = count_leading_zeros(DPARAM1 >> 32);
else
temp64 = 32 + count_leading_zeros(DPARAM1);
flags = FLAGS64_NZ(temp64); flags = FLAGS64_NZ(temp64);
DPARAM0 = temp64; DPARAM0 = temp64;
break; break;

View File

@ -1588,7 +1588,7 @@ void dspp_device::update_fifo_dma()
while (mask != 0) while (mask != 0)
{ {
uint32_t channel = 31 - count_leading_zeros(mask); uint32_t channel = 31 - count_leading_zeros_32(mask);
const fifo_dma & dma = m_fifo_dma[channel]; const fifo_dma & dma = m_fifo_dma[channel];

View File

@ -996,14 +996,14 @@ void mc88100_device::execute(u32 const inst)
break; break;
case 0x740: // ff1: find first bit set case 0x740: // ff1: find first bit set
{ {
unsigned const count = count_leading_zeros(m_r[S2]); unsigned const count = count_leading_zeros_32(m_r[S2]);
m_r[D] = (count == 32) ? count : 31 - count; m_r[D] = (count == 32) ? count : 31 - count;
} }
break; break;
case 0x760: // ff0: find first bit clear case 0x760: // ff0: find first bit clear
{ {
unsigned const count = count_leading_ones(m_r[S2]); unsigned const count = count_leading_ones_32(m_r[S2]);
m_r[D] = (count == 32) ? count : 31 - count; m_r[D] = (count == 32) ? count : 31 - count;
} }

View File

@ -1175,7 +1175,7 @@ void r4000_base_device::cpu_exception(u32 exception, u16 const vector)
u32 const iphw = CAUSE & SR & CAUSE_IPHW; u32 const iphw = CAUSE & SR & CAUSE_IPHW;
if (iphw) if (iphw)
debug()->interrupt_hook(22 - count_leading_zeros((iphw - 1) & ~iphw)); debug()->interrupt_hook(22 - count_leading_zeros_32((iphw - 1) & ~iphw));
} }
} }
else else
@ -1530,7 +1530,7 @@ void r4000_base_device::cp0_tlbwi(u8 const index)
entry.pfn[0] = m_cp0[CP0_EntryLo0] & EL_WM; entry.pfn[0] = m_cp0[CP0_EntryLo0] & EL_WM;
entry.pfn[1] = m_cp0[CP0_EntryLo1] & EL_WM; entry.pfn[1] = m_cp0[CP0_EntryLo1] & EL_WM;
entry.low_bit = 32 - count_leading_zeros((entry.mask >> 1) | 0xfff); entry.low_bit = 32 - count_leading_zeros_32((entry.mask >> 1) | 0xfff);
LOGMASKED(LOG_TLB, "tlb write index %02d mask 0x%016x vpn2 0x%016x %c asid 0x%02x pfn0 0x%016x %c%c pfn1 0x%016x %c%c (%s)\n", LOGMASKED(LOG_TLB, "tlb write index %02d mask 0x%016x vpn2 0x%016x %c asid 0x%02x pfn0 0x%016x %c%c pfn1 0x%016x %c%c (%s)\n",
index, entry.mask, index, entry.mask,

View File

@ -215,7 +215,7 @@ void gte::setcp2dr( uint32_t pc, int reg, uint32_t value )
break; break;
case 30: case 30:
LZCR = (value & 0x80000000) == 0 ? count_leading_zeros(value) : count_leading_ones(value); LZCR = (value & 0x80000000) == 0 ? count_leading_zeros_32(value) : count_leading_ones_32(value);
break; break;
case 31: case 31:
@ -314,7 +314,7 @@ static inline uint32_t gte_divide( uint16_t numerator, uint16_t denominator )
0x00 0x00
}; };
int shift = count_leading_zeros( denominator ) - 16; int shift = count_leading_zeros_32( denominator ) - 16;
int r1 = ( denominator << shift ) & 0x7fff; int r1 = ( denominator << shift ) & 0x7fff;
int r2 = table[ ( ( r1 + 0x40 ) >> 7 ) ] + 0x101; int r2 = table[ ( ( r1 + 0x40 ) >> 7 ) ] + 0x101;

View File

@ -887,7 +887,7 @@ void romp_device::execute_run()
flags_log(m_gpr[R2]); flags_log(m_gpr[R2]);
break; break;
case 0xf5: // clz: count leading zeros case 0xf5: // clz: count leading zeros
m_gpr[R2] = count_leading_zeros(u16(m_gpr[R3])) - 16; m_gpr[R2] = count_leading_zeros_32(u16(m_gpr[R3])) - 16;
break; break;
case 0xf9: // mc03: move character zero from three case 0xf9: // mc03: move character zero from three

View File

@ -393,7 +393,7 @@ void tms3203x_device::int2float(tmsreg &srcdst)
// positive values; count leading zeros and shift // positive values; count leading zeros and shift
else if ((int32_t)man > 0) else if ((int32_t)man > 0)
{ {
cnt = count_leading_zeros(man); cnt = count_leading_zeros_32(man);
man <<= cnt; man <<= cnt;
exp = 31 - cnt; exp = 31 - cnt;
} }
@ -401,7 +401,7 @@ void tms3203x_device::int2float(tmsreg &srcdst)
// negative values; count leading ones and shift // negative values; count leading ones and shift
else else
{ {
cnt = count_leading_ones(man); cnt = count_leading_ones_32(man);
man <<= cnt; man <<= cnt;
exp = 31 - cnt; exp = 31 - cnt;
} }
@ -585,13 +585,13 @@ void tms3203x_device::addf(tmsreg &dst, tmsreg &src1, tmsreg &src2)
{ {
if (man > 0) if (man > 0)
{ {
cnt = count_leading_zeros((uint32_t)man); cnt = count_leading_zeros_32((uint32_t)man);
man <<= cnt; man <<= cnt;
exp -= cnt; exp -= cnt;
} }
else else
{ {
cnt = count_leading_ones((uint32_t)man); cnt = count_leading_ones_32((uint32_t)man);
man <<= cnt; man <<= cnt;
exp -= cnt; exp -= cnt;
} }
@ -698,13 +698,13 @@ void tms3203x_device::subf(tmsreg &dst, tmsreg &src1, tmsreg &src2)
{ {
if (man > 0) if (man > 0)
{ {
cnt = count_leading_zeros((uint32_t)man); cnt = count_leading_zeros_32((uint32_t)man);
man <<= cnt; man <<= cnt;
exp -= cnt; exp -= cnt;
} }
else else
{ {
cnt = count_leading_ones((uint32_t)man); cnt = count_leading_ones_32((uint32_t)man);
man <<= cnt; man <<= cnt;
exp -= cnt; exp -= cnt;
} }
@ -847,13 +847,13 @@ void tms3203x_device::norm(tmsreg &dst, tmsreg &src)
int cnt; int cnt;
if (man > 0) if (man > 0)
{ {
cnt = count_leading_zeros((uint32_t)man); cnt = count_leading_zeros_32((uint32_t)man);
man <<= cnt; man <<= cnt;
exp -= cnt; exp -= cnt;
} }
else else
{ {
cnt = count_leading_ones((uint32_t)man); cnt = count_leading_ones_32((uint32_t)man);
man <<= cnt; man <<= cnt;
exp -= cnt; exp -= cnt;
} }

View File

@ -2458,16 +2458,16 @@ void tms340x0_device::setcdp(uint16_t op)
// .. only single bit set, pitch is power of two! // .. only single bit set, pitch is power of two!
case 1: case 1:
{ {
m_convdp = 32 - count_leading_zeros(dptch); m_convdp = 32 - count_leading_zeros_32(dptch);
COUNT_CYCLES(4); COUNT_CYCLES(4);
return; return;
} }
// .. two bits, we can decompose it to sum of two power of two numbers // .. two bits, we can decompose it to sum of two power of two numbers
case 2: case 2:
{ {
uint8_t first_one = count_leading_zeros(dptch); uint8_t first_one = count_leading_zeros_32(dptch);
uint8_t v1 = 32 - first_one; uint8_t v1 = 32 - first_one;
uint8_t v2 = 32 - count_leading_zeros(dptch & ~(1 << (first_one - 1))); uint8_t v2 = 32 - count_leading_zeros_32(dptch & ~(1 << (first_one - 1)));
m_convdp = v2 | (v1 << 8); m_convdp = v2 | (v1 << 8);
COUNT_CYCLES(6); COUNT_CYCLES(6);

View File

@ -631,14 +631,9 @@ void uml::instruction::simplify()
if (m_param[1].is_immediate()) if (m_param[1].is_immediate())
{ {
if (m_size == 4) if (m_size == 4)
convert_to_mov_immediate(count_leading_zeros(m_param[1].immediate())); convert_to_mov_immediate(count_leading_zeros_32(m_param[1].immediate()));
else if (m_size == 8) else if (m_size == 8)
{ convert_to_mov_immediate(count_leading_zeros_64(m_param[1].immediate()));
if ((m_param[1].immediate() >> 32) == 0)
convert_to_mov_immediate(32 + count_leading_zeros(m_param[1].immediate()));
else
convert_to_mov_immediate(count_leading_zeros(m_param[1].immediate() >> 32));
}
} }
break; break;

View File

@ -396,11 +396,11 @@ void unsp_12_device::execute_fxxx_101_group(uint16_t op)
if (r4 & 0x8000) if (r4 & 0x8000)
{ {
m_core->m_r[REG_R2] = count_leading_ones(0xffff0000 | r4) - 17; m_core->m_r[REG_R2] = count_leading_ones_32(0xffff0000 | r4) - 17;
} }
else else
{ {
m_core->m_r[REG_R2] = count_leading_zeros(r4) - 17; // -17 because count_leading_zeros works with 32-bit values m_core->m_r[REG_R2] = count_leading_zeros_32(r4) - 17; // -17 because count_leading_zeros_32 works with 32-bit values
} }
return; return;

View File

@ -409,14 +409,14 @@ int kp69_base_device::z80daisy_irq_ack()
// Restrict to high-priority interrupts if any of those are pending // Restrict to high-priority interrupts if any of those are pending
if ((m_irr & m_pgr) != 0) if ((m_irr & m_pgr) != 0)
{ {
level = 31 - count_leading_zeros(u32(m_irr & m_pgr)); level = 31 - count_leading_zeros_32(u32(m_irr & m_pgr));
assert(level >= 0 && level < 16); assert(level >= 0 && level < 16);
if ((1 << level) < (m_isr & m_pgr)) if ((1 << level) < (m_isr & m_pgr))
level = -1; level = -1;
} }
else if (m_irr != 0 && (m_isr & m_pgr) == 0) else if (m_irr != 0 && (m_isr & m_pgr) == 0)
{ {
level = 31 - count_leading_zeros(u32(m_irr)); level = 31 - count_leading_zeros_32(u32(m_irr));
assert(level >= 0 && level < 16); assert(level >= 0 && level < 16);
if ((1 << level) < m_isr) if ((1 << level) < m_isr)
level = -1; level = -1;
@ -461,7 +461,7 @@ void kp69_base_device::z80daisy_irq_reti()
} }
else if (m_isr != 0) else if (m_isr != 0)
{ {
int level = 31 - count_leading_zeros(u32((m_isr & m_pgr) != 0 ? (m_isr & m_pgr) : m_isr)); int level = 31 - count_leading_zeros_32(u32((m_isr & m_pgr) != 0 ? (m_isr & m_pgr) : m_isr));
assert(level >= 0 && level < 16); assert(level >= 0 && level < 16);
m_isr &= ~(1 << level); m_isr &= ~(1 << level);

View File

@ -53,7 +53,7 @@ uint32_t arm_aic_device::irq_vector_r()
int midx = -1; int midx = -1;
do do
{ {
uint8_t idx = 31 - count_leading_zeros(mask); uint8_t idx = 31 - count_leading_zeros_32(mask);
if ((int)(m_aic_smr[idx] & 7) >= pri) if ((int)(m_aic_smr[idx] & 7) >= pri)
{ {
midx = idx; midx = idx;
@ -146,7 +146,7 @@ void arm_aic_device::check_irqs()
int pri = get_level(); int pri = get_level();
do do
{ {
uint8_t idx = 31 - count_leading_zeros(mask); uint8_t idx = 31 - count_leading_zeros_32(mask);
if ((int)(m_aic_smr[idx] & 7) > pri) if ((int)(m_aic_smr[idx] & 7) > pri)
{ {
m_core_status |= 2; m_core_status |= 2;

View File

@ -275,7 +275,7 @@ void ns32202_device::interrupt(void *ptr, s32 param)
// check equal priority unmasked pending cascade interrupt // check equal priority unmasked pending cascade interrupt
if ((m_csrc & mask) && (m_ipnd & mask) && !(m_imsk & mask)) if ((m_csrc & mask) && (m_ipnd & mask) && !(m_imsk & mask))
{ {
LOGMASKED(LOG_STATE, "unmasked pending cascade in-service interrupt %d\n", 31 - count_leading_zeros(mask)); LOGMASKED(LOG_STATE, "unmasked pending cascade in-service interrupt %d\n", 31 - count_leading_zeros_32(mask));
accept = true; accept = true;
} }
@ -285,7 +285,7 @@ void ns32202_device::interrupt(void *ptr, s32 param)
// check unmasked pending interrupt // check unmasked pending interrupt
if ((m_ipnd & mask) && !(m_imsk & mask)) if ((m_ipnd & mask) && !(m_imsk & mask))
{ {
LOGMASKED(LOG_STATE, "unmasked pending interrupt %d\n", 31 - count_leading_zeros(mask)); LOGMASKED(LOG_STATE, "unmasked pending interrupt %d\n", 31 - count_leading_zeros_32(mask));
accept = true; accept = true;
break; break;
} }
@ -324,7 +324,7 @@ u8 ns32202_device::interrupt_acknowledge(bool side_effects)
mask = (mask << 1) | (mask >> 15); mask = (mask << 1) | (mask >> 15);
} }
unsigned const number = 31 - count_leading_zeros(mask); unsigned const number = 31 - count_leading_zeros_32(mask);
if (side_effects) if (side_effects)
{ {
LOGMASKED(LOG_STATE, "acknowledge highest priority unmasked interrupt %d\n", number); LOGMASKED(LOG_STATE, "acknowledge highest priority unmasked interrupt %d\n", number);
@ -400,7 +400,7 @@ u8 ns32202_device::interrupt_return(bool side_effects)
// rotate priority mask // rotate priority mask
mask = (mask << 1) | (mask >> 15); mask = (mask << 1) | (mask >> 15);
} }
unsigned const number = 31 - count_leading_zeros(mask); unsigned const number = 31 - count_leading_zeros_32(mask);
if (side_effects) if (side_effects)
{ {

View File

@ -497,7 +497,7 @@ INPUT_CHANGED_MEMBER(sensorboard_device::sensor)
INPUT_CHANGED_MEMBER(sensorboard_device::ui_spawn) INPUT_CHANGED_MEMBER(sensorboard_device::ui_spawn)
{ {
u8 pos = (newval) ? (u8)param : 32 - count_leading_zeros(m_inp_spawn->read()); u8 pos = (newval) ? (u8)param : 32 - count_leading_zeros_32(m_inp_spawn->read());
if (pos == 0 || pos > m_maxspawn) if (pos == 0 || pos > m_maxspawn)
return; return;

View File

@ -135,7 +135,7 @@ static inline int32_t fast_reciplog(int64_t value, int32_t *log2)
} }
/* determine how many leading zeros in the value and shift it up high */ /* determine how many leading zeros in the value and shift it up high */
lz = count_leading_zeros(temp); lz = count_leading_zeros_32(temp);
temp <<= lz; temp <<= lz;
exp += lz; exp += lz;
@ -1852,7 +1852,7 @@ do
wfloat = 0xffff; \ wfloat = 0xffff; \
else \ else \
{ \ { \
int exp = count_leading_zeros(temp); \ int exp = count_leading_zeros_32(temp); \
wfloat = ((exp << 12) | ((~temp >> (19 - exp)) & 0xfff)) + 1; \ wfloat = ((exp << 12) | ((~temp >> (19 - exp)) & 0xfff)) + 1; \
} \ } \
} \ } \
@ -1873,7 +1873,7 @@ do
depthval = 0xffff; \ depthval = 0xffff; \
else \ else \
{ \ { \
int exp = count_leading_zeros(temp); \ int exp = count_leading_zeros_32(temp); \
depthval = ((exp << 12) | ((~temp >> (19 - exp)) & 0xfff)) + 1; \ depthval = ((exp << 12) | ((~temp >> (19 - exp)) & 0xfff)) + 1; \
} \ } \
} \ } \

View File

@ -788,7 +788,7 @@ std::pair<handler_entry *, handler_entry *> memory_view::make_handlers(address_s
m_space = &space; m_space = &space;
offs_t span = addrstart ^ addrend; offs_t span = addrstart ^ addrend;
u32 awidth = 32 - count_leading_zeros(span); u32 awidth = 32 - count_leading_zeros_32(span);
h_make(awidth, m_config->data_width(), m_config->addr_shift(), m_config->endianness(), space, *this, m_handler_read, m_handler_write); h_make(awidth, m_config->data_width(), m_config->addr_shift(), m_config->endianness(), space, *this, m_handler_read, m_handler_write);
m_handler_read->ref(); m_handler_read->ref();

View File

@ -519,14 +519,14 @@ void validity_checker::validate_inlines()
for (int i = 0; i <= 32; i++) for (int i = 0; i <= 32; i++)
{ {
u32 t = i < 32 ? (1 << (31 - i) | testu32a >> i) : 0; u32 t = i < 32 ? (1 << (31 - i) | testu32a >> i) : 0;
u8 resultu8 = count_leading_zeros(t); u8 resultu8 = count_leading_zeros_32(t);
if (resultu8 != i) if (resultu8 != i)
osd_printf_error("Error testing count_leading_zeros %08x=%02x (expected %02x)\n", t, resultu8, i); osd_printf_error("Error testing count_leading_zeros_32 %08x=%02x (expected %02x)\n", t, resultu8, i);
t ^= 0xffffffff; t ^= 0xffffffff;
resultu8 = count_leading_ones(t); resultu8 = count_leading_ones_32(t);
if (resultu8 != i) if (resultu8 != i)
osd_printf_error("Error testing count_leading_ones %08x=%02x (expected %02x)\n", t, resultu8, i); osd_printf_error("Error testing count_leading_ones_32 %08x=%02x (expected %02x)\n", t, resultu8, i);
} }
} }

View File

@ -62,7 +62,7 @@ inline bool menu_confswitch::switch_group_descriptor::matches(ioport_field const
inline unsigned menu_confswitch::switch_group_descriptor::switch_count() const noexcept inline unsigned menu_confswitch::switch_group_descriptor::switch_count() const noexcept
{ {
return (sizeof(mask) * 8) - count_leading_zeros(mask); return (sizeof(mask) * 8) - count_leading_zeros_32(mask);
} }

View File

@ -93,9 +93,9 @@ union bitmap_headers
bool dib_parse_mask(uint32_t mask, unsigned &shift, unsigned &bits) bool dib_parse_mask(uint32_t mask, unsigned &shift, unsigned &bits)
{ {
shift = count_leading_zeros(mask); shift = count_leading_zeros_32(mask);
mask <<= shift; mask <<= shift;
bits = count_leading_ones(mask); bits = count_leading_ones_32(mask);
mask <<= shift; mask <<= shift;
shift = 32 - shift - bits; shift = 32 - shift - bits;
return !mask; return !mask;

View File

@ -171,7 +171,7 @@ void ggm_state::update_reset(ioport_value state)
DEVICE_IMAGE_LOAD_MEMBER(ggm_state::load_cart) DEVICE_IMAGE_LOAD_MEMBER(ggm_state::load_cart)
{ {
u32 size = m_cart->common_get_size("rom"); u32 size = m_cart->common_get_size("rom");
m_cart_mask = ((1 << (31 - count_leading_zeros(size))) - 1) & 0xffff; m_cart_mask = ((1 << (31 - count_leading_zeros_32(size))) - 1) & 0xffff;
m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE); m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom"); m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");

View File

@ -148,7 +148,7 @@ void arb_state::update_reset()
DEVICE_IMAGE_LOAD_MEMBER(arb_state::cart_load) DEVICE_IMAGE_LOAD_MEMBER(arb_state::cart_load)
{ {
u32 size = m_cart->common_get_size("rom"); u32 size = m_cart->common_get_size("rom");
m_cart_mask = ((1 << (31 - count_leading_zeros(size))) - 1) & 0x7fff; m_cart_mask = ((1 << (31 - count_leading_zeros_32(size))) - 1) & 0x7fff;
m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE); m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom"); m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");

View File

@ -143,7 +143,7 @@ u8 cc1_state::ppi_porta_r()
{ {
// 74148(priority encoder) I0-I7: inputs // 74148(priority encoder) I0-I7: inputs
// d0-d2: 74148 S0-S2, d3: 74148 GS // d0-d2: 74148 S0-S2, d3: 74148 GS
u8 data = count_leading_zeros(m_inputs[0]->read()) - 24; u8 data = count_leading_zeros_32(m_inputs[0]->read()) - 24;
if (data == 8) data = 0xf; if (data == 8) data = 0xf;
// d5-d7: more inputs (direct) // d5-d7: more inputs (direct)

View File

@ -696,7 +696,7 @@ static const uint8_t keyboard_table[ 80 ][ 2 ] = {
bool hp80_base_state::kb_scan_ioport(ioport_value pressed , unsigned idx_base , uint8_t& row , uint8_t& col) bool hp80_base_state::kb_scan_ioport(ioport_value pressed , unsigned idx_base , uint8_t& row , uint8_t& col)
{ {
if (pressed) { if (pressed) {
unsigned bit_no = 31 - count_leading_zeros(pressed); unsigned bit_no = 31 - count_leading_zeros_32(pressed);
row = (idx_base + bit_no) / 8; row = (idx_base + bit_no) / 8;
col = (idx_base + bit_no) % 8; col = (idx_base + bit_no) % 8;
return true; return true;

View File

@ -558,7 +558,7 @@ TIMER_DEVICE_CALLBACK_MEMBER(hp9825_state::kb_scan)
void hp9825_state::kb_scan_ioport(ioport_value pressed , ioport_port &port , unsigned idx_base , int& max_seq_len , unsigned& max_seq_idx) void hp9825_state::kb_scan_ioport(ioport_value pressed , ioport_port &port , unsigned idx_base , int& max_seq_len , unsigned& max_seq_idx)
{ {
while (pressed) { while (pressed) {
unsigned bit_no = 31 - count_leading_zeros(pressed); unsigned bit_no = 31 - count_leading_zeros_32(pressed);
ioport_value mask = BIT_MASK<ioport_value>(bit_no); ioport_value mask = BIT_MASK<ioport_value>(bit_no);
int seq_len = port.field(mask)->seq().length(); int seq_len = port.field(mask)->seq().length();
if (seq_len > max_seq_len) { if (seq_len > max_seq_len) {

View File

@ -550,7 +550,7 @@ attotime hp9845_base_state::time_to_gv_mem_availability() const
void hp9845_base_state::kb_scan_ioport(ioport_value pressed , ioport_port &port , unsigned idx_base , int& max_seq_len , unsigned& max_seq_idx) void hp9845_base_state::kb_scan_ioport(ioport_value pressed , ioport_port &port , unsigned idx_base , int& max_seq_len , unsigned& max_seq_idx)
{ {
while (pressed) { while (pressed) {
unsigned bit_no = 31 - count_leading_zeros(pressed); unsigned bit_no = 31 - count_leading_zeros_32(pressed);
ioport_value mask = BIT_MASK(bit_no); ioport_value mask = BIT_MASK(bit_no);
int seq_len = port.field(mask)->seq().length(); int seq_len = port.field(mask)->seq().length();
if (seq_len > max_seq_len) { if (seq_len > max_seq_len) {

View File

@ -132,7 +132,7 @@ u8 intel02_state::input_r()
{ {
// d0-d3: buttons through a maze of logic gates // d0-d3: buttons through a maze of logic gates
// basically giving each button its own 4-bit scancode // basically giving each button its own 4-bit scancode
u8 data = count_leading_zeros(m_inputs[0]->read()) - 17; u8 data = count_leading_zeros_32(m_inputs[0]->read()) - 17;
// d4: Vcc, d5-d7: buttons (direct) // d4: Vcc, d5-d7: buttons (direct)
return data | (~m_inputs[1]->read() << 4 & 0xf0); return data | (~m_inputs[1]->read() << 4 & 0xf0);

View File

@ -401,7 +401,7 @@ u8 odyssey2_state::p2_read()
{ {
// P12: 74156 keyboard decoder enable, 74156 inputs from P20-P22 // P12: 74156 keyboard decoder enable, 74156 inputs from P20-P22
// 74148 priority encoder, GS to P24, outputs to P25-P27 // 74148 priority encoder, GS to P24, outputs to P25-P27
u8 inp = count_leading_zeros(m_keyboard[m_p2 & 0x07]->read()) - 24; u8 inp = count_leading_zeros_32(m_keyboard[m_p2 & 0x07]->read()) - 24;
if (inp < 8) if (inp < 8)
data &= inp << 5 | 0xf; data &= inp << 5 | 0xf;
} }

View File

@ -257,7 +257,7 @@ void olibochu_state::sound_command_w(offs_t offset, uint8_t data)
else else
m_cmd = (m_cmd & 0xff00) | uint16_t(data); m_cmd = (m_cmd & 0xff00) | uint16_t(data);
unsigned c = count_leading_zeros(uint32_t(m_cmd)) - 16; unsigned c = count_leading_zeros_32(uint32_t(m_cmd)) - 16;
if (c < 16) if (c < 16)
m_soundlatch->write(c); m_soundlatch->write(c);
} }

View File

@ -407,7 +407,7 @@ DEVICE_IMAGE_LOAD_MEMBER(cm32p_state::card_load)
u8* base = pcmcard->get_rom_base(); u8* base = pcmcard->get_rom_base();
if (size < 0x080000) if (size < 0x080000)
{ {
uint32_t mirror = (1 << (31 - count_leading_zeros(size))); uint32_t mirror = (1 << (31 - count_leading_zeros_32(size)));
if (mirror < 0x020000) // due to how address descrambling works, we can currently only do mirroring for 128K pages if (mirror < 0x020000) // due to how address descrambling works, we can currently only do mirroring for 128K pages
mirror = 0x020000; mirror = 0x020000;
for (uint32_t ofs = mirror; ofs < 0x080000; ofs += mirror) for (uint32_t ofs = mirror; ofs < 0x080000; ofs += mirror)

View File

@ -147,7 +147,7 @@ void subhuntr_state::txtram_w(offs_t offset, u8 data)
u8 subhuntr_state::intack_r() u8 subhuntr_state::intack_r()
{ {
unsigned const source = count_leading_zeros(m_intreqs) - 24; unsigned const source = count_leading_zeros_32(m_intreqs) - 24;
u8 const vector = ((m_intreq_cnf->read() & 0x01) ? 0x91 : 0x11) | (source << 1); u8 const vector = ((m_intreq_cnf->read() & 0x01) ? 0x91 : 0x11) | (source << 1);
switch (source) switch (source)
{ {

View File

@ -54,6 +54,62 @@ inline bool _addu_64x64_co(uint64_t a, uint64_t b, uint64_t &sum)
INLINE BIT MANIPULATION FUNCTIONS INLINE BIT MANIPULATION FUNCTIONS
***************************************************************************/ ***************************************************************************/
/*-------------------------------------------------
count_leading_zeros_32 - return the number of
leading zero bits in a 32-bit value
-------------------------------------------------*/
#ifndef count_leading_zeros_32
inline uint8_t count_leading_zeros_32(uint32_t val)
{
// uses CPU feature if available, otherwise falls back to runtime library call
static_assert(sizeof(val) == sizeof(unsigned), "expected 32-bit unsigned int");
return uint8_t(unsigned(val ? __builtin_clz(val) : 32));
}
#endif
/*-------------------------------------------------
count_leading_ones_32 - return the number of
leading one bits in a 32-bit value
-------------------------------------------------*/
#ifndef count_leading_ones_32
inline uint8_t count_leading_ones_32(uint32_t val)
{
return count_leading_zeros_32(~val);
}
#endif
/*-------------------------------------------------
count_leading_zeros_64 - return the number of
leading zero bits in a 64-bit value
-------------------------------------------------*/
#ifndef count_leading_zeros_64
inline uint8_t count_leading_zeros_64(uint64_t val)
{
// uses CPU feature if available, otherwise falls back to runtime library call
static_assert(sizeof(val) == sizeof(unsigned long long), "expected 64-bit unsigned long long int");
return uint8_t(unsigned(val ? __builtin_clzll(val) : 64));
}
#endif
/*-------------------------------------------------
count_leading_ones_64 - return the number of
leading one bits in a 64-bit value
-------------------------------------------------*/
#ifndef count_leading_ones_64
inline uint8_t count_leading_ones_64(uint64_t val)
{
return count_leading_zeros_64(~val);
}
#endif
/*------------------------------------------------- /*-------------------------------------------------
population_count_32 - return the number of population_count_32 - return the number of
one bits in a 32-bit value one bits in a 32-bit value

View File

@ -239,14 +239,14 @@ _mulu_64x64(uint64_t a, uint64_t b, uint64_t &hi)
***************************************************************************/ ***************************************************************************/
/*------------------------------------------------- /*-------------------------------------------------
count_leading_zeros - return the number of count_leading_zeros_32 - return the number of
leading zero bits in a 32-bit value leading zero bits in a 32-bit value
-------------------------------------------------*/ -------------------------------------------------*/
#if defined(__aarch64__) #if defined(__aarch64__)
#define count_leading_zeros _count_leading_zeros #define count_leading_zeros_32 _count_leading_zeros_32
inline uint8_t ATTR_CONST ATTR_FORCE_INLINE inline uint8_t ATTR_CONST ATTR_FORCE_INLINE
_count_leading_zeros(uint32_t value) _count_leading_zeros_32(uint32_t value)
{ {
uint32_t result; uint32_t result;
@ -256,20 +256,20 @@ _count_leading_zeros(uint32_t value)
: [value] "r" (value) : [value] "r" (value)
); );
return result; return uint8_t(result);
} }
#endif #endif
/*------------------------------------------------- /*-------------------------------------------------
count_leading_ones - return the number of count_leading_ones_32 - return the number of
leading one bits in a 32-bit value leading one bits in a 32-bit value
-------------------------------------------------*/ -------------------------------------------------*/
#if defined(__aarch64__) #if defined(__aarch64__)
#define count_leading_ones _count_leading_ones #define count_leading_ones_32 _count_leading_ones_32
inline uint8_t ATTR_CONST ATTR_FORCE_INLINE inline uint8_t ATTR_CONST ATTR_FORCE_INLINE
_count_leading_ones(uint32_t value) _count_leading_ones_32(uint32_t value)
{ {
uint32_t result; uint32_t result;
@ -279,7 +279,53 @@ _count_leading_ones(uint32_t value)
: [value] "r" (~value) : [value] "r" (~value)
); );
return result; return uint8_t(result);
}
#endif
/*-------------------------------------------------
count_leading_zeros_64 - return the number of
leading zero bits in a 64-bit value
-------------------------------------------------*/
#if defined(__aarch64__)
#define count_leading_zeros_64 _count_leading_zeros_64
inline uint8_t ATTR_CONST ATTR_FORCE_INLINE
_count_leading_zeros_64(uint64_t value)
{
uint64_t result;
__asm__ (
" clz %[result], %[value] \n"
: [result] "=r" (result)
: [value] "r" (value)
);
return uint8_t(result);
}
#endif
/*-------------------------------------------------
count_leading_ones_64 - return the number of
leading one bits in a 64-bit value
-------------------------------------------------*/
#if defined(__aarch64__)
#define count_leading_ones_64 _count_leading_ones_64
inline uint8_t ATTR_CONST ATTR_FORCE_INLINE
_count_leading_ones_64(uint64_t value)
{
uint64_t result;
__asm__ (
" clz %[result], %[value] \n"
: [result] "=r" (result)
: [value] "r" (~value)
);
return uint8_t(result);
} }
#endif #endif

View File

@ -239,13 +239,13 @@ _mulu_64x64(uint64_t a, uint64_t b, uint64_t &hi)
***************************************************************************/ ***************************************************************************/
/*------------------------------------------------- /*-------------------------------------------------
count_leading_zeros - return the number of count_leading_zeros_32 - return the number of
leading zero bits in a 32-bit value leading zero bits in a 32-bit value
-------------------------------------------------*/ -------------------------------------------------*/
#define count_leading_zeros _count_leading_zeros #define count_leading_zeros_32 _count_leading_zeros_32
inline uint8_t ATTR_CONST ATTR_FORCE_INLINE inline uint8_t ATTR_CONST ATTR_FORCE_INLINE
_count_leading_zeros(uint32_t value) _count_leading_zeros_32(uint32_t value)
{ {
uint32_t result; uint32_t result;
@ -255,18 +255,18 @@ _count_leading_zeros(uint32_t value)
: [value] "r" (value) : [value] "r" (value)
); );
return result; return uint8_t(result);
} }
/*------------------------------------------------- /*-------------------------------------------------
count_leading_ones - return the number of count_leading_ones_32 - return the number of
leading one bits in a 32-bit value leading one bits in a 32-bit value
-------------------------------------------------*/ -------------------------------------------------*/
#define count_leading_ones _count_leading_ones #define count_leading_ones_32 _count_leading_ones_32
inline uint8_t ATTR_CONST ATTR_FORCE_INLINE inline uint8_t ATTR_CONST ATTR_FORCE_INLINE
_count_leading_ones(uint32_t value) _count_leading_ones_32(uint32_t value)
{ {
uint32_t result; uint32_t result;
@ -276,7 +276,53 @@ _count_leading_ones(uint32_t value)
: [value] "r" (~value) : [value] "r" (~value)
); );
return result; return uint8_t(result);
} }
/*-------------------------------------------------
count_leading_zeros_64 - return the number of
leading zero bits in a 64-bit value
-------------------------------------------------*/
#if defined(__ppc64__)
#define count_leading_zeros_64 _count_leading_zeros_64
inline uint8_t ATTR_CONST ATTR_FORCE_INLINE
_count_leading_zeros_64(uint64_t value)
{
uint64_t result;
__asm__ (
" cntlzd %[result], %[value] \n"
: [result] "=r" (result)
: [value] "r" (value)
);
return uint8_t(result);
}
#endif
/*-------------------------------------------------
count_leading_ones_64 - return the number of
leading one bits in a 64-bit value
-------------------------------------------------*/
#if defined(__ppc64__)
#define count_leading_ones_64 _count_leading_ones_64
inline uint8_t ATTR_CONST ATTR_FORCE_INLINE
_count_leading_ones_64(uint64_t value)
{
uint64_t result;
__asm__ (
" cntlzd %[result], %[value] \n"
: [result] "=r" (result)
: [value] "r" (~value)
);
return uint8_t(result);
}
#endif
#endif // MAME_OSD_EIGCCPPC_H #endif // MAME_OSD_EIGCCPPC_H

View File

@ -433,13 +433,13 @@ _mulu_64x64(uint64_t a, uint64_t b, uint64_t &hi)
***************************************************************************/ ***************************************************************************/
/*------------------------------------------------- /*-------------------------------------------------
count_leading_zeros - return the number of count_leading_zeros_32 - return the number of
leading zero bits in a 32-bit value leading zero bits in a 32-bit value
-------------------------------------------------*/ -------------------------------------------------*/
#define count_leading_zeros _count_leading_zeros #define count_leading_zeros_32 _count_leading_zeros_32
inline uint8_t ATTR_CONST ATTR_FORCE_INLINE inline uint8_t ATTR_CONST ATTR_FORCE_INLINE
_count_leading_zeros(uint32_t value) _count_leading_zeros_32(uint32_t value)
{ {
uint32_t result; uint32_t result;
__asm__ ( __asm__ (
@ -450,18 +450,18 @@ _count_leading_zeros(uint32_t value)
, [bias] "rm" (~uint32_t(0)) // 'bias' can be register or memory , [bias] "rm" (~uint32_t(0)) // 'bias' can be register or memory
: "cc" // clobbers condition codes : "cc" // clobbers condition codes
); );
return 31U - result; return uint8_t(31U - result);
} }
/*------------------------------------------------- /*-------------------------------------------------
count_leading_ones - return the number of count_leading_ones_32 - return the number of
leading one bits in a 32-bit value leading one bits in a 32-bit value
-------------------------------------------------*/ -------------------------------------------------*/
#define count_leading_ones _count_leading_ones #define count_leading_ones_32 _count_leading_ones_32
inline uint8_t ATTR_CONST ATTR_FORCE_INLINE inline uint8_t ATTR_CONST ATTR_FORCE_INLINE
_count_leading_ones(uint32_t value) _count_leading_ones_32(uint32_t value)
{ {
uint32_t result; uint32_t result;
__asm__ ( __asm__ (
@ -472,7 +472,55 @@ _count_leading_ones(uint32_t value)
, [bias] "rm" (~uint32_t(0)) // 'bias' can be register or memory , [bias] "rm" (~uint32_t(0)) // 'bias' can be register or memory
: "cc" // clobbers condition codes : "cc" // clobbers condition codes
); );
return 31U - result; return uint8_t(31U - result);
} }
/*-------------------------------------------------
count_leading_zeros_64 - return the number of
leading zero bits in a 64-bit value
-------------------------------------------------*/
#ifdef __x86_64__
#define count_leading_zeros_64 _count_leading_zeros_64
inline uint8_t ATTR_CONST ATTR_FORCE_INLINE
_count_leading_zeros_64(uint64_t value)
{
uint64_t result;
__asm__ (
" bsrq %[value], %[result] ;"
" cmovzq %[bias], %[result] ;"
: [result] "=&r" (result) // result can be in any register
: [value] "rm" (value) // 'value' can be register or memory
, [bias] "rm" (~uint64_t(0)) // 'bias' can be register or memory
: "cc" // clobbers condition codes
);
return uint8_t(63U - result);
}
#endif
/*-------------------------------------------------
count_leading_ones_64 - return the number of
leading one bits in a 64-bit value
-------------------------------------------------*/
#ifdef __x86_64__
#define count_leading_ones_64 _count_leading_ones_64
inline uint8_t ATTR_CONST ATTR_FORCE_INLINE
_count_leading_ones_64(uint64_t value)
{
uint64_t result;
__asm__ (
" bsrq %[value], %[result] ;"
" cmovzq %[bias], %[result] ;"
: [result] "=&r" (result) // result can be in any register
: [value] "rm" (~value) // 'value' can be register or memory
, [bias] "rm" (~uint64_t(0)) // 'bias' can be register or memory
: "cc" // clobbers condition codes
);
return uint8_t(63U - result);
}
#endif
#endif // MAME_OSD_EIGCCX86_H #endif // MAME_OSD_EIGCCX86_H

View File

@ -15,6 +15,9 @@
#include <intrin.h> #include <intrin.h>
#pragma intrinsic(_BitScanReverse) #pragma intrinsic(_BitScanReverse)
#ifdef PTR64
#pragma intrinsic(_BitScanReverse64)
#endif
/*************************************************************************** /***************************************************************************
@ -22,13 +25,13 @@
***************************************************************************/ ***************************************************************************/
/*------------------------------------------------- /*-------------------------------------------------
count_leading_zeros - return the number of count_leading_zeros_32 - return the number of
leading zero bits in a 32-bit value leading zero bits in a 32-bit value
-------------------------------------------------*/ -------------------------------------------------*/
#ifndef count_leading_zeros #ifndef count_leading_zeros_32
#define count_leading_zeros _count_leading_zeros #define count_leading_zeros_32 _count_leading_zeros_32
__forceinline uint8_t _count_leading_zeros(uint32_t value) __forceinline uint8_t _count_leading_zeros_32(uint32_t value)
{ {
unsigned long index; unsigned long index;
return _BitScanReverse(&index, value) ? (31U - index) : 32U; return _BitScanReverse(&index, value) ? (31U - index) : 32U;
@ -37,17 +40,55 @@ __forceinline uint8_t _count_leading_zeros(uint32_t value)
/*------------------------------------------------- /*-------------------------------------------------
count_leading_ones - return the number of count_leading_ones_32 - return the number of
leading one bits in a 32-bit value leading one bits in a 32-bit value
-------------------------------------------------*/ -------------------------------------------------*/
#ifndef count_leading_ones #ifndef count_leading_ones_32
#define count_leading_ones _count_leading_ones #define count_leading_ones_32 _count_leading_ones_32
__forceinline uint8_t _count_leading_ones(uint32_t value) __forceinline uint8_t _count_leading_ones_32(uint32_t value)
{ {
unsigned long index; unsigned long index;
return _BitScanReverse(&index, ~value) ? (31U - index) : 32U; return _BitScanReverse(&index, ~value) ? (31U - index) : 32U;
} }
#endif #endif
/*-------------------------------------------------
count_leading_zeros_64 - return the number of
leading zero bits in a 64-bit value
-------------------------------------------------*/
#ifndef count_leading_zeros_64
#define count_leading_zeros_64 _count_leading_zeros_64
__forceinline uint8_t _count_leading_zeros_64(uint64_t value)
{
unsigned long index;
#ifdef PTR64
return _BitScanReverse64(&index, value) ? (63U - index) : 64U;
#else
return _BitScanReverse(&index, uint32_t(value >> 32)) ? (31U - index) : _BitScanReverse(&index, uint32_t(value)) ? (63U - index) : 64U;
#endif
}
#endif
/*-------------------------------------------------
count_leading_ones_64 - return the number of
leading one bits in a 64-bit value
-------------------------------------------------*/
#ifndef count_leading_ones_64
#define count_leading_ones_64 _count_leading_ones_64
__forceinline uint8_t _count_leading_ones_64(uint64_t value)
{
unsigned long index;
#ifdef PTR64
return _BitScanReverse64(&index, ~value) ? (63U - index) : 64U;
#else
return _BitScanReverse(&index, ~uint32_t(value >> 32)) ? (31U - index) : _BitScanReverse(&index, ~uint32_t(value)) ? (63U - index) : 64U;
#endif
}
#endif
#endif // MAME_OSD_EIVC_H #endif // MAME_OSD_EIVC_H

75
src/osd/eivcarm.h Normal file
View File

@ -0,0 +1,75 @@
// license:BSD-3-Clause
// copyright-holders:Vas Crabb
//============================================================
//
// eivcarm.h
//
// ARM/AArch64 inline implementations for MSVC compiler.
//
//============================================================
#ifndef MAME_OSD_EIVCARM_H
#define MAME_OSD_EIVCARM_H
#pragma once
#include <intrin.h>
#pragma intrinsic(_CountLeadingZeros)
#pragma intrinsic(_CountLeadingZeros64)
#pragma intrinsic(_CountLeadingOnes)
#pragma intrinsic(_CountLeadingOnes64)
/***************************************************************************
INLINE BIT MANIPULATION FUNCTIONS
***************************************************************************/
/*-------------------------------------------------
count_leading_zeros_32 - return the number of
leading zero bits in a 32-bit value
-------------------------------------------------*/
#define count_leading_zeros_32 _count_leading_zeros_32
__forceinline uint8_t _count_leading_zeros_32(uint32_t value)
{
return uint8_t(_CountLeadingZeros(value));
}
/*-------------------------------------------------
count_leading_ones_32 - return the number of
leading one bits in a 32-bit value
-------------------------------------------------*/
#define count_leading_ones_32 _count_leading_ones_32
__forceinline uint8_t _count_leading_ones_32(uint32_t value)
{
return uint8_t(_CountLeadingOnes(value));
}
/*-------------------------------------------------
count_leading_zeros_64 - return the number of
leading zero bits in a 64-bit value
-------------------------------------------------*/
#define count_leading_zeros_64 _count_leading_zeros_64
__forceinline uint8_t _count_leading_zeros_64(uint64_t value)
{
return uint8_t(_CountLeadingZeros64(value));
}
/*-------------------------------------------------
count_leading_ones_64 - return the number of
leading one bits in a 64-bit value
-------------------------------------------------*/
#define count_leading_ones_64 _count_leading_ones_64
__forceinline uint8_t _count_leading_ones_64(uint64_t value)
{
return uint8_t(_CountLeadingOnes64(value));
}
#endif // MAME_OSD_EIVCARM_H

View File

@ -33,8 +33,10 @@
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#if (defined(_M_IX86) || defined(_M_X64)) #if defined(_M_IX86) || defined(_M_X64)
#include "eivcx86.h" #include "eivcx86.h"
#elif defined(_M_ARM) || defined(_M_ARM64)
#include "eivcarm.h"
#endif #endif
#include "eivc.h" #include "eivc.h"
@ -352,12 +354,12 @@ inline bool addu_64x64_co(uint64_t a, uint64_t b, uint64_t &sum)
***************************************************************************/ ***************************************************************************/
/*------------------------------------------------- /*-------------------------------------------------
count_leading_zeros - return the number of count_leading_zeros_32 - return the number of
leading zero bits in a 32-bit value leading zero bits in a 32-bit value
-------------------------------------------------*/ -------------------------------------------------*/
#ifndef count_leading_zeros #ifndef count_leading_zeros_32
inline uint8_t count_leading_zeros(uint32_t val) inline uint8_t count_leading_zeros_32(uint32_t val)
{ {
if (!val) return 32U; if (!val) return 32U;
uint8_t count; uint8_t count;
@ -368,12 +370,12 @@ inline uint8_t count_leading_zeros(uint32_t val)
/*------------------------------------------------- /*-------------------------------------------------
count_leading_ones - return the number of count_leading_ones_32 - return the number of
leading one bits in a 32-bit value leading one bits in a 32-bit value
-------------------------------------------------*/ -------------------------------------------------*/
#ifndef count_leading_ones #ifndef count_leading_ones_32
inline uint8_t count_leading_ones(uint32_t val) inline uint8_t count_leading_ones_32(uint32_t val)
{ {
uint8_t count; uint8_t count;
for (count = 0; int32_t(val) < 0; count++) val <<= 1; for (count = 0; int32_t(val) < 0; count++) val <<= 1;
@ -382,6 +384,37 @@ inline uint8_t count_leading_ones(uint32_t val)
#endif #endif
/*-------------------------------------------------
count_leading_zeros_64 - return the number of
leading zero bits in a 64-bit value
-------------------------------------------------*/
#ifndef count_leading_zeros_64
inline uint8_t count_leading_zeros_64(uint64_t val)
{
if (!val) return 64U;
uint8_t count;
for (count = 0; int64_t(val) >= 0; count++) val <<= 1;
return count;
}
#endif
/*-------------------------------------------------
count_leading_ones_64 - return the number of
leading one bits in a 64-bit value
-------------------------------------------------*/
#ifndef count_leading_ones_64
inline uint8_t count_leading_ones_64(uint64_t val)
{
uint8_t count;
for (count = 0; int64_t(val) < 0; count++) val <<= 1;
return count;
}
#endif
/*------------------------------------------------- /*-------------------------------------------------
population_count_32 - return the number of population_count_32 - return the number of
one bits in a 32-bit value one bits in a 32-bit value

View File

@ -1345,7 +1345,7 @@ int main(int argc, char *argv[])
} }
// Compute the shift amount from pc delta to granularity-sized elements // Compute the shift amount from pc delta to granularity-sized elements
u32 granularity_shift = 31 - count_leading_zeros(disasm->opcode_alignment()); u32 granularity_shift = 31 - count_leading_zeros_32(disasm->opcode_alignment());
// Number of pc steps to disassemble // Number of pc steps to disassemble
u32 count = pclength; u32 count = pclength;
@ -1355,7 +1355,7 @@ int main(int argc, char *argv[])
// pc to string conversion // pc to string conversion
std::function<std::string (offs_t pc)> pc_to_string; std::function<std::string (offs_t pc)> pc_to_string;
int aw = 32 - count_leading_zeros(pc_mask); int aw = 32 - count_leading_zeros_32(pc_mask);
bool is_octal = opts.octal; // Parameter? Per-cpu config? bool is_octal = opts.octal; // Parameter? Per-cpu config?
if((flags & util::disasm_interface::PAGED2LEVEL) == util::disasm_interface::PAGED2LEVEL) { if((flags & util::disasm_interface::PAGED2LEVEL) == util::disasm_interface::PAGED2LEVEL) {
int bits1 = disasm->page_address_bits(); int bits1 = disasm->page_address_bits();