https://gcc.gnu.org/g:9ac0ff5ea5f5a2c96f1599d271a42e226929d30b
commit r15-9001-g9ac0ff5ea5f5a2c96f1599d271a42e226929d30b Author: Richard Biener <rguent...@suse.de> Date: Fri Mar 21 19:30:31 2025 +0100 Export native_encode_real operating on REAL_VALUE_TYPE The following exports the native_encode_real worker, and makes it take a scalar float mode and REAL_VALUE_TYPE data instead of a tree for use in the COBOL frontend, avoiding creating of a temporary tree. * fold-const.h (native_encode_real): Export. * fold-const.cc (native_encode_real): Change API to take mode and REAL_VALUE_TYPE. (native_encode_expr): Adjust. Diff: --- gcc/fold-const.cc | 13 +++++++------ gcc/fold-const.h | 2 ++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index fef7a6cc48ef..a4fb0147a0b1 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -7572,11 +7572,11 @@ native_encode_fixed (const_tree expr, unsigned char *ptr, int len, int off) Return the number of bytes placed in the buffer, or zero upon failure. */ -static int -native_encode_real (const_tree expr, unsigned char *ptr, int len, int off) +int +native_encode_real (scalar_float_mode mode, const REAL_VALUE_TYPE *val, + unsigned char *ptr, int len, int off) { - tree type = TREE_TYPE (expr); - int total_bytes = GET_MODE_SIZE (SCALAR_FLOAT_TYPE_MODE (type)); + int total_bytes = GET_MODE_SIZE (mode); int byte, offset, word, words, bitpos; unsigned char value; @@ -7596,7 +7596,7 @@ native_encode_real (const_tree expr, unsigned char *ptr, int len, int off) words = (32 / BITS_PER_UNIT) / UNITS_PER_WORD; - real_to_target (tmp, TREE_REAL_CST_PTR (expr), TYPE_MODE (type)); + real_to_target (tmp, val, mode); for (bitpos = 0; bitpos < total_bytes * BITS_PER_UNIT; bitpos += BITS_PER_UNIT) @@ -7836,7 +7836,8 @@ native_encode_expr (const_tree expr, unsigned char *ptr, int len, int off) return native_encode_int (expr, ptr, len, off); case REAL_CST: - return native_encode_real (expr, ptr, len, off); + return native_encode_real (SCALAR_FLOAT_TYPE_MODE (TREE_TYPE (expr)), + TREE_REAL_CST_PTR (expr), ptr, len, off); case FIXED_CST: return native_encode_fixed (expr, ptr, len, off); diff --git a/gcc/fold-const.h b/gcc/fold-const.h index f20fb58271df..43deea4d69c5 100644 --- a/gcc/fold-const.h +++ b/gcc/fold-const.h @@ -35,6 +35,8 @@ extern bool folding_cxx_constexpr; extern int native_encode_expr (const_tree, unsigned char *, int, int off = -1); extern int native_encode_initializer (tree, unsigned char *, int, int off = -1, unsigned char * = nullptr); +extern int native_encode_real (scalar_float_mode, const REAL_VALUE_TYPE *, + unsigned char *, int, int off = -1); extern tree native_interpret_expr (tree, const unsigned char *, int); extern tree native_interpret_real (tree, const unsigned char *, int); extern bool can_native_interpret_type_p (tree);