Use of __builtin_expect() to mark rare error conditions. Use of __attribute__((noretu...
authorJuan Jose Garcia Ripoll <jjgarcia@jjgr-2.local>
Wed, 3 Feb 2010 22:30:16 +0000 (23:30 +0100)
committerJuan Jose Garcia Ripoll <jjgarcia@jjgr-2.local>
Wed, 3 Feb 2010 22:30:16 +0000 (23:30 +0100)
src/c/alloc_2.d
src/c/dpp.c
src/cmp/cmplam.lsp
src/h/ecl.h
src/h/external.h

index 13ceec2..e4bf514 100755 (executable)
 #include <winsock.h>
 #endif
 
-#if !defined(__GNUC__)
-# define __builtin_expect(form,value) (form)
-#else
-# if (__GNUC__ < 3)
-#  define __builtin_expect(form,value) (form)
-# endif
-#endif
-
 #ifdef GBC_BOEHM
 
 static void finalize_queued();
index 75c80fe..bbf46cf 100755 (executable)
@@ -675,7 +675,7 @@ put_declaration(void)
   }
   if (nopt == 0 && !rest_flag && !key_flag) {
     put_lineno();
-    fprintf(out, "\tif (narg!=%d) FEwrong_num_arguments(MAKE_FIXNUM(%d));\n", nreq, function_code);
+    fprintf(out, "\tif (__builtin_expect(narg!=%d,0)) FEwrong_num_arguments(MAKE_FIXNUM(%d));\n", nreq, function_code);
   } else {
     simple_varargs = !rest_flag && !key_flag && ((nreq + nopt) < 32);
     if (key_flag) {
@@ -696,11 +696,11 @@ put_declaration(void)
                rest_var, rest_var, ((nreq > 0) ? required[nreq-1] : "narg"),
                nreq);
     put_lineno();
-    fprintf(out, "\tif (narg < %d", nreq);
+    fprintf(out, "\tif (__builtin_expect(narg < %d", nreq);
     if (nopt > 0 && !rest_flag && !key_flag) {
       fprintf(out, "|| narg > %d", nreq + nopt);
     }
-    fprintf(out, ") FEwrong_num_arguments(MAKE_FIXNUM(%d));\n", function_code);
+    fprintf(out, ",0)) FEwrong_num_arguments(MAKE_FIXNUM(%d));\n", function_code);
     for (i = 0;  i < nopt;  i++) {
       put_lineno();
       fprintf(out, "\tif (narg > %d) {\n", nreq+i);
index e797db6..35e429a 100644 (file)
@@ -354,12 +354,12 @@ The function thus belongs to the type of functions that ecl_make_cfun accepts."
   (unless (or local-entry-p (not (compiler-check-args)))
     (incf *inline-blocks*)
     (if (and use-narg (not varargs))
-       (wt-nl "if(narg!=" nreq ") FEwrong_num_arguments_anonym();")
+       (wt-nl "if (__builtin_expect(narg!=" nreq ",0)) FEwrong_num_arguments_anonym();")
        (when varargs
          (when requireds
-           (wt-nl "if(narg<" nreq ") FEwrong_num_arguments_anonym();"))
+           (wt-nl "if (__builtin_expect(narg<" nreq ",0)) FEwrong_num_arguments_anonym();"))
          (unless (or rest keywords allow-other-keys)
-           (wt-nl "if(narg>" (+ nreq nopt) ") FEwrong_num_arguments_anonym();"))))
+           (wt-nl "if (__builtin_expect(narg>" (+ nreq nopt) ",0)) FEwrong_num_arguments_anonym();"))))
     (wt-nl "{"))
 
   ;; If the number of required arguments exceeds the number of variables we
index afb522d..6096b9c 100644 (file)
 #else
 #define ECL_INLINE
 #endif
+#if !defined(__GNUC__)
+# define __builtin_expect(form,value) (form)
+#else
+# if (__GNUC__ < 3)
+#  define __builtin_expect(form,value) (form)
+# endif
+#endif
 
 typedef void (*ecl_init_function_t)(cl_object block);
 
index 422c521..2cacf79 100755 (executable)
@@ -549,8 +549,8 @@ extern ECL_API void FEcannot_open(cl_object fn) /*__attribute__((noreturn))*/;
 extern ECL_API void FEend_of_file(cl_object strm) /*__attribute__((noreturn))*/;
 extern ECL_API void FEclosed_stream(cl_object strm) /*__attribute__ ((noreturn))*/;
 extern ECL_API void FEwrong_type_argument(cl_object type, cl_object value) /*__attribute__((noreturn))*/;
-extern ECL_API void FEwrong_num_arguments(cl_object fun) /*__attribute__((noreturn))*/;
-extern ECL_API void FEwrong_num_arguments_anonym(void) /*__attribute__((noreturn))*/;
+extern ECL_API void FEwrong_num_arguments(cl_object fun) __attribute__((noreturn));
+extern ECL_API void FEwrong_num_arguments_anonym(void) __attribute__((noreturn));
 extern ECL_API void FEunbound_variable(cl_object sym) /*__attribute__((noreturn))*/;
 extern ECL_API void FEinvalid_macro_call(cl_object obj) /*__attribute__((noreturn))*/;
 extern ECL_API void FEinvalid_variable(const char *s, cl_object obj) /*__attribute__((noreturn))*/;