On 1/14/22, Ozkan Sezer <[email protected]> wrote:
> On 1/14/22, Alexei Podtelezhnikov <[email protected]> wrote:
>>> #if defined(_MSC_VER) && defined(_M_IX86)
>>
>> I think this is appropriate, it makes it clear which compiler is
>> intended.
>
> OK, as you wish.
>
>> As for `near`, I found the undefine option
>> https://users.pja.edu.pl/~jms/qnx/help/watcom/compiler-tools/cpopts.html#SWu
>
> Ah, nothing specific for near macro itself, but the standart '-U'
> like many other compilers.
>
>> Do you use any special build tools/scripts to insert it?
>
> I use a makefile for os/2, so I can add -Unear to CFLAGS (tested
> and works.)
>
>> Finally, does Watcom have 64-bit types these days? We could insert it in
>> https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/include/freetype/config/integer-types.h
>
> As of version 11.0, it supports long long: You can check like:
> #if (__WATCOMC__ >= 1100)
>
> It also supports __int64 but don't know as of which version.
>
>> Do you know of any fast most-significnat-bit functions, like
>> __builtin_clz, for Watcom?
>
> You can inline-asm the bsr instruction with Watcom's aux pragma for
> _BitScanReverse behavior, provided that you handle x==0 special case,
> (replace uint32_t with unsigned long if you like). Like:
>
> #if defined(__WATCOMC__) && defined(__386__)
> extern __inline int _bsr_watcom(uint32_t);
> #pragma aux _bsr_watcom = \
>     "bsr eax, eax" \
>     parm [eax] nomemory \
>     value [eax] \
>     modify exact [eax] nomemory;
> #endif
>
> Or, if you specifically want __builtin_clz-like behavior, here is a
> version which xors the result with 31:
> static __inline int _clz_watcom(uint32_t);
> #pragma aux _clz_watcom = \
>     "bsr eax, eax" \
>     "xor eax, 31" \
>     parm [eax] nomemory \
>     value [eax] \
>     modify exact [eax] nomemory;
> #endif

Attaching new patches. Tell me if you need any changes.
diff --git a/include/freetype/internal/compiler-macros.h b/include/freetype/internal/compiler-macros.h
index 88c0bf0..1a6633c 100644
--- a/include/freetype/internal/compiler-macros.h
+++ b/include/freetype/internal/compiler-macros.h
@@ -295,17 +295,15 @@ FT_BEGIN_HEADER
    */
 #ifdef __cplusplus
 #define FT_CALLBACK_DEF( x )  extern "C"  x
 #else
 #define FT_CALLBACK_DEF( x )  static  x
 #endif
 
-#if defined( __i386__ )
-#define FT_COMPARE_DEF( x )  FT_CALLBACK_DEF( x ) __attribute__(( cdecl ))
-#elif defined( _M_IX86 )
+#if defined( _MSC_VER ) && defined( _M_IX86 )
 #define FT_COMPARE_DEF( x )  FT_CALLBACK_DEF( x ) __cdecl
 #else
 #define FT_COMPARE_DEF( x )  FT_CALLBACK_DEF( x )
 #endif
 
 #define FT_BASE_CALLBACK( x )      FT_FUNCTION_DECLARATION( x )
 #define FT_BASE_CALLBACK_DEF( x )  FT_FUNCTION_DEFINITION( x )
diff --git a/include/freetype/config/integer-types.h b/include/freetype/config/integer-types.h
index b772845..af848fb 100644
--- a/include/freetype/config/integer-types.h
+++ b/include/freetype/config/integer-types.h
@@ -219,15 +219,18 @@
 
   /* this compiler provides the `__int64` type */
 #define FT_INT64   __int64
 #define FT_UINT64  unsigned __int64
 
 #elif defined( __WATCOMC__ )   /* Watcom C++ */
 
-  /* Watcom doesn't provide 64-bit data types */
+#if ( __WATCOMC__ >= 1100 )    /* As of Watcom 11.0 */
+#define FT_INT64   long long int
+#define FT_UINT64  unsigned long long int
+#endif
 
 #elif defined( __MWERKS__ )    /* Metrowerks CodeWarrior */
 
 #define FT_INT64   long long int
 #define FT_UINT64  unsigned long long int
 
 #elif defined( __GNUC__ )
diff --git a/include/freetype/internal/ftcalc.h b/include/freetype/internal/ftcalc.h
index 46e7f22..e228617 100644
--- a/include/freetype/internal/ftcalc.h
+++ b/include/freetype/internal/ftcalc.h
@@ -401,20 +401,31 @@ FT_BEGIN_HEADER
 
     _BitScanReverse( &where, x );
 
     return (FT_Int32)where;
   }
 
 #define FT_MSB( x )  FT_MSB_i386( x )
 
 #endif
 
+#elif defined( __WATCOMC__ ) && defined( __386__ )
+
+extern __inline FT_Int32 FT_MSB_i386(FT_UInt32);
+#pragma aux FT_MSB_i386 = \
+  "bsr eax, eax" \
+  parm [eax] nomemory \
+  value [eax] \
+  modify exact [eax] nomemory;
+
+#define FT_MSB( x )  FT_MSB_i386( x )
+
 #elif defined( __DECC ) || defined( __DECCXX )
 
 #include <builtins.h>
 
 #define FT_MSB( x )  (FT_Int)( 63 - _leadz( x ) )
 
 #elif defined( _CRAYC )
 
 #include <intrinsics.h>
 

Reply via email to