poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Patch] Do not rely on optimize function attribute


From: Luca Saiu
Subject: [Patch] Do not rely on optimize function attribute
Date: Sun, 28 Jun 2020 18:06:39 +0200
User-agent: Gnus (Gnus v5.13), GNU Emacs 27.0.50, x86_64-pc-linux-gnu

Here is the patch we have discussed about.  Is it okay?

Regards,

-- 
Luca Saiu
* My personal web site:  http://ageinghacker.net
* GNU epsilon:           http://www.gnu.org/software/epsilon
* Jitter:                http://ageinghacker.net/projects/jitter

I support everyone's freedom of mocking any opinion or belief, no
matter how deeply held, with open disrespect and the same unrelented
enthusiasm of a toddler who has just learned the word "poo".
diff --git a/ChangeLog b/ChangeLog
index fe5481ba..f039e08f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2020-06-28  Luca Saiu  <positron@gnu.org>
+
+       do not rely on the unreliable "optimize" GCC function attribute
+       * libpoke/pvm-env.c (pvm_env_back): New static function.
+       (pvm_env_lookup, pvm_env_set_var): Rewrite avoiding recursion,
+       and factor the commen logic using the new static function.
+       Remove __attribute__((optimize ("optimize-sibling-calls"))).
+       Remove comment, now obsolete.
+
 2020-06-24  Jose E. Marchesi  <jemarch@gnu.org>
 
        * configure.ac (PACKAGE_BUGZILLA): ac_define.
diff --git a/libpoke/pvm-env.c b/libpoke/pvm-env.c
index dd25d3e9..04c60db6 100644
--- a/libpoke/pvm-env.c
+++ b/libpoke/pvm-env.c
@@ -87,25 +87,28 @@ pvm_env_register (pvm_env env, pvm_val val)
   env->vars[env->num_vars++] = val;
 }
 
-/* Note the function attribute to assure the functions are compiled
-   with tail-recursion optimization.  */
+/* Given an environment return the frame back frames up from the bottom
+   one.  back is allowed to be zero, but not negative. */
+static pvm_env
+pvm_env_back (pvm_env env, int back)
+{
+  pvm_env frame = env;
+  int i;
+  for (i = 0; i < back; i ++)
+    frame = frame->up;
+  return frame;
+}
 
-pvm_val __attribute__((optimize ("optimize-sibling-calls")))
+pvm_val
 pvm_env_lookup (pvm_env env, int back, int over)
 {
-  if (back == 0)
-    return env->vars[over];
-  else
-    return pvm_env_lookup (env->up, back - 1, over);
+  return pvm_env_back (env, back)->vars[over];
 }
 
-void __attribute__((optimize ("optimize-sibling-calls")))
+void
 pvm_env_set_var (pvm_env env, int back, int over, pvm_val val)
 {
-  if (back == 0)
-    env->vars[over] = val;
-  else
-    pvm_env_set_var (env->up, back - 1, over, val);
+  pvm_env_back (env, back)->vars[over] = val;
 }
 
 int

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]