[PATCH 7/13] Coarray shared memory library

Jerry D <[email protected]>
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
Dear all, as requested,

See attached patch 7 of 13

Best Regards,

Jerry
pr88076_v4_7.diff (text/x-patch, 1.3 KB)
commit a33545504b85ea484a0c75526463488816063ecb
Author: Andre Vehreschild <[email protected]>
Date:   Mon Sep 1 14:11:27 2025 +0200

    Fortran: Detect working CLZL or use alternative.
    
    libgfortran/ChangeLog:
    
            * caf/shmem/allocator.c (next_power_of_two): Use sane clzl
            implementation or alternative.

diff --git a/libgfortran/caf/shmem/allocator.c b/libgfortran/caf/shmem/allocator.c
index d900167cfc2..3ea4d50e045 100644
--- a/libgfortran/caf/shmem/allocator.c
+++ b/libgfortran/caf/shmem/allocator.c
@@ -25,6 +25,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 /* Main allocation routine, works like malloc.  Round up allocations
    to the next power of two and keep free lists in buckets.  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "libgfortran.h"
 
 #include "allocator.h"
@@ -74,8 +78,16 @@ allocator_init_supervisor (allocator *a, allocator_shared *s, shared_memory sm)
 static size_t
 next_power_of_two (size_t size)
 {
+#ifdef HAVE_SANE_BUILTIN_CLZL
   assert (size);
+#if (__INTPTR_WIDTH__ == 64)
   return 1 << (VOIDP_BITS - __builtin_clzl (size - 1));
+#else
+  return 1 << (VOIDP_BITS - __builtin_clz (size - 1));
+#endif
+#else
+  return 1 << (int)ceil(log2(size));
+#endif
 }
 
 shared_mem_ptr
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.