11

I have recently developed a half-float/16-bit float library (link to Github) for Zilog Z80. It was a part of my project to run some neural network and graphics POCs for ZX Spectrum.

The library uses IEEE 754 format and supports both inf/nan and subnormal values.

I implemented addition, subtraction and multiplication in assembly and still have some functions in C (division, comparison, to/from int, to string) need to be ported to assembly and some new (sqrt/log/exp/trigonometry). So it is work in progress.

Most importantly I found it to be virtually as fast as fixed precision calculations for many real applications. For example, multiplication of float16 is actually faster than fixed4:12 because it requires multiplication of 11 significant bits instead of 16.

Here some runtime results:

3d graphics with object rotation :
f16: 10.16s/4.9FPS
fix: 9.82s/5.0FPS

Mandelbrot 256 by 192 pixels
f16: 33:53
fix: 19:43

Neural network training mnist digits 0-1
type: train/test
f16: 1:53/0:37
fix: 1:48/0:34

I this it can be very valuable since it provides quite a large dynamic range and performance close to fixed point computing, being much faster and having much smaller data footprint than full 32-bit floating point one.

Question: where can I find communities that can be interested/benefit from such a project?

6
  • Slightly tangential comment/question, but if this was just for NNs on a system that doesn't have floating point, why not use either a "block" floating point or fixed-point? The maths routines would surely be far more efficient, a NN can be retrained to work just as well and doesn't need Nans/Infs/denorms.
    – Simon F
    Jan 30, 2020 at 9:25
  • 1
    @SimonF actually I implemented NN for fixed, float32 and float16. As you probably understand the NN was merely an exercise of implementing something is done in GPUs measuring its performance in TFLOPs on speccy. On the other side having NaNs/Infs improves stability of code so you know when something goes wrong. Denorms significantly increase the dynamic range for half float and more importantly allows data transfer. I found that denorms do not add that much overhead. BTW fixed point computations for NN was very tricky due to undetected overflows - it was hard to get it right.
    – Artyom
    Jan 30, 2020 at 13:42
  • BTW: blog.cppcms.com/post/125 the idea behind implementing NN on speccy.
    – Artyom
    Jan 30, 2020 at 13:43
  • 256x192? For the ZX Spectrum? Why not using the ROM ones? speed? Jan 31, 2020 at 10:46
  • 1
    @RuiFRibeiro yes for spectrum, ROM operations have higher precision and slower. And for fixed ops you need 16 by 16 -> 32 bit multiplication that ROM does not have.
    – Artyom
    Jan 31, 2020 at 20:08

2 Answers 2

8

I am afraid that there are no general communities for "processor-specific assembler routines". Pieces of information are fragmented to many websites and groups around the web. In the case of Zilog Z80 - it should be on the brand fan pages (e.g. "Spectrum" communities, "Sharp MZ", "CP/M", "MSX" etc.). But, fortunately, there is an info hub for Z80 related things. Try to contact its webmaster and offer the code to publish.

The common way is, as mentioned, the GitHub. Use the proper tags and a good description of your code and publish it. Everyone will have a chance to find it and use it then. And please, do not forget to apply license terms (I strongly recommend the BSD-like one, e.g. the MIT license) to allow other developers to use your work.

2
  • it is licensed under MIT, it is in the folder above (the float16 library is a part of another project currently)
    – Artyom
    Jan 30, 2020 at 6:44
  • I wasn't aware of github tags, I put everything into a separate project: github.com/artyom-beilis/float16
    – Artyom
    Feb 9, 2020 at 16:33
5

Github would seem to be the obvious place, and I see there are already a couple of libraries there

2
  • it is on github :-), also what is important it is IEEE half, meaning you can easily convert values to half outside
    – Artyom
    Jan 29, 2020 at 19:58
  • 1
    I confess I thought the link was to something else and missed it! I'll suggest that writing some documentation, most especially the README, is what will bring others to use your project.
    – jonathanjo
    Jan 29, 2020 at 20:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .