8000 Allow float8, int8, and related datatypes to be passed by value on ma… · postgrespro/postgres_cluster@8472bf7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8472bf7

Browse files
committed
Allow float8, int8, and related datatypes to be passed by value on machines
where Datum is 8 bytes wide. Since this will break old-style C functions (those still using version 0 calling convention) that have arguments or results of these types, provide a configure option to disable it and retain the old pass-by-reference behavior. Likewise, provide a configure option to disable the recently-committed float4 pass-by-value change. Zoltan Boszormenyi, plus configurability stuff by me.
1 parent be93954 commit 8472bf7

File tree

36 files changed

+661
-243
lines changed
  • fmgr
  • init
  • bin
  • include
  • test/regress
  • tools/msvc
  • 36 files changed

    +661
    -243
    lines changed

    configure

    Lines changed: 133 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1362,6 +1362,8 @@ Optional Features:
    13621362
    --enable-cassert enable assertion checks (for debugging)
    13631363
    --enable-thread-safety make client libraries thread-safe
    13641364
    --enable-thread-safety-force force thread-safety despite thread test failure
    1365+
    --disable-float4-byval disable float4 passed by value
    1366+
    --disable-float8-byval disable float8 passed by value
    13651367
    --disable-largefile omit support for large files
    13661368

    13671369
    Optional Packages:
    @@ -20838,6 +20840,137 @@ _ACEOF
    2083820840

    2083920841

    2084020842

    20843+
    # Decide whether float4 is passed by value: user-selectable, enabled by default
    20844+
    { echo "$as_me:$LINENO: checking whether to build with float4 passed by value" >&5
    20845+
    echo $ECHO_N "checking whether to build with float4 passed by value... $ECHO_C" >&6; }
    20846+
    20847+
    pgac_args="$pgac_args enable_float4_byval"
    20848+
    20849+
    # Check whether --enable-float4-byval was given.
    20850+
    if test "${enable_float4_byval+set}" = set; then
    20851+
    enableval=$enable_float4_byval;
    20852+
    case $enableval in
    20853+
    yes)
    20854+
    20855+
    cat >>confdefs.h <<\_ACEOF
    20856+
    #define USE_FLOAT4_BYVAL 1
    20857+
    _ACEOF
    20858+
    20859+
    float4passbyval=true
    20860+
    ;;
    20861+
    no)
    20862+
    float4passbyval=false
    20863+
    ;;
    20864+
    *)
    20865+
    { { echo "$as_me:$LINENO: error: no argument expected for --enable-float4-byval option" >&5
    20866+
    echo "$as_me: error: no argument expected for --enable-float4-byval option" >&2;}
    20867+
    { (exit 1); exit 1; }; }
    20868+
    ;;
    20869+
    esac
    20870+
    20871+
    else
    20872+
    enable_float4_byval=yes
    20873+
    20874+
    cat >>confdefs.h <<\_ACEOF
    20875+
    #define USE_FLOAT4_BYVAL 1
    20876+
    _ACEOF
    20877+
    20878+
    float4passbyval=true
    20879+
    fi
    20880+
    20881+
    20882+
    { echo "$as_me:$LINENO: result: $enable_float4_byval" >&5
    20883+
    echo "${ECHO_T}$enable_float4_byval" >&6; }
    20884+
    20885+
    cat >>confdefs.h <<_ACEOF
    20886+
    #define FLOAT4PASSBYVAL $float4passbyval
    20887+
    _ACEOF
    20888+
    20889+
    20890+
    # Decide whether float8 is passed by value.
    20891+
    # Note: this setting also controls int8 and related types such as timestamp.
    20892+
    # If sizeof(Datum) >= 8, this is user-selectable, enabled by default.
    20893+
    # If not, trying to select it is an error.
    20894+
    { echo "$as_me:$LINENO: checking whether to build with float8 passed by value" >&5
    20895+
    echo $ECHO_N "checking whether to build with float8 passed by value... $ECHO_C" >&6; }
    20896+
    if test $ac_cv_sizeof_unsigned_long -ge 8 ; then
    20897+
    20898+
    pgac_args="$pgac_args enable_float8_byval"
    20899+
    20900+
    # Check whether --enable-float8-byval was given.
    20901+
    if test "${enable_float8_byval+set}" = set; then
    20902+
    enableval=$enable_float8_byval;
    20903+
    case $enableval in
    20904+
    yes)
    20905+
    :
    20906+
    ;;
    20907+
    no)
    20908+
    :
    20909+
    ;;
    20910+
    *)
    20911+
    { { echo "$as_me:$LINENO: error: no argument expected for --enable-float8-byval option" >&5
    20912+
    echo "$as_me: error: no argument expected for --enable-float8-byval option" >&2;}
    20913+
    { (exit 1); exit 1; }; }
    20914+
    ;;
    20915+
    esac
    20916+
    20917+
    else
    20918+
    enable_float8_byval=yes
    20919+
    20920+
    fi
    20921+
    20922+
    20923+
    else
    20924+
    20925+
    pgac_args="$pgac_args enable_float8_byval"
    20926+
    20927+
    # Check whether --enable-float8-byval was given.
    20928+
    if test "${enable_float8_byval+set}" = set; then
    20929+
    enableval=$enable_float8_byval;
    20930+
    case $enableval in
    20931+
    yes)
    20932+
    :
    20933+
    ;;
    20934+
    no)
    20935+
    :
    20936+
    ;;
    20937+
    *)
    20938+
    { { echo "$as_me:$LINENO: error: no argument expected for --enable-float8-byval option" >&5
    20939+
    echo "$as_me: error: no argument expected for --enable-float8-byval option" >&2;}
    20940+
    { (exit 1); exit 1; }; }
    20941+
    ;;
    20942+
    esac
    20943+
    20944+
    else
    20945+
    enable_float8_byval=no
    20946+
    20947+
    fi
    20948+
    20949+
    20950+
    if test "$enable_float8_byval" = yes ; then
    20951+
    { { echo "$as_me:$LINENO: error: --enable-float8-byval is not supported on 32-bit platforms." >&5
    20952+
    echo "$as_me: error: --enable-float8-byval is not supported on 32-bit platforms." >&2;}
    20953+
    { (exit 1); exit 1; }; }
    20954+
    fi
    20955+
    fi
    20956+
    if test "$enable_float8_byval" = yes ; then
    20957+
    20958+
    cat >>confdefs.h <<\_ACEOF
    20959+
    #define USE_FLOAT8_BYVAL 1
    20960+
    _ACEOF
    20961+
    20962+
    float8passbyval=true
    20963+
    else
    20964+
    float8passbyval=false
    20965+
    fi
    20966+
    { echo "$as_me:$LINENO: result: $enable_float8_byval" >&5
    20967+
    echo "${ECHO_T}$enable_float8_byval" >&6; }
    20968+
    20969+
    cat >>confdefs.h <<_ACEOF
    20970+
    #define FLOAT8PASSBYVAL $float8passbyval
    20971+
    _ACEOF
    20972+
    20973+
    2084120974
    # Determine memory alignment requirements for the basic C data types.
    2084220975

    2084320976
    { echo "$as_me:$LINENO: checking for short" >&5

    configure.in

    Lines changed: 34 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -1,5 +1,5 @@
    11
    dnl Process this file with autoconf to produce a configure script.
    2-
    dnl $PostgreSQL: pgsql/configure.in,v 1.555 2008/03/30 04:08:14 neilc Exp $
    2+
    dnl $PostgreSQL: pgsql/configure.in,v 1.556 2008/04/21 00:26:44 tgl Exp $
    33
    dnl
    44
    dnl Developers, please strive to achieve this order:
    55
    dnl
    @@ -1368,6 +1368,39 @@ AC_CHECK_SIZEOF([unsigned long])
    13681368
    # And one for the size of size_t (enables tweaks for > 32bit address space)
    13691369
    AC_CHECK_SIZEOF([size_t])
    13701370

    1371+
    # Decide whether float4 is passed by value: user-selectable, enabled by default
    1372+
    AC_MSG_CHECKING([whether to build with float4 passed by value])
    1373+
    PGAC_ARG_BOOL(enable, float4-byval, yes, [ --disable-float4-byval disable float4 passed by value],
    1374+
    [AC_DEFINE([USE_FLOAT4_BYVAL], 1,
    1375+
    [Define to 1 if you want float4 values to be passed by value. (--enable-float4-byval)])
    1376+
    float4passbyval=true],
    1377+
    [float4passbyval=false])
    1378+
    AC_MSG_RESULT([$enable_float4_byval])
    1379+
    AC_DEFINE_UNQUOTED([FLOAT4PASSBYVAL], [$float4passbyval], [float4 values are passed by value if 'true', by reference if 'false'])
    1380+
    1381+
    # Decide whether float8 is passed by value.
    1382+
    # Note: this setting also controls int8 and related types such as timestamp.
    1383+
    # If sizeof(Datum) >= 8, this is user-selectable, enabled by default.
    1384+
    # If not, trying to select it is an error.
    1385+
    AC_MSG_CHECKING([whether to build with float8 passed by value])
    1386+
    if test $ac_cv_sizeof_unsigned_long -ge 8 ; then
    1387+
    PGAC_ARG_BOOL(enable, float8-byval, yes, [ --disable-float8-byval disable float8 passed by value])
    1388+
    else
    1389+
    PGAC_ARG_BOOL(enable, float8-byval, no, [ --disable-float8-byval disable float8 passed by value])
    1390+
    if test "$enable_float8_byval" = yes ; then
    1391+
    AC_MSG_ERROR([--enable-float8-byval is not supported on 32-bit platforms.])
    1392+
    fi
    1393+
    fi
    1394+
    if test "$enable_float8_byval" = yes ; then
    1395+
    AC_DEFINE([USE_FLOAT8_BYVAL], 1,
    1396+
    [Define to 1 if you want float8, int8, etc values to be passed by value. (--enable-float8-byval)])
    1397+
    float8passbyval=true
    1398+
    else
    1399+
    float8passbyval=false
    1400+
    fi
    1401+
    AC_MSG_RESULT([$enable_float8_byval])
    1402+
    AC_DEFINE_UNQUOTED([FLOAT8PASSBYVAL], [$float8passbyval], [float8, int8, and related values are passed by value if 'true', by reference if 'false'])
    1403+
    13711404
    # Determine memory alignment requirements for the basic C data types.
    13721405

    13731406
    AC_CHECK_ALIGNOF(short)

    contrib/btree_gist/btree_cash.c

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -96,7 +96,7 @@ Datum
    9696
    gbt_cash_consistent(PG_FUNCTION_ARGS)
    9797
    {
    9898
    GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
    99-
    Cash query = (*((Cash *) PG_GETARG_POINTER(1)));
    99+
    Cash query = PG_GETARG_CASH(1);
    100100
    StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
    101101
    /* Oid subtype = PG_GETARG_OID(3); */
    102102
    bool *recheck = (bool *) PG_GETARG_POINTER(4);

    contrib/btree_gist/btree_time.c

    Lines changed: 42 additions & 22 deletions
    Original file line numberDiff line numberDiff line change
    @@ -31,46 +31,66 @@ Datum gbt_time_penalty(PG_FUNCTION_ARGS);
    3131
    Datum gbt_time_same(PG_FUNCTION_ARGS);
    3232

    3333

    34-
    #define P_TimeADTGetDatum(x) PointerGetDatum( &(x) )
    34+
    #ifdef USE_FLOAT8_BYVAL
    35+
    #define TimeADTGetDatumFast(X) TimeADTGetDatum(X)
    36+
    #else
    37+
    #define TimeADTGetDatumFast(X) PointerGetDatum(&(X))
    38+
    #endif
    39+
    3540

    3641
    static bool
    3742
    gbt_timegt(const void *a, const void *b)
    3843
    {
    39-
    return DatumGetBool(
    40-
    DirectFunctionCall2(time_gt, PointerGetDatum(a), PointerGetDatum(b))
    41-
    );
    44+
    const TimeADT *aa = (const TimeADT *) a;
    45+
    const TimeADT *bb = (const TimeADT *) b;
    46+
    47+
    return DatumGetBool(DirectFunctionCall2(time_gt,
    48+
    TimeADTGetDatumFast(*aa),
    49+
    TimeADTGetDatumFast(*bb)));
    4250
    }
    4351

    4452
    static bool
    4553
    gbt_timege(const void *a, const void *b)
    4654
    {
    47-
    return DatumGetBool(
    48-
    DirectFunctionCall2(time_ge, PointerGetDatum(a), PointerGetDatum(b))
    49-
    );
    55+
    const TimeADT *aa = (const TimeADT *) a;
    56+
    const TimeADT *bb = (const TimeADT *) b;
    57+
    58+
    return DatumGetBool(DirectFunctionCall2(time_ge,
    59+
    TimeADTGetDatumFast(*aa),
    60+
    TimeADTGetDatumFast(*bb)));
    5061
    }
    5162

    5263
    static bool
    5364
    gbt_timeeq(const void *a, const void *b)
    5465
    {
    55-
    return DatumGetBool(
    56-
    DirectFunctionCall2(time_eq, PointerGetDatum(a), PointerGetDatum(b))
    57-
    );
    66+
    const TimeADT *aa = (const TimeADT *) a;
    67+
    const TimeADT *bb = (const TimeADT *) b;
    68+
    69+
    return DatumGetBool(DirectFunctionCall2(time_eq,
    70+
    TimeADTGetDatumFast(*aa),
    71+
    TimeADTGetDatumFast(*bb)));
    5872
    }
    5973

    6074
    static bool
    6175
    gbt_timele(const void *a, const void *b)
    6276
    {
    63-
    return DatumGetBool(
    64-
    DirectFunctionCall2(time_le, PointerGetDatum(a), PointerGetDatum(b))
    65-
    );
    77+
    const TimeADT *aa = (const TimeADT *) a;
    78+
    const TimeADT *bb = (const TimeADT *) b;
    79+
    80+
    return DatumGetBool(DirectFunctionCall2(time_le,
    81+
    TimeADTGetDatumFast(*aa),
    82+
    TimeADTGetDatumFast(*bb)));
    6683
    }
    6784

    6885
    static bool
    6986
    gbt_timelt(const void *a, const void *b)
    7087
    {
    71-
    return DatumGetBool(
    72-
    DirectFunctionCall2(time_lt, PointerGetDatum(a), PointerGetDatum(b))
    73-
    );
    88+
    const TimeADT *aa = (const TimeADT *) a;
    89+
    const TimeADT *bb = (const TimeADT *) b;
    90+
    91+
    return DatumGetBool(DirectFunctionCall2(time_lt,
    92+
    TimeADTGetDatumFast(*aa),
    93+
    TimeADTGetDatumFast(*bb)));
    7494
    }
    7595

    7696

    @@ -221,15 +241,15 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
    221241

    222242
    intr = DatumGetIntervalP(DirectFunctionCall2(
    223243
    time_mi_time,
    224-
    P_TimeADTGetDatum(newentry->upper),
    225-
    P_TimeADTGetDatum(origentry->upper)));
    244+
    TimeADTGetDatumFast(newentry->upper),
    245+
    TimeADTGetDatumFast(origentry->upper)));
    226246
    res = INTERVAL_TO_SEC(intr);
    227247
    res = Max(res, 0);
    228248

    229249
    intr = DatumGetIntervalP(DirectFunctionCall2(
    230250
    time_mi_time,
    231-
    P_TimeADTGetDatum(origentry->lower),
    232-
    P_TimeADTGetDatum(newentry->lower)));
    251+
    TimeADTGetDatumFast(origentry->lower),
    252+
    TimeADTGetDatumFast(newentry->lower)));
    233253
    res2 = INTERVAL_TO_SEC(intr);
    234254
    res2 = Max(res2, 0);
    235255

    @@ -241,8 +261,8 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
    241261
    {
    242262
    intr = DatumGetIntervalP(DirectFunctionCall2(
    243263
    time_mi_time,
    244-
    P_TimeADTGetDatum(origentry->upper),
    245-
    P_TimeADTGetDatum(origentry->lower)));
    264+
    TimeADTGetDatumFast(origentry->upper),
    265+
    TimeADTGetDatumFast(origentry->lower)));
    246266
    *result += FLT_MIN;
    247267
    *result += (float) (res / (res + INTERVAL_TO_SEC(intr)));
    248268
    *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));

    0 commit comments

    Comments
     (0)
    0