[PATCH] Mark highly predictable branches as likely/unlikely

Matt Turner mattst88 at gmail.com
Wed Apr 7 15:49:16 PDT 2010


Highly predicatble branches include
 - unlikely: error conditions, such as those leading to
	- RADEON_FALLBACK
	- goto fail
	- return FALSE (as an error
 - likely: if (info->useEXA)

gtkperf scores on a Radeon 4650, original->new
GtkEntry - time:  0.05->0.05
GtkComboBox - time:  1.07->1.09
GtkComboBoxEntry - time:  0.80->0.80
GtkSpinButton - time:  0.37->0.35
GtkProgressBar - time:  0.31->0.30
GtkToggleButton - time:  0.32->0.31
GtkCheckButton - time:  0.21->0.20
GtkRadioButton - time:  0.28->0.28
GtkTextView - Add text - time:  0.74->0.72
GtkTextView - Scroll - time:  0.28->0.27
GtkDrawingArea - Lines - time:  0.92->0.93
GtkDrawingArea - Circles - time:  1.77->1.69
GtkDrawingArea - Text - time:  1.40->1.34
GtkDrawingArea - Pixbufs - time:  0.13->1.3
---
Total time:  8.67->8.46

Idea from Obscene_CNN.

Signed-off-by: Matt Turner <mattst88 at gmail.com>
---
 src/atombios_output.c            |    2 +-
 src/drmmode_display.c            |    6 +-
 src/r600_exa.c                   |  144 ++++++++++++++++------------------
 src/r600_textured_videofuncs.c   |    4 +-
 src/r6xx_accel.c                 |    4 +-
 src/radeon.h                     |   12 +++-
 src/radeon_accel.c               |    8 +-
 src/radeon_commonfuncs.c         |    2 +-
 src/radeon_dri.c                 |    8 +-
 src/radeon_dri2.c                |    6 +-
 src/radeon_driver.c              |   12 ++--
 src/radeon_exa.c                 |   20 +++---
 src/radeon_exa_funcs.c           |   44 +++++-----
 src/radeon_exa_render.c          |  160 ++++++++++++++++---------------------
 src/radeon_kms.c                 |   12 ++--
 src/radeon_legacy_memory.c       |    4 +-
 src/radeon_macros.h              |    2 +-
 src/radeon_textured_video.c      |   10 +-
 src/radeon_textured_videofuncs.c |   24 +++---
 src/radeon_vbo.h                 |    2 +-
 20 files changed, 233 insertions(+), 253 deletions(-)

diff --git a/src/atombios_output.c b/src/atombios_output.c
index 0a54657..14aef14 100644
--- a/src/atombios_output.c
+++ b/src/atombios_output.c
@@ -2189,7 +2189,7 @@ void RADEON_DP_GetDPCD(xf86OutputPtr output)
     int ret;
 
     ret = atom_dp_aux_native_read(output, DP_DPCD_REV, 0, 8, msg);
-    if (ret) {
+    if (unlikely(ret)) {
 	memcpy(radeon_output->dpcd, msg, 8);
 	if (0) {
 	    int i;
diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 399a6a7..a55c387 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -328,7 +328,7 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		}
 		ret = drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
 				     fb_id, x, y, output_ids, output_count, &kmode);
-		if (ret)
+		if (unlikely(ret))
 			xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR,
 				   "failed to set mode: %s", strerror(-ret));
 		else
@@ -440,7 +440,7 @@ drmmode_crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
 			   crtc->scrn->bitsPerPixel, rotate_pitch,
 			   rotate_bo->handle,
 			   &drmmode_crtc->rotate_fb_id);
-	if (ret) {
+	if (unlikely(ret)) {
 		ErrorF("failed to add rotate fb\n");
 	}
 
@@ -1092,7 +1092,7 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 			   scrn->bitsPerPixel, pitch * cpp,
 			   info->front_bo->handle,
 			   &drmmode->fb_id);
-	if (ret)
+	if (unlikely(ret))
 		goto fail;
 
 	if (!info->r600_shadow_fb) {
diff --git a/src/r600_exa.c b/src/r600_exa.c
index 26b59d8..9468b54 100644
--- a/src/r600_exa.c
+++ b/src/r600_exa.c
@@ -209,25 +209,25 @@ R600SetAccelState(ScrnInfoPtr pScrn,
     accel_state->planemask = planemask;
 
     /* bad pitch */
-    if (accel_state->src_obj[0].pitch & 7)
+    if (unlikely(accel_state->src_obj[0].pitch & 7))
 	RADEON_FALLBACK(("Bad src pitch 0x%08x\n", accel_state->src_obj[0].pitch));
 
     /* bad offset */
-    if (accel_state->src_obj[0].offset & 0xff)
+    if (unlikely(accel_state->src_obj[0].offset & 0xff))
 	RADEON_FALLBACK(("Bad src offset 0x%08x\n", accel_state->src_obj[0].offset));
 
     /* bad pitch */
-    if (accel_state->src_obj[1].pitch & 7)
+    if (unlikely(accel_state->src_obj[1].pitch & 7))
 	RADEON_FALLBACK(("Bad src pitch 0x%08x\n", accel_state->src_obj[1].pitch));
 
     /* bad offset */
-    if (accel_state->src_obj[1].offset & 0xff)
+    if (unlikely(accel_state->src_obj[1].offset & 0xff))
 	RADEON_FALLBACK(("Bad src offset 0x%08x\n", accel_state->src_obj[1].offset));
 
-    if (accel_state->dst_obj.pitch & 7)
+    if (unlikely(accel_state->dst_obj.pitch & 7))
 	RADEON_FALLBACK(("Bad dst pitch 0x%08x\n", accel_state->dst_obj.pitch));
 
-    if (accel_state->dst_obj.offset & 0xff)
+    if (unlikely(accel_state->dst_obj.offset & 0xff))
 	RADEON_FALLBACK(("Bad dst offset 0x%08x\n", accel_state->dst_obj.offset));
 
     accel_state->vs_size = 512;
@@ -250,7 +250,7 @@ R600SetAccelState(ScrnInfoPtr pScrn,
 	    radeon_cs_space_add_persistent_bo(info->cs, accel_state->dst_obj.bo,
 					      0, accel_state->dst_obj.domain);
 	ret = radeon_cs_space_check(info->cs);
-	if (ret)
+	if (unlikely(ret))
 	    RADEON_FALLBACK(("Not enough RAM to hw accel operation\n"));
 
     } else
@@ -294,9 +294,9 @@ R600PrepareSolid(PixmapPtr pPix, int alu, Pixel pm, Pixel fg)
     float ps_alu_consts[4];
     struct r600_accel_object dst;
 
-    if (!R600CheckBPP(pPix->drawable.bitsPerPixel))
+    if (unlikely(!R600CheckBPP(pPix->drawable.bitsPerPixel)))
 	RADEON_FALLBACK(("R600CheckDatatype failed\n"));
-    if (!R600ValidPM(pm, pPix->drawable.bitsPerPixel))
+    if (unlikely(!R600ValidPM(pm, pPix->drawable.bitsPerPixel)))
 	RADEON_FALLBACK(("invalid planemask\n"));
 
 #if defined(XF86DRM_MODE)
@@ -316,12 +316,12 @@ R600PrepareSolid(PixmapPtr pPix, int alu, Pixel pm, Pixel fg)
     dst.bpp = pPix->drawable.bitsPerPixel;
     dst.domain = RADEON_GEM_DOMAIN_VRAM;
 	
-    if (!R600SetAccelState(pScrn,
+    if (unlikely(!R600SetAccelState(pScrn,
 			   NULL,
 			   NULL,
 			   &dst,
 			   accel_state->solid_vs_offset, accel_state->solid_ps_offset,
-			   alu, pm))
+			   alu, pm)))
 	return FALSE;
 
     CLEAR (cb_conf);
@@ -713,11 +713,11 @@ R600PrepareCopy(PixmapPtr pSrc,   PixmapPtr pDst,
     struct radeon_accel_state *accel_state = info->accel_state;
     struct r600_accel_object src_obj, dst_obj;
 
-    if (!R600CheckBPP(pSrc->drawable.bitsPerPixel))
+    if (unlikely(!R600CheckBPP(pSrc->drawable.bitsPerPixel)))
 	RADEON_FALLBACK(("R600CheckDatatype src failed\n"));
-    if (!R600CheckBPP(pDst->drawable.bitsPerPixel))
+    if (unlikely(!R600CheckBPP(pDst->drawable.bitsPerPixel)))
 	RADEON_FALLBACK(("R600CheckDatatype dst failed\n"));
-    if (!R600ValidPM(planemask, pDst->drawable.bitsPerPixel))
+    if (unlikely(!R600ValidPM(planemask, pDst->drawable.bitsPerPixel)))
 	RADEON_FALLBACK(("Invalid planemask\n"));
 
     dst_obj.pitch = exaGetPixmapPitch(pDst) / (pDst->drawable.bitsPerPixel / 8);
@@ -754,12 +754,12 @@ R600PrepareCopy(PixmapPtr pSrc,   PixmapPtr pDst,
     dst_obj.bpp = pDst->drawable.bitsPerPixel;
     dst_obj.domain = RADEON_GEM_DOMAIN_VRAM;
 
-    if (!R600SetAccelState(pScrn,
+    if (unlikely(!R600SetAccelState(pScrn,
 			   &src_obj,
 			   NULL,
 			   &dst_obj,
 			   accel_state->copy_vs_offset, accel_state->copy_ps_offset,
-			   rop, planemask))
+			   rop, planemask)))
 	return FALSE;
 
     if (accel_state->same_surface == TRUE) {
@@ -774,12 +774,12 @@ R600PrepareCopy(PixmapPtr pSrc,   PixmapPtr pDst,
 	    accel_state->copy_area_bo = radeon_bo_open(info->bufmgr, 0, size, 0,
 						       RADEON_GEM_DOMAIN_VRAM,
 						       0);
-	    if (accel_state->copy_area_bo == NULL)
+	    if (unlikely(accel_state->copy_area_bo == NULL))
 		RADEON_FALLBACK(("temp copy surface alloc failed\n"));
 
 	    radeon_cs_space_add_persistent_bo(info->cs, accel_state->copy_area_bo,
 					      RADEON_GEM_DOMAIN_VRAM, RADEON_GEM_DOMAIN_VRAM);
-	    if (radeon_cs_space_check(info->cs)) {
+	    if (unlikely(radeon_cs_space_check(info->cs))) {
 		radeon_bo_unref(accel_state->copy_area_bo);
 		accel_state->copy_area_bo = NULL;
 		return FALSE;
@@ -793,7 +793,7 @@ R600PrepareCopy(PixmapPtr pSrc,   PixmapPtr pDst,
 		accel_state->copy_area = NULL;
 	    }
 	    accel_state->copy_area = exaOffscreenAlloc(pDst->drawable.pScreen, size, 256, TRUE, NULL, NULL);
-	    if (!accel_state->copy_area)
+	    if (unlikely(!accel_state->copy_area))
 		RADEON_FALLBACK(("temp copy surface alloc failed\n"));
 	}
     } else
@@ -1018,19 +1018,18 @@ static Bool R600CheckCompositeTexture(PicturePtr pPict,
     max_tex_w = 8192;
     max_tex_h = 8192;
 
-    if ((w > max_tex_w) || (h > max_tex_h))
+    if (unlikely((w > max_tex_w) || (h > max_tex_h)))
 	RADEON_FALLBACK(("Picture w/h too large (%dx%d)\n", w, h));
 
     for (i = 0; i < sizeof(R600TexFormats) / sizeof(R600TexFormats[0]); i++) {
 	if (R600TexFormats[i].fmt == pPict->format)
 	    break;
     }
-    if (i == sizeof(R600TexFormats) / sizeof(R600TexFormats[0]))
+    if (unlikely(i == sizeof(R600TexFormats) / sizeof(R600TexFormats[0])))
 	RADEON_FALLBACK(("Unsupported picture format 0x%x\n",
 			 (int)pPict->format));
 
-    if (pPict->filter != PictFilterNearest &&
-	pPict->filter != PictFilterBilinear)
+    if (unlikely(pPict->filter != PictFilterNearest && pPict->filter != PictFilterBilinear))
 	RADEON_FALLBACK(("Unsupported filter 0x%x\n", pPict->filter));
 
     /* for REPEAT_NONE, Render semantics are that sampling outside the source
@@ -1043,7 +1042,7 @@ static Bool R600CheckCompositeTexture(PicturePtr pPict,
      */
     /* FIXME R6xx */
     if (pPict->transform != 0 && repeatType == RepeatNone && PICT_FORMAT_A(pPict->format) == 0) {
-	if (!(((op == PictOpSrc) || (op == PictOpClear)) && (PICT_FORMAT_A(pDstPict->format) == 0)))
+	if (unlikely(!(((op == PictOpSrc) || (op == PictOpClear)) && (PICT_FORMAT_A(pDstPict->format) == 0))))
 	    RADEON_FALLBACK(("REPEAT_NONE unsupported for transformed xRGB source\n"));
     }
 
@@ -1295,10 +1294,10 @@ static Bool R600CheckComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskP
     int max_tex_w, max_tex_h, max_dst_w, max_dst_h;
 
     /* Check for unsupported compositing operations. */
-    if (op >= (int) (sizeof(R600BlendOp) / sizeof(R600BlendOp[0])))
+    if (unlikely(op >= (int)(sizeof(R600BlendOp) / sizeof(R600BlendOp[0]))))
 	RADEON_FALLBACK(("Unsupported Composite op 0x%x\n", op));
 
-    if (!pSrcPicture->pDrawable)
+    if (unlikely(!pSrcPicture->pDrawable))
 	RADEON_FALLBACK(("Solid or gradient pictures not supported yet\n"));
 
     pSrcPixmap = RADEONGetDrawablePixmap(pSrcPicture->pDrawable);
@@ -1308,8 +1307,7 @@ static Bool R600CheckComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskP
     max_dst_w = 8192;
     max_dst_h = 8192;
 
-    if (pSrcPixmap->drawable.width >= max_tex_w ||
-	pSrcPixmap->drawable.height >= max_tex_h) {
+    if (unlikely(pSrcPixmap->drawable.width >= max_tex_w || pSrcPixmap->drawable.height >= max_tex_h)) {
 	RADEON_FALLBACK(("Source w/h too large (%d,%d).\n",
 			 pSrcPixmap->drawable.width,
 			 pSrcPixmap->drawable.height));
@@ -1317,8 +1315,7 @@ static Bool R600CheckComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskP
 
     pDstPixmap = RADEONGetDrawablePixmap(pDstPicture->pDrawable);
 
-    if (pDstPixmap->drawable.width >= max_dst_w ||
-	pDstPixmap->drawable.height >= max_dst_h) {
+    if (unlikely(pDstPixmap->drawable.width >= max_dst_w || pDstPixmap->drawable.height >= max_dst_h)) {
 	RADEON_FALLBACK(("Dest w/h too large (%d,%d).\n",
 			 pDstPixmap->drawable.width,
 			 pDstPixmap->drawable.height));
@@ -1327,13 +1324,12 @@ static Bool R600CheckComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskP
     if (pMaskPicture) {
 	PixmapPtr pMaskPixmap;
 
-	if (!pMaskPicture->pDrawable)
+	if (unlikely(!pMaskPicture->pDrawable))
 	    RADEON_FALLBACK(("Solid or gradient pictures not supported yet\n"));
 
 	pMaskPixmap = RADEONGetDrawablePixmap(pMaskPicture->pDrawable);
 
-	if (pMaskPixmap->drawable.width >= max_tex_w ||
-	    pMaskPixmap->drawable.height >= max_tex_h) {
+	if (unlikely(pMaskPixmap->drawable.width >= max_tex_w || pMaskPixmap->drawable.height >= max_tex_h)) {
 	    RADEON_FALLBACK(("Mask w/h too large (%d,%d).\n",
 			     pMaskPixmap->drawable.width,
 			     pMaskPixmap->drawable.height));
@@ -1344,22 +1340,20 @@ static Bool R600CheckComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskP
 	     * on the source value.  We can only get one of those into the
 	     * single source value that we get to blend with.
 	     */
-	    if (R600BlendOp[op].src_alpha &&
-		(R600BlendOp[op].blend_cntl & COLOR_SRCBLEND_mask) !=
-		(BLEND_ZERO << COLOR_SRCBLEND_shift)) {
+	    if (unlikely(R600BlendOp[op].src_alpha && (R600BlendOp[op].blend_cntl & COLOR_SRCBLEND_mask) != (BLEND_ZERO << COLOR_SRCBLEND_shift))) {
 		RADEON_FALLBACK(("Component alpha not supported with source "
 				 "alpha and source value blending.\n"));
 	    }
 	}
 
-	if (!R600CheckCompositeTexture(pMaskPicture, pDstPicture, op, 1))
+	if (unlikely(!R600CheckCompositeTexture(pMaskPicture, pDstPicture, op, 1)))
 	    return FALSE;
     }
 
-    if (!R600CheckCompositeTexture(pSrcPicture, pDstPicture, op, 0))
+    if (unlikely(!R600CheckCompositeTexture(pSrcPicture, pDstPicture, op, 0)))
 	return FALSE;
 
-    if (!R600GetDestFormat(pDstPicture, &tmp1))
+    if (unlikely(!R600GetDestFormat(pDstPicture, &tmp1)))
 	return FALSE;
 
     return TRUE;
@@ -1378,7 +1372,7 @@ static Bool R600PrepareComposite(int op, PicturePtr pSrcPicture,
     shader_config_t vs_conf, ps_conf;
     struct r600_accel_object src_obj, mask_obj, dst_obj;
 
-    if (pDst->drawable.bitsPerPixel < 8 || pSrc->drawable.bitsPerPixel < 8)
+    if (unlikely(pDst->drawable.bitsPerPixel < 8 || pSrc->drawable.bitsPerPixel < 8))
 	return FALSE;
 
 #if defined(XF86DRM_MODE)
@@ -1426,12 +1420,12 @@ static Bool R600PrepareComposite(int op, PicturePtr pSrcPicture,
 	mask_obj.bpp = pMask->drawable.bitsPerPixel;
 	mask_obj.domain = RADEON_GEM_DOMAIN_VRAM | RADEON_GEM_DOMAIN_GTT;
 
-	if (!R600SetAccelState(pScrn,
+	if (unlikely(!R600SetAccelState(pScrn,
 			       &src_obj,
 			       &mask_obj,
 			       &dst_obj,
 			       accel_state->comp_vs_offset, accel_state->comp_mask_ps_offset,
-			       3, 0xffffffff))
+			       3, 0xffffffff)))
 	    return FALSE;
 
 	accel_state->msk_pic = pMaskPicture;
@@ -1446,12 +1440,12 @@ static Bool R600PrepareComposite(int op, PicturePtr pSrcPicture,
 	    accel_state->src_alpha = FALSE;
 	}
     } else {
-	if (!R600SetAccelState(pScrn,
+	if (unlikely(!R600SetAccelState(pScrn,
 			       &src_obj,
 			       NULL,
 			       &dst_obj,
 			       accel_state->comp_vs_offset, accel_state->comp_ps_offset,
-			       3, 0xffffffff))
+			       3, 0xffffffff)))
 	    return FALSE;
 
 	accel_state->msk_pic = NULL;
@@ -1459,7 +1453,7 @@ static Bool R600PrepareComposite(int op, PicturePtr pSrcPicture,
 	accel_state->src_alpha = FALSE;
     }
 
-    if (!R600GetDestFormat(pDstPicture, &dst_format))
+    if (unlikely(!R600GetDestFormat(pDstPicture, &dst_format)))
 	return FALSE;
 
     CLEAR (cb_conf);
@@ -1479,14 +1473,14 @@ static Bool R600PrepareComposite(int op, PicturePtr pSrcPicture,
     set_screen_scissor(pScrn, accel_state->ib, 0, 0, accel_state->dst_obj.width, accel_state->dst_obj.height);
     set_window_scissor(pScrn, accel_state->ib, 0, 0, accel_state->dst_obj.width, accel_state->dst_obj.height);
 
-    if (!R600TextureSetup(pSrcPicture, pSrc, 0)) {
+    if (unlikely(!R600TextureSetup(pSrcPicture, pSrc, 0))) {
         R600IBDiscard(pScrn, accel_state->ib);
         r600_vb_discard(pScrn);
         return FALSE;
     }
 
     if (pMask) {
-        if (!R600TextureSetup(pMaskPicture, pMask, 1)) {
+        if (unlikely(!R600TextureSetup(pMaskPicture, pMask, 1))) {
             R600IBDiscard(pScrn, accel_state->ib);
             r600_vb_discard(pScrn);
             return FALSE;
@@ -1719,14 +1713,14 @@ R600CopyToVRAM(ScrnInfoPtr pScrn,
     drmBufPtr scratch;
     struct r600_accel_object scratch_obj, dst_obj;
 
-    if (dst_pitch & 7)
+    if (unlikely(dst_pitch & 7))
 	return FALSE;
 
-    if (dst_mc_addr & 0xff)
+    if (unlikely(dst_mc_addr & 0xff))
 	return FALSE;
 
     scratch = RADEONCPGetBuffer(pScrn);
-    if (scratch == NULL)
+    if (unlikely(scratch == NULL))
 	return FALSE;
 
     scratch_mc_addr = info->gartLocation + info->dri->bufStart + (scratch->idx * scratch->total);
@@ -1749,12 +1743,12 @@ R600CopyToVRAM(ScrnInfoPtr pScrn,
     dst_obj.bpp = bpp;
     dst_obj.domain = RADEON_GEM_DOMAIN_VRAM;
 
-    if (!R600SetAccelState(pScrn,
+    if (unlikely(!R600SetAccelState(pScrn,
 			   &scratch_obj,
 			   NULL,
 			   &dst_obj,
 			   accel_state->copy_vs_offset, accel_state->copy_ps_offset,
-			   3, 0xffffffff))
+			   3, 0xffffffff)))
 	return FALSE;
 
     /* memcopy from sys to scratch */
@@ -1834,16 +1828,16 @@ R600DownloadFromScreen(PixmapPtr pSrc, int x, int y, int w, int h,
     struct r600_accel_object scratch_obj, src_obj;
 
     /* bad pipe setup in drm prior to 1.32 */
-    if (info->dri->pKernelDRMVersion->version_minor < 32) {
+    if (unlikely(info->dri->pKernelDRMVersion->version_minor < 32)) {
 	    if ((info->ChipFamily == CHIP_FAMILY_RV740) && (w < 32 || h < 32))
 		    return FALSE;
     }
 
-    if (src_pitch & 7)
+    if (unlikely(src_pitch & 7))
 	return FALSE;
 
     scratch = RADEONCPGetBuffer(pScrn);
-    if (scratch == NULL)
+    if (unlikely(scratch == NULL))
 	return FALSE;
 
     scratch_mc_addr = info->gartLocation + info->dri->bufStart + (scratch->idx * scratch->total);
@@ -1865,12 +1859,12 @@ R600DownloadFromScreen(PixmapPtr pSrc, int x, int y, int w, int h,
     scratch_obj.domain = RADEON_GEM_DOMAIN_GTT;
     scratch_obj.bo = NULL;
 
-    if (!R600SetAccelState(pScrn,
+    if (unlikely(!R600SetAccelState(pScrn,
 			   &src_obj,
 			   NULL,
 			   &scratch_obj,
 			   accel_state->copy_vs_offset, accel_state->copy_ps_offset,
-			   3, 0xffffffff))
+			   3, 0xffffffff)))
 	return FALSE;
 
     /* blit from vram to scratch */
@@ -1933,19 +1927,19 @@ R600UploadToScreenCS(PixmapPtr pDst, int x, int y, int w, int h,
     int i;
     struct r600_accel_object src_obj, dst_obj;
 
-    if (bpp < 8)
+    if (unlikely(bpp < 8))
 	return FALSE;
 
     driver_priv = exaGetPixmapDriverPrivate(pDst);
 
     /* If we know the BO won't be busy, don't bother */
-    if (!radeon_bo_is_referenced_by_cs(driver_priv->bo, info->cs) &&
-	!radeon_bo_is_busy(driver_priv->bo, &dst_domain))
+    if (unlikely(!radeon_bo_is_referenced_by_cs(driver_priv->bo, info->cs) &&
+	!radeon_bo_is_busy(driver_priv->bo, &dst_domain)))
 	return FALSE;
 
     size = scratch_pitch * h;
     scratch = radeon_bo_open(info->bufmgr, 0, size, 0, RADEON_GEM_DOMAIN_GTT, 0);
-    if (scratch == NULL) {
+    if (unlikely(scratch == NULL)) {
 	return FALSE;
     }
 
@@ -1976,7 +1970,7 @@ R600UploadToScreenCS(PixmapPtr pDst, int x, int y, int w, int h,
     }
 
     r = radeon_bo_map(scratch, 0);
-    if (r) {
+    if (unlikely(r)) {
         r = FALSE;
         goto out;
     }
@@ -2019,7 +2013,7 @@ R600DownloadFromScreenCS(PixmapPtr pSrc, int x, int y, int w,
     Bool r;
     struct r600_accel_object src_obj, dst_obj;
 
-    if (bpp < 8)
+    if (unlikely(bpp < 8))
 	return FALSE;
 
     driver_priv = exaGetPixmapDriverPrivate(pSrc);
@@ -2035,12 +2029,12 @@ R600DownloadFromScreenCS(PixmapPtr pSrc, int x, int y, int w,
     if (!src_domain)
 	radeon_bo_is_busy(driver_priv->bo, &src_domain);
 
-    if (src_domain != RADEON_GEM_DOMAIN_VRAM)
+    if (unlikely(src_domain != RADEON_GEM_DOMAIN_VRAM))
 	return FALSE;
 
     size = scratch_pitch * h;
     scratch = radeon_bo_open(info->bufmgr, 0, size, 0, RADEON_GEM_DOMAIN_GTT, 0);
-    if (scratch == NULL) {
+    if (unlikely(scratch == NULL)) {
 	return FALSE;
     }
     radeon_cs_space_reset_bos(info->cs);
@@ -2051,7 +2045,7 @@ R600DownloadFromScreenCS(PixmapPtr pSrc, int x, int y, int w,
     accel_state->dst_obj.domain = RADEON_GEM_DOMAIN_GTT;
     radeon_cs_space_add_persistent_bo(info->cs, scratch, 0, accel_state->dst_obj.domain);
     r = radeon_cs_space_check(info->cs);
-    if (r) {
+    if (unlikely(r)) {
         r = FALSE;
         goto out;
     }
@@ -2091,7 +2085,7 @@ R600DownloadFromScreenCS(PixmapPtr pSrc, int x, int y, int w,
 	radeon_cs_flush_indirect(pScrn);
 
     r = radeon_bo_map(scratch, 0);
-    if (r) {
+    if (unlikely(r)) {
         r = FALSE;
         goto out;
     }
@@ -2156,7 +2150,7 @@ R600AllocShaders(ScrnInfoPtr pScrn, ScreenPtr pScreen)
     if (info->cs) {
 	accel_state->shaders_bo = radeon_bo_open(info->bufmgr, 0, size, 0,
 						 RADEON_GEM_DOMAIN_VRAM, 0);
-	if (accel_state->shaders_bo == NULL) {
+	if (unlikely(accel_state->shaders_bo == NULL)) {
 	    ErrorF("Allocating shader failed\n");
 	    return FALSE;
 	}
@@ -2168,7 +2162,7 @@ R600AllocShaders(ScrnInfoPtr pScrn, ScreenPtr pScreen)
 	accel_state->shaders = exaOffscreenAlloc(pScreen, size, 256,
 						 TRUE, NULL, NULL);
 
-	if (accel_state->shaders == NULL)
+	if (unlikely(accel_state->shaders == NULL))
 	    return FALSE;
     }
 
@@ -2188,7 +2182,7 @@ R600LoadShaders(ScrnInfoPtr pScrn)
 
     if (info->cs) {
 	ret = radeon_bo_map(accel_state->shaders_bo, 1);
-	if (ret) {
+	if (unlikely(ret)) {
 	    FatalError("failed to map shader %d\n", ret);
 	    return FALSE;
 	}
@@ -2276,7 +2270,7 @@ R600DrawInit(ScreenPtr pScreen)
     ScrnInfoPtr pScrn =  xf86Screens[pScreen->myNum];
     RADEONInfoPtr info   = RADEONPTR(pScrn);
 
-    if (info->accel_state->exa == NULL) {
+    if (unlikely(info->accel_state->exa == NULL)) {
 	xf86DrvMsg(pScreen->myNum, X_ERROR, "Memory map not set up\n");
 	return FALSE;
     }
@@ -2359,7 +2353,7 @@ R600DrawInit(ScreenPtr pScreen)
     } else
 	info->accel_state->vsync = FALSE;
 
-    if (!exaDriverInit(pScreen, info->accel_state->exa)) {
+    if (unlikely(!exaDriverInit(pScreen, info->accel_state->exa))) {
 	xfree(info->accel_state->exa);
 	return FALSE;
     }
@@ -2369,7 +2363,7 @@ R600DrawInit(ScreenPtr pScreen)
     if (!info->cs)
 #endif
 #endif
-	if (!info->gartLocation)
+	if (unlikely(!info->gartLocation))
 	    return FALSE;
 
     info->accel_state->XInited3D = FALSE;
@@ -2385,10 +2379,10 @@ R600DrawInit(ScreenPtr pScreen)
     radeon_vbo_init_lists(pScrn);
 #endif
 
-    if (!R600AllocShaders(pScrn, pScreen))
+    if (unlikely(!R600AllocShaders(pScrn, pScreen)))
 	return FALSE;
 
-    if (!R600LoadShaders(pScrn))
+    if (unlikely(!R600LoadShaders(pScrn)))
 	return FALSE;
 
     exaMarkSync(pScreen);
diff --git a/src/r600_textured_videofuncs.c b/src/r600_textured_videofuncs.c
index 2a86df3..e71c70a 100644
--- a/src/r600_textured_videofuncs.c
+++ b/src/r600_textured_videofuncs.c
@@ -189,12 +189,12 @@ R600DisplayTexturedVideo(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv)
     dst_obj.bpp = pPixmap->drawable.bitsPerPixel;
     dst_obj.domain = RADEON_GEM_DOMAIN_VRAM;
 
-    if (!R600SetAccelState(pScrn,
+    if (unlikely(!R600SetAccelState(pScrn,
 			   &src_obj,
 			   NULL,
 			   &dst_obj,
 			   accel_state->xv_vs_offset, accel_state->xv_ps_offset,
-			   3, 0xffffffff))
+			   3, 0xffffffff)))
 	return;
 
 #ifdef COMPOSITE
diff --git a/src/r6xx_accel.c b/src/r6xx_accel.c
index a835d71..56d6c35 100644
--- a/src/r6xx_accel.c
+++ b/src/r6xx_accel.c
@@ -107,7 +107,7 @@ void R600IBDiscard(ScrnInfoPtr pScrn, drmBufPtr ib)
 	}
 	radeon_cs_erase(info->cs);
 	ret = radeon_cs_space_check(info->cs);
-	if (ret)
+	if (unlikely(ret))
 	    ErrorF("space check failed in flush\n");
 	if (info->dri2.enabled) {
 		info->accel_state->XInited3D = FALSE;
@@ -336,7 +336,7 @@ void cp_wait_vline_sync(ScrnInfoPtr pScrn, drmBufPtr ib, PixmapPtr pPix,
 	    return;
     } else {
 #ifdef USE_EXA
-	if (info->useEXA)
+	if (likely(info->useEXA))
 	    offset = exaGetPixmapOffset(pPix);
 	else
 #endif
diff --git a/src/radeon.h b/src/radeon.h
index 88f1516..e310c4e 100644
--- a/src/radeon.h
+++ b/src/radeon.h
@@ -145,6 +145,14 @@
 # define __FUNCTION__ __func__		/* C99 */
 #endif
 
+#if __GNUC__ >= 3
+# define likely(x)	__builtin_expect (!!(x), 1)
+# define unlikely(x)	__builtin_expect (!!(x), 0)
+#else
+# define likely(x)	(x)
+# define unlikely(x)	(x)
+#endif
+
 #ifndef HAVE_XF86MODEBANDWIDTH
 extern unsigned int xf86ModeBandwidth(DisplayModePtr mode, int depth);
 #define MODE_BANDWIDTH MODE_BAD
@@ -1647,7 +1655,7 @@ do {									\
 static __inline__ void RADEON_MARK_SYNC(RADEONInfoPtr info, ScrnInfoPtr pScrn)
 {
 #ifdef USE_EXA
-    if (info->useEXA)
+    if (likely(info->useEXA))
 	exaMarkSync(pScrn->pScreen);
 #endif
 #ifdef USE_XAA
@@ -1659,7 +1667,7 @@ static __inline__ void RADEON_MARK_SYNC(RADEONInfoPtr info, ScrnInfoPtr pScrn)
 static __inline__ void RADEON_SYNC(RADEONInfoPtr info, ScrnInfoPtr pScrn)
 {
 #ifdef USE_EXA
-    if (info->useEXA && pScrn->pScreen)
+    if (likely(info->useEXA && pScrn->pScreen))
 	exaWaitSync(pScrn->pScreen);
 #endif
 #ifdef USE_XAA
diff --git a/src/radeon_accel.c b/src/radeon_accel.c
index 0250d91..38bc6f6 100644
--- a/src/radeon_accel.c
+++ b/src/radeon_accel.c
@@ -562,7 +562,7 @@ uint32_t radeonGetPixmapOffset(PixmapPtr pPix)
     if (info->cs)
 	return 0;
 #ifdef USE_EXA
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 	offset = exaGetPixmapOffset(pPix);
     } else
 #endif
@@ -1059,14 +1059,14 @@ Bool RADEONAccelInit(ScreenPtr pScreen)
     RADEONInfoPtr  info  = RADEONPTR(pScrn);
 
 #ifdef USE_EXA
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 # ifdef XF86DRI
 	if (info->directRenderingEnabled) {
 	    if (info->ChipFamily >= CHIP_FAMILY_R600) {
-		if (!R600DrawInit(pScreen))
+		if (unlikely(!R600DrawInit(pScreen)))
 		    return FALSE;
 	    } else {
-		if (!RADEONDrawInitCP(pScreen))
+		if (unlikely(!RADEONDrawInitCP(pScreen)))
 		    return FALSE;
 	    }
 	} else
diff --git a/src/radeon_commonfuncs.c b/src/radeon_commonfuncs.c
index 8c46235..c87327f 100644
--- a/src/radeon_commonfuncs.c
+++ b/src/radeon_commonfuncs.c
@@ -847,7 +847,7 @@ void FUNC_NAME(RADEONWaitForVLine)(ScrnInfoPtr pScrn, PixmapPtr pPix,
 	    return;
     } else {
 #ifdef USE_EXA
-	if (info->useEXA)
+	if (likely(info->useEXA))
 	    offset = exaGetPixmapOffset(pPix);
 	else
 #endif
diff --git a/src/radeon_dri.c b/src/radeon_dri.c
index ee62e95..85798f3 100644
--- a/src/radeon_dri.c
+++ b/src/radeon_dri.c
@@ -558,7 +558,7 @@ static void RADEONDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
     int            dy       = pParent->drawable.y - ptOldOrg.y;
 
     /* XXX: Fix in EXA case. */
-    if (info->useEXA)
+    if (likely(info->useEXA))
 	return;
 
     /* If the copy will overlap in Y, reverse the order */
@@ -1677,7 +1677,7 @@ Bool RADEONDRIScreenInit(ScreenPtr pScreen)
     pDRIInfo->createDummyCtxPriv = FALSE;
 
 #ifdef USE_EXA
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 #if DRIINFO_MAJOR_VERSION == 5 && DRIINFO_MINOR_VERSION >= 3
        int major, minor, patch;
 
@@ -2070,7 +2070,7 @@ static void RADEONDRIRefreshArea(ScrnInfoPtr pScrn, RegionPtr pReg)
     /* pretty much a hack. */
 
 #ifdef USE_EXA
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 	uint32_t src_pitch_offset, dst_pitch_offset, datatype;
 
 	RADEONGetPixmapOffsetPitch(pPix, &src_pitch_offset);
@@ -2103,7 +2103,7 @@ static void RADEONDRIRefreshArea(ScrnInfoPtr pScrn, RegionPtr pReg)
 
 	if (xa <= xb && ya <= yb) {
 #ifdef USE_EXA
-	    if (info->useEXA) {
+	    if (likely(info->useEXA)) {
 		RADEONCopyCP(pPix, xa, ya, xa, ya, xb - xa + 1, yb - ya + 1);
 	    }
 #endif
diff --git a/src/radeon_dri2.c b/src/radeon_dri2.c
index 103972f..728c762 100644
--- a/src/radeon_dri2.c
+++ b/src/radeon_dri2.c
@@ -127,7 +127,7 @@ radeon_dri2_create_buffers(DrawablePtr drawable,
 	info->exa_force_create = FALSE;
         driver_priv = exaGetPixmapDriverPrivate(pixmap);
 	r = radeon_gem_get_kernel_name(driver_priv->bo, &buffers[i].name);
-	if (r)
+	if (unlikely(r))
 		return r;
 
         buffers[i].attachment = attachments[i];
@@ -209,7 +209,7 @@ radeon_dri2_create_buffer(DrawablePtr drawable,
     info->exa_force_create = FALSE;
     driver_priv = exaGetPixmapDriverPrivate(pixmap);
     r = radeon_gem_get_kernel_name(driver_priv->bo, &buffers->name);
-    if (r)
+    if (unlikely(r))
 	    return NULL;
 
     buffers->attachment = attachment;
@@ -331,7 +331,7 @@ radeon_dri2_screen_init(ScreenPtr pScreen)
     RADEONInfoPtr info = RADEONPTR(pScrn);
     DRI2InfoRec dri2_info = { 0 };
 
-    if (!info->useEXA) {
+    if (unlikely(!info->useEXA)) {
         xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "DRI2 requires EXA\n");
         return FALSE;
     }
diff --git a/src/radeon_driver.c b/src/radeon_driver.c
index b627637..da2d174 100644
--- a/src/radeon_driver.c
+++ b/src/radeon_driver.c
@@ -429,7 +429,7 @@ static Bool RADEONMapMMIO(ScrnInfoPtr pScrn)
 				   PCI_DEV_MAP_FLAG_WRITABLE,
 				   result);
 
-    if (err) {
+    if (unlikely(err)) {
 	xf86DrvMsg (pScrn->scrnIndex, X_ERROR,
                     "Unable to map MMIO aperture. %s (%d)\n",
                     strerror (err), err);
@@ -497,7 +497,7 @@ static Bool RADEONMapFB(ScrnInfoPtr pScrn)
 				   PCI_DEV_MAP_FLAG_WRITE_COMBINE,
 				   &info->FB);
 
-    if (err) {
+    if (unlikely(err)) {
 	xf86DrvMsg (pScrn->scrnIndex, X_ERROR,
                     "Unable to map FB aperture. %s (%d)\n",
                     strerror (err), err);
@@ -2208,7 +2208,7 @@ static Bool RADEONPreInitAccel(ScrnInfoPtr pScrn)
 		       "Will attempt to use R6xx/R7xx EXA support if DRI is enabled.\n");
 
 #ifdef USE_EXA
-	if (info->useEXA) {
+	if (likely(info->useEXA)) {
 	    info->exaReq.majorversion = EXA_VERSION_MAJOR;
 	    info->exaReq.minorversion = EXA_VERSION_MINOR;
 
@@ -3552,9 +3552,9 @@ Bool RADEONScreenInit(int scrnIndex, ScreenPtr pScreen,
 		   "Setting up accel memmap\n");
 
 #ifdef USE_EXA
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 #ifdef XF86DRI
-	if (hasDRI) {
+	if (likely(hasDRI)) {
 	    info->accelDFS = xf86ReturnOptValBool(info->Options, OPTION_ACCEL_DFS,
 						  info->cardType != CARD_AGP);
 
@@ -6004,7 +6004,7 @@ static Bool RADEONCloseScreen(int scrnIndex, ScreenPtr pScreen)
     xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG,
 		   "Disposing accel...\n");
 #ifdef USE_EXA
-    if (info->accel_state->exa) {
+    if (likely(info->accel_state->exa)) {
 	exaDriverFini(pScreen);
 	xfree(info->accel_state->exa);
 	info->accel_state->exa = NULL;
diff --git a/src/radeon_exa.c b/src/radeon_exa.c
index 217a0fe..c8e6d33 100644
--- a/src/radeon_exa.c
+++ b/src/radeon_exa.c
@@ -175,10 +175,10 @@ static Bool RADEONGetOffsetPitch(PixmapPtr pPix, int bpp, uint32_t *pitch_offset
 {
 	RINFO_FROM_SCREEN(pPix->drawable.pScreen);
 
-	if (pitch > 16320 || pitch % info->accel_state->exa->pixmapPitchAlign != 0)
+	if (unlikely(pitch > 16320 || pitch % info->accel_state->exa->pixmapPitchAlign != 0))
 		RADEON_FALLBACK(("Bad pitch 0x%08x\n", pitch));
 
-	if (offset % info->accel_state->exa->pixmapOffsetAlign != 0)
+	if (unlikely(offset % info->accel_state->exa->pixmapOffsetAlign != 0))
 		RADEON_FALLBACK(("Bad offset 0x%08x\n", offset));
 
 	pitch = pitch >> 6;
@@ -256,7 +256,7 @@ static Bool RADEONPrepareAccess_BE(PixmapPtr pPix, int index)
 
         rc = drmCommandWrite(info->dri->drmFD, DRM_RADEON_SURF_ALLOC,
 			     &drmsurfalloc, sizeof(drmsurfalloc));
-	if (rc < 0) {
+	if (unlikely(rc < 0)) {
 	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		       "drm: could not allocate surface for access"
 		       " swapper, err: %d!\n", rc);
@@ -325,7 +325,7 @@ Bool RADEONPrepareAccess_CS(PixmapPtr pPix, int index)
 #endif
 
     driver_priv = exaGetPixmapDriverPrivate(pPix);
-    if (!driver_priv)
+    if (unlikely(!driver_priv))
       return FALSE;
 
     /* if we have more refs than just the BO then flush */
@@ -334,7 +334,7 @@ Bool RADEONPrepareAccess_CS(PixmapPtr pPix, int index)
     
     /* flush IB */
     ret = radeon_bo_map(driver_priv->bo, 1);
-    if (ret) {
+    if (unlikely(ret)) {
       FatalError("failed to map pixmap %d\n", ret);
       return FALSE;
     }
@@ -365,7 +365,7 @@ void *RADEONEXACreatePixmap(ScreenPtr pScreen, int size, int align)
     struct radeon_exa_pixmap_priv *new_priv;
 
 #ifdef EXA_MIXED_PIXMAPS
-    if (info->accel_state->exa->flags & EXA_MIXED_PIXMAPS) {
+    if (likely(info->accel_state->exa->flags & EXA_MIXED_PIXMAPS)) {
         if (size != 0 && !info->exa_force_create &&
 	    info->exa_pixmaps == FALSE)
             return NULL;
@@ -404,7 +404,7 @@ void *RADEONEXACreatePixmap2(ScreenPtr pScreen, int width, int height,
     int pixmap_align;
 
 #ifdef EXA_MIXED_PIXMAPS
-    if (info->accel_state->exa->flags & EXA_MIXED_PIXMAPS) {
+    if (likely(info->accel_state->exa->flags & EXA_MIXED_PIXMAPS)) {
 	if (width != 0 && height != 0 && !info->exa_force_create &&
 	    info->exa_pixmaps == FALSE)
             return NULL;
@@ -492,7 +492,7 @@ Bool RADEONEXAPixmapIsOffscreen(PixmapPtr pPix)
 
     driver_priv = exaGetPixmapDriverPrivate(pPix);
 
-    if (!driver_priv)
+    if (unlikely(!driver_priv))
        return FALSE;
     if (driver_priv->bo)
        return TRUE;
@@ -565,12 +565,12 @@ Bool RADEONSetupMemEXA (ScreenPtr pScreen)
     int screen_size;
     int byteStride = pScrn->displayWidth * cpp;
 
-    if (info->accel_state->exa != NULL) {
+    if (unlikely(info->accel_state->exa != NULL)) {
 	xf86DrvMsg(pScreen->myNum, X_ERROR, "Memory map already initialized\n");
 	return FALSE;
     }
     info->accel_state->exa = exaDriverAlloc();
-    if (info->accel_state->exa == NULL)
+    if (unlikely(info->accel_state->exa == NULL))
 	return FALSE;
 
     /* Need to adjust screen size for 16 line tiles, and then make it align to.
diff --git a/src/radeon_exa_funcs.c b/src/radeon_exa_funcs.c
index cdc0edb..dfd1098 100644
--- a/src/radeon_exa_funcs.c
+++ b/src/radeon_exa_funcs.c
@@ -155,11 +155,11 @@ FUNC_NAME(RADEONPrepareSolid)(PixmapPtr pPix, int alu, Pixel pm, Pixel fg)
 
     TRACE;
 
-    if (pPix->drawable.bitsPerPixel == 24)
+    if (unlikely(pPix->drawable.bitsPerPixel == 24))
 	RADEON_FALLBACK(("24bpp unsupported\n"));
-    if (!RADEONGetDatatypeBpp(pPix->drawable.bitsPerPixel, &datatype))
+    if (unlikely(!RADEONGetDatatypeBpp(pPix->drawable.bitsPerPixel, &datatype)))
 	RADEON_FALLBACK(("RADEONGetDatatypeBpp failed\n"));
-    if (!RADEONGetPixmapOffsetPitch(pPix, &dst_pitch_offset))
+    if (unlikely(!RADEONGetPixmapOffsetPitch(pPix, &dst_pitch_offset)))
 	RADEON_FALLBACK(("RADEONGetPixmapOffsetPitch failed\n"));
 
     RADEON_SWITCH_TO_2D();
@@ -175,7 +175,7 @@ FUNC_NAME(RADEONPrepareSolid)(PixmapPtr pPix, int alu, Pixel pm, Pixel fg)
 	radeon_cs_space_add_persistent_bo(info->cs, driver_priv->bo, 0, RADEON_GEM_DOMAIN_VRAM);
 
 	ret = radeon_cs_space_check(info->cs);
-	if (ret)
+	if (unlikely(ret))
 	    RADEON_FALLBACK(("Not enough RAM to hw accel solid operation\n"));
 
 	driver_priv = exaGetPixmapDriverPrivate(pPix);
@@ -277,13 +277,13 @@ FUNC_NAME(RADEONPrepareCopy)(PixmapPtr pSrc,   PixmapPtr pDst,
     uint32_t datatype, src_pitch_offset, dst_pitch_offset;
     TRACE;
 
-    if (pDst->drawable.bitsPerPixel == 24)
+    if (unlikely(pDst->drawable.bitsPerPixel == 24))
 	RADEON_FALLBACK(("24bpp unsupported"));
-    if (!RADEONGetDatatypeBpp(pDst->drawable.bitsPerPixel, &datatype))
+    if (unlikely(!RADEONGetDatatypeBpp(pDst->drawable.bitsPerPixel, &datatype)))
 	RADEON_FALLBACK(("RADEONGetDatatypeBpp failed\n"));
-    if (!RADEONGetPixmapOffsetPitch(pSrc, &src_pitch_offset))
+    if (unlikely(!RADEONGetPixmapOffsetPitch(pSrc, &src_pitch_offset)))
 	RADEON_FALLBACK(("RADEONGetPixmapOffsetPitch source failed\n"));
-    if (!RADEONGetPixmapOffsetPitch(pDst, &dst_pitch_offset))
+    if (unlikely(!RADEONGetPixmapOffsetPitch(pDst, &dst_pitch_offset)))
 	RADEON_FALLBACK(("RADEONGetPixmapOffsetPitch dest failed\n"));
 
     RADEON_SWITCH_TO_2D();
@@ -304,7 +304,7 @@ FUNC_NAME(RADEONPrepareCopy)(PixmapPtr pSrc,   PixmapPtr pDst,
 	info->state_2d.dst_bo = driver_priv->bo;
 
 	ret = radeon_cs_space_check(info->cs);
-	if (ret)
+	if (unlikely(ret))
 	    RADEON_FALLBACK(("Not enough RAM to hw accel copy operation\n"));
     }
 #endif
@@ -373,7 +373,7 @@ RADEONUploadToScreenCP(PixmapPtr pDst, int x, int y, int w, int h,
 
     TRACE;
 
-    if (bpp < 8)
+    if (unlikely(bpp < 8))
 	return FALSE;
 
     if (info->directRenderingEnabled &&
@@ -471,11 +471,11 @@ RADEONUploadToScreenCS(PixmapPtr pDst, int x, int y, int w, int h,
     Bool r;
     int i;
 
-    if (bpp < 8)
+    if (unlikely(bpp < 8))
 	return FALSE;
 
     driver_priv = exaGetPixmapDriverPrivate(pDst);
-    if (!driver_priv || !driver_priv->bo)
+    if (unlikely(!driver_priv || !driver_priv->bo))
 	return FALSE;
 
 #if X_BYTE_ORDER == X_BIG_ENDIAN
@@ -506,14 +506,14 @@ RADEONUploadToScreenCS(PixmapPtr pDst, int x, int y, int w, int h,
 
     size = scratch_pitch * h;
     scratch = radeon_bo_open(info->bufmgr, 0, size, 0, RADEON_GEM_DOMAIN_GTT, 0);
-    if (scratch == NULL) {
+    if (unlikely(scratch == NULL)) {
 	return FALSE;
     }
     radeon_cs_space_reset_bos(info->cs);
     radeon_add_pixmap(info->cs, pDst, 0, RADEON_GEM_DOMAIN_VRAM);
     radeon_cs_space_add_persistent_bo(info->cs, scratch, RADEON_GEM_DOMAIN_GTT, 0);
     r = radeon_cs_space_check(info->cs);
-    if (r) {
+    if (unlikely(r)) {
         r = FALSE;
         goto out;
     }
@@ -522,7 +522,7 @@ RADEONUploadToScreenCS(PixmapPtr pDst, int x, int y, int w, int h,
 copy:
 #endif
     r = radeon_bo_map(scratch, 0);
-    if (r) {
+    if (unlikely(r)) {
         r = FALSE;
         goto out;
     }
@@ -569,11 +569,11 @@ RADEONDownloadFromScreenCS(PixmapPtr pSrc, int x, int y, int w,
     uint32_t swap = RADEON_HOST_DATA_SWAP_NONE;
     Bool r;
 
-    if (bpp < 8)
+    if (unlikely(bpp < 8))
 	return FALSE;
 
     driver_priv = exaGetPixmapDriverPrivate(pSrc);
-    if (!driver_priv || !driver_priv->bo)
+    if (unlikely(!driver_priv || !driver_priv->bo))
 	return FALSE;
 
 #if X_BYTE_ORDER == X_BIG_ENDIAN
@@ -612,14 +612,14 @@ RADEONDownloadFromScreenCS(PixmapPtr pSrc, int x, int y, int w,
 
     size = scratch_pitch * h;
     scratch = radeon_bo_open(info->bufmgr, 0, size, 0, RADEON_GEM_DOMAIN_GTT, 0);
-    if (scratch == NULL) {
+    if (unlikely(scratch == NULL)) {
 	return FALSE;
     }
     radeon_cs_space_reset_bos(info->cs);
     radeon_add_pixmap(info->cs, pSrc, RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM, 0);
     radeon_cs_space_add_persistent_bo(info->cs, scratch, 0, RADEON_GEM_DOMAIN_GTT);
     r = radeon_cs_space_check(info->cs);
-    if (r) {
+    if (unlikely(r)) {
         r = FALSE;
         goto out;
     }
@@ -637,7 +637,7 @@ RADEONDownloadFromScreenCS(PixmapPtr pSrc, int x, int y, int w,
 copy:
 #endif
     r = radeon_bo_map(scratch, 0);
-    if (r) {
+    if (unlikely(r)) {
         r = FALSE;
         goto out;
     }
@@ -775,7 +775,7 @@ Bool FUNC_NAME(RADEONDrawInit)(ScreenPtr pScreen)
 {
     RINFO_FROM_SCREEN(pScreen);
 
-    if (info->accel_state->exa == NULL) {
+    if (unlikely(info->accel_state->exa == NULL)) {
 	xf86DrvMsg(pScreen->myNum, X_ERROR, "Memory map not set up\n");
 	return FALSE;
     }
@@ -903,7 +903,7 @@ Bool FUNC_NAME(RADEONDrawInit)(ScreenPtr pScreen)
 
     RADEONEngineInit(pScrn);
 
-    if (!exaDriverInit(pScreen, info->accel_state->exa)) {
+    if (unlikely(!exaDriverInit(pScreen, info->accel_state->exa))) {
 	xfree(info->accel_state->exa);
 	return FALSE;
     }
diff --git a/src/radeon_exa_render.c b/src/radeon_exa_render.c
index e68faff..1919936 100644
--- a/src/radeon_exa_render.c
+++ b/src/radeon_exa_render.c
@@ -245,9 +245,7 @@ static Bool RADEONCheckTexturePOT(PicturePtr pPict, Bool canTile)
     int h = pPict->pDrawable->height;
     unsigned int repeatType = pPict->repeat ? pPict->repeatType : RepeatNone;
 
-    if ((repeatType == RepeatNormal || repeatType == RepeatReflect) &&
-	((w & (w - 1)) != 0 || (h & (h - 1)) != 0) &&
-	!(repeatType == RepeatNormal && !pPict->transform && canTile))
+    if (unlikely((repeatType == RepeatNormal || repeatType == RepeatReflect) && ((w & (w - 1)) != 0 || (h & (h - 1)) != 0) && !(repeatType == RepeatNormal && !pPict->transform && canTile)))
 	RADEON_FALLBACK(("NPOT repeating %s unsupported (%dx%d), transform=%d\n",
 			 canTile ? "source" : "mask", w, h, pPict->transform != 0));
 
@@ -303,16 +301,14 @@ static Bool RADEONSetupSourceTile(PicturePtr pPict,
 	int h = pPict->pDrawable->height;
 	
 	if (pPict->transform) {
-	    if (badPitch)
+	    if (unlikely(badPitch))
 		RADEON_FALLBACK(("Width %d and pitch %u not compatible for repeat\n",
 				 w, (unsigned)exaGetPixmapPitch(pPix)));
 	} else {
 	    info->accel_state->need_src_tile_x = (w & (w - 1)) != 0 || badPitch;
 	    info->accel_state->need_src_tile_y = (h & (h - 1)) != 0;
 
-	    if ((info->accel_state->need_src_tile_x ||
-		 info->accel_state->need_src_tile_y) &&
-		repeatType != RepeatNormal)
+	    if (unlikely((info->accel_state->need_src_tile_x || info->accel_state->need_src_tile_y) && repeatType != RepeatNormal))
 		RADEON_FALLBACK(("Can only tile RepeatNormal at this time\n"));
 
 	    if (!canTile1d)
@@ -342,22 +338,21 @@ static Bool R100CheckCompositeTexture(PicturePtr pPict, int unit)
      * see 197a62704742a4a19736c2637ac92d1dc5ab34ed
      */
 
-    if ((w > 2047) || (h > 2047))
+    if (unlikely((w > 2047) || (h > 2047)))
 	RADEON_FALLBACK(("Picture w/h too large (%dx%d)\n", w, h));
 
     for (i = 0; i < sizeof(R100TexFormats) / sizeof(R100TexFormats[0]); i++) {
 	if (R100TexFormats[i].fmt == pPict->format)
 	    break;
     }
-    if (i == sizeof(R100TexFormats) / sizeof(R100TexFormats[0]))
+    if (unlikely(i == sizeof(R100TexFormats) / sizeof(R100TexFormats[0])))
 	RADEON_FALLBACK(("Unsupported picture format 0x%x\n",
 			(int)pPict->format));
 
-    if (!RADEONCheckTexturePOT(pPict, unit == 0))
+    if (unlikely(!RADEONCheckTexturePOT(pPict, unit == 0)))
 	return FALSE;
 
-    if (pPict->filter != PictFilterNearest &&
-	pPict->filter != PictFilterBilinear)
+    if (unlikely(pPict->filter != PictFilterNearest && pPict->filter != PictFilterBilinear))
     {
 	RADEON_FALLBACK(("Unsupported filter 0x%x\n", pPict->filter));
     }
@@ -386,7 +381,7 @@ static Bool FUNC_NAME(R100TextureSetup)(PicturePtr pPict, PixmapPtr pPix,
 
     CHECK_OFFSET(pPix, 0x1f, "texture");
 
-    if ((txpitch & 0x1f) != 0)
+    if (unlikely((txpitch & 0x1f) != 0))
 	RADEON_FALLBACK(("Bad texture pitch 0x%x\n", (int)txpitch));
 
     for (i = 0; i < sizeof(R100TexFormats) / sizeof(R100TexFormats[0]); i++)
@@ -399,7 +394,7 @@ static Bool FUNC_NAME(R100TextureSetup)(PicturePtr pPict, PixmapPtr pPix,
 	txoffset |= RADEON_TXO_MACRO_TILE;
 
     if (repeat) {
-	if (!RADEONPitchMatches(pPix))
+	if (unlikely(!RADEONPitchMatches(pPix)))
 	    RADEON_FALLBACK(("Width %d and pitch %u not compatible for repeat\n",
 			     w, (unsigned)txpitch));
 
@@ -495,10 +490,10 @@ static Bool R100CheckComposite(int op, PicturePtr pSrcPicture,
     uint32_t tmp1;
 
     /* Check for unsupported compositing operations. */
-    if (op >= sizeof(RadeonBlendOp) / sizeof(RadeonBlendOp[0]))
+    if (unlikely(op >= sizeof(RadeonBlendOp) / sizeof(RadeonBlendOp[0])))
 	RADEON_FALLBACK(("Unsupported Composite op 0x%x\n", op));
 
-    if (!pSrcPicture->pDrawable)
+    if (unlikely(!pSrcPicture->pDrawable))
 	RADEON_FALLBACK(("Solid or gradient pictures not supported yet\n"));
 
     /* r100 limit should be 2048, there are issues with 2048
@@ -507,8 +502,7 @@ static Bool R100CheckComposite(int op, PicturePtr pSrcPicture,
 
     pSrcPixmap = RADEONGetDrawablePixmap(pSrcPicture->pDrawable);
 
-    if (pSrcPixmap->drawable.width > 2047 ||
-	pSrcPixmap->drawable.height > 2047) {
+    if (unlikely(pSrcPixmap->drawable.width > 2047 || pSrcPixmap->drawable.height > 2047)) {
 	RADEON_FALLBACK(("Source w/h too large (%d,%d).\n",
 			 pSrcPixmap->drawable.width,
 			 pSrcPixmap->drawable.height));
@@ -516,8 +510,7 @@ static Bool R100CheckComposite(int op, PicturePtr pSrcPicture,
 
     pDstPixmap = RADEONGetDrawablePixmap(pDstPicture->pDrawable);
 
-    if (pDstPixmap->drawable.width > 2047 ||
-	pDstPixmap->drawable.height > 2047) {
+    if (unlikely(pDstPixmap->drawable.width > 2047 || pDstPixmap->drawable.height > 2047)) {
 	RADEON_FALLBACK(("Dest w/h too large (%d,%d).\n",
 			 pDstPixmap->drawable.width,
 			 pDstPixmap->drawable.height));
@@ -526,13 +519,12 @@ static Bool R100CheckComposite(int op, PicturePtr pSrcPicture,
     if (pMaskPicture) {
 	PixmapPtr pMaskPixmap;
 
-	if (!pMaskPicture->pDrawable)
+	if (unlikely(!pMaskPicture->pDrawable))
 	    RADEON_FALLBACK(("Solid or gradient pictures not supported yet\n"));
 
 	pMaskPixmap = RADEONGetDrawablePixmap(pMaskPicture->pDrawable);
 
-	if (pMaskPixmap->drawable.width > 2047 ||
-	    pMaskPixmap->drawable.height > 2047) {
+	if (unlikely(pMaskPixmap->drawable.width > 2047 || pMaskPixmap->drawable.height > 2047)) {
 	    RADEON_FALLBACK(("Mask w/h too large (%d,%d).\n",
 			     pMaskPixmap->drawable.width,
 			     pMaskPixmap->drawable.height));
@@ -543,22 +535,20 @@ static Bool R100CheckComposite(int op, PicturePtr pSrcPicture,
 	     * on the source value.  We can only get one of those into the
 	     * single source value that we get to blend with.
 	     */
-	    if (RadeonBlendOp[op].src_alpha &&
-		(RadeonBlendOp[op].blend_cntl & RADEON_SRC_BLEND_MASK) !=
-		RADEON_SRC_BLEND_GL_ZERO) {
+	    if (unlikely(RadeonBlendOp[op].src_alpha && (RadeonBlendOp[op].blend_cntl & RADEON_SRC_BLEND_MASK) != RADEON_SRC_BLEND_GL_ZERO)) {
 		RADEON_FALLBACK(("Component alpha not supported with source "
 				 "alpha and source value blending.\n"));
 	    }
 	}
 
-	if (!R100CheckCompositeTexture(pMaskPicture, 1))
+	if (unlikely(!R100CheckCompositeTexture(pMaskPicture, 1)))
 	    return FALSE;
     }
 
-    if (!R100CheckCompositeTexture(pSrcPicture, 0))
+    if ((!R100CheckCompositeTexture(pSrcPicture, 0)))
 	return FALSE;
 
-    if (!RADEONGetDestFormat(pDstPicture, &tmp1))
+    if ((!RADEONGetDestFormat(pDstPicture, &tmp1)))
 	return FALSE;
 
     return TRUE;
@@ -594,7 +584,7 @@ RADEONPrepareCompositeCS(int op, PicturePtr pSrcPicture, PicturePtr pMaskPicture
 	radeon_add_pixmap(info->cs, pDst, 0, RADEON_GEM_DOMAIN_VRAM);
 
 	ret = radeon_cs_space_check(info->cs);
-	if (ret)
+	if (unlikely(ret))
 	    RADEON_FALLBACK(("Not enough RAM to hw accel composite operation\n"));
     }
 #endif
@@ -621,10 +611,10 @@ static Bool FUNC_NAME(R100PrepareComposite)(int op,
 
     TRACE;
 
-    if (!RADEONGetDestFormat(pDstPicture, &dst_format))
+    if (unlikely(!RADEONGetDestFormat(pDstPicture, &dst_format)))
 	return FALSE;
 
-    if (pDstPicture->format == PICT_a8 && RadeonBlendOp[op].dst_alpha)
+    if (unlikely(pDstPicture->format == PICT_a8 && RadeonBlendOp[op].dst_alpha))
 	RADEON_FALLBACK(("Can't dst alpha blend A8\n"));
 
     pixel_shift = pDst->drawable.bitsPerPixel >> 4;
@@ -636,10 +626,10 @@ static Bool FUNC_NAME(R100PrepareComposite)(int op,
 
     CHECK_OFFSET(pDst, 0x0f, "destination");
 
-    if (((dst_pitch >> pixel_shift) & 0x7) != 0)
+    if (unlikely(((dst_pitch >> pixel_shift) & 0x7) != 0))
 	RADEON_FALLBACK(("Bad destination pitch 0x%x\n", (int)dst_pitch));
 
-    if (!RADEONSetupSourceTile(pSrcPicture, pSrc, FALSE, TRUE))
+    if (unlikely(!RADEONSetupSourceTile(pSrcPicture, pSrc, FALSE, TRUE)))
 	return FALSE;
 
     RADEONPrepareCompositeCS(op, pSrcPicture, pMaskPicture, pDstPicture,
@@ -648,12 +638,12 @@ static Bool FUNC_NAME(R100PrepareComposite)(int op,
     /* switch to 3D after doing buffer space checks as the latter may flush */
     RADEON_SWITCH_TO_3D();
 
-    if (!FUNC_NAME(R100TextureSetup)(pSrcPicture, pSrc, 0))
+    if (unlikely(!FUNC_NAME(R100TextureSetup)(pSrcPicture, pSrc, 0)))
 	return FALSE;
     pp_cntl = RADEON_TEX_0_ENABLE | RADEON_TEX_BLEND_0_ENABLE;
 
     if (pMask != NULL) {
-	if (!FUNC_NAME(R100TextureSetup)(pMaskPicture, pMask, 1))
+	if (unlikely(!FUNC_NAME(R100TextureSetup)(pMaskPicture, pMask, 1)))
 	    return FALSE;
 	pp_cntl |= RADEON_TEX_1_ENABLE;
     } else {
@@ -733,7 +723,7 @@ static Bool R200CheckCompositeTexture(PicturePtr pPict, int unit)
      * see bug 19269
      */
 
-    if ((w > 2047) || (h > 2047))
+    if (unlikely((w > 2047) || (h > 2047)))
 	RADEON_FALLBACK(("Picture w/h too large (%dx%d)\n", w, h));
 
     for (i = 0; i < sizeof(R200TexFormats) / sizeof(R200TexFormats[0]); i++)
@@ -741,15 +731,14 @@ static Bool R200CheckCompositeTexture(PicturePtr pPict, int unit)
 	if (R200TexFormats[i].fmt == pPict->format)
 	    break;
     }
-    if (i == sizeof(R200TexFormats) / sizeof(R200TexFormats[0]))
+    if (unlikely(i == sizeof(R200TexFormats) / sizeof(R200TexFormats[0])))
 	RADEON_FALLBACK(("Unsupported picture format 0x%x\n",
 			 (int)pPict->format));
 
-    if (!RADEONCheckTexturePOT(pPict, unit == 0))
+    if (unlikely(!RADEONCheckTexturePOT(pPict, unit == 0)))
 	return FALSE;
 
-    if (pPict->filter != PictFilterNearest &&
-	pPict->filter != PictFilterBilinear)
+    if (unlikely(pPict->filter != PictFilterNearest && pPict->filter != PictFilterBilinear))
 	RADEON_FALLBACK(("Unsupported filter 0x%x\n", pPict->filter));
 
     return TRUE;
@@ -776,7 +765,7 @@ static Bool FUNC_NAME(R200TextureSetup)(PicturePtr pPict, PixmapPtr pPix,
     txoffset = 0;
     CHECK_OFFSET(pPix, 0x1f, "texture");
 
-    if ((txpitch & 0x1f) != 0)
+    if (unlikely((txpitch & 0x1f) != 0))
 	RADEON_FALLBACK(("Bad texture pitch 0x%x\n", (int)txpitch));
 
     for (i = 0; i < sizeof(R200TexFormats) / sizeof(R200TexFormats[0]); i++)
@@ -789,7 +778,7 @@ static Bool FUNC_NAME(R200TextureSetup)(PicturePtr pPict, PixmapPtr pPix,
 	txoffset |= R200_TXO_MACRO_TILE;
 
     if (repeat) {
-	if (!RADEONPitchMatches(pPix))
+	if (unlikely(!RADEONPitchMatches(pPix)))
 	    RADEON_FALLBACK(("Width %d and pitch %u not compatible for repeat\n",
 			     w, (unsigned)txpitch));
 
@@ -876,10 +865,10 @@ static Bool R200CheckComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskP
     TRACE;
 
     /* Check for unsupported compositing operations. */
-    if (op >= sizeof(RadeonBlendOp) / sizeof(RadeonBlendOp[0]))
+    if (unlikely(op >= sizeof(RadeonBlendOp) / sizeof(RadeonBlendOp[0])))
 	RADEON_FALLBACK(("Unsupported Composite op 0x%x\n", op));
 
-    if (!pSrcPicture->pDrawable)
+    if (unlikely(!pSrcPicture->pDrawable))
 	RADEON_FALLBACK(("Solid or gradient pictures not supported yet\n"));
 
     /* r200 limit should be 2048, there are issues with 2048
@@ -888,8 +877,7 @@ static Bool R200CheckComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskP
 
     pSrcPixmap = RADEONGetDrawablePixmap(pSrcPicture->pDrawable);
 
-    if (pSrcPixmap->drawable.width > 2047 ||
-	pSrcPixmap->drawable.height > 2047) {
+    if (unlikely(pSrcPixmap->drawable.width > 2047 || pSrcPixmap->drawable.height > 2047)) {
 	RADEON_FALLBACK(("Source w/h too large (%d,%d).\n",
 			 pSrcPixmap->drawable.width,
 			 pSrcPixmap->drawable.height));
@@ -897,8 +885,7 @@ static Bool R200CheckComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskP
 
     pDstPixmap = RADEONGetDrawablePixmap(pDstPicture->pDrawable);
 
-    if (pDstPixmap->drawable.width > 2047 ||
-	pDstPixmap->drawable.height > 2047) {
+    if (unlikely(pDstPixmap->drawable.width > 2047 || pDstPixmap->drawable.height > 2047)) {
 	RADEON_FALLBACK(("Dest w/h too large (%d,%d).\n",
 			 pDstPixmap->drawable.width,
 			 pDstPixmap->drawable.height));
@@ -907,13 +894,12 @@ static Bool R200CheckComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskP
     if (pMaskPicture) {
 	PixmapPtr pMaskPixmap;
 
-	if (!pMaskPicture->pDrawable)
+	if (unlikely(!pMaskPicture->pDrawable))
 	    RADEON_FALLBACK(("Solid or gradient pictures not supported yet\n"));
 
 	pMaskPixmap = RADEONGetDrawablePixmap(pMaskPicture->pDrawable);
 
-	if (pMaskPixmap->drawable.width > 2047 ||
-	    pMaskPixmap->drawable.height > 2047) {
+	if (unlikely(pMaskPixmap->drawable.width > 2047 || pMaskPixmap->drawable.height > 2047)) {
 	    RADEON_FALLBACK(("Mask w/h too large (%d,%d).\n",
 			     pMaskPixmap->drawable.width,
 			     pMaskPixmap->drawable.height));
@@ -924,22 +910,20 @@ static Bool R200CheckComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskP
 	     * on the source value.  We can only get one of those into the
 	     * single source value that we get to blend with.
 	     */
-	    if (RadeonBlendOp[op].src_alpha &&
-		(RadeonBlendOp[op].blend_cntl & RADEON_SRC_BLEND_MASK) !=
-		RADEON_SRC_BLEND_GL_ZERO) {
+	    if (unlikely(RadeonBlendOp[op].src_alpha && (RadeonBlendOp[op].blend_cntl & RADEON_SRC_BLEND_MASK) != RADEON_SRC_BLEND_GL_ZERO)) {
 		RADEON_FALLBACK(("Component alpha not supported with source "
 				 "alpha and source value blending.\n"));
 	    }
 	}
 
-	if (!R200CheckCompositeTexture(pMaskPicture, 1))
+	if (unlikely(!R200CheckCompositeTexture(pMaskPicture, 1)))
 	    return FALSE;
     }
 
-    if (!R200CheckCompositeTexture(pSrcPicture, 0))
+    if (unlikely(!R200CheckCompositeTexture(pSrcPicture, 0)))
 	return FALSE;
 
-    if (!RADEONGetDestFormat(pDstPicture, &tmp1))
+    if (unlikely(!RADEONGetDestFormat(pDstPicture, &tmp1)))
 	return FALSE;
 
     return TRUE;
@@ -959,10 +943,10 @@ static Bool FUNC_NAME(R200PrepareComposite)(int op, PicturePtr pSrcPicture,
 
     TRACE;
 
-    if (!RADEONGetDestFormat(pDstPicture, &dst_format))
+    if (unlikely(!RADEONGetDestFormat(pDstPicture, &dst_format)))
 	return FALSE;
 
-    if (pDstPicture->format == PICT_a8 && RadeonBlendOp[op].dst_alpha)
+    if (unlikely(pDstPicture->format == PICT_a8 && RadeonBlendOp[op].dst_alpha))
 	RADEON_FALLBACK(("Can't dst alpha blend A8\n"));
 
     pixel_shift = pDst->drawable.bitsPerPixel >> 4;
@@ -974,10 +958,10 @@ static Bool FUNC_NAME(R200PrepareComposite)(int op, PicturePtr pSrcPicture,
 
     CHECK_OFFSET(pDst, 0xf, "destination");
 
-    if (((dst_pitch >> pixel_shift) & 0x7) != 0)
+    if (unlikely(((dst_pitch >> pixel_shift) & 0x7) != 0))
 	RADEON_FALLBACK(("Bad destination pitch 0x%x\n", (int)dst_pitch));
 
-    if (!RADEONSetupSourceTile(pSrcPicture, pSrc, FALSE, TRUE))
+    if (unlikely(!RADEONSetupSourceTile(pSrcPicture, pSrc, FALSE, TRUE)))
 	return FALSE;
 
     RADEONPrepareCompositeCS(op, pSrcPicture, pMaskPicture, pDstPicture,
@@ -986,12 +970,12 @@ static Bool FUNC_NAME(R200PrepareComposite)(int op, PicturePtr pSrcPicture,
     /* switch to 3D after doing buffer space checks as it may flush */
     RADEON_SWITCH_TO_3D();
 
-    if (!FUNC_NAME(R200TextureSetup)(pSrcPicture, pSrc, 0))
+    if (unlikely(!FUNC_NAME(R200TextureSetup)(pSrcPicture, pSrc, 0)))
 	return FALSE;
     pp_cntl = RADEON_TEX_0_ENABLE | RADEON_TEX_BLEND_0_ENABLE;
 
     if (pMask != NULL) {
-	if (!FUNC_NAME(R200TextureSetup)(pMaskPicture, pMask, 1))
+	if (unlikely(!FUNC_NAME(R200TextureSetup)(pMaskPicture, pMask, 1)))
 	    return FALSE;
 	pp_cntl |= RADEON_TEX_1_ENABLE;
     } else {
@@ -1095,7 +1079,7 @@ static Bool R300CheckCompositeTexture(PicturePtr pPict,
 	max_tex_h = 2048;
     }
 
-    if ((w > max_tex_w) || (h > max_tex_h))
+    if (unlikely((w > max_tex_w) || (h > max_tex_h)))
 	RADEON_FALLBACK(("Picture w/h too large (%dx%d)\n", w, h));
 
     for (i = 0; i < sizeof(R300TexFormats) / sizeof(R300TexFormats[0]); i++)
@@ -1103,12 +1087,12 @@ static Bool R300CheckCompositeTexture(PicturePtr pPict,
 	if (R300TexFormats[i].fmt == pPict->format)
 	    break;
     }
-    if (i == sizeof(R300TexFormats) / sizeof(R300TexFormats[0]))
+    if (unlikely(i == sizeof(R300TexFormats) / sizeof(R300TexFormats[0])))
 	RADEON_FALLBACK(("Unsupported picture format 0x%x\n",
 			 (int)pPict->format));
 
     if (!RADEONCheckTexturePOT(pPict, unit == 0)) {
-	if (info->cs) {
+	if (likely(info->cs)) {
     		struct radeon_exa_pixmap_priv *driver_priv;
 		PixmapPtr pPix;
 
@@ -1119,8 +1103,7 @@ static Bool R300CheckCompositeTexture(PicturePtr pPict,
 	return FALSE;
     }
 
-    if (pPict->filter != PictFilterNearest &&
-	pPict->filter != PictFilterBilinear)
+    if (unlikely(pPict->filter != PictFilterNearest && pPict->filter != PictFilterBilinear))
 	RADEON_FALLBACK(("Unsupported filter 0x%x\n", pPict->filter));
 
     /* for REPEAT_NONE, Render semantics are that sampling outside the source
@@ -1132,7 +1115,7 @@ static Bool R300CheckCompositeTexture(PicturePtr pPict,
      * clipping.
      */
     if (pPict->transform != 0 && repeatType == RepeatNone && PICT_FORMAT_A(pPict->format) == 0) {
-	if (!(((op == PictOpSrc) || (op == PictOpClear)) && (PICT_FORMAT_A(pDstPict->format) == 0)))
+	if (unlikely(!(((op == PictOpSrc) || (op == PictOpClear)) && (PICT_FORMAT_A(pDstPict->format) == 0))))
 	    RADEON_FALLBACK(("REPEAT_NONE unsupported for transformed xRGB source\n"));
     }
 
@@ -1160,7 +1143,7 @@ static Bool FUNC_NAME(R300TextureSetup)(PicturePtr pPict, PixmapPtr pPix,
 
     CHECK_OFFSET(pPix, 0x1f, "texture");
 
-    if ((txpitch & 0x1f) != 0)
+    if (unlikely((txpitch & 0x1f) != 0))
 	RADEON_FALLBACK(("Bad texture pitch 0x%x\n", (int)txpitch));
 
     /* TXPITCH = pixels (texels) per line - 1 */
@@ -1332,10 +1315,10 @@ static Bool R300CheckComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskP
     TRACE;
 
     /* Check for unsupported compositing operations. */
-    if (op >= sizeof(RadeonBlendOp) / sizeof(RadeonBlendOp[0]))
+    if (unlikely(op >= sizeof(RadeonBlendOp) / sizeof(RadeonBlendOp[0])))
 	RADEON_FALLBACK(("Unsupported Composite op 0x%x\n", op));
 
-    if (!pSrcPicture->pDrawable)
+    if (unlikely(!pSrcPicture->pDrawable))
 	RADEON_FALLBACK(("Solid or gradient pictures not supported yet\n"));
 
     pSrcPixmap = RADEONGetDrawablePixmap(pSrcPicture->pDrawable);
@@ -1357,8 +1340,7 @@ static Bool R300CheckComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskP
 	}
     }
 
-    if (pSrcPixmap->drawable.width > max_tex_w ||
-	pSrcPixmap->drawable.height > max_tex_h) {
+    if (unlikely(pSrcPixmap->drawable.width > max_tex_w || pSrcPixmap->drawable.height > max_tex_h)) {
 	RADEON_FALLBACK(("Source w/h too large (%d,%d).\n",
 			 pSrcPixmap->drawable.width,
 			 pSrcPixmap->drawable.height));
@@ -1366,8 +1348,7 @@ static Bool R300CheckComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskP
 
     pDstPixmap = RADEONGetDrawablePixmap(pDstPicture->pDrawable);
 
-    if (pDstPixmap->drawable.width > max_dst_w ||
-	pDstPixmap->drawable.height > max_dst_h) {
+    if (unlikely(pDstPixmap->drawable.width > max_dst_w || pDstPixmap->drawable.height > max_dst_h)) {
 	RADEON_FALLBACK(("Dest w/h too large (%d,%d).\n",
 			 pDstPixmap->drawable.width,
 			 pDstPixmap->drawable.height));
@@ -1376,13 +1357,12 @@ static Bool R300CheckComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskP
     if (pMaskPicture) {
 	PixmapPtr pMaskPixmap;
 
-	if (!pMaskPicture->pDrawable)
+	if (unlikely(!pMaskPicture->pDrawable))
 	    RADEON_FALLBACK(("Solid or gradient pictures not supported yet\n"));
 
 	pMaskPixmap = RADEONGetDrawablePixmap(pMaskPicture->pDrawable);
 
-	if (pMaskPixmap->drawable.width > max_tex_w ||
-	    pMaskPixmap->drawable.height > max_tex_h) {
+	if (unlikely(pMaskPixmap->drawable.width > max_tex_w || pMaskPixmap->drawable.height > max_tex_h)) {
 	    RADEON_FALLBACK(("Mask w/h too large (%d,%d).\n",
 			     pMaskPixmap->drawable.width,
 			     pMaskPixmap->drawable.height));
@@ -1393,22 +1373,20 @@ static Bool R300CheckComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskP
 	     * on the source value.  We can only get one of those into the
 	     * single source value that we get to blend with.
 	     */
-	    if (RadeonBlendOp[op].src_alpha &&
-		(RadeonBlendOp[op].blend_cntl & RADEON_SRC_BLEND_MASK) !=
-		RADEON_SRC_BLEND_GL_ZERO) {
+	    if (unlikely(RadeonBlendOp[op].src_alpha && (RadeonBlendOp[op].blend_cntl & RADEON_SRC_BLEND_MASK) != RADEON_SRC_BLEND_GL_ZERO)) {
 		RADEON_FALLBACK(("Component alpha not supported with source "
 				 "alpha and source value blending.\n"));
 	    }
 	}
 
-	if (!R300CheckCompositeTexture(pMaskPicture, pDstPicture, op, 1, IS_R500_3D))
+	if (unlikely(!R300CheckCompositeTexture(pMaskPicture, pDstPicture, op, 1, IS_R500_3D)))
 	    return FALSE;
     }
 
-    if (!R300CheckCompositeTexture(pSrcPicture, pDstPicture, op, 0, IS_R500_3D))
+    if (unlikely(!R300CheckCompositeTexture(pSrcPicture, pDstPicture, op, 0, IS_R500_3D)))
 	return FALSE;
 
-    if (!R300GetDestFormat(pDstPicture, &tmp1))
+    if (unlikely(!R300GetDestFormat(pDstPicture, &tmp1)))
 	return FALSE;
 
     return TRUE;
@@ -1431,7 +1409,7 @@ static Bool FUNC_NAME(R300PrepareComposite)(int op, PicturePtr pSrcPicture,
     ACCEL_PREAMBLE();
     TRACE;
 
-    if (!R300GetDestFormat(pDstPicture, &dst_format))
+    if (unlikely(!R300GetDestFormat(pDstPicture, &dst_format)))
 	return FALSE;
 
     pixel_shift = pDst->drawable.bitsPerPixel >> 4;
@@ -1446,10 +1424,10 @@ static Bool FUNC_NAME(R300PrepareComposite)(int op, PicturePtr pSrcPicture,
 
     CHECK_OFFSET(pDst, 0x0f, "destination");
 
-    if (((dst_pitch >> pixel_shift) & 0x7) != 0)
+    if (unlikely(((dst_pitch >> pixel_shift) & 0x7) != 0))
 	RADEON_FALLBACK(("Bad destination pitch 0x%x\n", (int)dst_pitch));
 
-    if (!RADEONSetupSourceTile(pSrcPicture, pSrc, TRUE, FALSE))
+    if (unlikely(!RADEONSetupSourceTile(pSrcPicture, pSrc, TRUE, FALSE)))
 	return FALSE;
 
     RADEONPrepareCompositeCS(op, pSrcPicture, pMaskPicture, pDstPicture,
@@ -1458,12 +1436,12 @@ static Bool FUNC_NAME(R300PrepareComposite)(int op, PicturePtr pSrcPicture,
     /* have to execute switch after doing buffer sizing check as the latter flushes */
     RADEON_SWITCH_TO_3D();
 
-    if (!FUNC_NAME(R300TextureSetup)(pSrcPicture, pSrc, 0))
+    if (unlikely(!FUNC_NAME(R300TextureSetup)(pSrcPicture, pSrc, 0)))
 	return FALSE;
     txenable = R300_TEX_0_ENABLE;
 
     if (pMask != NULL) {
-	if (!FUNC_NAME(R300TextureSetup)(pMaskPicture, pMask, 1))
+	if (unlikely(!FUNC_NAME(R300TextureSetup)(pMaskPicture, pMask, 1)))
 	    return FALSE;
 	txenable |= R300_TEX_1_ENABLE;
     } else {
diff --git a/src/radeon_kms.c b/src/radeon_kms.c
index 15e5e3f..841ca8b 100644
--- a/src/radeon_kms.c
+++ b/src/radeon_kms.c
@@ -100,7 +100,7 @@ void radeon_cs_flush_indirect(ScrnInfoPtr pScrn)
     ret = radeon_cs_space_check_with_bo(info->cs,
 					accel_state->vb_bo,
 					RADEON_GEM_DOMAIN_GTT, 0);
-    if (ret)
+    if (unlikely(ret))
       ErrorF("space check failed in flush\n");
 
     if (info->reemit_current2d && info->state_2d.op)
@@ -204,7 +204,7 @@ static Bool RADEONIsAccelWorking(ScrnInfoPtr pScrn)
     ginfo.request = 0x3;
     ginfo.value = (uintptr_t)&tmp;
     r = drmCommandWriteRead(info->dri->drmFD, DRM_RADEON_INFO, &ginfo, sizeof(ginfo));
-    if (r) {
+    if (unlikely(r)) {
         /* If kernel is too old before 2.6.32 than assume accel is working */
         if (r == -EINVAL) {
             xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Kernel too old missing accel "
@@ -252,7 +252,7 @@ static Bool RADEONPreInitAccel_KMS(ScrnInfoPtr pScrn)
 
     info->useEXA = TRUE;
 
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 	int errmaj = 0, errmin = 0;
 	info->exaReq.majorversion = EXA_VERSION_MAJOR;
 	info->exaReq.minorversion = EXA_VERSION_MINOR;
@@ -604,7 +604,7 @@ static Bool RADEONCloseScreen_KMS(int scrnIndex, ScreenPtr pScreen)
     if (info->cs)
       radeon_cs_flush_indirect(pScrn);
 
-    if (info->accel_state->exa) {
+    if (likely(info->accel_state->exa)) {
 	exaDriverFini(pScreen);
 	xfree(info->accel_state->exa);
 	info->accel_state->exa = NULL;
@@ -662,7 +662,7 @@ Bool RADEONScreenInit_KMS(int scrnIndex, ScreenPtr pScreen,
     miSetPixmapDepths ();
 
     ret = drmSetMaster(info->dri->drmFD);
-    if (ret) {
+    if (unlikely(ret)) {
         ErrorF("Unable to retrieve master\n");
         return FALSE;
     }
@@ -880,7 +880,7 @@ Bool RADEONEnterVT_KMS(int scrnIndex, int flags)
 
 
     ret = drmSetMaster(info->dri->drmFD);
-    if (ret)
+    if (unlikely(ret))
 	ErrorF("Unable to retrieve master\n");
     info->accel_state->XInited3D = FALSE;
     info->accel_state->engineMode = EXA_ENGINEMODE_UNKNOWN;
diff --git a/src/radeon_legacy_memory.c b/src/radeon_legacy_memory.c
index 3e75291..07cff0d 100644
--- a/src/radeon_legacy_memory.c
+++ b/src/radeon_legacy_memory.c
@@ -37,7 +37,7 @@ radeon_legacy_allocate_memory(ScrnInfoPtr pScrn,
     }
 #endif
 #ifdef USE_EXA
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 	ExaOffscreenArea *area = *mem_struct;
 
 	if (area != NULL) {
@@ -120,7 +120,7 @@ radeon_legacy_free_memory(ScrnInfoPtr pScrn,
 #ifdef USE_EXA
     ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex];
 
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 	ExaOffscreenArea *area = mem_struct;
 
 	if (area != NULL)
diff --git a/src/radeon_macros.h b/src/radeon_macros.h
index 26d9825..b7d5c41 100644
--- a/src/radeon_macros.h
+++ b/src/radeon_macros.h
@@ -168,7 +168,7 @@ do {									\
 #define CHECK_OFFSET(pPix, mask, type) do {	\
     if (!info->cs) {			       \
 	uint32_t _pix_offset = radeonGetPixmapOffset(pPix);	\
-	if ((_pix_offset & mask) != 0)					\
+	if (unlikely((_pix_offset & mask) != 0))			\
 	    RADEON_FALLBACK(("Bad %s offset 0x%x\n", type, (int)_pix_offset)); \
     }									\
     } while(0)
diff --git a/src/radeon_textured_video.c b/src/radeon_textured_video.c
index 1490ccb..2db850b 100644
--- a/src/radeon_textured_video.c
+++ b/src/radeon_textured_video.c
@@ -68,7 +68,7 @@ RADEONTilingEnabled(ScrnInfoPtr pScrn, PixmapPtr pPix)
     RADEONInfoPtr info = RADEONPTR(pScrn);
 
 #ifdef USE_EXA
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 	if (info->tilingEnabled && exaGetPixmapOffset(pPix) == 0)
 	    return TRUE;
 	else
@@ -344,7 +344,7 @@ RADEONPutImageTextured(ScrnInfoPtr pScrn,
 	pPriv->pPixmap = (PixmapPtr)pDraw;
 
 #ifdef USE_EXA
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 	/* Force the pixmap into framebuffer so we can draw to it. */
 	info->exa_force_create = TRUE;
 	exaMoveInPixmap(pPriv->pPixmap);
@@ -376,7 +376,7 @@ RADEONPutImageTextured(ScrnInfoPtr pScrn,
 	src_bo = pPriv->src_bo[pPriv->currentBuffer];
 
 	ret = radeon_bo_map(src_bo, 1);
-	if (ret)
+	if (unlikely(ret))
 	    return BadAlloc;
 
 	pPriv->src_addr = src_bo->ptr;
@@ -713,7 +713,7 @@ Bool radeon_load_bicubic_texture(ScrnInfoPtr pScrn)
 							 &info->bicubic_memory,
 							 sizeof(bicubic_tex_512), 64,
 							 RADEON_GEM_DOMAIN_VRAM);
-    if (info->bicubic_offset == 0)
+    if (unlikely(info->bicubic_offset == 0))
 	return FALSE;
 
     if (info->cs)
@@ -725,7 +725,7 @@ Bool radeon_load_bicubic_texture(ScrnInfoPtr pScrn)
 	int ret;
 	if (info->cs) {
 	    ret = radeon_bo_map(info->bicubic_bo, 1);
-	    if (ret)
+	    if (unlikely(ret))
 		return FALSE;
 
 	    bicubic_addr = info->bicubic_bo->ptr;
diff --git a/src/radeon_textured_videofuncs.c b/src/radeon_textured_videofuncs.c
index f967331..9bc1499 100644
--- a/src/radeon_textured_videofuncs.c
+++ b/src/radeon_textured_videofuncs.c
@@ -117,7 +117,7 @@ FUNC_NAME(RADEONDisplayTexturedVideo)(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv
 	radeon_cs_space_add_persistent_bo(info->cs, driver_priv->bo, 0, RADEON_GEM_DOMAIN_VRAM);
 
 	ret = radeon_cs_space_check(info->cs);
-	if (ret) {
+	if (unlikely(ret)) {
 	    ErrorF("Not enough RAM to hw accel xv operation\n");
 	    return;
 	}
@@ -128,7 +128,7 @@ FUNC_NAME(RADEONDisplayTexturedVideo)(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv
 
     
 #ifdef USE_EXA
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 	dst_pitch = exaGetPixmapPitch(pPixmap);
     } else
 #endif
@@ -145,7 +145,7 @@ FUNC_NAME(RADEONDisplayTexturedVideo)(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv
 #endif
 
 #ifdef USE_EXA
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 	RADEON_SWITCH_TO_3D();
     } else
 #endif
@@ -513,7 +513,7 @@ FUNC_NAME(R200DisplayTexturedVideo)(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv)
 	radeon_cs_space_add_persistent_bo(info->cs, driver_priv->bo, 0, RADEON_GEM_DOMAIN_VRAM);
 
 	ret = radeon_cs_space_check(info->cs);
-	if (ret) {
+	if (unlikely(ret)) {
 	    ErrorF("Not enough RAM to hw accel xv operation\n");
 	    return;
 	}
@@ -523,7 +523,7 @@ FUNC_NAME(R200DisplayTexturedVideo)(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv)
     pixel_shift = pPixmap->drawable.bitsPerPixel >> 4;
 
 #ifdef USE_EXA
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 	dst_pitch = exaGetPixmapPitch(pPixmap);
     } else
 #endif
@@ -540,7 +540,7 @@ FUNC_NAME(R200DisplayTexturedVideo)(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv)
 #endif
 
 #ifdef USE_EXA
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 	RADEON_SWITCH_TO_3D();
     } else
 #endif
@@ -1062,7 +1062,7 @@ FUNC_NAME(R300DisplayTexturedVideo)(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv)
 	radeon_cs_space_add_persistent_bo(info->cs, driver_priv->bo, 0, RADEON_GEM_DOMAIN_VRAM);
 
 	ret = radeon_cs_space_check(info->cs);
-	if (ret) {
+	if (unlikely(ret)) {
 	    ErrorF("Not enough RAM to hw accel xv operation\n");
 	    return;
 	}
@@ -1072,7 +1072,7 @@ FUNC_NAME(R300DisplayTexturedVideo)(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv)
     pixel_shift = pPixmap->drawable.bitsPerPixel >> 4;
 
 #ifdef USE_EXA
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 	dst_pitch = exaGetPixmapPitch(pPixmap);
     } else
 #endif
@@ -1089,7 +1089,7 @@ FUNC_NAME(R300DisplayTexturedVideo)(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv)
 #endif
 
 #ifdef USE_EXA
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 	RADEON_SWITCH_TO_3D();
     } else
 #endif
@@ -2520,7 +2520,7 @@ FUNC_NAME(R500DisplayTexturedVideo)(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv)
 	radeon_cs_space_add_persistent_bo(info->cs, driver_priv->bo, 0, RADEON_GEM_DOMAIN_VRAM);
 
 	ret = radeon_cs_space_check(info->cs);
-	if (ret) {
+	if (unlikely(ret)) {
 	    ErrorF("Not enough RAM to hw accel xv operation\n");
 	    return;
 	}
@@ -2530,7 +2530,7 @@ FUNC_NAME(R500DisplayTexturedVideo)(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv)
     pixel_shift = pPixmap->drawable.bitsPerPixel >> 4;
 
 #ifdef USE_EXA
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 	dst_pitch = exaGetPixmapPitch(pPixmap);
     } else
 #endif
@@ -2547,7 +2547,7 @@ FUNC_NAME(R500DisplayTexturedVideo)(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv)
 #endif
 
 #ifdef USE_EXA
-    if (info->useEXA) {
+    if (likely(info->useEXA)) {
 	RADEON_SWITCH_TO_3D();
     } else
 #endif
diff --git a/src/radeon_vbo.h b/src/radeon_vbo.h
index a8c70b3..43fde05 100644
--- a/src/radeon_vbo.h
+++ b/src/radeon_vbo.h
@@ -39,7 +39,7 @@ radeon_vbo_space(ScrnInfoPtr pScrn, int vert_size)
 
 	if (!bo->ptr) {
 	    ret = radeon_bo_map(bo, 1);
-	    if (ret) {
+	    if (unlikely(ret)) {
 		FatalError("Failed to map vb %d\n", ret);
 		return NULL;
 	    }
-- 
1.6.4.4



More information about the xorg-driver-ati mailing list