English Amiga Board


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

 
 
Thread Tools
Old 06 December 2018, 21:41   #81
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 46
Posts: 3,603
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 offline  
Old 06 December 2018, 22:50   #82
litwr
Registered User

 
Join Date: Mar 2016
Location: Ozherele
Posts: 164
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, 23:20   #83
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,479
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, 23:52   #84
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 46
Posts: 3,603
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 offline  
Old 06 December 2018, 23:52   #85
ross
Per aspera ad astra

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 49
Posts: 2,170
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; 07 December 2018 at 00:03.
ross is offline  
Old 07 December 2018, 11:14   #86
chb
Registered User

 
Join Date: Dec 2014
Location: germany
Posts: 196
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, 11:18   #87
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 46
Posts: 3,603
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 offline  
Old 07 December 2018, 11:29   #88
ross
Per aspera ad astra

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 49
Posts: 2,170
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, 11:42   #89
hooverphonique
ex. demoscener "Bigmama"

 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 988
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, 11:48   #90
chb
Registered User

 
Join Date: Dec 2014
Location: germany
Posts: 196
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, 18:34   #91
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,239
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, 22:10   #92
litwr
Registered User

 
Join Date: Mar 2016
Location: Ozherele
Posts: 164
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, 23:36   #93
ross
Per aspera ad astra

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 49
Posts: 2,170
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 08 December 2018, 00:43   #94
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,479
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; 08 December 2018 at 00:45. Reason: a0
phx is offline  
Old 08 December 2018, 01:02   #95
ross
Per aspera ad astra

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 49
Posts: 2,170
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, 01:37   #96
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,265
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 01:42.
Leffmann is offline  
Old 08 December 2018, 02:18   #97
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,479
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, 11:13   #98
Asman
68k

Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 695
@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, 11:25   #99
litwr
Registered User

 
Join Date: Mar 2016
Location: Ozherele
Posts: 164
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 13:01.
litwr is offline  
Old 08 December 2018, 12:09   #100
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,239
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 03:05
The 6502 assembler code in "The Terminator" (1984) Shoonay Nostalgia & memories 2 15 May 2009 14:52
Assembler System Friendly code redblade Coders. General 3 29 July 2008 13:15
Amiga Cross Assembler to code intros! - Help! D4Ni3L3 Amiga scene 6 30 May 2008 17:53
3D code and/or internet code for Blitz Basic 2.1 EdzUp Retrogaming General Discussion 0 10 February 2002 12: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 15:49.


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