|
| From: | Richard Henderson |
| Subject: | Re: [Qemu-devel] [PATCH 5/8] target-tricore: Add instructions of RR opcode format, that have 0x4b as the first opcode |
| Date: | Fri, 12 Dec 2014 12:45:49 -0800 |
| User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 |
On 12/12/2014 09:31 AM, Bastian Koppelmann wrote:
> +uint32_t helper_parity(target_ulong r1)
> +{
> + uint32_t ret;
> + uint32_t nOnes, i;
> +
> + ret = 0;
> + nOnes = 0;
> + for (i = 0; i < 8; i++) {
> + ret ^= (r1 & 1);
> + r1 = r1 >> 1;
> + }
> + /* second byte */
> + nOnes = 0;
> + for (i = 0; i < 8; i++) {
> + nOnes ^= (r1 & 1);
> + r1 = r1 >> 1;
> + }
> + ret |= nOnes << 8;
> + /* third byte */
> + nOnes = 0;
> + for (i = 0; i < 8; i++) {
> + nOnes ^= (r1 & 1);
> + r1 = r1 >> 1;
> + }
> + ret |= nOnes << 16;
> + /* fourth byte */
> + nOnes = 0;
> + for (i = 0; i < 8; i++) {
> + nOnes ^= (r1 & 1);
> + r1 = r1 >> 1;
> + }
> + ret |= nOnes << 24;
> +
> + return ret;
> +}
> +
Probably doesn't matter much, but
ret = (ctpop8(r1) & 1)
| ((ctpop8(r1 >> 8) & 1) << 8)
| ((ctpop8(r1 >> 16) & 1) << 16)
| ((ctpop8(r1 >> 24) & 1) << 24);
One could also make a case for adding new helpers that
use __builtin_parity rather than __builtin_popcount.
I usually like to look at things like this and see how
the general infrastructure can be improved...
Otherwise,
Reviewed-by: Richard Henderson <address@hidden>
r~
| [Prev in Thread] | Current Thread | [Next in Thread] |