English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. Asm / Hardware (https://eab.abime.net/forumdisplay.php?f=112)
-   -   68000 code optimisations (https://eab.abime.net/showthread.php?t=57587)

meynaf 04 March 2023 16:13

Quote:

Originally Posted by remz (Post 1600352)
Curiosity: Why were 6 bits allocated to shift&rotate instructions instead of 5?
Is there any practicality to rotate more than 32?

More than 32 isn't really interesting, but 32 itself can be. And you need 6 bits to represent that value.
It needs verification, but i think it is really 5 for rotates and 6 only for shifts.

a/b 04 March 2023 17:10

They're all 6-bit (it was tested on real hw, a500 68000): they all take tbe same number of cycles.

Karlos 04 March 2023 17:13

Being able to shift 6 bits makes sense if you are thinking of some future 64-bit wide register implementation. Although that probably wasn't the actual reason.

meynaf 04 March 2023 17:18

Only logical reason is ability to shift by 32. With 5-bit, range is only 0-31.

mschulz 04 July 2023 07:56

Quote:

Originally Posted by meynaf (Post 1600367)
Only logical reason is ability to shift by 32. With 5-bit, range is only 0-31.

This, and also ROXL/ROXR rotations, where CPU deals with 33-bit number.

meynaf 06 July 2023 07:40

Quote:

Originally Posted by mschulz (Post 1626314)
This, and also ROXL/ROXR rotations, where CPU deals with 33-bit number.

Didn't think about it, but indeed, there maxing out at 31 would have missed something.
Actually, it is of course 9, 17 or 33 bits depending on the size.
One could think it is logical to cut at 6-bit for .l, 5-bit for .w, 4-bit for .b, but it's not what the cpu does - it's always 6 regardless of the operand size.
Note that PowerPC uses 6 bits as well, but not x86 (didn't check though, this is what i've read).

ross 06 July 2023 09:58

Quote:

Originally Posted by meynaf (Post 1626816)
.., but not x86 (didn't check though, this is what i've read).

From this page: https://c9x.me/x86/html/file_module_x86_id_273.html
it seems that starting from Intel 286 processor, the rotation is masked to 5 bits. and the masking is done in all operating modes, including the virtual-8086 mode (see note at the bottom of the page).
EDIT: of course the same for shift instructions (https://c9x.me/x86/html/file_module_x86_id_285.html)
I've written code for x86 several times, in a distant past, but never bothered about it and probably never considered it. Nice sh*t...

But we are off-topic :)

Don_Adan 17 September 2023 11:07

Based on this 6502 routine:

Code:

;Divide by 24 for 6502 CPU
;15 bytes, 27 cycles
 lsr
 lsr
 lsr
 sta temp
 lsr
 lsr
 adc temp
 ror
 lsr
 adc temp
 ror
 lsr

I wrote 68000 version, maybe useful for something.

Code:

; divide by 24, no rest, no overflow
 lsr.l #3,D0
 move.l D0,D1
 lsr.l #2,D0
 addx.l D1,D0
 lsr.l #2,D0
 addx.l D1,D0
 lsr.l #2,D0

Here is divide by 3:

Code:

; divide by 3, no rest, no overflow
 move.l D0,D1
 lsr.l #2,D0
 addx.l D1,D0
 lsr.l #2,D0
 addx.l D1,D0
 lsr.l #2,D0

Modified versions can handle divide by 3, 6, 12, 24, 48, 96 etc.
Not tested, but seems to be OK.

Don_Adan 17 September 2023 13:20

Here is divide by 3 with rest:

Code:

; divide by 3 with rest, no overflow
 move.l D0,D1
 lsr.l  #2,D0
 addx.l D1,D0
 lsr.l  #2,D0
 addx.l D1,D0
 lsr.l #2,D0 ; score
 sub.l D0,D1
 sub.l D0,D1
 sub.l D0,D1 ; rest



All times are GMT +2. The time now is 00:55.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.09753 seconds with 11 queries