0 votes
by Daniel Lee (630 points)

I'm trying to interface with a C shared library that uses floating point numbers.  It seems that the C function isn't taking arguments from either the float stack or the data stack.

First, the file testfloat.c contains one line:

extern float cadd( float a, float b) {return a + b;}

I compile with: gcc -shared -o testfloat.so testfloat.c

Here's my test session:

VFX Forth 64 5.20 [build 0131] 2022-09-12 for Linux x64
© MicroProcessor Engineering Ltd, 1998-2022

Library: ./testfloat.so  ok
Extern: float "C" cadd( float a, float b );  ok
 
3.14159e0 fs@  ok-1  F:-1
2.71828e0 fs@  ok-2  F:-2
 
f.s ( check the stacks before calling )
-- FP top of 2
2.71828
3.14159
 ok-2  F:-2
.s
DATA STACK
     top
              0 0000:0000:0000:0000
              0 0000:0000:0000:0000
 ok-2  F:-2

cadd  ok-2  F:-2  ( call the C function )

f.s
-- FP top of 2
2.71828
3.14159
 ok-2  F:-2
.s
DATA STACK
     top
              0 0000:0000:0000:0000
              0 0000:0000:0000:0000
 ok-2  F:-2

1 Answer

+1 vote
by Stephen Pelc (4.4k points)
Thank you for the test code! Much appreciated.

My apologies. The float code for locals and EXTERNs on x64 has suffered from bit rot. I hope to have new releases done next week. The root of the issue is that we have three float packages for x64:

1) NDP floats using old 8087 style. It has 80 bit floats (important for some) and is fast. It uses the 8 level internal NDP stack.

2) NDP floats with supporting external stack (R13).

3) 64 bit SSE floats with an external stack (R13).

In the medium term we intend to use the internal NDP stack with automagic conversions in XCALLs. This solution satisfies the performance people and the dynamic range people and the non-mathmos.

In the long term we will write an SSE optimiser, but this may/will have to wait until after the ARM64 and perhaps RISC-V releases.

In the meantime, rebuild VFX (see RebuildOsx64.sh) with SSE floats only.
by Daniel Lee (630 points)
Thanks for the clarification and update.  I'm looking forward to the release.  I cannot find a rebuild script in any of the recent Mac / Linux downloads.  It's okay, though. I can wait for the new release.
by Daniel Lee (630 points)
From reading the docs, it looks like the (missing) rebuild script calls mlinux.sh (mlin64.sh in the 64-bit version) and stage2lin.sh.  I will dig a little deeper.
by Bruno Degazio (310 points)
I have this problem too - malfunctioning Externs:  due to Floating point changes, and no way to rebuild VFX to use SSE.
by Bruno Degazio (310 points)
Daniel, it seems that shell scripts for rebuilding are included in the latest VFX release for MacOS, in the file mosx64.sh and related files.

Not sure if these will work as is, though. I see some references to the cross-compiler and some file-paths that appear to have changed since the scripts were written.
...