Skip to content

fix: add intrinsics to header for clang-msvc compilation#3

Closed
IlyaGredasov wants to merge 1 commit intodevatrun:mainfrom
IlyaGredasov:fix/clang-msvc-intrinsics-error
Closed

fix: add intrinsics to header for clang-msvc compilation#3
IlyaGredasov wants to merge 1 commit intodevatrun:mainfrom
IlyaGredasov:fix/clang-msvc-intrinsics-error

Conversation

@IlyaGredasov
Copy link
Copy Markdown

Such code can be compiled in clang wsl:

[/mnt/d/Programming/C++]$ cat test.cpp
#include <slimcpplib/long_int.h>
#include <slimcpplib/long_io.h>

using namespace slim::literals;

int main() {
        const slim::int256_t u = -10000_si256 << 100;
        std::cout << u << std::endl;
}
[/mnt/d/Programming/C++]$ clang++ test.cpp -std=c++20 -I slimcpplib/include
[/mnt/d/Programming/C++]$ ./a.out
-12676506002282294014967032053760000
[/mnt/d/Programming/C++]$

But msvc clang doesn't find intrinsics for compilation:

PS D:\Programming\C++> cat .\test.cpp
#include <slimcpplib/long_int.h>
#include <slimcpplib/long_io.h>

using namespace slim::literals;

int main() {
        const slim::int256_t u = -10000_si256 << 100;
        std::cout << u << std::endl;
}
PS D:\Programming\C++> clang++ .\test.cpp -std=c++20 -I .\slimcpplib\include
In file included from .\test.cpp:1:
In file included from .\slimcpplib\include\slimcpplib/long_int.h:39:
In file included from .\slimcpplib\include\slimcpplib\long_uint.h:35:
In file included from .\slimcpplib\include\slimcpplib\long_math_long.h:42:
.\slimcpplib\include\slimcpplib\long_math_msvc.h:231:12: error: use of undeclared identifier '_addcarry_u8'
  231 |     return _addcarry_u8(0, value1, value2, &value1);
      |            ^~~~~~~~~~~~
.\slimcpplib\include\slimcpplib\long_math_msvc.h:239:12: error: use of undeclared identifier '_addcarry_u16'
  239 |     return _addcarry_u16(0, value1, value2, &value1);
      |            ^~~~~~~~~~~~~
.\slimcpplib\include\slimcpplib\long_math_msvc.h:267:12: error: use of undeclared identifier '_addcarry_u8'
  267 |     return _addcarry_u8(carry, value1, value2, &value1);
      |            ^~~~~~~~~~~~
.\slimcpplib\include\slimcpplib\long_math_msvc.h:274:12: error: use of undeclared identifier '_addcarry_u16'
  274 |     return _addcarry_u16(carry, value1, value2, &value1);
      |            ^~~~~~~~~~~~~
.\slimcpplib\include\slimcpplib\long_math_msvc.h:322:12: error: use of undeclared identifier '_subborrow_u8'
  322 |     return _subborrow_u8(0, value1, value2, &value1);
      |            ^~~~~~~~~~~~~
.\slimcpplib\include\slimcpplib\long_math_msvc.h:330:12: error: use of undeclared identifier '_subborrow_u16'
  330 |     return _subborrow_u16(0, value1, value2, &value1);
      |            ^~~~~~~~~~~~~~
.\slimcpplib\include\slimcpplib\long_math_msvc.h:358:12: error: use of undeclared identifier '_subborrow_u8'
  358 |     return _subborrow_u8(borrow, value1, value2, &value1);
      |            ^~~~~~~~~~~~~
.\slimcpplib\include\slimcpplib\long_math_msvc.h:366:12: error: use of undeclared identifier '_subborrow_u16'
  366 |     return _subborrow_u16(static_cast<uint8_t>(borrow), value1, value2, &value1);
      |            ^~~~~~~~~~~~~~
In file included from .\test.cpp:1:
In file included from .\slimcpplib\include\slimcpplib/long_int.h:39:
.\slimcpplib\include\slimcpplib\long_uint.h:1032:32: warning: identifier '_ui128' preceded by whitespace in a literal
      operator declaration is deprecated [-Wdeprecated-literal-operator]
 1032 | constexpr uint128_t operator"" _ui128() noexcept
      |                     ~~~~~~~~~~~^~~~~~
      |                     operator""_ui128
.\slimcpplib\include\slimcpplib\long_uint.h:1038:32: warning: identifier '_ui256' preceded by whitespace in a literal
      operator declaration is deprecated [-Wdeprecated-literal-operator]
 1038 | constexpr uint256_t operator"" _ui256() noexcept
      |                     ~~~~~~~~~~~^~~~~~
      |                     operator""_ui256
In file included from .\test.cpp:1:
.\slimcpplib\include\slimcpplib/long_int.h:590:31: warning: identifier '_si128' preceded by whitespace in a literal
      operator declaration is deprecated [-Wdeprecated-literal-operator]
  590 | constexpr int128_t operator"" _si128() noexcept
      |                    ~~~~~~~~~~~^~~~~~
      |                    operator""_si128
.\slimcpplib\include\slimcpplib/long_int.h:596:31: warning: identifier '_si256' preceded by whitespace in a literal
      operator declaration is deprecated [-Wdeprecated-literal-operator]
  596 | constexpr int256_t operator"" _si256() noexcept
      |                    ~~~~~~~~~~~^~~~~~
      |                    operator""_si256
4 warnings and 8 errors generated.
PS D:\Programming\C++>

@devatrun
Copy link
Copy Markdown
Owner

It has now been verified that the code is successfully compiled for clang 11 (and higher), gcc 11 (and higher) and msvc 14 (and higher). If you need to compile using clang in msvc mode, then you must first set the desired environment and environment variables, for example using vcvarsall.bat. This is necessary so that the correspondent headers can be found during compilation.
Unfortunately, your proposal will lead to fragility and heavy reliance on Microsoft's implementation.

@IlyaGredasov IlyaGredasov deleted the fix/clang-msvc-intrinsics-error branch April 29, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants