简体   繁体   中英

`unsigned __int128` for Visual Studio 2019

I am trying to compile QuickJS, which is normally developed under linux and gcc has no problem with such code. However, I have troubles to compile this on Visual Studio 2019:

typedef unsigned __int128 uint128_t;

Does anyone know a trick to make this work as it is supposed to work?

在此处输入图片说明

The error is:

error C4235: Non-standard extension: The __int128 keyword is not supported for this architecture.

However, __m128 is supported, just not as unsigned , so that doesn't help with this.

__m128 is defined as a union thus:

typedef union __declspec(intrin_type) __declspec(align(16)) __m128 {
     float               m128_f32[4];
     unsigned __int64    m128_u64[2];
     __int8              m128_i8[16];
     __int16             m128_i16[8];
     __int32             m128_i32[4];
     __int64             m128_i64[2];
     unsigned __int8     m128_u8[16];
     unsigned __int16    m128_u16[8];
     unsigned __int32    m128_u32[4];
 } __m128;

Clearly it can be used for unsigned operations via its m128_uXX members but it cannot be used semantically like a built-in data type - including qualifying with unsigned , and it cannot be used in built-in arithmetic operations - it requires functions/extensions defined specifically defined to operate on it. It is intended for use with SSE/SSE2 SIMD extensions

Microsoft's implementation does not include an extension 128 bit integer type.

In terms of the QuickJS code, the problem is in the preceding libbf.h code there is:

#if defined(__x86_64__)
#define LIMB_LOG2_BITS 6
#else
#define LIMB_LOG2_BITS 5
#endif

#define LIMB_BITS (1 << LIMB_LOG2_BITS)

So that for 64 bit compilation LIMB_BITS == 64 . I suggest one of two solutions:

  • Use 32 bit compilation so that LIMB_BITS == 32
  • Modify libbf.h thus:
     #if defined(__x86_64__) || defined(_MSC_VER)
    so that the 128-bit definitions are omitted on an MS build.
  • Use a Windows compiler that has a __int128 built-in such as Mingw64.

I note that there is a QuickJS Visual Studio port here , but looking at the code and the lua script that generates the VS solution it is not immediately obvious to me how or even if this issue is resolved. The readme.md file says to download and install premake5, but the link is broken. I gave up at that point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM