summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/util/u_half.h
diff options
context:
space:
mode:
authorCorbin Simpson <[email protected]>2010-04-01 14:41:18 -0700
committerCorbin Simpson <[email protected]>2010-04-01 14:41:18 -0700
commit950300eb255f0e3507bf2757d16c3b5bc8ff3471 (patch)
tree32f374257a273fd27de266005a5343aaa2577471 /src/gallium/auxiliary/util/u_half.h
parent7e1aceaf0a1fb7b4ee44c7bc488f03b584b8b785 (diff)
util: Init half-float tables on demand.
Gets rid of unnecessary delays on startup and compiler-specific hax.
Diffstat (limited to 'src/gallium/auxiliary/util/u_half.h')
-rw-r--r--src/gallium/auxiliary/util/u_half.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/gallium/auxiliary/util/u_half.h b/src/gallium/auxiliary/util/u_half.h
index 5afdd925a62..50948cadf59 100644
--- a/src/gallium/auxiliary/util/u_half.h
+++ b/src/gallium/auxiliary/util/u_half.h
@@ -8,13 +8,14 @@
extern "C" {
#endif
-
extern uint32_t util_half_to_float_mantissa_table[2048];
extern uint32_t util_half_to_float_exponent_table[64];
extern uint32_t util_half_to_float_offset_table[64];
extern uint16_t util_float_to_half_base_table[512];
extern uint8_t util_float_to_half_shift_table[512];
+void util_half_init_tables(void);
+
/*
* Note that if the half float is a signaling NaN, the x87 FPU will turn
* it into a quiet NaN immediately upon loading into a float.
@@ -30,6 +31,7 @@ static INLINE uint32_t
util_half_to_floatui(half h)
{
unsigned exp = h >> 10;
+ util_half_init_tables();
return util_half_to_float_mantissa_table[util_half_to_float_offset_table[exp] + (h & 0x3ff)]
+ util_half_to_float_exponent_table[exp];
}
@@ -38,6 +40,7 @@ static INLINE float
util_half_to_float(half h)
{
union fi r;
+ util_half_init_tables();
r.ui = util_half_to_floatui(h);
return r.f;
}
@@ -46,6 +49,7 @@ static INLINE half
util_floatui_to_half(uint32_t v)
{
unsigned signexp = v >> 23;
+ util_half_init_tables();
return util_float_to_half_base_table[signexp]
+ ((v & 0x007fffff) >> util_float_to_half_shift_table[signexp]);
}
@@ -54,6 +58,7 @@ static INLINE half
util_float_to_half(float f)
{
union fi i;
+ util_half_init_tables();
i.f = f;
return util_floatui_to_half(i.ui);
}