English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General > Coders. Tutorials

 
 
Thread Tools
Old 06 December 2018, 20:41   #81
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by litwr View Post
IMHO AmigaOS gives too many ways to do the same things.
You haven't coded on Windows to say that !
meynaf is online now  
Old 06 December 2018, 21:50   #82
litwr
Registered User
 
Join Date: Mar 2016
Location: Ozherele
Posts: 229
Quote:
Originally Posted by alkis View Post
Excuse me maybe a bit ignorant question but does Amiga 500 have a dos.library V36 or above?

Quote:
Originally Posted by meynaf View Post
You haven't coded on Windows to say that !
Maybe. I have just done some coding in the plain Xlib, Fltk, OpenGL. IMHO AmigaOS gives more i/o-paradigms than the mention libraries. I really begin to like AmigaOS and it is sad that I can afford to study it more carefully now.

I have failed to find a way to use console and graphic output in the same window. However using SetDrMd, SetAPen ... allows to customize RasterPort output.

BTW. I'm a bit disappointed that 68000 doesn't have a command to swap bytes in a word. Even ancient PDP-11 has a SWAB instruction for this. 8088 gives you a go like XCHG BL,BH for 4 cycles. For 68000 I have to use ROL #8,D0 for 20 cycles.

EDIT. I have also discovered that shifts and rotates can be applied only to words in memory, this makes a code for such operations for bytes too big and slow. So IMHO for byte operations 8086 maybe has performance close to 68000.
litwr is offline  
Old 06 December 2018, 22:20   #83
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by litwr View Post
Excuse me maybe a bit ignorant question but does Amiga 500 have a dos.library V36 or above?
Yes. V36 means OS2.0. You will find Amiga 500s with any type of ROM, from 1.2 to 3.1. 1.3 is probably the most frequent.

Quote:
EDIT. I have also discovered that shifts and rotates can be applied only to words in memory
Certainly not true. Or I misunderstood you. There is "rol #x,Dn", "lsr #x,Dn", etc...
phx is offline  
Old 06 December 2018, 22:52   #84
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by litwr View Post
BTW. I'm a bit disappointed that 68000 doesn't have a command to swap bytes in a word. Even ancient PDP-11 has a SWAB instruction for this. 8088 gives you a go like XCHG BL,BH for 4 cycles. For 68000 I have to use ROL #8,D0 for 20 cycles.
There are faster ways to do that (for 68000).
meynaf is online now  
Old 06 December 2018, 22:52   #85
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by litwr View Post
EDIT. I have also discovered that shifts and rotates can be applied only to words in memory, this makes a code for such operations for bytes too big and slow. So IMHO for byte operations 8086 maybe has performance close to 68000.
Shift and rotate it's not meant to be used extensively with memory directly.
So an instruction like lsr <ea> can shift one bit only and the operand size is restricted to word (so you can think of it as lsr.w #1,<ea>).
But can be very useful: consider a sequence of roxl -(a0) or roxr (a0)+ and the result on a video bitplane

If you want a multi shift/rotate byte operation you can load to some data register, operate, then write to memory, not a big problem

Last edited by ross; 06 December 2018 at 23:03.
ross is offline  
Old 07 December 2018, 10:14   #86
chb
Registered User
 
Join Date: Dec 2014
Location: germany
Posts: 439
Quote:
Originally Posted by litwr View Post
BTW. I'm a bit disappointed that 68000 doesn't have a command to swap bytes in a word. Even ancient PDP-11 has a SWAB instruction for this. 8088 gives you a go like XCHG BL,BH for 4 cycles. For 68000 I have to use ROL #8,D0 for 20 cycles.
ROL #8,D0 is 22 cycles (6 + 2n).
There's a lot of routines for byte swapping that are faster than ROL, if you want to work directly in memory:
http://atari-forum.com/viewtopic.php?f=68&t=11779
Fastest is AFAICS 24 clock cycles to read from mem, byte-swap and write back a word using movep (actually 96 cycles for four words):
Code:
movep.l	0(a0),d0	
movep.l	1(a0),d1	
movep.l	d0,1(a1)
movep.l	d1,0(a1)
But yes, a byte-swap instruction would be handy sometimes.
chb is offline  
Old 07 December 2018, 10:18   #87
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
On 68020+ there is a barrel shifter so ROL/ROR timing is no longer a problem. Having added an extra instruction for byte swapping in words would have led to duplicates.
meynaf is online now  
Old 07 December 2018, 10:29   #88
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by chb View Post
ROL #8,D0 is 22 cycles (6 + 2n).
Or if you care only about extract high bits you can do:

Code:
	move.w	d0,-(sp)
	move.b	(sp)+,d0 *
16 cycles.

[* based on 68k stack auto-align property ]
ross is offline  
Old 07 December 2018, 10:42   #89
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
Quote:
Originally Posted by litwr View Post
It is easy to open a console window just opening a file named "CON:" by Open call. Is it possible to adjust this console window? I would like to remove borders and a title.
IMHO AmigaOS gives too many ways to do the same things.
You can change title, position, size, and a few other things by adding them to the "filename" you use to open the console (e.g. "con:0/0/640/100/window title/wait/close").


If you want more esoteric window attributes, you will need to create the window yourself (you already did that), and then, using console.device, create and attach a console to your window. That way you can use char control sequences, etc.
hooverphonique is offline  
Old 07 December 2018, 10:48   #90
chb
Registered User
 
Join Date: Dec 2014
Location: germany
Posts: 439
Quote:
Originally Posted by meynaf View Post
On 68020+ there is a barrel shifter so ROL/ROR timing is no longer a problem. Having added an extra instruction for byte swapping in words would have led to duplicates.
Hmm, according to the 68020 manual ROR/ROL is 5/8/8 cycles (best case/cache case/worst case), a SWAP is 1/4/4, so still quite a bit faster. The rotate operations seem to be considerably slower than the pure shifts.

But there's a slightly mysterious sentence in the Programmer's Reference Manual:
Quote:
Fast byte swapping is possible by using the ROR and ROL instructions with a shift count of eight, enhancing the performance of the shift/rotate instructions.
Is there a special case for n = 8 which needs less cycles?
chb is offline  
Old 07 December 2018, 17:34   #91
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by ross View Post
Or if you care only about extract high bits you can do:

Code:
    move.w    d0,-(sp)
    move.b    (sp)+,d0 *
16 cycles.

[* based on 68k stack auto-align property ]

That's still one of my favorite 68k tricks.
StingRay is offline  
Old 07 December 2018, 21:10   #92
litwr
Registered User
 
Join Date: Mar 2016
Location: Ozherele
Posts: 229
Quote:
Originally Posted by ross View Post
Or if you care only about extract high bits you can do:
Code:
	move.w	d0,-(sp)
	move.b	(sp)+,d0 *
16 cycles.
[* based on 68k stack auto-align property ]
I like such tricks! Can it work with 68020? BTW I have a routine to print the next text, for example,
Code:
         bsr printstr
         dc.b "Hello World!",0
         even

printstr:
         movea.l (sp)+,a2
         lea stringbuf(a3),a4   ;A3 is a base for data section
         moveq #0,d0
.l1:     addq.w #1,d0
         move.b (a2)+,d1
         move.b d1,(a4)+
         bne .l1
         
         move.l a2,d1
         addq.l #1,d1    ;is it necessary?
         andi.b #$fe,d1
         move.l d1,-(sp)

         ;movea.l GRAPHICS_BASE(a3),a6
         ;movea.l RASTER_PORT(a3),a1
         lea stringbuf(a3),a0
         subq.w #1,d0
         jmp Text(a6)
So I have to remove a possible digit 1 at A2. Maybe is there yet another trick which help to improve address register inability to be ANDed?

Quote:
Originally Posted by chb View Post
Is there a special case for n = 8 which needs less cycles?
I am sure this is a mistake in the book.
litwr is offline  
Old 07 December 2018, 22:36   #93
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by litwr View Post
I like such tricks! Can it work with 68020?
Yes.

Quote:
BTW I have a routine to print the next text, for example,
Code:
         bsr printstr
         dc.b "Hello World!",0
         even

printstr:
         movea.l (sp)+,a2
         lea stringbuf(a3),a4   ;A3 is a base for data section
         moveq #0,d0
.l1:     addq.w #1,d0
         move.b (a2)+,d1
         move.b d1,(a4)+
         bne .l1
         
         move.l a2,d1
         addq.l #1,d1    ;is it necessary?
         andi.b #$fe,d1
         move.l d1,-(sp)

         ;movea.l GRAPHICS_BASE(a3),a6
         ;movea.l RASTER_PORT(a3),a1
         lea stringbuf(a3),a0
         subq.w #1,d0
         jmp Text(a6)
I'm sorry but your code style is so wrong for so much reasons (at least for the 68k architecture). Why mixing code/data and mess with stack and alignment?
Even understanding what you want to do in such a simple routine is complicated by how you write it!

You can use a simple straightforward call:
Code:
        move.w  #(endstr-string-1),d0
        lea     string(pc),a0
;       movea.l RASTER_PORT(a3),a1
;       movea.l GRAPHICS_BASE(a3),a6
        jsr     _LVOText(a6)
;       code continue..

string  dc.b 'Hello World!',0
endstr   
        even
If you insist in complicating your life then this can be a "wrong way" better version:
Code:
        bsr     printstr
        dc.b 'Hello World!',0
        even
;       code continue..

printstr:
        moveq   #-1,d0 
        movea.l (sp),a0
.l      addq.l  #1,d0
        tst.b   (a0,d0.l)
        bne.b   .l
        move.l  d0,d1
        addq.l  #2,d1
        lsr.l   #1,d1
        add.l   d1,d1
        add.l   d1,(sp)

;       movea.l GRAPHICS_BASE(a3),a6
;       movea.l RASTER_PORT(a3),a1
        jmp Text(a6)
ross is offline  
Old 07 December 2018, 23:43   #94
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
I like doing strlen() with dbeq. It also takes advantage of the 68010 DBcc-cache.
Code:
        moveq   #-1,d0
.1:     tst.b   (a0)+
        dbeq    d0,.1
        not.l   d0
EDIT: Oh, just noticed a0 should not be modified. Nevermind.

Last edited by phx; 07 December 2018 at 23:45. Reason: a0
phx is offline  
Old 08 December 2018, 00:02   #95
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by phx View Post
I like doing strlen() with dbeq. It also takes advantage of the 68010 DBcc-cache.
Code:
        moveq   #-1,d0
.1:     tst.b   (a0)+
        dbeq    d0,.1
        not.l   d0
EDIT: Oh, just noticed a0 should not be modified. Nevermind.
Yes, my first thought was for dbeq then i realized i had to keep a0
ross is offline  
Old 08 December 2018, 00:37   #96
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
Code:
    moveq   #-1, d0
.1  tst.b   (a0)+
    dbeq    d0, .1
    add.l   d0, a0
    not.l   d0
But isn't Bcc faster than DBcc?
Code:
    move.l  a0, d0
.1  tst.b   (a0)+
    bne     .1
    sub.l   d0, a0
    exg     a0, d0
    subq.l  #1, d0

Last edited by Leffmann; 08 December 2018 at 00:42.
Leffmann is offline  
Old 08 December 2018, 01:18   #97
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by Leffmann View Post
But isn't Bcc faster than DBcc?
Indeed. You're right.

So the only advantages by using DBcc are:
- it is still faster on the 68010 (DBcc-loop cache)
- it is shorter
phx is offline  
Old 08 December 2018, 10:13   #98
Asman
68k
 
Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 828
@Leffmann, phx
If my calculations are right than bcc version is 2 cycles slower (on 68000 of course)
Lets see
Code:
	moveq   #-1, d0	;4c
.1	tst.b   (a0)+	;8c*x
	dbeq    d0, .1	;10c*(x-1) + 12c
	add.l   d0, a0	;8c
	not.l   d0	;4c
;total 4c+ 8c*x + 10c*(x-1) + 12c + 8c + 4c = 28c + 18c * x 0 - 10c =
; = 18c + 18c*x
Code:
	move.l  a0, d0	;4c
.1	tst.b   (a0)+	;8c*x
	bne     .1	;10c*(x-1) + 8c
	sub.l   d0, a0	;8c
	exg     a0, d0	;6c
	subq.l  #1, d0	;4c
;toal 4c + 8c*x + 10c*x - 10c + 8c + 8c + 6c + 4c =
; = 20c + 18c*x
The fastest which I know is to use ax register like this
Code:
	move.l	a0,a1	;4c
	moveq	#-1,d0	;4c
.loop	tst.b	(a1)+	;8c*x
	dbeq.b	.loop	;10c*(x-1) + 12c
	not.l	d0	;4c
;total 8c + 18c*x - 10c +12c + 4c =
; = 16c + 18c*x
Asman is offline  
Old 08 December 2018, 10:25   #99
litwr
Registered User
 
Join Date: Mar 2016
Location: Ozherele
Posts: 229
Quote:
Originally Posted by ross View Post
You can use a simple straightforward call:
This approach has a disadvantage - you have to give a name for a string which is used only once. Possibly we need a macro which will be generate unique names.

Quote:
Originally Posted by ross View Post
If you insist in complicating your life then this can be a "wrong way" better version:
Thank you. Your code is much better than mine. Why did I those increment and decrement?!

Last edited by litwr; 08 December 2018 at 12:01.
litwr is offline  
Old 08 December 2018, 11:09   #100
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by litwr View Post
This approach has a disadvantage - you have to give a name for a string which is used only once. Possibly we need a macro which will be generate unique names.

You can use local labels. Though, the approach to use the stack to obtain the (string) addresses can indeed be quite useful.
StingRay 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
Misc Amiga Assembler Source Code copse Coders. General 14 20 October 2019 02:05
The 6502 assembler code in "The Terminator" (1984) Shoonay Nostalgia & memories 2 15 May 2009 13:52
Assembler System Friendly code redblade Coders. General 3 29 July 2008 12:15
Amiga Cross Assembler to code intros! - Help! W4r3DeV1L Amiga scene 6 30 May 2008 16:53
3D code and/or internet code for Blitz Basic 2.1 EdzUp Retrogaming General Discussion 0 10 February 2002 11:40

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 11:41.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.10428 seconds with 16 queries