> > > diff --git a/gcc/config/riscv/iterators.md b/gcc/config/riscv/iterators.md > > > index 9b767038452..c81b08e3cc5 100644 > > > --- a/gcc/config/riscv/iterators.md > > > +++ b/gcc/config/riscv/iterators.md > > > @@ -288,3 +288,8 @@ (define_int_iterator QUIET_COMPARISON > > > [UNSPEC_FLT_QUIET UNSPEC_FLE_QUIET]) > > > (define_int_attr quiet_pattern [(UNSPEC_FLT_QUIET "lt") > > > (UNSPEC_FLE_QUIET "le")]) > > > (define_int_attr QUIET_PATTERN [(UNSPEC_FLT_QUIET "LT") > > > (UNSPEC_FLE_QUIET "LE")]) > > > > > > +(define_int_iterator ROUND [UNSPEC_ROUND UNSPEC_FLOOR UNSPEC_CEIL > > > UNSPEC_BTRUNC UNSPEC_ROUNDEVEN UNSPEC_NEARBYINT]) > > > +(define_int_attr round_pattern [(UNSPEC_ROUND "round") (UNSPEC_FLOOR > > > "floor") (UNSPEC_CEIL "ceil") > > > + (UNSPEC_BTRUNC "btrunc") (UNSPEC_ROUNDEVEN > > > "roundeven") (UNSPEC_NEARBYINT "nearbyint")]) > > > +(define_int_attr round_rm [(UNSPEC_ROUND "rmm") (UNSPEC_FLOOR "rdn") > > > (UNSPEC_CEIL "rup") > > > + (UNSPEC_BTRUNC "rtz") (UNSPEC_ROUNDEVEN "rne") > > > (UNSPEC_NEARBYINT "dyn")]) > > Do we really need to use unspecs for all these cases? I would expect > > some correspond to the trunc, round, ceil, nearbyint, etc well known RTX > > codes. > > > > In general, we should try to avoid unspecs when there is a clear > > semantic match between the instruction and GCC's RTX opcodes. So please > > review the existing RTX code semantics to see if any match the new > > instructions. If there are matches, use those RTX codes rather than > > UNSPECs. > > I'll try, thanks.
I encountered some confusion about this. I checked gcc's documents and found no RTX codes that can correspond to round, ceil, nearbyint, etc. Only "(fix:m x)" seems to correspond to trunc, which can be expressed as rounding towards zero, while others have not yet been found. In addition, I found that other architectures also seem to adopt the unspecs for all these cases on the latest master branch. arm: https://github.com/gcc-mirror/gcc/commit/1dd4fe1fd892458ce29f15f3ca95125a11b2534f#diff-159a39276c509272adfaeef91c2110f54f65c38f7fd1ab2f1e750af0a7f86377R1251 rs6000: https://github.com/gcc-mirror/gcc/commit/7042fe5ef83ff0585eb91144817105f26d566d4c#diff-1a2d4976d867ead4556899cab1dbb39f5069574276e06a2976fb62b771ece2e3R6995 i386: https://github.com/gcc-mirror/gcc/commit/3e8c4b925a9825fdb8c81f47b621f63108894362#diff-f00b14a8846eb6aaeb981077e36ac3668160d7dabb490beeb1f62792afa83281R23332 Can you give me some advice? > > > @@ -1580,6 +1609,26 @@ (define_insn > > > "l<rint_pattern><ANYF:mode><GPR:mode>2" > > > [(set_attr "type" "fcvt") > > > (set_attr "mode" "<ANYF:MODE>")]) > > > > > > +(define_insn "<round_pattern><ANYF:mode>2" > > > + [(set (match_operand:ANYF 0 "register_operand" "=f") > > > + (unspec:ANYF > > > + [(match_operand:ANYF 1 "register_operand" " f")] > > > + ROUND))] > > > + "TARGET_HARD_FLOAT && TARGET_ZFA" > > > + "fround.<ANYF:fmt>\t%0,%1,<round_rm>" > > > + [(set_attr "type" "fcvt") > > > + (set_attr "mode" "<ANYF:MODE>")]) > > > + > > > +(define_insn "rint<ANYF:mode>2" > > > + [(set (match_operand:ANYF 0 "register_operand" "=f") > > > + (unspec:ANYF > > > + [(match_operand:ANYF 1 "register_operand" " f")] > > > + UNSPEC_RINT))] > > > + "TARGET_HARD_FLOAT && TARGET_ZFA" > > > + "froundnx.<ANYF:fmt>\t%0,%1" > > > + [(set_attr "type" "fcvt") > > > + (set_attr "mode" "<ANYF:MODE>")]) > > Please review the existing RTX codes and their semantics in the > > internals manual and if any of the new instructions match those existing > > primitives, implement them using those RTX codes rather than with an UNSPEC. > > > > I'll try, thanks. > thanks. Jin Ma