On Fri, Mar 21, 2025 at 07:12:23PM +0100, Richard Biener wrote: > So this is the following hunk where I totally misunderstood > real_to_target when converting this from native_encode_expr and > a tree to using REAL_VALUE_TYPE: > > @@ -15702,13 +15714,16 @@ initial_from_float128(cbl_field_t *field, > _Float128 va > lue) > switch( field->data.capacity ) > { > case 4: > - *(_Float32 *)retval = (_Float32) value; > + value = real_value_truncate (TYPE_MODE (FLOAT), value); > + real_to_target ((long *)retval, &value, TYPE_MODE (FLOAT)); > break; > case 8: > - *(_Float64 *)retval = (_Float64) value; > + value = real_value_truncate (TYPE_MODE (DOUBLE), value); > + real_to_target ((long *)retval, &value, TYPE_MODE (DOUBLE)); > break; > case 16: > - *(_Float128 *)retval = (_Float128) value; > + value = real_value_truncate (TYPE_MODE (FLOAT128), value); > + real_to_target ((long *)retval, &value, TYPE_MODE (FLOAT128)); > break; > > an incremental fix is the following, exposing a native_encode_real > with REAL_VALUE_TYPE input would be nicer, but going back to > native_encode_expr works. So - can you apply the following and > re-try? A testcase for the 0.01 vs. 0.0 thing would be nice to have > as well.
I think you could avoid the jump through build_real + native_encode_expr by moving parts of native_encode_real into a helper function and export that helper function from fold-const.h (unless you want to duplicate it). Basically add a helper where you pass REAL_VALUE_TYPE * + scalar_float_mode instead of tree. real_to_target writes up to 6 longs where each long contains 32 bits and then one needs to store bytes from that according to target endianity. > --- a/gcc/cobol/genapi.cc > +++ b/gcc/cobol/genapi.cc > @@ -15710,20 +15710,24 @@ initial_from_float128(cbl_field_t *field) > > case FldFloat: > { > + tree tem; > retval = (char *)xmalloc(field->data.capacity); > switch( field->data.capacity ) > { > case 4: > value = real_value_truncate (TYPE_MODE (FLOAT), value); > - real_to_target ((long *)retval, &value, TYPE_MODE (FLOAT)); > + tem = build_real (FLOAT, value); > + native_encode_expr (tem, (unsigned char *)retval, 4, 0); > break; Jakub