]> git.ipfire.org Git - thirdparty/gcc.git/commit
xtensa: Implement l(ceil|floor)sfsi2 insn patterns and their scaled variants
authorTakayuki 'January June' Suwa <jjsuwa_sys3175@yahoo.co.jp>
Sun, 8 Jun 2025 05:05:05 +0000 (14:05 +0900)
committerMax Filippov <jcmvbkbc@gmail.com>
Sun, 8 Jun 2025 10:31:20 +0000 (03:31 -0700)
commit5f3b5b0616fe883e86e95d9476371cf87059ca7f
treed27d197709b47ec2da996e666504516d32af67fc
parentb76f1fb7bf8a7b66b8acd469309257f8b18c0c51
xtensa: Implement l(ceil|floor)sfsi2 insn patterns and their scaled variants

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.
* 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
gcc/config/xtensa/xtensa.md