diff options
author | Dylan Baker <[email protected]> | 2018-09-06 15:49:35 -0700 |
---|---|---|
committer | Dylan Baker <[email protected]> | 2020-04-21 11:09:03 -0700 |
commit | 9d9a2819ee0e862f60abf50ba239a341b664845a (patch) | |
tree | e4c3e833504aa357913ba2919dacc9a116bb3517 | |
parent | 72acb66527df6f38c7b8b15fa5062a616d67074b (diff) |
replace IFLOOR with util_ifloor
which are exactly the same function with exactly the same implementation
Reviewed-by: Marek Olšák <[email protected]>
Reviewed-by: Kristian H. Kristensen <[email protected]>
Reviewed-by: Matt Turner <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3024>
-rw-r--r-- | src/mesa/main/drawpix.c | 5 | ||||
-rw-r--r-- | src/mesa/program/prog_execute.c | 2 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_bitmap.c | 4 | ||||
-rw-r--r-- | src/mesa/swrast/s_blit.c | 14 | ||||
-rw-r--r-- | src/mesa/swrast/s_texfilter.c | 64 | ||||
-rw-r--r-- | src/mesa/swrast/s_triangle.c | 4 | ||||
-rw-r--r-- | src/util/imports.h | 31 |
7 files changed, 47 insertions, 77 deletions
diff --git a/src/mesa/main/drawpix.c b/src/mesa/main/drawpix.c index efec78cda05..45896c15552 100644 --- a/src/mesa/main/drawpix.c +++ b/src/mesa/main/drawpix.c @@ -36,6 +36,7 @@ #include "state.h" #include "glformats.h" #include "fbobject.h" +#include "util/u_math.h" /* @@ -323,8 +324,8 @@ _mesa_Bitmap( GLsizei width, GLsizei height, /* Truncate, to satisfy conformance tests (matches SGI's OpenGL). */ if (width > 0 && height > 0) { const GLfloat epsilon = 0.0001F; - GLint x = IFLOOR(ctx->Current.RasterPos[0] + epsilon - xorig); - GLint y = IFLOOR(ctx->Current.RasterPos[1] + epsilon - yorig); + GLint x = util_ifloor(ctx->Current.RasterPos[0] + epsilon - xorig); + GLint y = util_ifloor(ctx->Current.RasterPos[1] + epsilon - yorig); if (ctx->Unpack.BufferObj) { /* unpack from PBO */ diff --git a/src/mesa/program/prog_execute.c b/src/mesa/program/prog_execute.c index c50465dfc49..6ada78565cc 100644 --- a/src/mesa/program/prog_execute.c +++ b/src/mesa/program/prog_execute.c @@ -434,7 +434,7 @@ _mesa_execute_program(struct gl_context * ctx, { GLfloat t[4]; fetch_vector4(&inst->SrcReg[0], machine, t); - machine->AddressReg[0][0] = IFLOOR(t[0]); + machine->AddressReg[0][0] = util_ifloor(t[0]); if (DEBUG_PROG) { printf("ARL %d\n", machine->AddressReg[0][0]); } diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 475ab2fc8cd..06cbb980013 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -698,8 +698,8 @@ st_DrawAtlasBitmaps(struct gl_context *ctx, const float xorig = g->xorig, yorig = g->yorig; const float s0 = g->x, t0 = g->y; const float s1 = s0 + g->w, t1 = t0 + g->h; - const float x0 = IFLOOR(ctx->Current.RasterPos[0] - xorig + epsilon); - const float y0 = IFLOOR(ctx->Current.RasterPos[1] - yorig + epsilon); + const float x0 = util_ifloor(ctx->Current.RasterPos[0] - xorig + epsilon); + const float y0 = util_ifloor(ctx->Current.RasterPos[1] - yorig + epsilon); const float x1 = x0 + g->w, y1 = y0 + g->h; const float clip_x0 = x0 * clip_x_scale - 1.0f; const float clip_y0 = y0 * clip_y_scale - 1.0f; diff --git a/src/mesa/swrast/s_blit.c b/src/mesa/swrast/s_blit.c index 557f107b536..362d4daad17 100644 --- a/src/mesa/swrast/s_blit.c +++ b/src/mesa/swrast/s_blit.c @@ -409,7 +409,7 @@ resample_linear_row_ub(GLint srcWidth, GLint dstWidth, for (dstCol = 0; dstCol < dstWidth; dstCol++) { const GLfloat srcCol = (dstCol + 0.5F) / dstWidth * srcWidth - 0.5F; - GLint srcCol0 = MAX2(0, IFLOOR(srcCol)); + GLint srcCol0 = MAX2(0, util_ifloor(srcCol)); GLint srcCol1 = srcCol0 + 1; GLfloat colWeight = srcCol - srcCol0; /* fractional part of srcCol */ GLfloat red, green, blue, alpha; @@ -441,10 +441,10 @@ resample_linear_row_ub(GLint srcWidth, GLint dstWidth, srcColor0[srcCol0][ACOMP], srcColor0[srcCol1][ACOMP], srcColor1[srcCol0][ACOMP], srcColor1[srcCol1][ACOMP]); - dstColor[dstCol][RCOMP] = IFLOOR(red); - dstColor[dstCol][GCOMP] = IFLOOR(green); - dstColor[dstCol][BCOMP] = IFLOOR(blue); - dstColor[dstCol][ACOMP] = IFLOOR(alpha); + dstColor[dstCol][RCOMP] = util_ifloor(red); + dstColor[dstCol][GCOMP] = util_ifloor(green); + dstColor[dstCol][BCOMP] = util_ifloor(blue); + dstColor[dstCol][ACOMP] = util_ifloor(alpha); } } @@ -464,7 +464,7 @@ resample_linear_row_float(GLint srcWidth, GLint dstWidth, for (dstCol = 0; dstCol < dstWidth; dstCol++) { const GLfloat srcCol = (dstCol + 0.5F) / dstWidth * srcWidth - 0.5F; - GLint srcCol0 = MAX2(0, IFLOOR(srcCol)); + GLint srcCol0 = MAX2(0, util_ifloor(srcCol)); GLint srcCol1 = srcCol0 + 1; GLfloat colWeight = srcCol - srcCol0; /* fractional part of srcCol */ GLfloat red, green, blue, alpha; @@ -630,7 +630,7 @@ blit_linear(struct gl_context *ctx, for (dstRow = 0; dstRow < dstHeight; dstRow++) { const GLint dstY = dstYpos + dstRow; GLfloat srcRow = (dstRow + 0.5F) / dstHeight * srcHeight - 0.5F; - GLint srcRow0 = MAX2(0, IFLOOR(srcRow)); + GLint srcRow0 = MAX2(0, util_ifloor(srcRow)); GLint srcRow1 = srcRow0 + 1; GLfloat rowWeight = srcRow - srcRow0; /* fractional part of srcRow */ diff --git a/src/mesa/swrast/s_texfilter.c b/src/mesa/swrast/s_texfilter.c index 13d517b6261..5da7f888140 100644 --- a/src/mesa/swrast/s_texfilter.c +++ b/src/mesa/swrast/s_texfilter.c @@ -43,7 +43,7 @@ * Also note, FRAC(x) doesn't truly return the fractional part of x for x < 0. * Instead, if x < 0 then FRAC(x) = 1 - true_frac(x). */ -#define FRAC(f) ((f) - IFLOOR(f)) +#define FRAC(f) ((f) - util_ifloor(f)) @@ -169,11 +169,11 @@ linear_texel_locations(GLenum wrapMode, case GL_REPEAT: u = s * size - 0.5F; if (swImg->_IsPowerOfTwo) { - *i0 = IFLOOR(u) & (size - 1); + *i0 = util_ifloor(u) & (size - 1); *i1 = (*i0 + 1) & (size - 1); } else { - *i0 = REMAINDER(IFLOOR(u), size); + *i0 = REMAINDER(util_ifloor(u), size); *i1 = REMAINDER(*i0 + 1, size); } break; @@ -185,7 +185,7 @@ linear_texel_locations(GLenum wrapMode, else u = s * size; u -= 0.5F; - *i0 = IFLOOR(u); + *i0 = util_ifloor(u); *i1 = *i0 + 1; if (*i0 < 0) *i0 = 0; @@ -203,19 +203,19 @@ linear_texel_locations(GLenum wrapMode, else u = s * size; u -= 0.5F; - *i0 = IFLOOR(u); + *i0 = util_ifloor(u); *i1 = *i0 + 1; } break; case GL_MIRRORED_REPEAT: { - const GLint flr = IFLOOR(s); + const GLint flr = util_ifloor(s); if (flr & 1) u = 1.0F - (s - (GLfloat) flr); else u = s - (GLfloat) flr; u = (u * size) - 0.5F; - *i0 = IFLOOR(u); + *i0 = util_ifloor(u); *i1 = *i0 + 1; if (*i0 < 0) *i0 = 0; @@ -230,7 +230,7 @@ linear_texel_locations(GLenum wrapMode, else u *= size; u -= 0.5F; - *i0 = IFLOOR(u); + *i0 = util_ifloor(u); *i1 = *i0 + 1; break; case GL_MIRROR_CLAMP_TO_EDGE_EXT: @@ -240,7 +240,7 @@ linear_texel_locations(GLenum wrapMode, else u *= size; u -= 0.5F; - *i0 = IFLOOR(u); + *i0 = util_ifloor(u); *i1 = *i0 + 1; if (*i0 < 0) *i0 = 0; @@ -259,7 +259,7 @@ linear_texel_locations(GLenum wrapMode, else u *= size; u -= 0.5F; - *i0 = IFLOOR(u); + *i0 = util_ifloor(u); *i1 = *i0 + 1; } break; @@ -271,7 +271,7 @@ linear_texel_locations(GLenum wrapMode, else u = s * size; u -= 0.5F; - *i0 = IFLOOR(u); + *i0 = util_ifloor(u); *i1 = *i0 + 1; break; default: @@ -299,7 +299,7 @@ nearest_texel_location(GLenum wrapMode, case GL_REPEAT: /* s limited to [0,1) */ /* i limited to [0,size-1] */ - i = IFLOOR(s * size); + i = util_ifloor(s * size); if (swImg->_IsPowerOfTwo) i &= (size - 1); else @@ -316,7 +316,7 @@ nearest_texel_location(GLenum wrapMode, else if (s > max) i = size - 1; else - i = IFLOOR(s * size); + i = util_ifloor(s * size); } return i; case GL_CLAMP_TO_BORDER: @@ -330,14 +330,14 @@ nearest_texel_location(GLenum wrapMode, else if (s >= max) i = size; else - i = IFLOOR(s * size); + i = util_ifloor(s * size); } return i; case GL_MIRRORED_REPEAT: { const GLfloat min = 1.0F / (2.0F * size); const GLfloat max = 1.0F - min; - const GLint flr = IFLOOR(s); + const GLint flr = util_ifloor(s); GLfloat u; if (flr & 1) u = 1.0F - (s - (GLfloat) flr); @@ -348,7 +348,7 @@ nearest_texel_location(GLenum wrapMode, else if (u > max) i = size - 1; else - i = IFLOOR(u * size); + i = util_ifloor(u * size); } return i; case GL_MIRROR_CLAMP_EXT: @@ -361,7 +361,7 @@ nearest_texel_location(GLenum wrapMode, else if (u >= 1.0F) i = size - 1; else - i = IFLOOR(u * size); + i = util_ifloor(u * size); } return i; case GL_MIRROR_CLAMP_TO_EDGE_EXT: @@ -376,7 +376,7 @@ nearest_texel_location(GLenum wrapMode, else if (u > max) i = size - 1; else - i = IFLOOR(u * size); + i = util_ifloor(u * size); } return i; case GL_MIRROR_CLAMP_TO_BORDER_EXT: @@ -391,7 +391,7 @@ nearest_texel_location(GLenum wrapMode, else if (u > max) i = size; else - i = IFLOOR(u * size); + i = util_ifloor(u * size); } return i; case GL_CLAMP: @@ -402,7 +402,7 @@ nearest_texel_location(GLenum wrapMode, else if (s >= 1.0F) i = size - 1; else - i = IFLOOR(s * size); + i = util_ifloor(s * size); return i; default: _mesa_problem(NULL, "Bad wrap mode"); @@ -417,7 +417,7 @@ linear_repeat_texel_location(GLuint size, GLfloat s, GLint *i0, GLint *i1, GLfloat *weight) { GLfloat u = s * size - 0.5F; - *i0 = IFLOOR(u) & (size - 1); + *i0 = util_ifloor(u) & (size - 1); *i1 = (*i0 + 1) & (size - 1); *weight = FRAC(u); } @@ -431,11 +431,11 @@ clamp_rect_coord_nearest(GLenum wrapMode, GLfloat coord, GLint max) { switch (wrapMode) { case GL_CLAMP: - return IFLOOR( CLAMP(coord, 0.0F, max - 1) ); + return util_ifloor( CLAMP(coord, 0.0F, max - 1) ); case GL_CLAMP_TO_EDGE: - return IFLOOR( CLAMP(coord, 0.5F, max - 0.5F) ); + return util_ifloor( CLAMP(coord, 0.5F, max - 0.5F) ); case GL_CLAMP_TO_BORDER: - return IFLOOR( CLAMP(coord, -0.5F, max + 0.5F) ); + return util_ifloor( CLAMP(coord, -0.5F, max + 0.5F) ); default: _mesa_problem(NULL, "bad wrapMode in clamp_rect_coord_nearest"); return 0; @@ -456,13 +456,13 @@ clamp_rect_coord_linear(GLenum wrapMode, GLfloat coord, GLint max, case GL_CLAMP: /* Not exactly what the spec says, but it matches NVIDIA output */ fcol = CLAMP(coord - 0.5F, 0.0F, max - 1); - i0 = IFLOOR(fcol); + i0 = util_ifloor(fcol); i1 = i0 + 1; break; case GL_CLAMP_TO_EDGE: fcol = CLAMP(coord, 0.5F, max - 0.5F); fcol -= 0.5F; - i0 = IFLOOR(fcol); + i0 = util_ifloor(fcol); i1 = i0 + 1; if (i1 > max - 1) i1 = max - 1; @@ -470,7 +470,7 @@ clamp_rect_coord_linear(GLenum wrapMode, GLfloat coord, GLint max, case GL_CLAMP_TO_BORDER: fcol = CLAMP(coord, -0.5F, max + 0.5F); fcol -= 0.5F; - i0 = IFLOOR(fcol); + i0 = util_ifloor(fcol); i1 = i0 + 1; break; default: @@ -491,7 +491,7 @@ clamp_rect_coord_linear(GLenum wrapMode, GLfloat coord, GLint max, static GLint tex_array_slice(GLfloat coord, GLsizei size) { - GLint slice = IFLOOR(coord + 0.5f); + GLint slice = util_ifloor(coord + 0.5f); slice = CLAMP(slice, 0, size - 1); return slice; } @@ -1435,8 +1435,8 @@ opt_sample_rgb_2d(struct gl_context *ctx, (void) swImg; for (k=0; k<n; k++) { - GLint i = IFLOOR(texcoords[k][0] * width) & colMask; - GLint j = IFLOOR(texcoords[k][1] * height) & rowMask; + GLint i = util_ifloor(texcoords[k][0] * width) & colMask; + GLint j = util_ifloor(texcoords[k][1] * height) & rowMask; GLint pos = (j << shift) | i; GLubyte *texel = (GLubyte *) swImg->ImageSlices[0] + 3 * pos; rgba[k][RCOMP] = UBYTE_TO_FLOAT(texel[2]); @@ -1480,8 +1480,8 @@ opt_sample_rgba_2d(struct gl_context *ctx, (void) swImg; for (i = 0; i < n; i++) { - const GLint col = IFLOOR(texcoords[i][0] * width) & colMask; - const GLint row = IFLOOR(texcoords[i][1] * height) & rowMask; + const GLint col = util_ifloor(texcoords[i][0] * width) & colMask; + const GLint row = util_ifloor(texcoords[i][1] * height) & rowMask; const GLint pos = (row << shift) | col; const GLuint texel = *((GLuint *) swImg->ImageSlices[0] + pos); rgba[i][RCOMP] = UBYTE_TO_FLOAT( (texel >> 24) ); diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c index 65b10a89dfa..467439c3fc0 100644 --- a/src/mesa/swrast/s_triangle.c +++ b/src/mesa/swrast/s_triangle.c @@ -621,8 +621,8 @@ fast_persp_span(struct gl_context *ctx, SWspan *span, (1.0 / tex_coord[2]) : 1.0; \ GLfloat s_tmp = (GLfloat) (tex_coord[0] * invQ); \ GLfloat t_tmp = (GLfloat) (tex_coord[1] * invQ); \ - GLint s = IFLOOR(s_tmp) & info->smask; \ - GLint t = IFLOOR(t_tmp) & info->tmask; \ + GLint s = util_ifloor(s_tmp) & info->smask; \ + GLint t = util_ifloor(t_tmp) & info->tmask; \ GLint pos = (t << info->twidth_log2) + s; \ const GLchan *tex00 = info->texture + COMP * pos; \ DO_TEX; \ diff --git a/src/util/imports.h b/src/util/imports.h index 385b37c81b5..d56bd77e03b 100644 --- a/src/util/imports.h +++ b/src/util/imports.h @@ -129,37 +129,6 @@ static inline int IROUND_POS(float f) return (int) (f + 0.5F); } -/** Return (as an integer) floor of float */ -static inline int IFLOOR(float f) -{ -#if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__) - /* - * IEEE floor for computers that round to nearest or even. - * 'f' must be between -4194304 and 4194303. - * This floor operation is done by "(iround(f + .5) + iround(f - .5)) >> 1", - * but uses some IEEE specific tricks for better speed. - * Contributed by Josh Vanderhoof - */ - int ai, bi; - double af, bf; - af = (3 << 22) + 0.5 + (double)f; - bf = (3 << 22) + 0.5 - (double)f; - /* GCC generates an extra fstp/fld without this. */ - __asm__ ("fstps %0" : "=m" (ai) : "t" (af) : "st"); - __asm__ ("fstps %0" : "=m" (bi) : "t" (bf) : "st"); - return (ai - bi) >> 1; -#else - int ai, bi; - double af, bf; - fi_type u; - af = (3 << 22) + 0.5 + (double)f; - bf = (3 << 22) + 0.5 - (double)f; - u.f = (float) af; ai = u.i; - u.f = (float) bf; bi = u.i; - return (ai - bi) >> 1; -#endif -} - /********************************************************************** * Functions |