Don't have an account? Register now to chat, post, use our tools, and much more.
Latest Headlines
Online Users
There are 89 users online: 5 members, 55 guests and 29 bots. Members: chickendude, lboe, skompc, Svenne, willwac. Bots: VoilaBot (3), Spinn3r (2), MSN/Bing (1), Magpie Crawler (3), VoilaBot (1), Googlebot (18), MSN/Bing (1).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
|
| Author |
Message |
|
cerzus69

Member

Joined: 30 Jan 2011 Posts: 125
|
Posted: 07 Dec 2011 07:59:54 am Post subject: 24 bit multiplication |
|
|
I have been looking for two days now to find a z80 ASM routine that multiplies two 24 bit numbers to get a 48 bit result.
I need it because I want to try and make a Mandelbrot set generator for the Ti84+ using Q2.21 Fixed Point numbers.
Now I would try to come up with one myself but if anyone knows of an existing one I'd like to know!
Thanks _________________ cerzus69 edited a post |
|
| Back to top |
|
|
KermMartian

Site Admin

Joined: 14 Mar 2005 Posts: 55736 Location: Earth, Sol, Milky Way
|
Posted: 07 Dec 2011 02:15:34 pm Post subject: Re: 24 bit multiplication |
|
|
Welcome back, Cerzus! It's been far too long since I've seen you around here; how's life? Did you see that Benumbered is one of the candidates for the 2011 POTY at ticalc.org?
| cerzus69 wrote: | | I have been looking for two days now to find a z80 ASM routine that multiplies two 24 bit numbers to get a 48 bit result. | Hmm, z80 Bits goes up as high as 16x16, so theoretically you could apply that 16 times, could you not? _________________
 |
|
| Back to top |
|
|
cerzus69

Member

Joined: 30 Jan 2011 Posts: 125
|
Posted: 08 Dec 2011 10:12:18 am Post subject: |
|
|
Possible, but that would not be very efficient now would it? I know there must be a better way and in fact I posed the same question at Omnimaga and got someone to come up with a code fragment so I might have what I need. Need to check it first though...
Still there may be another optimized version somewhere out there.[/quote] _________________ cerzus69 edited a post |
|
| Back to top |
|
|
KermMartian

Site Admin

Joined: 14 Mar 2005 Posts: 55736 Location: Earth, Sol, Milky Way
|
Posted: 08 Dec 2011 10:13:43 am Post subject: |
|
|
Well, since you can't get faster than one iteration per a bit, as far as I can figure out, applying a 16x16 multiply 16 times would be the fastest thing to do in my opinion. If you had enough registers, you could probably collapse it to 8 iterations through, but we have a serious lack of registers, of course. _________________
 |
|
| Back to top |
|
|
cerzus69

Member

Joined: 30 Jan 2011 Posts: 125
|
Posted: 08 Dec 2011 10:17:31 am Post subject: |
|
|
Give me some time to let your reply sink in and have me understand it, please.  _________________ cerzus69 edited a post |
|
| Back to top |
|
|
KermMartian

Site Admin

Joined: 14 Mar 2005 Posts: 55736 Location: Earth, Sol, Milky Way
|
Posted: 08 Dec 2011 10:18:35 am Post subject: |
|
|
| cerzus69 wrote: | Give me some time to let your reply sink in and have me understand it, please.  | Perhaps I should start by asking how well you understand some of the smaller multiplication routines on z80 bits, then, before I inundate you too much with synthesizing your own routine based on their concepts.  _________________
 |
|
| Back to top |
|
|
cerzus69

Member

Joined: 30 Jan 2011 Posts: 125
|
Posted: 08 Dec 2011 10:48:37 am Post subject: |
|
|
Let's say I understand the theory behind bitwise multiplication. The implementation of the 8*8 routine is clear to me, 16*16 is a little harder and you saying just doing the 16bit routine 16 times kind of made sense to me, but to be honest I haven't delved too deep into the subject to completely understand it. _________________ cerzus69 edited a post |
|
| Back to top |
|
|
christop

Power User

Joined: 09 Mar 2011 Posts: 385 Location: Arizona, USA
|
Posted: 08 Dec 2011 03:33:57 pm Post subject: |
|
|
Why do you need such precise values? Are you planning to support extreme levels of zoom in your program?
Instead of 24-bit fixed-point values, could you use 24-bit floating point numbers? You could have a 1-bit sign, 7-bit exponent, and 16-bit significand (1.7.16 minifloat). Multiplying 16-bit values is easier and faster with the limited number of registers found on the z80, and the exponent will give you a much larger range of values. Such a floating-point value would be more precise, too, once the top 8 bits of the fixed-point value become zero (both will have 16 bits of precision at that point). This happens when it's less than 0.03125.
(Incidentally, this 1.7.16 floating-point format is the same as that used by some Radeon GPU's: http://en.wikipedia.org/wiki/Minifloat)
You may even be able to get away with an 8-bit significand (1.7.8 minifloat), but that would probably give you a lot of visible artifacts in your fractals at all zoom levels (but it would be faaaast!).
I'm quite familiar with working with floating-point values, so I can help out a bit if you want to go this route. It's really not much more difficult to work with than fixed-point (unless you want to implement all rounding modes, subnormal numbers, infinities, not-a-numbers, exceptions, flags, and other such goodies as found in the IEEE 754 standard but which are not needed for this application). _________________ Christopher Williams |
|
| Back to top |
|
|
cerzus69

Member

Joined: 30 Jan 2011 Posts: 125
|
Posted: 09 Dec 2011 11:55:34 am Post subject: |
|
|
Tkank you christop for your elaborate response.
21 bits for decimals is not extremely precise in my opinion. 13 bits (as in a Q2.13 format) would give me a max zoom of 341.33.. (using 96 pixels and a range of real [-2, +2] at zoom 1). In that case the difference per pixel at max zoom is 0.0001220703125, which is the smallest number representable with 13 bits. Next step up would be 2 times that amount per pixel. Logically that would be zoom 170.66.. and there wouldn't be any other zoom levels available between those two.
I'd like to have a little more room hence those extra 8 bits.
On the other hand I think the minifloats you are talking about could very well be a better solution. As long as operations on them are reasonably fast of course.
I am still working on Q2.13 at the moment, but I will definitely have a look at minifloats. _________________ cerzus69 edited a post |
|
| Back to top |
|
|
cerzus69

Member

Joined: 30 Jan 2011 Posts: 125
|
Posted: 13 Dec 2011 10:56:39 am Post subject: |
|
|
Okay, so now I've got 3 iterate functions that return the number of mandelbrot iterations for numbers between -4 and + 4. They are for Q2.5, Q2.13 and Q2.21 fixed point formats.
The 24-bit multiplication I am using for the last one is courtesy of jacobly at omnimaga:
Code: MUL24: ;(hldebc = hlc * bde)
ld (iy + asm_Flag1), b
xor a
ld ix, 0
ld b, 24
MUL24Loop:
add ix, ix
rla
rl c
adc hl, hl
jr nc, MUL24Next
add ix, de
adc a, (iy + asm_Flag1)
jr nc, MUL24Next
inc c
jr nz, MUL24Next
inc hl
MUL24Next:
djnz MUL24Loop
ld e, a
ld d, c
push ix ;ld c, ixl
pop bc ;ld b, ixh
ret
Thought I'd share it here for any future use.
Now, I'm on to taking a look at (half precision) floats and see if I can get their speed and accuracy at a nice balance to compete with fixed point numbers. _________________ cerzus69 edited a post |
|
| Back to top |
|
|
KermMartian

Site Admin

Joined: 14 Mar 2005 Posts: 55736 Location: Earth, Sol, Milky Way
|
Posted: 13 Dec 2011 10:58:56 am Post subject: |
|
|
I take issue with the slowdown from using iy+asm_flag1; I'm trying to think what might be better there... _________________
 |
|
| Back to top |
|
|
cerzus69

Member

Joined: 30 Jan 2011 Posts: 125
|
Posted: 13 Dec 2011 11:03:14 am Post subject: |
|
|
Hey, at least it's a lot faster than 16 times the 16*16 multiplication! But, please, tell if you come up with something.
EDIT: I do understand the routine now though, just so you know.  _________________ cerzus69 edited a post |
|
| Back to top |
|
|
|
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
|
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
|
© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.030255 seconds.
|