/*
 *  m68k micro operations
 *
 *  Copyright (c) 2006-2007 CodeSourcery
 *  Written by Paul Brook
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "exec.h"
#include "m68k-qreg.h"

#ifndef offsetof
#define offsetof(type, field) ((size_t) &((type *)0)->field)
#endif

static long qreg_offsets[] = {
#define DEFO32(name, offset) offsetof(CPUState, offset),
#define DEFR(name, reg, mode) -1,
#define DEFF64(name, offset) offsetof(CPUState, offset),
    0,
#include "qregs.def"
};

#define CPU_FP_STATUS env->fp_status

#define RAISE_EXCEPTION(n) do { \
    env->exception_index = n; \
    cpu_loop_exit(); \
    } while(0)

#define get_op helper_get_op
#define set_op helper_set_op
#define get_opf64 helper_get_opf64
#define set_opf64 helper_set_opf64
uint32_t
get_op(int qreg)
{
    if (qreg >= TARGET_NUM_QREGS) {
        return env->qregs[qreg - TARGET_NUM_QREGS];
    } else if (qreg == QREG_T0) {
        return T0;
    } else {
        return *(uint32_t *)(((long)env) + qreg_offsets[qreg]);
    }
}

void set_op(int qreg, uint32_t val)
{
    if (qreg >= TARGET_NUM_QREGS) {
        env->qregs[qreg - TARGET_NUM_QREGS] = val;
    } else if (qreg == QREG_T0) {
        T0 = val;
    } else {
        *(uint32_t *)(((long)env) + qreg_offsets[qreg]) = val;
    }
}

float64 get_opf64(int qreg)
{
    if (qreg < TARGET_NUM_QREGS) {
        return *(float64 *)(((long)env) + qreg_offsets[qreg]);
    } else {
        return *(float64 *)&env->qregs[qreg - TARGET_NUM_QREGS];
    }
}

void set_opf64(int qreg, float64 val)
{
    if (qreg < TARGET_NUM_QREGS) {
        *(float64 *)(((long)env) + qreg_offsets[qreg]) = val;
    } else {
        *(float64 *)&env->qregs[qreg - TARGET_NUM_QREGS] = val;
    }
}

#define OP(name) void OPPROTO glue(op_,name) (void)

OP(mov32)
{
    set_op(PARAM1, get_op(PARAM2));
    FORCE_RET();
}

OP(mov32_im)
{
    set_op(PARAM1, PARAM2);
    FORCE_RET();
}

OP(movf64)
{
    set_opf64(PARAM1, get_opf64(PARAM2));
    FORCE_RET();
}

OP(zerof64)
{
    set_opf64(PARAM1, float64_zero);
    FORCE_RET();
}

OP(add32)
{
    uint32_t op2 = get_op(PARAM2);
    uint32_t op3 = get_op(PARAM3);
    set_op(PARAM1, op2 + op3);
    FORCE_RET();
}

OP(sub32)
{
    uint32_t op2 = get_op(PARAM2);
    uint32_t op3 = get_op(PARAM3);
    set_op(PARAM1, op2 - op3);
    FORCE_RET();
}

OP(mul32)
{
    uint32_t op2 = get_op(PARAM2);
    uint32_t op3 = get_op(PARAM3);
    set_op(PARAM1, op2 * op3);
    FORCE_RET();
}

OP(not32)
{
    uint32_t arg = get_op(PARAM2);
    set_op(PARAM1, ~arg);
    FORCE_RET();
}

OP(neg32)
{
    uint32_t arg = get_op(PARAM2);
    set_op(PARAM1, -arg);
    FORCE_RET();
}

OP(bswap32)
{
    uint32_t arg = get_op(PARAM2);
    arg = (arg >> 24) | (arg << 24)
          | ((arg >> 16) & 0xff00) | ((arg << 16) & 0xff0000);
    set_op(PARAM1, arg);
    FORCE_RET();
}

OP(btest)
{
    uint32_t op1 = get_op(PARAM1);
    uint32_t op2 = get_op(PARAM2);
    if (op1 & op2)
        env->cc_dest &= ~CCF_Z;
    else
        env->cc_dest |= CCF_Z;
    FORCE_RET();
}

OP(ff1)
{
    uint32_t arg = get_op(PARAM2);
    int n;
    for (n = 32; arg; n--)
        arg >>= 1;
    set_op(PARAM1, n);
    FORCE_RET();
}

OP(subx_cc)
{
    uint32_t op1 = get_op(PARAM1);
    uint32_t op2 = get_op(PARAM2);
    uint32_t res;
    if (env->cc_x) {
        env->cc_x = (op1 <= op2);
        env->cc_op = CC_OP_SUBX;
        res = op1 - (op2 + 1);
    } else {
        env->cc_x = (op1 < op2);
        env->cc_op = CC_OP_SUB;
        res = op1 - op2;
    }
    set_op(PARAM1, res);
    FORCE_RET();
}

OP(addx_cc)
{
    uint32_t op1 = get_op(PARAM1);
    uint32_t op2 = get_op(PARAM2);
    uint32_t res;
    if (env->cc_x) {
        res = op1 + op2 + 1;
        env->cc_x = (res <= op2);
        env->cc_op = CC_OP_ADDX;
    } else {
        res = op1 + op2;
        env->cc_x = (res < op2);
        env->cc_op = CC_OP_ADD;
    }
    set_op(PARAM1, res);
    FORCE_RET();
}

/* Logic ops.  */

OP(and32)
{
    uint32_t op2 = get_op(PARAM2);
    uint32_t op3 = get_op(PARAM3);
    set_op(PARAM1, op2 & op3);
    FORCE_RET();
}

OP(or32)
{
    uint32_t op2 = get_op(PARAM2);
    uint32_t op3 = get_op(PARAM3);
    set_op(PARAM1, op2 | op3);
    FORCE_RET();
}

OP(xor32)
{
    uint32_t op2 = get_op(PARAM2);
    uint32_t op3 = get_op(PARAM3);
    set_op(PARAM1, op2 ^ op3);
    FORCE_RET();
}

/* Shifts.  */
OP(shl32)
{
    uint32_t op2 = get_op(PARAM2);
    uint32_t op3 = get_op(PARAM3);
    uint32_t result;
    result = op2 << op3;
    set_op(PARAM1, result);
    FORCE_RET();
}

OP(shl_cc)
{
    uint32_t op1 = get_op(PARAM1);
    uint32_t op2 = get_op(PARAM2);
    uint32_t result;
    result = op1 << op2;
    set_op(PARAM1, result);
    env->cc_x = (op1 << (op2 - 1)) & 1;
    FORCE_RET();
}

OP(shr32)
{
    uint32_t op2 = get_op(PARAM2);
    uint32_t op3 = get_op(PARAM3);
    uint32_t result;
    result = op2 >> op3;
    set_op(PARAM1, result);
    FORCE_RET();
}

OP(shr_cc)
{
    uint32_t op1 = get_op(PARAM1);
    uint32_t op2 = get_op(PARAM2);
    uint32_t result;
    result = op1 >> op2;
    set_op(PARAM1, result);
    env->cc_x = (op1 >> (op2 - 1)) & 1;
    FORCE_RET();
}

OP(sar32)
{
    int32_t op2 = get_op(PARAM2);
    uint32_t op3 = get_op(PARAM3);
    uint32_t result;
    result = op2 >> op3;
    set_op(PARAM1, result);
    FORCE_RET();
}

OP(sar_cc)
{
    int32_t op1 = get_op(PARAM1);
    uint32_t op2 = get_op(PARAM2);
    uint32_t result;
    result = op1 >> op2;
    set_op(PARAM1, result);
    env->cc_x = (op1 >> (op2 - 1)) & 1;
    FORCE_RET();
}

/* Value extend.  */

OP(ext8u32)
{
    uint32_t op2 = get_op(PARAM2);
    set_op(PARAM1, (uint8_t)op2);
    FORCE_RET();
}

OP(ext8s32)
{
    uint32_t op2 = get_op(PARAM2);
    set_op(PARAM1, (int8_t)op2);
    FORCE_RET();
}

OP(ext16u32)
{
    uint32_t op2 = get_op(PARAM2);
    set_op(PARAM1, (uint16_t)op2);
    FORCE_RET();
}

OP(ext16s32)
{
    uint32_t op2 = get_op(PARAM2);
    set_op(PARAM1, (int16_t)op2);
    FORCE_RET();
}

OP(flush_flags)
{
    cpu_m68k_flush_flags(env, env->cc_op);
    FORCE_RET();
}

OP(divu)
{
    uint32_t num;
    uint32_t den;
    uint32_t quot;
    uint32_t rem;
    uint32_t flags;

    num = env->div1;
    den = env->div2;
    /* ??? This needs to make sure the throwing location is accurate.  */
    if (den == 0)
        RAISE_EXCEPTION(EXCP_DIV0);
    quot = num / den;
    rem = num % den;
    flags = 0;
    /* Avoid using a PARAM1 of zero.  This breaks dyngen because it uses
       the address of a symbol, and gcc knows symbols can't have address
       zero.  */
    if (PARAM1 == 2 && quot > 0xffff)
        flags |= CCF_V;
    if (quot == 0)
        flags |= CCF_Z;
    else if ((int32_t)quot < 0)
        flags |= CCF_N;
    env->div1 = quot;
    env->div2 = rem;
    env->cc_dest = flags;
    FORCE_RET();
}

OP(divs)
{
    int32_t num;
    int32_t den;
    int32_t quot;
    int32_t rem;
    int32_t flags;

    num = env->div1;
    den = env->div2;
    if (den == 0)
        RAISE_EXCEPTION(EXCP_DIV0);
    quot = num / den;
    rem = num % den;
    flags = 0;
    if (PARAM1 == 2 && quot != (int16_t)quot)
        flags |= CCF_V;
    if (quot == 0)
        flags |= CCF_Z;
    else if (quot < 0)
        flags |= CCF_N;
    env->div1 = quot;
    env->div2 = rem;
    env->cc_dest = flags;
    FORCE_RET();
}

/* Halt is special because it may be a semihosting call.  */
OP(halt)
{
    RAISE_EXCEPTION(EXCP_HALT_INSN);
    FORCE_RET();
}

OP(stop)
{
    env->halted = 1;
    RAISE_EXCEPTION(EXCP_HLT);
    FORCE_RET();
}

OP(raise_exception)
{
    RAISE_EXCEPTION(PARAM1);
    FORCE_RET();
}

/* Floating point comparison sets flags differently to other instructions.  */

OP(sub_cmpf64)
{
    float64 src0;
    float64 src1;
    src0 = get_opf64(PARAM2);
    src1 = get_opf64(PARAM3);
    set_opf64(PARAM1, helper_sub_cmpf64(env, src0, src1));
    FORCE_RET();
}

OP(update_xflag_tst)
{
    uint32_t op1 = get_op(PARAM1);
    env->cc_x = op1;
    FORCE_RET();
}

OP(update_xflag_lt)
{
    uint32_t op1 = get_op(PARAM1);
    uint32_t op2 = get_op(PARAM2);
    env->cc_x = (op1 < op2);
    FORCE_RET();
}

OP(get_xflag)
{
    set_op(PARAM1, env->cc_x);
    FORCE_RET();
}

OP(logic_cc)
{
    uint32_t op1 = get_op(PARAM1);
    env->cc_dest = op1;
    FORCE_RET();
}

OP(update_cc_add)
{
    uint32_t op1 = get_op(PARAM1);
    uint32_t op2 = get_op(PARAM2);
    env->cc_dest = op1;
    env->cc_src = op2;
    FORCE_RET();
}

OP(fp_result)
{
    env->fp_result = get_opf64(PARAM1);
    FORCE_RET();
}

OP(set_sr)
{
    env->sr = get_op(PARAM1) & 0xffff;
    m68k_switch_sp(env);
    FORCE_RET();
}

OP(jmp_im)
{
    GOTO_LABEL_PARAM(1);
}

OP(set_T0_z32)
{
    uint32_t arg = get_op(PARAM1);
    T0 = (arg == 0);
    FORCE_RET();
}

OP(set_T0_nz32)
{
    uint32_t arg = get_op(PARAM1);
    T0 = (arg != 0);
    FORCE_RET();
}

OP(set_T0_s32)
{
    int32_t arg = get_op(PARAM1);
    T0 = (arg < 0);
    FORCE_RET();
}

OP(set_T0_ns32)
{
    int32_t arg = get_op(PARAM1);
    T0 = (arg >= 0);
    FORCE_RET();
}

OP(jmp_T0)
{
    if (T0)
        GOTO_LABEL_PARAM(1);
    FORCE_RET();
}

/* Floating point.  */
OP(f64_to_i32)
{
    set_op(PARAM1, float64_to_int32(get_opf64(PARAM2), &CPU_FP_STATUS));
    FORCE_RET();
}

OP(f64_to_f32)
{
    union {
        float32 f;
        uint32_t i;
    } u;
    u.f = float64_to_float32(get_opf64(PARAM2), &CPU_FP_STATUS);
    set_op(PARAM1, u.i);
    FORCE_RET();
}

OP(i32_to_f64)
{
    set_opf64(PARAM1, int32_to_float64(get_op(PARAM2), &CPU_FP_STATUS));
    FORCE_RET();
}

OP(f32_to_f64)
{
    union {
        float32 f;
        uint32_t i;
    } u;
    u.i = get_op(PARAM2);
    set_opf64(PARAM1, float32_to_float64(u.f, &CPU_FP_STATUS));
    FORCE_RET();
}

OP(absf64)
{
    float64 op0 = get_opf64(PARAM2);
    set_opf64(PARAM1, float64_abs(op0));
    FORCE_RET();
}

OP(chsf64)
{
    float64 op0 = get_opf64(PARAM2);
    set_opf64(PARAM1, float64_chs(op0));
    FORCE_RET();
}

OP(sqrtf64)
{
    float64 op0 = get_opf64(PARAM2);
    set_opf64(PARAM1, float64_sqrt(op0, &CPU_FP_STATUS));
    FORCE_RET();
}

OP(addf64)
{
    float64 op0 = get_opf64(PARAM2);
    float64 op1 = get_opf64(PARAM3);
    set_opf64(PARAM1, float64_add(op0, op1, &CPU_FP_STATUS));
    FORCE_RET();
}

OP(subf64)
{
    float64 op0 = get_opf64(PARAM2);
    float64 op1 = get_opf64(PARAM3);
    set_opf64(PARAM1, float64_sub(op0, op1, &CPU_FP_STATUS));
    FORCE_RET();
}

OP(mulf64)
{
    float64 op0 = get_opf64(PARAM2);
    float64 op1 = get_opf64(PARAM3);
    set_opf64(PARAM1, float64_mul(op0, op1, &CPU_FP_STATUS));
    FORCE_RET();
}

OP(divf64)
{
    float64 op0 = get_opf64(PARAM2);
    float64 op1 = get_opf64(PARAM3);
    set_opf64(PARAM1, float64_div(op0, op1, &CPU_FP_STATUS));
    FORCE_RET();
}

OP(iround_f64)
{
    float64 op0 = get_opf64(PARAM2);
    set_opf64(PARAM1, float64_round_to_int(op0, &CPU_FP_STATUS));
    FORCE_RET();
}

OP(itrunc_f64)
{
    float64 op0 = get_opf64(PARAM2);
    set_opf64(PARAM1, float64_trunc_to_int(op0, &CPU_FP_STATUS));
    FORCE_RET();
}

OP(compare_quietf64)
{
    float64 op0 = get_opf64(PARAM2);
    float64 op1 = get_opf64(PARAM3);
    set_op(PARAM1, float64_compare_quiet(op0, op1, &CPU_FP_STATUS));
    FORCE_RET();
}

OP(movec)
{
    int op1 = get_op(PARAM1);
    uint32_t op2 = get_op(PARAM2);
    helper_movec(env, op1, op2);
}

/* Memory access.  */

#define MEMSUFFIX _raw
#include "op_mem.h"

#if !defined(CONFIG_USER_ONLY)
#define MEMSUFFIX _user
#include "op_mem.h"
#define MEMSUFFIX _kernel
#include "op_mem.h"
#endif

/* MAC unit.  */
/* TODO: The MAC instructions use 64-bit arithmetic fairly extensively.
   This results in fairly large ops (and sometimes other issues) on 32-bit
   hosts.  Maybe move most of them into helpers.  */
OP(macmuls)
{
    uint32_t op1 = get_op(PARAM1);
    uint32_t op2 = get_op(PARAM2);
    int64_t product;
    int64_t res;

    product = (uint64_t)op1 * op2;
    res = (product << 24) >> 24;
    if (res != product) {
        env->macsr |= MACSR_V;
        if (env->macsr & MACSR_OMC) {
            /* Make sure the accumulate operation overflows.  */
            if (product < 0)
                res = ~(1ll << 50);
            else
                res = 1ll << 50;
        }
    }
    env->mactmp = res;
    FORCE_RET();
}

OP(macmulu)
{
    uint32_t op1 = get_op(PARAM1);
    uint32_t op2 = get_op(PARAM2);
    uint64_t product;

    product = (uint64_t)op1 * op2;
    if (product & (0xffffffull << 40)) {
        env->macsr |= MACSR_V;
        if (env->macsr & MACSR_OMC) {
            /* Make sure the accumulate operation overflows.  */
            product = 1ll << 50;
        } else {
            product &= ((1ull << 40) - 1);
        }
    }
    env->mactmp = product;
    FORCE_RET();
}

OP(macmulf)
{
    int32_t op1 = get_op(PARAM1);
    int32_t op2 = get_op(PARAM2);
    uint64_t product;
    uint32_t remainder;

    product = (uint64_t)op1 * op2;
    if (env->macsr & MACSR_RT) {
        remainder = product & 0xffffff;
        product >>= 24;
        if (remainder > 0x800000)
            product++;
        else if (remainder == 0x800000)
            product += (product & 1);
    } else {
        product >>= 24;
    }
    env->mactmp = product;
    FORCE_RET();
}

OP(macshl)
{
    env->mactmp <<= 1;
}

OP(macshr)
{
    env->mactmp >>= 1;
}

OP(macadd)
{
    int acc = PARAM1;
    env->macc[acc] += env->mactmp;
    FORCE_RET();
}

OP(macsub)
{
    int acc = PARAM1;
    env->macc[acc] -= env->mactmp;
    FORCE_RET();
}

OP(macsats)
{
    int acc = PARAM1;
    int64_t sum;
    int64_t result;

    sum = env->macc[acc];
    result = (sum << 16) >> 16;
    if (result != sum) {
        env->macsr |= MACSR_V;
    }
    if (env->macsr & MACSR_V) {
        env->macsr |= MACSR_PAV0 << acc;
        if (env->macsr & MACSR_OMC) {
            /* The result is saturated to 32 bits, despite overflow occuring
               at 48 bits.  Seems weird, but that's what the hardware docs
               say.  */
            result = (result >> 63) ^ 0x7fffffff;
        }
    }
    env->macc[acc] = result;
    FORCE_RET();
}

OP(macsatu)
{
    int acc = PARAM1;
    uint64_t sum;

    sum = env->macc[acc];
    if (sum & (0xffffull << 48)) {
        env->macsr |= MACSR_V;
    }
    if (env->macsr & MACSR_V) {
        env->macsr |= MACSR_PAV0 << acc;
        if (env->macsr & MACSR_OMC) {
            if (sum > (1ull << 53))
                sum = 0;
            else
                sum = (1ull << 48) - 1;
        } else {
            sum &= ((1ull << 48) - 1);
        }
    }
    FORCE_RET();
}

OP(macsatf)
{
    int acc = PARAM1;
    int64_t sum;
    int64_t result;

    sum = env->macc[acc];
    result = (sum << 16) >> 16;
    if (result != sum) {
        env->macsr |= MACSR_V;
    }
    if (env->macsr & MACSR_V) {
        env->macsr |= MACSR_PAV0 << acc;
        if (env->macsr & MACSR_OMC) {
            result = (result >> 63) ^ 0x7fffffffffffll;
        }
    }
    env->macc[acc] = result;
    FORCE_RET();
}

OP(mac_clear_flags)
{
    env->macsr &= ~(MACSR_V | MACSR_Z | MACSR_N | MACSR_EV);
}

OP(mac_set_flags)
{
    int acc = PARAM1;
    uint64_t val;
    val = env->macc[acc];
    if (val == 0)
        env->macsr |= MACSR_Z;
    else if (val & (1ull << 47));
        env->macsr |= MACSR_N;
    if (env->macsr & (MACSR_PAV0 << acc)) {
        env->macsr |= MACSR_V;
    }
    if (env->macsr & MACSR_FI) {
        val = ((int64_t)val) >> 40;
        if (val != 0 && val != -1)
            env->macsr |= MACSR_EV;
    } else if (env->macsr & MACSR_SU) {
        val = ((int64_t)val) >> 32;
        if (val != 0 && val != -1)
            env->macsr |= MACSR_EV;
    } else {
        if ((val >> 32) != 0)
            env->macsr |= MACSR_EV;
    }
    FORCE_RET();
}

OP(get_macf)
{
    int acc = PARAM2;
    int64_t val;
    int rem;
    uint32_t result;

    val = env->macc[acc];
    if (env->macsr & MACSR_SU) {
        /* 16-bit rounding.  */
        rem = val & 0xffffff;
        val = (val >> 24) & 0xffffu;
        if (rem > 0x800000)
            val++;
        else if (rem == 0x800000)
            val += (val & 1);
    } else if (env->macsr & MACSR_RT) {
        /* 32-bit rounding.  */
        rem = val & 0xff;
        val >>= 8;
        if (rem > 0x80)
            val++;
        else if (rem == 0x80)
            val += (val & 1);
    } else {
        /* No rounding.  */
        val >>= 8;
    }
    if (env->macsr & MACSR_OMC) {
        /* Saturate.  */
        if (env->macsr & MACSR_SU) {
            if (val != (uint16_t) val) {
                result = ((val >> 63) ^ 0x7fff) & 0xffff;
            } else {
                result = val & 0xffff;
            }
        } else {
            if (val != (uint32_t)val) {
                result = ((uint32_t)(val >> 63) & 0x7fffffff);
            } else {
                result = (uint32_t)val;
            }
        }
    } else {
        /* No saturation.  */
        if (env->macsr & MACSR_SU) {
            result = val & 0xffff;
        } else {
            result = (uint32_t)val;
        }
    }
    set_op(PARAM1, result);
    FORCE_RET();
}

OP(get_maci)
{
    int acc = PARAM2;
    set_op(PARAM1, (uint32_t)env->macc[acc]);
    FORCE_RET();
}

OP(get_macs)
{
    int acc = PARAM2;
    int64_t val = env->macc[acc];
    uint32_t result;
    if (val == (int32_t)val) {
        result = (int32_t)val;
    } else {
        result = (val >> 61) ^ 0x7fffffff;
    }
    set_op(PARAM1, result);
    FORCE_RET();
}

OP(get_macu)
{
    int acc = PARAM2;
    uint64_t val = env->macc[acc];
    uint32_t result;
    if ((val >> 32) == 0) {
        result = (uint32_t)val;
    } else {
        result = 0xffffffffu;
    }
    set_op(PARAM1, result);
    FORCE_RET();
}

OP(clear_mac)
{
    int acc = PARAM1;

    env->macc[acc] = 0;
    env->macsr &= ~(MACSR_PAV0 << acc);
    FORCE_RET();
}

OP(move_mac)
{
    int dest = PARAM1;
    int src = PARAM2;
    uint32_t mask;
    env->macc[dest] = env->macc[src];
    mask = MACSR_PAV0 << dest;
    if (env->macsr & (MACSR_PAV0 << src))
        env->macsr |= mask;
    else
        env->macsr &= ~mask;
    FORCE_RET();
}

OP(get_mac_extf)
{
    uint32_t val;
    int acc = PARAM2;
    val = env->macc[acc] & 0x00ff;
    val = (env->macc[acc] >> 32) & 0xff00;
    val |= (env->macc[acc + 1] << 16) & 0x00ff0000;
    val |= (env->macc[acc + 1] >> 16) & 0xff000000;
    set_op(PARAM1, val);
    FORCE_RET();
}

OP(get_mac_exti)
{
    uint32_t val;
    int acc = PARAM2;
    val = (env->macc[acc] >> 32) & 0xffff;
    val |= (env->macc[acc + 1] >> 16) & 0xffff0000;
    set_op(PARAM1, val);
    FORCE_RET();
}

OP(set_macf)
{
    int acc = PARAM2;
    int32_t val = get_op(PARAM1);
    env->macc[acc] = ((int64_t)val) << 8;
    env->macsr &= ~(MACSR_PAV0 << acc);
    FORCE_RET();
}

OP(set_macs)
{
    int acc = PARAM2;
    int32_t val = get_op(PARAM1);
    env->macc[acc] = val;
    env->macsr &= ~(MACSR_PAV0 << acc);
    FORCE_RET();
}

OP(set_macu)
{
    int acc = PARAM2;
    uint32_t val = get_op(PARAM1);
    env->macc[acc] = val;
    env->macsr &= ~(MACSR_PAV0 << acc);
    FORCE_RET();
}

OP(set_mac_extf)
{
    int acc = PARAM2;
    int32_t val = get_op(PARAM1);
    int64_t res;
    int32_t tmp;
    res = env->macc[acc] & 0xffffffff00ull;
    tmp = (int16_t)(val & 0xff00);
    res |= ((int64_t)tmp) << 32;
    res |= val & 0xff;
    env->macc[acc] = res;
    res = env->macc[acc + 1] & 0xffffffff00ull;
    tmp = (val & 0xff000000);
    res |= ((int64_t)tmp) << 16;
    res |= (val >> 16) & 0xff;
    env->macc[acc + 1] = res;
}

OP(set_mac_exts)
{
    int acc = PARAM2;
    int32_t val = get_op(PARAM1);
    int64_t res;
    int32_t tmp;
    res = (uint32_t)env->macc[acc];
    tmp = (int16_t)val;
    res |= ((int64_t)tmp) << 32;
    env->macc[acc] = res;
    res = (uint32_t)env->macc[acc + 1];
    tmp = val & 0xffff0000;
    res |= (int64_t)tmp << 16;
    env->macc[acc + 1] = res;
}

OP(set_mac_extu)
{
    int acc = PARAM2;
    int32_t val = get_op(PARAM1);
    uint64_t res;
    res = (uint32_t)env->macc[acc];
    res |= ((uint64_t)(val & 0xffff)) << 32;
    env->macc[acc] = res;
    res = (uint32_t)env->macc[acc + 1];
    res |= (uint64_t)(val & 0xffff0000) << 16;
    env->macc[acc + 1] = res;
}

OP(set_macsr)
{
    m68k_set_macsr(env, get_op(PARAM1));
}
