Use ALIGN macro instead of open coding it.
PATCH 1/2 Use ALIGN macro instead of open coding it.
From: Matt Turner <[email protected]>
Signed-off-by Matt Turner <[email protected]>
--- src/intel_memory.c | 2 +- src/intel_video.c | 38 ++++++++++++++++---------------------- src/legacy/i810/i810_accel.c | 2 +- src/legacy/i810/i810_common.h | 2 ++ src/legacy/i810/i810_driver.c | 3 +-- src/legacy/i810/i810_video.c | 18 +++++++++--------- src/xvmc/i915_xvmc.c | 4 +++- 7 files changed, 33 insertions(+), 36 deletions(-)
src/intel_memory.c +1 -1
@@ -167,7 +167,7 @@ intel_check_display_stride(ScrnInfoPtr scrn, int stride, Bool tiling)*/ static inline int intel_pad_drawable_width (int width) { -return (width +63 ) & ~63 ; +return ALIGN (width,64 ); }/**
src/intel_video.c +16 -22
@@ -1277,10 +1277,10 @@ intel_clip_video_helper(ScrnInfoPtr scrn, *top = y1 >>16 ; *left = (x1 >>16 ) & ~1 ; - *npixels = ((((x2 +0xffff ) >>16 ) +1 ) & ~1 ) - *left; + *npixels =ALIGN (((x2 +0xffff ) >>16 ),2 ) - *left;if (is_planar_fourcc (id)) { *top &= ~1 ; - *nlines = ((((y2 +0xffff ) >>16 ) +1 ) & ~1 ) - *top; + *nlines =ALIGN (((y2 +0xffff ) >>16 ),2 ) - *top; }else *nlines = ((y2 +0xffff ) >>16 ) - *top;
@@ -1385,32 +1385,32 @@ intel_setup_dst_params(ScrnInfoPtr scrn, intel_adaptor_private *adaptor_priv, sh int id) {intel_screen_private *intel =intel_get_screen_private (scrn); -int pitchAlignMask; +int pitchAlign;/* Only needs to be DWORD-aligned for textured on i915, but overlay has * stricter requirements. */ if (adaptor_priv->textured) { - pitchAlignMask =3 ; + pitchAlign =4 ; }else {if (IS_I965G (intel))/* Actually the alignment is 64 bytes, too. But the * stride must be at least 512 bytes. Take the easy fix * and align on 512 bytes unconditionally. */ - pitchAlignMask =511 ; + pitchAlign =512 ;else if (IS_I830 (intel) ||IS_845G (intel))/* Harsh, errata on these chipsets limit the stride to be * a multiple of 256 bytes. */ - pitchAlignMask =255 ; + pitchAlign =256 ;else - pitchAlignMask =63 ; + pitchAlign =64 ; }#if INTEL_XVMC /* for i915 xvmc, hw requires 1kb aligned surfaces */ if ((id ==FOURCC_XVMC ) &&IS_I915 (intel)) - pitchAlignMask =0x3ff ; + pitchAlign =1024 ;#endif /* Determine the desired destination pitch (representing the chroma's pitch,
@@ -1418,26 +1418,20 @@ intel_setup_dst_params(ScrnInfoPtr scrn, intel_adaptor_private *adaptor_priv, sh*/ if (is_planar_fourcc (id)) {if (adaptor_priv->rotation & (RR_Rotate_90 | RR_Rotate_270)) { - *dstPitch = - ((height /2 ) + pitchAlignMask) & ~pitchAlignMask; - *dstPitch2 = - (height + pitchAlignMask) & ~pitchAlignMask; + *dstPitch =ALIGN ((height /2 ), pitchAlign); + *dstPitch2 =ALIGN (height, pitchAlign); *size = *dstPitch * width *3 ; }else { - *dstPitch = - ((width /2 ) + pitchAlignMask) & ~pitchAlignMask; - *dstPitch2 = - (width + pitchAlignMask) & ~pitchAlignMask; + *dstPitch =ALIGN ((width /2 ), pitchAlign); + *dstPitch2 =ALIGN (width, pitchAlign); *size = *dstPitch * height *3 ; } }else {if (adaptor_priv->rotation & (RR_Rotate_90 | RR_Rotate_270)) { - *dstPitch = - ((height <<1 ) + pitchAlignMask) & ~pitchAlignMask; + *dstPitch =ALIGN ((height <<1 ), pitchAlign); *size = *dstPitch * width; }else { - *dstPitch = - ((width <<1 ) + pitchAlignMask) & ~pitchAlignMask; + *dstPitch =ALIGN ((width <<1 ), pitchAlign); *size = *dstPitch * height; } *dstPitch2 =0 ;
@@ -1472,8 +1466,8 @@ intel_copy_video_data(ScrnInfoPtr scrn, intel_adaptor_private *adaptor_priv,int size;if (is_planar_fourcc (id)) { - srcPitch = (width +0x3 ) & ~0x3 ; - srcPitch2 = ((width >>1 ) +0x3 ) & ~0x3 ; + srcPitch =ALIGN (width,0x4 ); + srcPitch2 =ALIGN ((width >>1 ),0x4 ); }else { srcPitch = width <<1 ; }
src/legacy/i810/i810_accel.c +1 -1
@@ -129,7 +129,7 @@ I810AccelInit(ScreenPtr pScreen)*/ if (pI810->Scratch.Size !=0 ) {int i; -int width = ((pScrn->displayWidth +31 ) & ~31 ) /8 ; +int width =ALIGN (pScrn->displayWidth,32 ) /8 ;int nr_buffers = pI810->Scratch.Size / width;unsigned char *ptr = pI810->FbBase + pI810->Scratch.Start;
src/legacy/i810/i810_common.h +2 -0
@@ -50,6 +50,8 @@#define KB (x) ((x) * 1024)#define MB (x) ((x) * KB(1024)) +#define ALIGN (i,m) (((i) + (m) - 1) & ~((m) - 1)) +/* Using usleep() makes things noticably slow. */ #if 0 #define DELAY (x) usleep(x)
src/legacy/i810/i810_driver.c +1 -2
@@ -1545,8 +1545,7 @@ I810AllocateFront(ScrnInfoPtr pScrn)if (!I810AllocLow (&(pI810->FrontBuffer), &(pI810->SysMem), - ((pI810->FbMemBox.x2 * - pI810->FbMemBox.y2 * pI810->cpp) +4095 ) & ~4095 )) { +ALIGN ((pI810->FbMemBox.x2 * pI810->FbMemBox.y2 * pI810->cpp),4096 ))) {xf86DrvMsg (pScrn->scrnIndex,X_WARNING ,"Framebuffer allocation failed\n" );return FALSE;
src/legacy/i810/i810_video.c +9 -9
@@ -750,14 +750,14 @@ I810DisplayVideo(switch (id) {case FOURCC_YV12 :case FOURCC_I420 : - swidth = (width +7 ) & ~7 ; + swidth =ALIGN (width,8 ); overlay->SWID = (swidth <<15 ) | swidth; overlay->SWIDQW = (swidth <<12 ) | (swidth >>3 );break ;case FOURCC_UYVY :case FOURCC_YUY2 :default : - swidth = ((width +3 ) & ~3 ) <<1 ; + swidth =ALIGN (width,4 ) <<1 ; overlay->SWID = swidth; overlay->SWIDQW = swidth >>3 ;break ;
@@ -1013,15 +1013,15 @@ I810PutImage(switch (id) {case FOURCC_YV12 :case FOURCC_I420 : - srcPitch = (width +3 ) & ~3 ; - dstPitch = ((width >>1 ) +7 ) & ~7 ;/* of chroma */ + srcPitch =ALIGN (width,4 ); + dstPitch =ALIGN ((width >>1 ),8 );/* of chroma */ size = dstPitch * height *3 ;break ;case FOURCC_UYVY :case FOURCC_YUY2 :default : srcPitch = (width <<1 ); - dstPitch = (srcPitch +7 ) & ~7 ; + dstPitch =ALIGN (srcPitch,8 ); size = dstPitch * height;break ; }
@@ -1062,13 +1062,13 @@ I810PutImage(/* copy data */ top = y1 >>16 ; left = (x1 >>16 ) & ~1 ; - npixels = ((((x2 +0xffff ) >>16 ) +1 ) & ~1 ) - left; + npixels =ALIGN (((x2 +0xffff ) >>16 ),2 ) - left;switch (id) {case FOURCC_YV12 :case FOURCC_I420 : top &= ~1 ; - nlines = ((((y2 +0xffff ) >>16 ) +1 ) & ~1 ) - top; + nlines =ALIGN (((y2 +0xffff ) >>16 ),2 ) - top;I810CopyPlanarData (pScrn, buf, srcPitch, dstPitch, height, top, left, nlines, npixels, id);break ;
@@ -1213,8 +1213,8 @@ I810AllocateSurface(if ((w >1024 ) || (h >1024 ))return BadAlloc; - w = (w +1 ) & ~1 ; - pitch = ((w <<1 ) +15 ) & ~15 ; + w =ALIGN (w,2 ); + pitch =ALIGN ((w <<1 ),16 ); bpp = pScrn->bitsPerPixel >>3 ; size = ((pitch * h) + bpp -1 ) / bpp;
src/xvmc/i915_xvmc.c +3 -1
@@ -31,7 +31,9 @@#include "i915_structs.h" #include "i915_program.h" -#define STRIDE (w) (((w) + 0x3ff) & ~0x3ff) +#define ALIGN (i,m) (((i) + (m) - 1) & ~((m) - 1)) + +#define STRIDE (w) (ALIGN((w), 1024))#define SIZE_Y420 (w, h) (h * STRIDE(w))#define SIZE_UV420 (w, h) ((h >> 1) * STRIDE(w >> 1))#define SIZE_YUV420 (w, h) (SIZE_Y420(w,h) + SIZE_UV420(w,h) * 2)
Signature · 1 line
1.7.1
PATCH 2/2 Replace ROUND_* macros with ALIGN.
From: Matt Turner <[email protected]>
Signed-off-by Matt Turner <[email protected]>
--- src/common.h | 4 ---- src/intel_memory.c | 2 +- src/intel_uxa.c | 6 +++--- src/legacy/i810/i810_common.h | 4 ---- 4 files changed, 4 insertions(+), 12 deletions(-)
src/common.h +0 -4
@@ -160,10 +160,6 @@ static inline void memcpy_volatile(volatile void *dst, const void *src,#define I810_REG_SIZE 0x80000#define GTT_PAGE_SIZE KB(4) -#define ROUND_TO (x, y) (((x) + (y) - 1) / (y) * (y)) -#define ROUND_DOWN_TO (x, y) ((x) / (y) * (y)) -#define ROUND_TO_PAGE (x) ROUND_TO((x), GTT_PAGE_SIZE) -#define ROUND_TO_MB (x) ROUND_TO((x), MB(1))#define PRIMARY_RINGBUFFER_SIZE KB(128)#define MIN_SCRATCH_BUFFER_SIZE KB(16)#define MAX_SCRATCH_BUFFER_SIZE KB(64)
src/intel_memory.c +1 -1
@@ -128,7 +128,7 @@ intel_get_fence_pitch(intel_screen_private *intel, unsigned long pitch,/* 965 is flexible */ if (IS_I965G (intel)) -return ROUND_TO (pitch, tile_width); +return ALIGN (pitch, tile_width);/* Pre-965 needs power of two tile width */ for (i = tile_width; i < pitch; i <<=1 ) ;
src/intel_uxa.c +3 -3
@@ -142,7 +142,7 @@ intel_uxa_pixmap_compute_size(PixmapPtr pixmap,if (*tiling !=I915_TILING_NONE ) {/* First check whether tiling is necessary. */ pitch = (w * pixmap->drawable.bitsPerPixel +7 ) /8 ; - pitch =ROUND_TO (pitch, intel->accel_pixmap_pitch_alignment); + pitch =ALIGN (pitch, intel->accel_pixmap_pitch_alignment); size = pitch *ALIGN (h,2 );if (!IS_I965G (intel)) {/* Older hardware requires fences to be pot size
@@ -179,7 +179,7 @@ intel_uxa_pixmap_compute_size(PixmapPtr pixmap, aligned_h =ALIGN (h,32 ); *stride =intel_get_fence_pitch (intel, -ROUND_TO (pitch,512 ), +ALIGN (pitch,512 ), *tiling);/* Round the object up to the size of the fence it will live in
@@ -199,7 +199,7 @@ intel_uxa_pixmap_compute_size(PixmapPtr pixmap,* subspan doesn't address an invalid page offset beyond the * end of the GTT. */ - *stride =ROUND_TO (pitch, intel->accel_pixmap_pitch_alignment); + *stride =ALIGN (pitch, intel->accel_pixmap_pitch_alignment); size = *stride *ALIGN (h,2 ); }
src/legacy/i810/i810_common.h +0 -4
@@ -138,10 +138,6 @@ extern int I810_DEBUG;#define I810_REG_SIZE 0x80000#define GTT_PAGE_SIZE KB(4) -#define ROUND_TO (x, y) (((x) + (y) - 1) / (y) * (y)) -#define ROUND_DOWN_TO (x, y) ((x) / (y) * (y)) -#define ROUND_TO_PAGE (x) ROUND_TO((x), GTT_PAGE_SIZE) -#define ROUND_TO_MB (x) ROUND_TO((x), MB(1))#define PRIMARY_RINGBUFFER_SIZE KB(128)#define MIN_SCRATCH_BUFFER_SIZE KB(16)#define MAX_SCRATCH_BUFFER_SIZE KB(64)
Signature · 1 line
1.7.1