On Sat, Jun 7, 2025 at 10:05 PM Takayuki 'January June' Suwa
<jjsuwa_sys3...@yahoo.co.jp> wrote:
>
> By using the previously unused CEIL|FLOOR.S floating-point coprocessor
> instructions.  In addition, two instruction operand format codes are added
> to output the scale value as assembler source.
>
>      /* example */
>      int test0(float a) {
>        return __builtin_lceilf(a);
>      }
>      int test1(float a) {
>        return __builtin_lceilf(a * 2);
>      }
>      int test2(float a) {
>        return __builtin_lfloorf(a);
>      }
>      int test3(float a) {
>        return __builtin_lfloorf(a * 32768);
>      }
>
>      ;; result
>      test0:
>         entry   sp, 32
>         wfr     f0, a2
>         ceil.s  a2, f0, 0
>         retw.n
>      test1:
>         entry   sp, 32
>         wfr     f0, a2
>         ceil.s  a2, f0, 1
>         retw.n
>      test2:
>         entry   sp, 32
>         wfr     f0, a2
>         floor.s a2, f0, 0
>         retw.n
>      test3:
>         entry   sp, 32
>         wfr     f0, a2
>         floor.s a2, f0, 15
>         retw.n
>
> However, because the rounding-half behavior (e.g., the rule that determines
> whether 1.5 should be rounded to 1 or 2) of the two is inconsistent;
> the lroundsfsi2 pattern is explicitly specified that rounding to nearest
> integer and away from zero, but the other hand, the ROUND.S instruction is
> not specified that by the ISA and is implementation-dependent.
>
> Therefore lroundsfsi2 cannot be implemented by ROUND.S.
>
> gcc/ChangeLog:
>
>         * config/xtensa/xtensa.cc (printx, print_operand):
>         Add two instruction operand format codes 'U' and 'V',
>         whose represent scale factors of 0 to 15th positive/negative
>         power of two.
>         * gcc/config/xtensa/xtensa.md (c_enum "unspec"):
>         Add UNSPEC_CEIL and UNSPEC_FLOOR.
>         (int_iterator ANY_ROUND, int_attr m_round):
>         New integer iterator and its attribute.
>         (fix<s_fix>_truncsfsi2, *fix<s_fix>_truncsfsi2_2x,
>         *fix<s_fix>_truncsfsi2_scaled, float<s_float>sisf2,
>         *float<s_float>sisf2_scaled):
>         Use output templates with the operand formats added above,
>         instead of individual output statements.
>         (l<m_round>sfsi2, *l<m_round>sfsi2_2x, *l<m_round>sfsi2_scaled):
>         New insn patterns.
> ---
>   gcc/config/xtensa/xtensa.cc | 16 ++++++++++++
>   gcc/config/xtensa/xtensa.md | 50 ++++++++++++++++++++++++++++---------
>   2 files changed, 54 insertions(+), 12 deletions(-)

Regtested for target=xtensa-linux-uclibc, no new regressions.
Committed to master.

-- 
Thanks.
-- Max

Reply via email to