I've noticed that for many years now there have been a recurring Windows
related complaint about "Error: unknown constraint 't'" message, which goes as
There appears to be a patch for it (didn't test it), but it seems it was never taken:
I decided to approach it from a different direction, and while at it also add 3 missing libm
functions. Following these changes, at least 2 medium sized projects which tcc couldn't
built on windows (using the windows official distribution package), now build and appear
to be working well (mujs and Duktape).
If there are no objections, I'll push that to the mob branch soon. The patch is attached,
and that's the commit message:
----------------------------------------------------------
win: libm: fix "unknown constraint 't'", missing fpclassify/round/etc
Some libm functions were broken at win32/include/math.h in few ways:
1. Unknown constraint 't': a similar piece of code was used in several inline
functions at math.h (from mingw), and currently the tcc asm doesn't support
it. This broke __fpclassifyl, __isnan* and __signbit*, and indirectly broke
the macros fpclassify, isfinite, isinf, isnan, isnormal and signbit.
2. Even if 't' was supported by tcc's asm, there were no definitions for
__fpclassify and __fpclassifyf, therefore breaking the macro fpclassify.
Newer mingw(w64) math.h doesn't have this issue, but still uses 't' in asm.
3. Other than the above, some common libm functions werere not implemented
anywhere in the tcc Windows distribution package - mainly fmin/fmax/round.
Newer mingw(64) math.h stil doesn't include these implementations.
To address these issues, code which used inline asm with 't' was replaced with
a C implementation, and the missing __fpclassify functions were added.
The code is mostly taken from MUSL rs-1.0 (MIT) [*], and is placed as inline
functions at win32/include/tcc/tcc_libm.h, which is now included from math.h,
and is also copied to the win32 install target.
Future enhancements:
- Support 't' contraint in asm. Newer mingw headers still use it, and it would
make future porting of mingw headers easier.
- Enumerate the still-missing libm functions (if there are such) and add missing
implementations. Most should be simple and will add good value to tcc.
- Possibly move the code at tcc/tcc_libm.h to a C file and create an actual
libm.a library, or just create a dummy libm. For build procedures which expect
libm, this could allow to complete successfully, assuming no yet-unimplemented
functions are used.
- Add some tests for common libm functions.
[*] - http://git.musl-libc.org/cgit/musl/tree/src/math?h=rs-1.0