[PATCH 04/27] arc: TCG and decoder glue code and helpers

Richard Henderson richard.henderson at linaro.org
Wed Apr 7 03:37:15 BST 2021


On 4/5/21 7:31 AM, cupertinomiranda at gmail.com wrote:
> +static inline target_ulong
> +carry_add_flag(target_ulong dest, target_ulong b, target_ulong c, uint8_t size)
> +{
> +    target_ulong t1, t2, t3;
> +
> +    t1 = b & c;
> +    t2 = b & (~dest);
> +    t3 = c & (~dest);
> +    t1 = t1 | t2 | t3;
> +    return (t1 >> (size - 1)) & 1;
> +}
> +
> +target_ulong helper_carry_add_flag(target_ulong dest, target_ulong b,
> +                                   target_ulong c) {
> +    return carry_add_flag(dest, b, c, TARGET_LONG_BITS);
> +}
> +
> +static inline target_ulong
> +overflow_add_flag(target_ulong dest, target_ulong b, target_ulong c,
> +                  uint8_t size)
> +{
> +    dest >>= (size - 1);
> +    b >>= (size - 1);
> +    c >>= (size - 1);
> +    if ((dest == 0 && b == 1 && c == 1)
> +        || (dest == 1 && b == 0 && c == 0)) {
> +        return 1;
> +    } else {
> +        return 0;
> +    }
> +}
> +target_ulong helper_overflow_add_flag(target_ulong dest, target_ulong b,
> +                                      target_ulong c) {
> +    return overflow_add_flag(dest, b, c, TARGET_LONG_BITS);
> +}
> +
> +static inline target_ulong
> +overflow_sub_flag(target_ulong dest, target_ulong b, target_ulong c,
> +                  uint8_t size)
> +{
> +    dest >>= (size - 1);
> +    b >>= (size - 1);
> +    c >>= (size - 1);
> +    if ((dest == 1 && b == 0 && c == 1)
> +        || (dest == 0 && b == 1 && c == 0)) {
> +        return 1;
> +    } else {
> +        return 0;
> +    }
> +}
> +target_ulong helper_overflow_sub_flag(target_ulong dest, target_ulong b,
> +                                      target_ulong c) {
> +    return overflow_sub_flag(dest, b, c, TARGET_LONG_BITS);
> +}
> +
> +target_ulong helper_repl_mask(target_ulong dest, target_ulong src,
> +                              target_ulong mask)
> +{
> +    target_ulong ret = dest & (~mask);
> +    ret |= (src & mask);
> +
> +    return ret;
> +}
> +
> +target_ulong helper_mpymu(CPUARCState *env, target_ulong b, target_ulong c)
> +{
> +    uint64_t _b = (uint64_t) b;
> +    uint64_t _c = (uint64_t) c;
> +
> +    return (uint32_t) ((_b * _c) >> 32);
> +}
> +
> +target_ulong helper_mpym(CPUARCState *env, target_ulong b, target_ulong c)
> +{
> +    int64_t _b = (int64_t) ((int32_t) b);
> +    int64_t _c = (int64_t) ((int32_t) c);
> +
> +    /*
> +     * fprintf(stderr, "B = 0x%llx, C = 0x%llx, result = 0x%llx\n",
> +     *         _b, _c, _b * _c);
> +     */
> +    return (_b * _c) >> 32;
> +}

All completely trivial in tcg:

   tcg_gen_add2_tl,
   tcg_gen_mulu2_tl,
   tcg_gen_muls2_tl.

and simple arithmetic for overflow -- see gen_add_CC in arm/translate.c.


r~



More information about the linux-snps-arc mailing list