mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 08:43:55 -06:00
target/ppc: Implement cfuged instruction
Signed-off-by: Matheus Ferst <matheus.ferst@eldorado.org.br> Message-Id: <20210601193528.2533031-12-matheus.ferst@eldorado.org.br> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
9a14365eeb
commit
89ccd7dc3f
4 changed files with 79 additions and 0 deletions
|
@ -320,6 +320,68 @@ target_ulong helper_popcntb(target_ulong val)
|
|||
}
|
||||
#endif
|
||||
|
||||
uint64_t helper_cfuged(uint64_t src, uint64_t mask)
|
||||
{
|
||||
/*
|
||||
* Instead of processing the mask bit-by-bit from the most significant to
|
||||
* the least significant bit, as described in PowerISA, we'll handle it in
|
||||
* blocks of 'n' zeros/ones from LSB to MSB. To avoid the decision to use
|
||||
* ctz or cto, we negate the mask at the end of the loop.
|
||||
*/
|
||||
target_ulong m, left = 0, right = 0;
|
||||
unsigned int n, i = 64;
|
||||
bool bit = false; /* tracks if we are processing zeros or ones */
|
||||
|
||||
if (mask == 0 || mask == -1) {
|
||||
return src;
|
||||
}
|
||||
|
||||
/* Processes the mask in blocks, from LSB to MSB */
|
||||
while (i) {
|
||||
/* Find how many bits we should take */
|
||||
n = ctz64(mask);
|
||||
if (n > i) {
|
||||
n = i;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extracts 'n' trailing bits of src and put them on the leading 'n'
|
||||
* bits of 'right' or 'left', pushing down the previously extracted
|
||||
* values.
|
||||
*/
|
||||
m = (1ll << n) - 1;
|
||||
if (bit) {
|
||||
right = ror64(right | (src & m), n);
|
||||
} else {
|
||||
left = ror64(left | (src & m), n);
|
||||
}
|
||||
|
||||
/*
|
||||
* Discards the processed bits from 'src' and 'mask'. Note that we are
|
||||
* removing 'n' trailing zeros from 'mask', but the logical shift will
|
||||
* add 'n' leading zeros back, so the population count of 'mask' is kept
|
||||
* the same.
|
||||
*/
|
||||
src >>= n;
|
||||
mask >>= n;
|
||||
i -= n;
|
||||
bit = !bit;
|
||||
mask = ~mask;
|
||||
}
|
||||
|
||||
/*
|
||||
* At the end, right was ror'ed ctpop(mask) times. To put it back in place,
|
||||
* we'll shift it more 64-ctpop(mask) times.
|
||||
*/
|
||||
if (bit) {
|
||||
n = ctpop64(mask);
|
||||
} else {
|
||||
n = 64 - ctpop64(mask);
|
||||
}
|
||||
|
||||
return left | (right >> n);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* PowerPC 601 specific instructions (POWER bridge) */
|
||||
target_ulong helper_div(CPUPPCState *env, target_ulong arg1, target_ulong arg2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue