I found some amazing Z80 code, and I want to use it, but I haven't been able to contact the author. They put it up on their website (http://www.retroprogramming.com/2017/07/a-fast-z80-integer-square-root.html), and I don't see any licensing or anything, so is it appropriate to use it so long as I give full credit? They don't even have an email up Sad
It's far better than even my most optimized one.

Also, I see that they have some other really cool code that I want to try out :O
Yes you can use it Smile
From a strict legal perspective it defaults to "all rights reserved" and copying that (with no statement on licensing by the author) is copyright infringement. From a practical perspective, the author putting it out there like that seems to suggest they are happy to let others use it; if they weren't they might have only provided a binary or no actual code at all.

It is of course still nice to include a pointer back to the original source, not only for the author's sake but also for the benefit of readers of your code who may want further explanation.
Thanks, and thanks for explaining. I think to be safe, I'll recreate it based on the general algorithm, since my inputs/outputs are different anyway.
So I made my own rolled version that is actually faster than the one they offered. It is also two bytes smaller than what I was using for Grammer (and 20% faster), while using fewer registers, so that's a huge boon:

Code:

sqrtDE:
;returns HL as the sqrt, DE as the remainder
;34 bytes
;min: 931cc
;max: 1123cc
;avg: 1027cc
;931+8{24,0}

  ld bc,$8000
  ld h,c
  ld l,c
  ld a,c
sqrt_loop:
  srl b
  rra
  ld c,a
  add hl,bc
  ex de,hl
  sbc hl,de
  jr nc,+_
  add hl,de
  ex de,hl
  or a
  sbc hl,bc
  .db $DA   ;start of jp c,** which is 10cc to skip the next two bytes.
_:
  ex de,hl
  add hl,bc
  srl h
  rr l
  srl b
  rra
  jr nc,sqrt_loop
  ret



I wanted to see if my version was better than Axe's so that I could offer it as an optimization, so I looked it up and holy hell is Axe's a lot faster. I tracked back through the optimizations thread to find that it was none other than Runer112 who came up with such an amazing routine.

Here is the post and here is the slightly optimized code that later makes it into Axe (along with my notes on speed):
Quote:


Code:

p_Sqrt:
;766cc+8{0,6}
;min: 766cc
;max: 814cc
;avg: 790cc
 ld a,l
 ld l,h
 ld de,$0040
 ld h,d
 ld b,8
 or a
__SqrtLoop:
 sbc hl,de
 jr nc,__SqrtSkip
 add hl,de
__SqrtSkip:
 ccf
 rl d
 rla
 adc hl,hl
 rla
 adc hl,hl
 djnz __SqrtLoop
 ld h,b
 ld l,d
 ret
__SqrtEnd:



Runer's routine is 237cc faster in the average case (about 23%) ! And now I know who to ask Razz

EDIT: Hahaha, calc84maniac posted code later that is almost exactly the same as what I came up with. We even both used the JP C,** trick, but mine still ends up a bit faster and the same size just because I copied C to A outside the loop and just used A for the shifting.
If I could follow what you are doing I might have appreciation, but right now all I can offer is respect. I would never be able to give that much attention to details like that.
No ! you and all humans have a brain able of doing anything they want.
People have always the possibility to learn, practice, invent, imagine...
So never put you some limits.
Opened this topic hoping it would be an ethical/moral debate, was severely disappointed

Dear Friend wrote:
No ! you and all humans have a brain able of doing anything they want.
People have always the possibility to learn, practice, invent, imagine...
So never put you some limits.

This is true. Anything you set your mind to, or have a heart for, you can do. However, that is not what this topic is about.

I wish you luck on your project, Xeda!
Yeah it... It was but it only lasted through the third post Smile the issue at hand was fairly cut and dry, it would seem.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement