diff options
| author | Heikki Linnakangas | 2016-08-31 13:00:28 +0000 |
|---|---|---|
| committer | Heikki Linnakangas | 2016-08-31 13:00:28 +0000 |
| commit | 14cca1bf8e31ed39dbc26dd6c610f1113e759972 (patch) | |
| tree | 489757c243e8ec3564adfe383f494426dc0e16ae /src/backend/utils/fmgr/fmgr.c | |
| parent | 0e0f43d6fdc2e1fbd5261245ed4cf85302a3f653 (diff) | |
Use static inline functions for float <-> Datum conversions.
Now that we are OK with using static inline functions, we can use them
to avoid function call overhead of pass-by-val versions of Float4GetDatum,
DatumGetFloat8, and Float8GetDatum. Those functions are only a few CPU
instructions long, but they could not be written into macros previously,
because we need a local union variable for the conversion.
I kept the pass-by-ref versions as regular functions. They are very simple
too, but they call palloc() anyway, so shaving a few instructions from the
function call doesn't seem so important there.
Discussion: <[email protected]>
Diffstat (limited to 'src/backend/utils/fmgr/fmgr.c')
| -rw-r--r-- | src/backend/utils/fmgr/fmgr.c | 63 |
1 files changed, 6 insertions, 57 deletions
diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c index 7e6a60d6241..7aae35074fa 100644 --- a/src/backend/utils/fmgr/fmgr.c +++ b/src/backend/utils/fmgr/fmgr.c @@ -2126,10 +2126,7 @@ fmgr(Oid procedureId,...) * * int8, float4, and float8 can be passed by value if Datum is wide enough. * (For backwards-compatibility reasons, we allow pass-by-ref to be chosen - * at compile time even if pass-by-val is possible.) For the float types, - * we need a support routine even if we are passing by value, because many - * machines pass int and float function parameters/results differently; - * so we need to play weird games with unions. + * at compile time even if pass-by-val is possible.) * * Note: there is only one switch controlling the pass-by-value option for * both int8 and float8; this is to avoid making things unduly complicated @@ -2149,77 +2146,29 @@ Int64GetDatum(int64 X) } #endif /* USE_FLOAT8_BYVAL */ +#ifndef USE_FLOAT4_BYVAL + Datum Float4GetDatum(float4 X) { -#ifdef USE_FLOAT4_BYVAL - union - { - float4 value; - int32 retval; - } myunion; - - myunion.value = X; - return SET_4_BYTES(myunion.retval); -#else float4 *retval = (float4 *) palloc(sizeof(float4)); *retval = X; return PointerGetDatum(retval); -#endif } +#endif -#ifdef USE_FLOAT4_BYVAL - -float4 -DatumGetFloat4(Datum X) -{ - union - { - int32 value; - float4 retval; - } myunion; - - myunion.value = GET_4_BYTES(X); - return myunion.retval; -} -#endif /* USE_FLOAT4_BYVAL */ +#ifndef USE_FLOAT8_BYVAL Datum Float8GetDatum(float8 X) { -#ifdef USE_FLOAT8_BYVAL - union - { - float8 value; - int64 retval; - } myunion; - - myunion.value = X; - return SET_8_BYTES(myunion.retval); -#else float8 *retval = (float8 *) palloc(sizeof(float8)); *retval = X; return PointerGetDatum(retval); -#endif } - -#ifdef USE_FLOAT8_BYVAL - -float8 -DatumGetFloat8(Datum X) -{ - union - { - int64 value; - float8 retval; - } myunion; - - myunion.value = GET_8_BYTES(X); - return myunion.retval; -} -#endif /* USE_FLOAT8_BYVAL */ +#endif /*------------------------------------------------------------------------- |
