[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC PATCH 4/6] softfloat: add float*_to_int128 conversion methods
From: |
Richard Henderson |
Subject: |
Re: [RFC PATCH 4/6] softfloat: add float*_to_int128 conversion methods |
Date: |
Tue, 29 Mar 2022 06:10:53 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 |
On 3/28/22 14:14, matheus.ferst@eldorado.org.br wrote:
+static int64_t partsN(float_to_sint2)(FloatPartsN *p, FloatRoundMode rmode,
+ int scale, float_status *s, uint64_t *lo)
+{
+ int flags = 0;
+ uint64_t hi;
Similar comment about 'lo' vs '*lo'.
+ if (p->exp <= DECOMPOSED_BINARY_POINT) {
+ hi = 0;
+ *lo = p->frac_hi >> (DECOMPOSED_BINARY_POINT - p->exp);
+ } else if (p->exp <= 127) {
+ int shift = 127 - p->exp;
+ hi = shr_double(0, p->frac_hi, shift);
Same comment about double-shift w/ 0.
+ if (N > 64) {
+ *lo = shr_double(p->frac_hi, p->frac_lo, shift);
+ } else {
+ *lo = shr_double(p->frac_hi, 0, shift);
+ }
+ } else {
+ hi = UINT64_MAX;
+ *lo = UINT64_MAX;
+ }
+ if (p->sign) {
+ if (hi < INT64_MIN || (hi == INT64_MIN && *lo == 0)) {
+ *lo = -*lo;
+ hi = ~hi + !*lo;
+ } else {
+ flags = float_flag_invalid | float_flag_invalid_cvti;
+ hi = INT64_MIN;
+ *lo = 0;
+ }
+ } else if (hi > INT64_MAX) {
+ flags = float_flag_invalid | float_flag_invalid_cvti;
+ hi = INT64_MAX;
+ *lo = UINT64_MAX;
+ }
Hmm. It seemed easy to arrange the code this way with just a uint64_t, but here I think
it might be worth detecting overflow earlier, via exp.
if (p->exp < 127) {
/* No overflow possible */
int shift = 127 - p->exp;
if (shift >= 64) {
hi = 0;
lo = p->frac_hi >> (shift - 64);
} else {
hi = p->frac_hi >> shift;
lo = shr_double(p->frac_hi, N > 64 ? p->frac_lo : 0, shift);
}
if (p->sign) {
lo = -lo;
hi = ~hi + !lo;
}
break;
}
/* The only valid 127-bit number is UINT128_MIN. */
if (p->exp == 127 &&
p->sign &&
p->frac_hi == DECOMPOSED_IMPLICIT_BIT &&
(N <= 64 || p->frac_lo == 0)) {
hi = INT64_MIN;
lo = 0;
break;
}
/* Overflow. */
flags = ...;
if (p->sign)
...
r~
- [RFC PATCH 0/6] softfloat 128-bit integer support, matheus . ferst, 2022/03/28
- [RFC PATCH 1/6] softfloat: add uint128_to_float* conversion methods, matheus . ferst, 2022/03/28
- [RFC PATCH 2/6] softfloat: add int128_to_float* conversion methods, matheus . ferst, 2022/03/28
- [RFC PATCH 3/6] softfloat: add float*_to_uint128 conversion methods, matheus . ferst, 2022/03/28
- [RFC PATCH 4/6] softfloat: add float*_to_int128 conversion methods, matheus . ferst, 2022/03/28
- Re: [RFC PATCH 4/6] softfloat: add float*_to_int128 conversion methods,
Richard Henderson <=
- [RFC PATCH 5/6] target/ppc: implement xscv[su]qqp, matheus . ferst, 2022/03/28
- [RFC PATCH 6/6] target/ppc: implement xscvqp[su]qz, matheus . ferst, 2022/03/28
- Re: [RFC PATCH 0/6] softfloat 128-bit integer support, Richard Henderson, 2022/03/28