English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 22 January 2020, 18:19   #1
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 243
Is this a bug in EASy68K?

When writing a function I stumbled on this, and did a small test to confirm:


Code:
    move.l  #$abababab,d1
    movem.w d1,-(sp)
    movem.w (sp)+,d1            ; d1 now contains $ffffabab

I haven't tested it yet on WinUAE or real machine, as I don't have access at the moment, and now I wonder if this is a bug in EASy68k or not? I thought it would be legal to save only a word operand on the stack?
According to the M6800PRM.pdf this would be legal, so I assume a bug.
sparhawk is offline  
Old 22 January 2020, 18:32   #2
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 174
(Second, mem to reg) movem.w automatically sign-extends registers to longwords.
a/b is offline  
Old 22 January 2020, 18:51   #3
DanScott
Lemon. / Core Design

DanScott's Avatar
 
Join Date: Mar 2016
Location: Sunny Bournemouth, UK
Posts: 538
Yes, word reads from stack to register are sign extended to a long
DanScott is offline  
Old 22 January 2020, 19:11   #4
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 47
Posts: 3,664
movem.w from memory to registers always sign extend (this can actually be useful).
If you want to restore only a word operand, use move instead of movem.
meynaf is offline  
Old 22 January 2020, 23:41   #5
Cyprian
Registered User

 
Join Date: Jul 2014
Location: Warsaw/Poland
Posts: 46
interesting finding.

never heard before about data register sign extension.
Cyprian is offline  
Old 23 January 2020, 10:30   #6
Kalms
Registered User
 
Join Date: Nov 2006
Location: Stockholm, Sweden
Posts: 224
For your reference, the M68000PRM states on page 4-128 in the MOVEM description:

Quote:
Moves the contents of selected registers to or from consecutive memory locations starting at the location specified by the effective address. A register is selected if the bit in the mask field corresponding to that register is set. The instruction size determines whether 16 or 32 bits of each register are transferred. In the case of a word transfer to either address or data registers, each word is sign-extended to 32 bits, and the resulting long word is loaded into the associated register.
Kalms is offline  
Old 23 January 2020, 10:46   #7
Antiriad_UK
OCS forever!

Antiriad_UK's Avatar
 
Join Date: Mar 2019
Location: Birmingham, UK
Posts: 170
This was one of the tricks that I was really pleased to learn when relearning last year. I went through a load of routines stripping out ext.l used after a movem
Antiriad_UK is offline  
Old 23 January 2020, 13:49   #8
DanScott
Lemon. / Core Design

DanScott's Avatar
 
Join Date: Mar 2016
Location: Sunny Bournemouth, UK
Posts: 538
Don't think I ever actually used an ext.l after a movem ever... but it's a handy trick to know for any future implementations
DanScott is offline  
Old 23 January 2020, 14:52   #9
ross
Per aspera ad astra

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 49
Posts: 2,425
I organize everytime my data for movem access (both .w or .l).
And sign extension on data registers is usually usefull.

There a case I've also used movem to a single dx register, just to have not CPU flags set
(yes, a little slow, but with only worst alternatives available..)

[movem exist also for no register at all encoding, like
movem.l -(sp)
->
$48e7,$0
]
ross is offline  
Old 23 January 2020, 18:23   #10
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 243
Quote:
Originally Posted by ross View Post
[movem exist also for no register at all encoding, like
movem.l -(sp)
->
$48e7,$0
]

And what does this do? Only decrement stack?
sparhawk is offline  
Old 23 January 2020, 18:53   #11
ross
Per aspera ad astra

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 49
Posts: 2,425
Quote:
Originally Posted by sparhawk View Post
And what does this do? Only decrement stack?
Absolutely nothing (apart the 8 cycles for the two memory accesses on 68k, flags, stack and sp value sre untouched).
The only use that comes to mind is for some ugly SMC code, that varies registries selection based on value set on 2nd opcode instruction.

Well, forget about it
ross is offline  
Old 24 January 2020, 15:43   #12
ross
Per aspera ad astra

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 49
Posts: 2,425
Speaking of Easy68k I found two flaws, if someone is registered on their forum it could report the problem.

1.
(and this is big..)
Code:
  movea.l #$00800001,a5
  lea (a5,a5.l),a5
it completely fail to calculate final value for A5 because only 24 bits is maintained in result.
So at the end A5=$2..

2.
Code:
    btst    #0,d0
wrongly reported as 6 cycles instead of 10 (like other bit instructions).


Anyway I've a doubt about bit instructions and my manual is not clear about it..
Code:
instruction  size            dynamic                 static
                        register   memory       register   memory	
BCHG         byte          -       8(1/1) +        -       12(2/1) +
             long        8(1/0) *    -          12(2/0) *     -
BCLR         byte          -       8(1/1) +        -       12(2/1) +
             long       10(1/0) *    -          14(2/0) *     -
BSET         byte          -       8(1/1) +        -       12(2/1) +
             long        8(1/0) *    -          12(2/0) *     -
BTST         byte          -  	   4(1/0) +        -        8(2/0) +
             long        6(1/0)      -          10(2/0)       -

	+ add effective address calculation time
	* indicates maximum value
Is indicated in * which is a maximum value.
But I've not found where is it specified what affects this maximum value.
ross is offline  
Old 24 January 2020, 18:59   #13
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 44
Posts: 23,573
Quote:
what affects this maximum value
Bits number larger than 15: instruction becomes 2 cycles slower.
Toni Wilen is offline  
Old 24 January 2020, 19:32   #14
ross
Per aspera ad astra

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 49
Posts: 2,425
Quote:
Originally Posted by Toni Wilen View Post
Bits number larger than 15: instruction becomes 2 cycles slower.
Thanks Toni, another thing to keep in mind when optimizing 68k code.



EDIT
Another important thing to remember: if possible use logical operations directly, that are faster.
As it is very probable that bxxx instructions are microcoded, internally are fluxed to the basic operations in ALU.

This also explains why bclr is slower:
bchg -> set, eor
bset -> set, or
bclr -> set, not, and

Last edited by ross; 24 January 2020 at 20:34.
ross is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bug I think... NLS support.WinUAE 8 24 July 2017 23:09
Bug in x64 file requester and bug in Blizzard PPC ROM filesize headkase support.WinUAE 5 26 June 2016 15:17
A little PM bug Dizzy project.EAB 19 19 December 2006 21:00
Got a bug Error support.WinUAE 2 17 March 2004 14:36

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 13:21.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.08625 seconds with 13 queries