[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v4 2/2] target-m68k: add 680x0 divu/divs variant
From: |
Laurent Vivier |
Subject: |
Re: [Qemu-devel] [PATCH v4 2/2] target-m68k: add 680x0 divu/divs variants |
Date: |
Sun, 27 Nov 2016 20:41:14 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 |
Le 01/11/2016 à 21:03, Laurent Vivier a écrit :
> diff --git a/target-m68k/op_helper.c b/target-m68k/op_helper.c
> index 48e02e4..a4bfa4e 100644
> +void HELPER(divull)(CPUM68KState *env, int numr, int regr, uint32_t den)
> +{
> + uint64_t num = deposit64(env->dregs[numr], 32, 32, env->dregs[regr]);
> + uint64_t quot;
> + uint32_t rem;
> +
> + if (den == 0) {
> + raise_exception_ra(env, EXCP_DIV0, GETPC());
> + }
> + quot = num / den;
> + rem = num % den;
> +
> + env->cc_c = 0; /* always cleared, even if overflow */
> + if (quot > 0xffffffffULL) {
> + env->cc_v = -1;
> + /* nothing else is modified */
> + /* real 68040 keeps Z and N on overflow,
> + * whereas documentation says "undefined"
> + */
> + return;
> + }
...
> +
> +void HELPER(divsll)(CPUM68KState *env, int numr, int regr, int32_t den)
> +{
> + int64_t num = deposit64(env->dregs[numr], 32, 32, env->dregs[regr]);
> + int64_t quot;
> int32_t rem;
>
> - num = env->div1;
> - den = env->div2;
> if (den == 0) {
> - raise_exception(env, EXCP_DIV0);
> + raise_exception_ra(env, EXCP_DIV0, GETPC());
> }
> quot = num / den;
> rem = num % den;
>
> - env->cc_v = (word && quot != (int16_t)quot ? -1 : 0);
> + env->cc_c = 0; /* always cleared, even if overflow */
> + if (quot != (int32_t)quot) {
> + env->cc_v = -1;
> + /* nothing else is modified */
> + /* real 68040 keeps Z and N on overflow,
> + * whereas documentation says "undefined"
> + */
> + return;
> + }
On a real 68040, for divsll and divull, Z is unset.
(while divsw/divuw don't modify it as we do).
So I will update the patch with this behavior.
Laurent