Author Topic: Looking for a fast 3 bytes left rotation(axe friendly)  (Read 2424 times)

0 Members and 1 Guest are viewing this topic.

Offline Soulthym

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 17
  • Rating: +1/-0
    • View Profile
Looking for a fast 3 bytes left rotation(axe friendly)
« on: July 19, 2013, 09:16:04 am »
Hi! everyone,I was wondering how to make a really fast 3 bytes rotation routine(or not) that is axe friendly, so I came out with this:
Code: [Select]
ld a,(hl)
inc hl
ld b,(hl)
inc hl
ld c,(hl)
ld d,a
rl d
rl c
rl b
rl a
ld (hl),c
dec hl
ld (hl),b
dec hl
ld (hl),a
The hex code is like that
Code: [Select]
7E
23
46
23
4E
57
CB12
CB11
CB10
CB17
71
2B
70
2B
77
Please don't forget it must be axe friendly, so we use it like that:
Code: [Select]
.pointer
Pic1
Asm(7E2346234E57CB12CB11CB10CB17712B702B77)

Sorry if my English is bad, I'm French
« Last Edit: July 19, 2013, 09:19:32 am by Soulthym »

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Looking for a fast 3 bytes left rotation(axe friendly)
« Reply #1 on: July 19, 2013, 01:01:15 pm »
To rotate 3 bytes pointed to by hl one bit to the left, I think this is the fastest way it can be done:

13 bytes, 79 cycles
Axe: Asm(7E872323CB162BCB162BCE0077)
Source:
Code: [Select]
ld a,(hl)
add a,a
inc hl
inc hl
rl (hl)
dec hl
rl (hl)
dec hl
adc a,0
ld (hl),a

I assume you may want rotation to the right as well:

12 bytes, 80 cycles
Axe: Asm(7E1F23CB1E23CB1E2B2BCB1E)
Source:
Code: [Select]
ld a,(hl)
rra
inc hl
rr (hl)
inc hl
rr (hl)
dec hl
dec hl
rr (hl)


And for what it's worth, your code was already pretty close to mine in terms of speed; 102 cycles for yours versus 79/80 cycles for mine. :)

If you plan on using these code snippets a lot, it may be a good idea to put them in a subroutine and calling it each time you need it, which would save you 10/9 bytes, at the cost of 27 cycles, for each use.
« Last Edit: July 19, 2013, 01:01:53 pm by Runer112 »

Offline Soulthym

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 17
  • Rating: +1/-0
    • View Profile
Re: Looking for a fast 3 bytes left rotation(axe friendly)
« Reply #2 on: July 19, 2013, 06:46:13 pm »
I'm so glad you answered me so fast and thank you about that! I have another question: where did you find the timings for "add a,a" I can't find it anywhere! So if you have all the timings in a text file, would it be possible to post it?
Thank you very much!

Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: Looking for a fast 3 bytes left rotation(axe friendly)
« Reply #3 on: July 20, 2013, 03:40:02 am »
Here you go. The whole z80 instruction set detailed.