Replace use of __builtin_expect() with two macros, ecl_{likely,unlikely}
authorJuan Jose Garcia Ripoll <jjgarcia@jjgr-2.local>
Thu, 4 Feb 2010 15:54:05 +0000 (16:54 +0100)
committerJuan Jose Garcia Ripoll <jjgarcia@jjgr-2.local>
Thu, 4 Feb 2010 15:54:05 +0000 (16:54 +0100)
src/c/alloc_2.d
src/c/cfun.d
src/c/cmpaux.d
src/c/compiler.d
src/c/dpp.c
src/c/eval.d
src/c/macros.d
src/c/mapfun.d
src/cmp/cmplam.lsp
src/h/ecl.h
src/h/external.h

index e4bf514..5472524 100755 (executable)
@@ -217,7 +217,7 @@ allocate_object_own(register struct ecl_type_information *type_info)
 
         ecl_disable_interrupts_env(the_env);
        lb = type_info->size + TYPD_EXTRA_BYTES;
-       if (__builtin_expect(SMALL_OBJ(lb),1)) {
+       if (ecl_likely(SMALL_OBJ(lb))) {
                lg = GC_size_map[lb];
                opp = &(cl_object_free_list[lg]);
                LOCK();
@@ -258,7 +258,7 @@ cl_object_mark_proc(void *addr, struct GC_ms_entry *msp, struct GC_ms_entry *msl
 {
 #if 1
        cl_type t = ((cl_object)addr)->d.t;
-       if (__builtin_expect(t > t_start && t < t_end, 1)) {
+       if (ecl_likely(t > t_start && t < t_end)) {
                struct ecl_type_information *info = type_info + t;
                GC_word d = info->descriptor;
                GC_word *p;
@@ -466,7 +466,7 @@ ecl_alloc_object(cl_type t)
 {
 #ifdef GBC_BOEHM_PRECISE
         struct ecl_type_information *ti;
-        if (__builtin_expect(t > t_start && t < t_end, 1)) {
+        if (ecl_likely(t > t_start && t < t_end)) {
                 ti = type_info + t;
                 return ti->allocator(ti);
         }
index f2118a0..320f302 100644 (file)
@@ -33,7 +33,7 @@ ecl_make_cfun(cl_objectfn_fixed c_function, cl_object name, cl_object cblock, in
         cf->cfunfixed.file = Cnil;
         cf->cfunfixed.file_position = MAKE_FIXNUM(-1);
        cf->cfunfixed.narg = narg;
-       if (__builtin_expect(narg < 0 || narg > C_ARGUMENTS_LIMIT, 0))
+       if (ecl_unlikely(narg < 0 || narg > C_ARGUMENTS_LIMIT))
                 FEprogram_error_noreturn("ecl_make_cfun: function requires "
                                          "too many arguments.",0);
        return cf;
index 493fa2a..e9c94ed 100644 (file)
@@ -231,7 +231,7 @@ cl_parse_key(
        for (; args[0].narg > 1; ) {
                cl_object keyword = cl_va_arg(args);
                cl_object value = cl_va_arg(args);
-               if (__builtin_expect(!SYMBOLP(keyword), 0))
+               if (ecl_unlikely(!SYMBOLP(keyword)))
                        FEprogram_error_noreturn("LAMBDA: Keyword expected, got ~S.",
                                                  1, keyword);
                if (rest != NULL) {
@@ -255,10 +255,10 @@ cl_parse_key(
                        unknown_keyword = keyword;
        goon:;
        }
-       if (__builtin_expect(args[0].narg != 0, 0))
+       if (ecl_unlikely(args[0].narg != 0))
                FEprogram_error_noreturn("Odd number of keys", 0);
-       if (__builtin_expect(unknown_keyword != OBJNULL && !allow_other_keys &&
-                             (supplied_allow_other_keys == Cnil ||
-                              supplied_allow_other_keys == OBJNULL), 0))
+       if (ecl_unlikely(unknown_keyword != OBJNULL && !allow_other_keys &&
+                         (supplied_allow_other_keys == Cnil ||
+                          supplied_allow_other_keys == OBJNULL)))
                FEprogram_error("Unknown keyword ~S", 1, unknown_keyword);
 }
index 7f1af4e..3039926 100644 (file)
@@ -216,7 +216,7 @@ asm_clear(cl_env_ptr env, cl_index h) {
 
 static void
 asm_op2(cl_env_ptr env, int code, int n) {
-       if (__builtin_expect(n < -MAX_OPARG || MAX_OPARG < n, 0))
+       if (ecl_unlikely(n < -MAX_OPARG || MAX_OPARG < n))
                FEprogram_error_noreturn("Argument to bytecode is too large", 0);
        asm_op(env, code);
        asm_arg(env, n);
@@ -241,9 +241,9 @@ asm_jmp(cl_env_ptr env, int op) {
 static void
 asm_complete(cl_env_ptr env, int op, cl_index pc) {
        cl_fixnum delta = current_pc(env) - pc;  /* [1] */
-       if (__builtin_expect(op && (asm_ref(env, pc-1) != op), 0))
+       if (ecl_unlikely(op && (asm_ref(env, pc-1) != op)))
                FEprogram_error_noreturn("Non matching codes in ASM-COMPLETE2", 0);
-       else if (__builtin_expect(delta < -MAX_OPARG || delta > MAX_OPARG, 0))
+       else if (ecl_unlikely(delta < -MAX_OPARG || delta > MAX_OPARG))
                FEprogram_error_noreturn("Too large jump", 0);
        else {
 #ifdef ECL_SMALL_BYTECODES
index bbf46cf..9c9a08a 100755 (executable)
@@ -675,7 +675,9 @@ put_declaration(void)
   }
   if (nopt == 0 && !rest_flag && !key_flag) {
     put_lineno();
-    fprintf(out, "\tif (__builtin_expect(narg!=%d,0)) FEwrong_num_arguments(MAKE_FIXNUM(%d));\n", nreq, function_code);
+    fprintf(out, "\tif (ecl_unlikely(narg!=%d))");
+    fprintf(out, "\t   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 +698,11 @@ put_declaration(void)
                rest_var, rest_var, ((nreq > 0) ? required[nreq-1] : "narg"),
                nreq);
     put_lineno();
-    fprintf(out, "\tif (__builtin_expect(narg < %d", nreq);
+    fprintf(out, "\tif (ecl_unlikely(narg < %d", nreq);
     if (nopt > 0 && !rest_flag && !key_flag) {
       fprintf(out, "|| narg > %d", nreq + nopt);
     }
-    fprintf(out, ",0)) FEwrong_num_arguments(MAKE_FIXNUM(%d));\n", function_code);
+    fprintf(out, ")) 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 4d4b456..bdc2feb 100644 (file)
@@ -43,11 +43,11 @@ ecl_apply_from_stack_frame(cl_object frame, cl_object x)
        cl_object fun = x;
       AGAIN:
         frame->frame.env->function = fun;
-       if (__builtin_expect(fun == OBJNULL || fun == Cnil, 0))
+       if (ecl_unlikely(fun == OBJNULL || fun == Cnil))
                FEundefined_function(x);
        switch (type_of(fun)) {
        case t_cfunfixed:
-               if (__builtin_expect(narg != (cl_index)fun->cfun.narg, 0))
+               if (ecl_unlikely(narg != (cl_index)fun->cfun.narg))
                        FEwrong_num_arguments(fun);
                return APPLY_fixed(narg, fun->cfunfixed.entry_fixed, sp);
        case t_cfun:
@@ -68,7 +68,7 @@ ecl_apply_from_stack_frame(cl_object frame, cl_object x)
                goto AGAIN;
 #endif
        case t_symbol:
-               if (__builtin_expect(fun->symbol.stype & stp_macro, 0))
+               if (ecl_unlikely(fun->symbol.stype & stp_macro))
                        FEundefined_function(x);
                fun = SYM_FUN(fun);
                goto AGAIN;
@@ -86,7 +86,7 @@ ecl_function_dispatch(cl_env_ptr env, cl_object x)
 {
        cl_object fun = x;
  AGAIN:
-       if (__builtin_expect(fun == OBJNULL || fun == Cnil, 0))
+       if (ecl_unlikely(fun == OBJNULL || fun == Cnil))
                FEundefined_function(x);
        switch (type_of(fun)) {
        case t_cfunfixed:
@@ -104,7 +104,7 @@ ecl_function_dispatch(cl_env_ptr env, cl_object x)
                 return fun->instance.entry;
 #endif
        case t_symbol:
-               if (__builtin_expect(fun->symbol.stype & stp_macro, 0))
+               if (ecl_unlikely(fun->symbol.stype & stp_macro))
                        FEundefined_function(x);
                fun = SYM_FUN(fun);
                goto AGAIN;
@@ -153,7 +153,7 @@ cl_funcall(cl_narg narg, cl_object function, ...)
                                ecl_stack_frame_push(frame, lastarg->frame.base[i]);
                        }
                } else loop_for_in (lastarg) {
-                        if (__builtin_expect(i >= CALL_ARGUMENTS_LIMIT, 0)) {
+                        if (ecl_unlikely(i >= CALL_ARGUMENTS_LIMIT)) {
                                ecl_stack_frame_close(frame);
                                FEprogram_error_noreturn("CALL-ARGUMENTS-LIMIT exceeded",0);
                        }
index 44a19ff..9a6dbd7 100644 (file)
@@ -174,7 +174,7 @@ static cl_object
 when_macro(cl_object whole, cl_object env)
 {
        cl_object args = CDR(whole);
-       if (__builtin_expect(ecl_endp(args), 0))
+       if (ecl_unlikely(ecl_endp(args)))
                FEprogram_error_noreturn("Syntax error: ~S.", 1, whole);
        return cl_list(3, @'if', CAR(args), CONS(@'progn', CDR(args)));
 }
index bdc5a06..ce064a1 100644 (file)
@@ -26,7 +26,7 @@
        ECL_STACK_FRAME_FROM_VA_LIST(env,cdrs_frame,list);              \
        ECL_STACK_FRAME_COPY(cars_frame, cdrs_frame);                   \
        narg = cars_frame->frame.size;                                  \
-       if (__builtin_expect(narg == 0, 0)) {                           \
+       if (ecl_unlikely(narg == 0)) {                                  \
                FEprogram_error_noreturn("MAP*: Too few arguments", 0); \
        }
 
index 35e429a..46c46c0 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 (__builtin_expect(narg!=" nreq ",0)) FEwrong_num_arguments_anonym();")
+       (wt-nl "if (ecl_unlikely(narg!=" nreq ")) FEwrong_num_arguments_anonym();")
        (when varargs
          (when requireds
-           (wt-nl "if (__builtin_expect(narg<" nreq ",0)) FEwrong_num_arguments_anonym();"))
+           (wt-nl "if (ecl_unlikely(narg<" nreq ")) FEwrong_num_arguments_anonym();"))
          (unless (or rest keywords allow-other-keys)
-           (wt-nl "if (__builtin_expect(narg>" (+ nreq nopt) ",0)) FEwrong_num_arguments_anonym();"))))
+           (wt-nl "if (ecl_unlikely(narg>" (+ nreq nopt) ")) FEwrong_num_arguments_anonym();"))))
     (wt-nl "{"))
 
   ;; If the number of required arguments exceeds the number of variables we
index 6096b9c..d131027 100644 (file)
 #include <ecl/unify.h>
 #endif
 
-#if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
-#define ECL_INLINE inline
-#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);
 
 #endif /* ECL_H */
index 379424c..c8923ce 100755 (executable)
@@ -5,6 +5,24 @@ extern "C" {
 
 #define _ARGS(x) x
 
+#if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
+#define ECL_INLINE inline
+#else
+#define ECL_INLINE
+#endif
+#if !defined(__GNUC__)
+# define ecl_likely(form) (form)
+# define ecl_unlikely(form) (form)
+#else
+# if (__GNUC__ < 3)
+#  define ecl_likely(form) (form)
+#  define ecl_unlikely(form) (form)
+# else
+#  define ecl_likely(form) __builtin_expect(form,1)
+#  define ecl_unlikely(form) __builtin_expect(form,0)
+# endif
+#endif
+
 /*
  * Per-thread data.
  */