* [PATCH/RFA] h8300 sim: add daa and das insns
@ 2003-04-08 6:24 Michael Snyder
2003-04-12 21:25 ` Kazu Hirata
0 siblings, 1 reply; 3+ messages in thread
From: Michael Snyder @ 2003-04-08 6:24 UTC (permalink / raw)
To: gdb-patches; +Cc: kazu, dvenkat, avolkov
[-- Attachment #1: Type: text/plain, Size: 36 bytes --]
Here's my implementation of daa/das:
[-- Attachment #2: daa.diff --]
[-- Type: text/plain, Size: 3063 bytes --]
2003-04-07 Michael Snyder <msnyder@redhat.com>
* compile.c (sim_resume): Implement daa and das insns.
Index: compile.c
===================================================================
RCS file: /cvs/cvsfiles/devo/sim/h8300/compile.c,v
retrieving revision 1.70
diff -p -r1.70 compile.c
*** compile.c 2003/03/27 22:01:29 1.70
--- compile.c 2003/04/08 06:20:31
*************** sim_resume (SIM_DESC sd, int step, int s
*** 2138,2143 ****
--- 2146,2202 ----
}
goto next;
+ case O (O_DAA, SB):
+ /* Decimal Adjust Addition. This is for BCD arithmetic. */
+ res = GET_B_REG (code->src.reg);
+ if (!c && (0 <= (res >> 4) && (res >> 4) <= 9) &&
+ !h && (0 <= (res & 0xf) && (res & 0xf) <= 9))
+ res = res; /* Value added == 0. */
+ else if (!c && (0 <= (res >> 4) && (res >> 4) <= 8) &&
+ !h && (10 <= (res & 0xf) && (res & 0xf) <= 15))
+ res = res + 0x6; /* Value added == 6. */
+ else if (!c && (0 <= (res >> 4) && (res >> 4) <= 9) &&
+ h && (0 <= (res & 0xf) && (res & 0xf) <= 3))
+ res = res + 0x6; /* Value added == 6. */
+ else if (!c && (10 <= (res >> 4) && (res >> 4) <= 15) &&
+ !h && (0 <= (res & 0xf) && (res & 0xf) <= 9))
+ res = res + 0x60; /* Value added == 60. */
+ else if (!c && (9 <= (res >> 4) && (res >> 4) <= 15) &&
+ !h && (10 <= (res & 0xf) && (res & 0xf) <= 15))
+ res = res + 0x66; /* Value added == 66. */
+ else if (!c && (10 <= (res >> 4) && (res >> 4) <= 15) &&
+ h && (0 <= (res & 0xf) && (res & 0xf) <= 3))
+ res = res + 0x66; /* Value added == 66. */
+ else if ( c && (1 <= (res >> 4) && (res >> 4) <= 2) &&
+ !h && (0 <= (res & 0xf) && (res & 0xf) <= 9))
+ res = res + 0x60; /* Value added == 60. */
+ else if ( c && (1 <= (res >> 4) && (res >> 4) <= 2) &&
+ !h && (10 <= (res & 0xf) && (res & 0xf) <= 15))
+ res = res + 0x66; /* Value added == 66. */
+ else if (c && (1 <= (res >> 4) && (res >> 4) <= 3) &&
+ h && (0 <= (res & 0xf) && (res & 0xf) <= 3))
+ res = res + 0x66; /* Value added == 66. */
+
+ goto alu8;
+
+ case O (O_DAS, SB):
+ /* Decimal Adjust Subtraction. This is for BCD arithmetic. */
+ res = GET_B_REG (code->src.reg); /* FIXME fetch, fetch2... */
+ if (!c && (0 <= (res >> 4) && (res >> 4) <= 9) &&
+ !h && (0 <= (res & 0xf) && (res & 0xf) <= 9))
+ res = res; /* Value added == 0. */
+ else if (!c && (0 <= (res >> 4) && (res >> 4) <= 8) &&
+ h && (6 <= (res & 0xf) && (res & 0xf) <= 15))
+ res = res + 0xfa; /* Value added == 0xfa. */
+ else if ( c && (7 <= (res >> 4) && (res >> 4) <= 15) &&
+ !h && (0 <= (res & 0xf) && (res & 0xf) <= 9))
+ res = res + 0xa0; /* Value added == 0xa0. */
+ else if (c && (6 <= (res >> 4) && (res >> 4) <= 15) &&
+ h && (6 <= (res & 0xf) && (res & 0xf) <= 15))
+ res = res + 0x9a; /* Value added == 0x9a. */
+
+ goto alu8;
+
default:
illegal:
cpu.state = SIM_STATE_STOPPED;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH/RFA] h8300 sim: add daa and das insns
2003-04-08 6:24 [PATCH/RFA] h8300 sim: add daa and das insns Michael Snyder
@ 2003-04-12 21:25 ` Kazu Hirata
2003-04-13 16:57 ` Michael Snyder
0 siblings, 1 reply; 3+ messages in thread
From: Kazu Hirata @ 2003-04-12 21:25 UTC (permalink / raw)
To: msnyder; +Cc: gdb-patches, dvenkat, avolkov
Hi Michael,
> Here's my implementation of daa/das:
+ if (!c && (0 <= (res >> 4) && (res >> 4) <= 9) &&
+ !h && (0 <= (res & 0xf) && (res & 0xf) <= 9))
The GNU coding standard says
if (A
&& B)
so we would have to fix formatting.
+ else if ( c && (1 <= (res >> 4) && (res >> 4) <= 2) &&
+ !h && (0 <= (res & 0xf) && (res & 0xf) <= 9))
+ res = res + 0x60; /* Value added == 60. */
+ else if ( c && (1 <= (res >> 4) && (res >> 4) <= 2) &&
+ !h && (10 <= (res & 0xf) && (res & 0xf) <= 15))
+ res = res + 0x66; /* Value added == 66. */
+ else if (c && (1 <= (res >> 4) && (res >> 4) <= 3) &&
+ h && (0 <= (res & 0xf) && (res & 0xf) <= 3))
+ res = res + 0x66; /* Value added == 66. */
IMHO, for the last three cases of DAA, the carry flag won't be set to
1 because adding 0x66 does not generate a carry. We can put a hack
like "res |= 0x100;" after "res += 0x66;" or replace "res += 0x66;"
with "res += 0x166;" so that "alu8:" can take care of this, but I
don't know how much you like these. :-)
Thanks,
Kazu Hirata
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH/RFA] h8300 sim: add daa and das insns
2003-04-12 21:25 ` Kazu Hirata
@ 2003-04-13 16:57 ` Michael Snyder
0 siblings, 0 replies; 3+ messages in thread
From: Michael Snyder @ 2003-04-13 16:57 UTC (permalink / raw)
To: Kazu Hirata; +Cc: gdb-patches, dvenkat, avolkov
Kazu Hirata wrote:
>
> Hi Michael,
>
> > Here's my implementation of daa/das:
>
> + if (!c && (0 <= (res >> 4) && (res >> 4) <= 9) &&
> + !h && (0 <= (res & 0xf) && (res & 0xf) <= 9))
>
> The GNU coding standard says
>
> if (A
> && B)
Ugh. I hate it, but OK. My way scans so much better...
> so we would have to fix formatting.
>
> + else if ( c && (1 <= (res >> 4) && (res >> 4) <= 2) &&
> + !h && (0 <= (res & 0xf) && (res & 0xf) <= 9))
> + res = res + 0x60; /* Value added == 60. */
> + else if ( c && (1 <= (res >> 4) && (res >> 4) <= 2) &&
> + !h && (10 <= (res & 0xf) && (res & 0xf) <= 15))
> + res = res + 0x66; /* Value added == 66. */
> + else if (c && (1 <= (res >> 4) && (res >> 4) <= 3) &&
> + h && (0 <= (res & 0xf) && (res & 0xf) <= 3))
> + res = res + 0x66; /* Value added == 66. */
>
> IMHO, for the last three cases of DAA, the carry flag won't be set to
> 1 because adding 0x66 does not generate a carry. We can put a hack
> like "res |= 0x100;" after "res += 0x66;" or replace "res += 0x66;"
> with "res += 0x166;" so that "alu8:" can take care of this, but I
> don't know how much you like these. :-)
Right you are. I think your suggestion is both necessary and sufficient.
Sure it's odd, but this is binary coded decimal we're talking about...
I'll check it in with your suggestions. Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-04-13 16:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-08 6:24 [PATCH/RFA] h8300 sim: add daa and das insns Michael Snyder
2003-04-12 21:25 ` Kazu Hirata
2003-04-13 16:57 ` Michael Snyder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox