NO

Author Topic: Berkeley SoftFloat  (Read 5460 times)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Berkeley SoftFloat
« on: August 09, 2017, 07:39:18 PM »
Berkeley SoftFloat support 80-bit and 128-bit floats too.
I try to get it work with PellesC.

example
Code: [Select]
#include <stdio.h>
#define SOFTFLOAT_FAST_INT64
#include <SoftFloat.h>
#include <primitiveTypes.h>
#if defined(_WIN64) || __POCC_TARGET__ >= 3
#pragma comment(lib, "SoftFloat3x64.lib")
#else
#pragma comment(lib, "SoftFloat3.lib")
#endif

int __cdecl main(int argc, char **argv)
{
char buf[128];
unsigned char *p;
extFloat80_t f80 = i32_to_extF80( 1 );
extFloat80_t f80s = extF80_add(f80, f80);
p = (unsigned char *)&f80;
for (int i=0; i<10; i++) printf("%02X ", (unsigned char)*p++);
puts("");
p = (unsigned char *)&f80s;
for (int i=0; i<10; i++) printf("%02X ", (unsigned char)*p++);
puts("");
float128_t f128 = ui64_to_f128( 1 );
p = (unsigned char *)&f128;
for (int i=0; i<16; i++) printf("%02X ", (unsigned char)*p++);
puts("");
return 0;
}
EDIT: missing platform.h and msvcrt_void.c added.
EDIT: project with source in zip TestSoftFloat80_WS_src.zip

To test ready-made libraries, use SoftFloat3_WS_test.zip and SoftFloat3lib.zip as example.
« Last Edit: August 10, 2017, 12:19:35 PM by TimoVJL »
May the source be with you

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: Berkeley SoftFloat
« Reply #1 on: August 10, 2017, 09:54:53 AM »
The IDE says
Don't know how to build "C:\Masm32\PellesC\Projects\Timo\SoftFloat\source\extF80_add.c".
 :(
Anything else missing?

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Berkeley SoftFloat
« Reply #2 on: August 10, 2017, 09:57:24 AM »
It was without source.

Downloaded from here

EDIT: project with source in zip TestSoftFloat80_WS_src.zip
« Last Edit: August 10, 2017, 10:08:43 AM by TimoVJL »
May the source be with you

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: Berkeley SoftFloat
« Reply #3 on: August 10, 2017, 04:16:13 PM »
Any idea why the IDE tells me "Bad version on TestSoftFloat80X64.ppj"?

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Berkeley SoftFloat
« Reply #4 on: August 10, 2017, 04:40:34 PM »
It happens, if someone opened workspace in poide.exe version 8 (32-bit)
« Last Edit: August 10, 2017, 04:52:13 PM by TimoVJL »
May the source be with you

Offline jack

  • Member
  • *
  • Posts: 62
Re: Berkeley SoftFloat
« Reply #5 on: August 11, 2017, 02:22:13 AM »
for input/output I use ioldouble from http://www.moshier.net/#Rubid_pc filename smldbl12.zip

Offline jack

  • Member
  • *
  • Posts: 62
Re: Berkeley SoftFloat
« Reply #6 on: August 11, 2017, 04:46:58 AM »
I built the softfloat lib with ioldouble included, but can't compile this simple example
Code: [Select]
#include <stdio.h>
#include "SoftFloat.h"
#include "primitiveTypes.h"

extern void e64toasc(extFloat80_t *x, char *string, int ndigs);
extern void asctoe64( char *s, extFloat80_t *x );

int __cdecl main(int argc, char **argv)
{
char buf[128]="3.1415926535897932384626433832795";
extFloat80_t f80;
asctoe64( buf, &f80 );
e64toasc( &f80, buf, 10 );
printf("%s\n",buf);
return 0;
}
POLINK: error: Unresolved external symbol 'alloca'

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Berkeley SoftFloat
« Reply #7 on: August 11, 2017, 08:10:59 AM »
add
Code: [Select]
#include <stdlib.h>and use compiler option -Go Define compatibility names.
May the source be with you

Offline jack

  • Member
  • *
  • Posts: 62
Re: Berkeley SoftFloat
« Reply #8 on: August 11, 2017, 11:36:30 AM »
I already tried that but no luck, gcc has no problem.

Offline jack

  • Member
  • *
  • Posts: 62
Re: Berkeley SoftFloat
« Reply #9 on: August 11, 2017, 12:14:30 PM »
your advise is good, but it also had to be applied to building the soft float lib, now it works without complaints.
Code: [Select]
#include <stdio.h>
#include <stdlib.h>

#include "SoftFloat.h"
#include "primitiveTypes.h"

extern void e64toasc(extFloat80_t *x, char *string, int ndigs);
extern void asctoe64( char *s, extFloat80_t *x );
extern void e113toasc(float128_t *x, char *string, int ndigs);
extern void asctoe113( char *s, float128_t *x );

int __cdecl main(int argc, char **argv)
{
char buf[128]="3.1415926535897932384626433832795028842";
float128_t f128, f128b;
asctoe113( buf, &f128 );
f128M_add(&f128, &f128, &f128b);
e113toasc( &f128b, buf, 33 );
printf("%s\n",buf);
return 0;
}
Quote
6.283185307179586476925286766559006E0

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Berkeley SoftFloat
« Reply #10 on: August 11, 2017, 02:29:43 PM »
Only the project need that with ioldoubl, not SoftFloat3.lib.

I haven't check if ioldoubl.c needs splitting for smaller code size, as PellesC don't support COMDAT.

Nice to see that someone is testing it ;)
May the source be with you

Offline jack

  • Member
  • *
  • Posts: 62
Re: Berkeley SoftFloat
« Reply #11 on: August 11, 2017, 03:57:13 PM »
a bit off topic, I hope won't mind.
I did some timing on softfloat3c and QD https://github.com/scibuilder/QD and QD is from 1.7 to 3.5 times faster, up to 5.7 faster in 32-bit vs softfloat x86
but I manually edited the makefile for the 32-bit build to use sse2 otherwise if using the fpu one has to use fpu_fix_start and fpu_fix_end between calculations, slowing things down considerably.
« Last Edit: August 11, 2017, 05:04:33 PM by jack »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Berkeley SoftFloat
« Reply #12 on: August 11, 2017, 09:03:39 PM »
Hardly, people like also to know other or better options.

QD is programmed in C++, so not so usable for C without making a dll.
Average gcc programmer even notice that in their tests, what have to link with static libs.
« Last Edit: August 11, 2017, 09:35:37 PM by TimoVJL »
May the source be with you