This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-ffi.git


The following commit(s) were added to refs/heads/main by this push:
     new 4b3b01a8 [FIX] Fix reference counting compilation on MSVC x86 (#916)
4b3b01a8 is described below

commit 4b3b01a89228fab58f41a9dcb48503625926f292
Author: miyan <[email protected]>
AuthorDate: Wed Nov 4 22:25:56 2026 +0800

    [FIX] Fix reference counting compilation on MSVC x86 (#916)
    
    Another issue found in https://github.com/microsoft/vcpkg/pull/54810
    
    build error on 32bit:
    ```
    D:\b\tvm-ffi\src\v0.1.15-e4904dcca0.clean\include\tvm/ffi/object.h(263): 
error C3861: '_InterlockedIncrement64': identifier not found
    D:\b\tvm-ffi\src\v0.1.15-e4904dcca0.clean\include\tvm/ffi/object.h(320): 
error C3861: '_InterlockedDecrement64': identifier not found
    ```
    
    Use the Windows SDK `InterlockedIncrement64` and
    `InterlockedDecrement64` wrappers, which support both 32-bit x86 and
    64-bit x64 targets. On x86, they use a compare-exchange loop; on x64,
    they map directly to the corresponding intrinsics.
---
 include/tvm/ffi/object.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/tvm/ffi/object.h b/include/tvm/ffi/object.h
index e7bbe129..7144b432 100644
--- a/include/tvm/ffi/object.h
+++ b/include/tvm/ffi/object.h
@@ -260,7 +260,8 @@ class Object {
   /*! \brief increase strong reference count, the caller must already hold a 
strong reference */
   TVM_FFI_INLINE void IncRef() {
 #ifdef _MSC_VER
-    _InterlockedIncrement64(
+    // Use the Windows SDK wrapper, which also supports 32-bit x86.
+    InterlockedIncrement64(
         reinterpret_cast<volatile __int64*>(&header_.combined_ref_count));  // 
NOLINT(*)
 #else
     __atomic_fetch_add(&(header_.combined_ref_count), 1, __ATOMIC_RELAXED);
@@ -317,7 +318,7 @@ class Object {
 #ifdef _MSC_VER
     // use simpler impl in windows to ensure correctness
     uint64_t count_before_sub =
-        _InterlockedDecrement64(                                              
//
+        InterlockedDecrement64(                                               
//
             reinterpret_cast<volatile __int64*>(&header_.combined_ref_count)  
// NOLINT(*)
             ) +
         1;

Reply via email to