]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
benchtests: Add attribute_optimize
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 6 Feb 2024 19:51:25 +0000 (16:51 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 28 Oct 2025 16:54:55 +0000 (13:54 -0300)
Similar to tst-printf-bz18872.sh, add the attribute_optimize to avoid
build failures with compilers that do not support "GCC optimize" pragma.

benchtests/bench-pthread-lock-base.c
benchtests/bench-pthread-locks.c
benchtests/bench-util.h

index 5386addf0416edfcdfa9003202c9bf08526e4815..c8c90c7d6aa3bc05c7d75e6b2b5bd233692c4fa6 100644 (file)
@@ -28,6 +28,7 @@
 #include <sys/time.h>
 #include <sys/sysinfo.h>
 #include "bench-timing.h"
+#include "bench-util.h"
 #include "json-lib.h"
 
 static bench_lock_t lock;
@@ -36,10 +37,8 @@ static pthread_barrier_t barrier;
 
 #define START_ITERS 1000
 
-#pragma GCC push_options
-#pragma GCC optimize(1)
-
-static int __attribute__ ((noinline)) fibonacci (int i)
+static int __attribute__ ((noinline)) attribute_optimize (1)
+fibonacci (int i)
 {
   asm("");
   if (i > 2)
@@ -48,6 +47,7 @@ static int __attribute__ ((noinline)) fibonacci (int i)
 }
 
 static void
+attribute_optimize (1)
 do_filler (void)
 {
   char buf1[512], buf2[512];
@@ -56,6 +56,7 @@ do_filler (void)
 }
 
 static void
+attribute_optimize (1)
 do_filler_shared (void)
 {
   static char buf1[512], buf2[512];
@@ -63,8 +64,6 @@ do_filler_shared (void)
   memcpy (buf1, buf2, f);
 }
 
-#pragma GCC pop_options
-
 #define UNIT_WORK_CRT do_filler_shared ()
 #define UNIT_WORK_NON_CRT do_filler ()
 
index 8971c77da950c468b0d811aab295fbaafce2798e..6f219db999849d7d114ca93d1b63458525bd0cd0 100644 (file)
@@ -29,6 +29,7 @@
 #include <sys/time.h>
 #include <math.h>
 #include "bench-timing.h"
+#include "bench-util.h"
 #include "json-lib.h"
 
 /* The point of this benchmark is to measure the overhead of an empty
@@ -61,10 +62,7 @@ typedef timing_t (*test_t)(long, int);
    total time each test iteration takes, so as to not swamp the useful
    timings.  */
 
-#pragma GCC push_options
-#pragma GCC optimize(1)
-
-static int __attribute__((noinline))
+static int __attribute__((noinline)) attribute_optimize (1)
 fibonacci (int i)
 {
   asm("");
@@ -73,7 +71,7 @@ fibonacci (int i)
   return 10+i;
 }
 
-static void
+static void attribute_optimize (1)
 do_filler (void)
 {
   static char buf1[512], buf2[512];
@@ -81,8 +79,6 @@ do_filler (void)
   memcpy (buf1, buf2, f);
 }
 
-#pragma GCC pop_options
-
 static timing_t
 test_mutex (long iters, int filler)
 {
index 02180c388744faeee240f6e51fb6c4669571256f..819fb3482a86efbfbe87a7228118e21c1cfa5ee8 100644 (file)
     __v;                                         \
   })
 
+#if __GNUC_PREREQ (4, 4) || __glibc_has_attribute (__optimize__)
+# define attribute_optimize(level) __attribute__ ((optimize (level)))
+#else
+# define attribute_optimize(level)
+#endif
+
 #ifndef START_ITER
 # define START_ITER (100000000)
 #endif