summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/radeon_textured_video.c26
-rw-r--r--src/radeon_textured_videofuncs.c43
2 files changed, 28 insertions, 41 deletions
diff --git a/src/radeon_textured_video.c b/src/radeon_textured_video.c
index 8fc380e1..c7d06202 100644
--- a/src/radeon_textured_video.c
+++ b/src/radeon_textured_video.c
@@ -80,6 +80,32 @@ static __inline__ uint32_t F_TO_DW(float val)
return tmp.l;
}
+/* Borrowed from Mesa */
+static __inline__ uint32_t F_TO_24(float val)
+{
+ float mantissa;
+ int exponent;
+ uint32_t float24 = 0;
+
+ if (val == 0.0)
+ return 0;
+
+ mantissa = frexpf(val, &exponent);
+
+ /* Handle -ve */
+ if (mantissa < 0) {
+ float24 |= (1 << 23);
+ mantissa = mantissa * -1.0;
+ }
+ /* Handle exponent, bias of 63 */
+ exponent += 62;
+ float24 |= (exponent << 16);
+ /* Kill 7 LSB of mantissa */
+ float24 |= (F_TO_DW(mantissa) & 0x7FFFFF) >> 7;
+
+ return float24;
+}
+
#define ACCEL_MMIO
#define ACCEL_PREAMBLE() unsigned char *RADEONMMIO = info->MMIO
#define BEGIN_ACCEL(n) RADEONWaitForFifo(pScrn, (n))
diff --git a/src/radeon_textured_videofuncs.c b/src/radeon_textured_videofuncs.c
index 8fb87981..8c90f418 100644
--- a/src/radeon_textured_videofuncs.c
+++ b/src/radeon_textured_videofuncs.c
@@ -90,45 +90,6 @@ do { \
#endif /* !ACCEL_CP */
-#ifndef __FLOAT_TO_S16E7__
-#define __FLOAT_TO_S16E7__
-
-static int float_to_s16e7(float in)
-{
- union {
- float f;
- int i;
- } x;
-
- int s, e, f, out; // sign, exponent, fraction
-
- x.f = in;
- s = (x.i & (1 << 31)) >> 31;
- e = (x.i & 0x7f800000) >> 23;
- f = (x.i & 0x007fffff);
-
- /* unbias the exponent */
- e = e - 127;
- if (e < -63)
- e = -63;
- else if (e > 63)
- e = 63;
-
- e += 63;
-
- /* prepend implicit 1 to fraction */
- f |= (1 << 23);
- /* cut mantissa to 16 bits */
- f = (f & 0xffff80) >> 8;
-
- out = s;
- out = (out << 7) | e;
- out = (out << 16) | f;
-
- return out;
-}
-#endif
-
static void
FUNC_NAME(RADEONDisplayTexturedVideo)(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv)
{
@@ -710,13 +671,13 @@ FUNC_NAME(RADEONDisplayTexturedVideo)(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv
R300_ALU_ALPHA_OMASK(R300_ALU_ALPHA_MASK_A)));
/* Shader constants. */
- OUT_ACCEL_REG(R300_US_ALU_CONST_R(0), float_to_s16e7(1.0/(float)pPriv->w));
+ OUT_ACCEL_REG(R300_US_ALU_CONST_R(0), F_TO_24(1.0/(float)pPriv->w));
OUT_ACCEL_REG(R300_US_ALU_CONST_G(0), 0);
OUT_ACCEL_REG(R300_US_ALU_CONST_B(0), 0);
OUT_ACCEL_REG(R300_US_ALU_CONST_A(0), 0);
OUT_ACCEL_REG(R300_US_ALU_CONST_R(1), 0);
- OUT_ACCEL_REG(R300_US_ALU_CONST_G(1), float_to_s16e7(1.0/(float)pPriv->h));
+ OUT_ACCEL_REG(R300_US_ALU_CONST_G(1), F_TO_24(1.0/(float)pPriv->h));
OUT_ACCEL_REG(R300_US_ALU_CONST_B(1), 0);
OUT_ACCEL_REG(R300_US_ALU_CONST_A(1), 0);