Looking for floating point libraries

Programming the 6502 microprocessor and its relatives in assembly and other languages.
User avatar
hjalfi
Posts: 107
Joined: 12 Oct 2017

Looking for floating point libraries

Post by hjalfi »

As title.

I already know of:

- Wozniak & Rankin's one from Dr. Dobbs in 1976 (4-byte binary, difficult copyright licensing/issues)
- Microsoft's one in their BASIC (no license)
- Acorn's in their BASIC (no license)
- the Atari MATHPACK clone from Altirra (GPL; 6-byte BCD)
- the C64-compatible routines from the X16 kernal replacement (mostly copied from Microsoft, AFAICT)
- Louis Chorich's Atari floating point library (commercial, 6-byte, presumably BCD but the docs don't say)
- Apple's SANE (source lost)
- Some Random Internet Guy's library (no license, 5-byte BCD, no negative numbers)

Anyone know of more?
gfoot
Posts: 871
Joined: 09 Jul 2021

Re: Looking for floating point libraries

Post by gfoot »

I wrote some floating point routines earlier this year, I'm not sure if they count as a library though. I think I posted it on Stardot as it was using the BBC BASIC assembler, and had routines to load values from BASIC variables. I only implemented the basics though (addition, subtraction, multiplication). I made a two byte version and a three byte version. The API was load-store register-based, a bit like ARM I guess.
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: Looking for floating point libraries

Post by barrym95838 »

Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Looking for floating point libraries

Post by BigDumbDinosaur »

x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
hjalfi
Posts: 107
Joined: 12 Oct 2017

Re: Looking for floating point libraries

Post by hjalfi »

Here's another one, written this decade: https://hackaday.io/project/181098-home ... r-for-6502 32-bit BCD, no license (but unusually, the author can be contacted without the use of a spirit medium!).
User avatar
hjalfi
Posts: 107
Joined: 12 Oct 2017

Re: Looking for floating point libraries

Post by hjalfi »

https://web.archive.org/web/20200128060 ... calc65.htm: 64-bit BCD, full set of trigonometric functions... no license and 'all rights reserved'.
dmsc
Posts: 153
Joined: 17 Sep 2018

Re: Looking for floating point libraries

Post by dmsc »

Hi!
hjalfi wrote:
As title.

I already know of:

- Wozniak & Rankin's one from Dr. Dobbs in 1976 (4-byte binary, difficult copyright licensing/issues)
- Microsoft's one in their BASIC (no license)
- Acorn's in their BASIC (no license)
- the Atari MATHPACK clone from Altirra (GPL; 6-byte BCD)
The Altirra ROM replacement is not under the GPL, but under the MIT license, much more permissive.
hjalfi wrote:
- the C64-compatible routines from the X16 kernal replacement (mostly copied from Microsoft, AFAICT)
- Louis Chorich's Atari floating point library (commercial, 6-byte, presumably BCD but the docs don't say)
- Apple's SANE (source lost)
The VBCC 6502 compiler uses those, and includes a library with all the split objects.
Quote:
- Some Random Internet Guy's library (no license, 5-byte BCD, no negative numbers)

Anyone know of more?
The Mad Pascal compiler (at https://github.com/tebe6502/Mad-Pascal ) includes:
- 32-bit FLOAT: https://github.com/tebe6502/Mad-Pascal/ ... single.asm
- 16-bit FLOAT: https://github.com/tebe6502/Mad-Pascal/ ... dd_sub.asm and other files.

Have Fun!
User avatar
hjalfi
Posts: 107
Joined: 12 Oct 2017

Re: Looking for floating point libraries

Post by hjalfi »

dmsc wrote:
The Altirra ROM replacement is not under the GPL, but under the MIT license, much more permissive.
Oops. I knew that, honest.
dmsc wrote:
That's a nice find. The comment at the top of the first suggests the 32-bit code partially came from David Schmenk's Java VM for the Apple 2 (https://sourceforge.net/projects/vm02/, GPL-2), but the 16-bit stuff looks native.
johnwbyrd
Posts: 89
Joined: 01 May 2017

Re: Looking for floating point libraries

Post by johnwbyrd »

Here's a standards-compliant implementation. Only compiles on llvm-mos as far as I know.

https://github.com/rweather/berkeley-softfloat-3-6502
BillG
Posts: 710
Joined: 12 Mar 2020
Location: North Tejas

Re: Looking for floating point libraries

Post by BillG »

I know you want something with a permissive license.

I am not a patent lawyer and I do not play one on television; if you were to paraphrase code from one processor architecture to a different one, is the result considered to be infringing? If not, that may be a relatively easy way to get there. I have always presumed that to be safe; it is not unlike coding from an algorithm in a book or journal.

Floating point code has been published for the Motorola 8-bit processors. Same for 8080/Z80. Source code for 8087 emulation from the Borland compilers (80x86) is also out there.

Are you picky between BCD versus binary?

A long time ago, I set out to write IEEE 754 compliant floating point for the 6800. I have single precision generally working but have yet to work out how to implement the guard, round and sticky bits. Because the AVR instruction set looked so easy to program, I also built a version for that. Future steps:

* Figure out the guard, round and sticky bits
* Improve the speed
* Implement 6-byte, double and extended precision
* Port to other processors
User avatar
drogon
Posts: 1671
Joined: 14 Feb 2018
Location: Scotland
Contact:

Re: Looking for floating point libraries

Post by drogon »

johnwbyrd wrote:
Here's a standards-compliant implementation. Only compiles on llvm-mos as far as I know.

https://github.com/rweather/berkeley-softfloat-3-6502
This is interesting as it ought to be possible to port it to cc65 which is probably (at the moment) more accessible to more 6502 users than the llvm-mos branch is.

The idea if implementing floating point in a language that doesn't intrinsically support it [1] isn't new either - in the early 80's BCPL didn't support floating point either, but there were libraries - one I used was the package for the BBC Micros implementation of BCPL which supported various formats and previsions. FP numbers were held in vectors (arrays) and you called functions to do the FP operations.

https://www.computinghistory.org.uk/det ... s-Package/

-Gordon

[1] Yes, C supports floating point but cc65 doesn't, so it would have to be implemented by external means.
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/
Chromatix
Posts: 1462
Joined: 21 May 2018

Re: Looking for floating point libraries

Post by Chromatix »

BillG wrote:
I have single precision generally working but have yet to work out how to implement the guard, round and sticky bits.
I discussed the guard and sticky bits here, including pseudocode to perform correct rounding using them: viewtopic.php?f=2&t=5352#p64001
resman
Posts: 154
Joined: 12 Dec 2015
Location: Lake Tahoe
Contact:

Re: Looking for floating point libraries

Post by resman »

I wrote some 32 bit single precision FP routines for VM02. Not much error handling. Search for FLOATING_POINT:

https://github.com/dschmenk/VM02/blob/master/src/ops.s
BillG
Posts: 710
Joined: 12 Mar 2020
Location: North Tejas

Re: Looking for floating point libraries

Post by BillG »

Chromatix wrote:
BillG wrote:
I have single precision generally working but have yet to work out how to implement the guard, round and sticky bits.
I discussed the guard and sticky bits here, including pseudocode to perform correct rounding using them: viewtopic.php?f=2&t=5352#p64001
Thanks for that. Completing floating point implementation will be a huge leap forward for some cross-compilers in progress.
Post Reply