This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Using __builtin_expect() in the body of unlikely branch


On Mon, 7 Jan 2019, Konstantin Kharlamov wrote:

In most projects a definite pattern that's unlikely to be executed is a PRINT_ERR macro which is basically a wrapper around fprintf() call. E.g.

	if (some_error) {
		PRINT_ERR("ERR");
		// do cleanup
		return;
	}

I wonder, is there a way to hint GCC that, whenever that code appears, whatever branch was prior to that is unlikely to be executed?

Make PRINT_ERR a function with __attribute__((cold)).

--
Marc Glisse


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]