Skip to content

Commit bc6174c

Browse files
Update README.md
1 parent b5fa376 commit bc6174c

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

README.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,47 @@ symlink(joinpath(homedir(), ".julia/v0.4/Quadmath/examples/"), joinpath(homedir(
1313
```
1414
Then 'Quadmath_examples' will be listed in the JuliaBox home screen. The examples contain among others
1515
+ [BesselZeros.ipynb](https://github.com/HaraldHofstaetter/Quadmath.jl/blob/master/examples/BesselZeros.ipynb):
16-
In this notebook it is demonstrated that Float128 is about 4 times faster than BigFloat with 113 bit precision
17-
(the precision of Float128).
16+
In this notebook it is demonstrated that `Float128` is about 4 times faster than `BigFloat` with 113 bit precision
17+
(the precision of `Float128`).
18+
19+
##Bugs
20+
+ `ccall` does not treat parameters and returning values of Julia type `Float128` as C type `__float128` as it would
21+
be appropriate.
22+
23+
Unfortunately, this is a bug which cannot easily be fixed.
24+
The [x86-64 Application Binary Interface](http://www.x86-64.org/documentation.html)
25+
says that parameters and returning values of type `__float128` should be passed preferably in the (128 bit long) SSE floating point registers `xmm0`,...,`xmm7`. However, for the datatype `Float128` defined as
26+
```julia
27+
bitstype 128 Float128 <: AbstractFloat
28+
```
29+
in [Quadmath.jl](https://github.com/HaraldHofstaetter/Quadmath.jl/blob/master/src/Quadmath.jl),
30+
`ccall` seems to use the same calling convention as for something like
31+
```c
32+
struct{
33+
uint64_t u0;
34+
uint64_t u1;
35+
} words64;
36+
```
37+
in C.
38+
39+
A remedy is to implement a wrapper function for each external function with `__float128` parameters or return values,
40+
that you want to call by `ccall`. Such a wrapper takes parameters `x` of type `myfloat128` declared as
41+
```c
42+
typedef union
43+
{
44+
__float128 value;
45+
46+
struct{
47+
uint64_t u0;
48+
uint64_t u1;
49+
} words64;
50+
} myfloat128;
51+
```
52+
and calls the original function with `x.value` as actual parameter for the coorresponding formal parameter of type
53+
`__float128`.
54+
This is eaxtly the technique we use in
55+
[quadmath_wrapper.c](https://github.com/HaraldHofstaetter/Quadmath.jl/blob/master/deps/src/)
56+
to call the functions of the [libquadmath](https://gcc.gnu.org/onlinedocs/libquadmath/) library.
57+
58+
59+

0 commit comments

Comments
 (0)