On Tue, 2024-09-10 at 16:50 +0800, 梅杰 wrote: > As for the function `__builtin_rint`, although it exists, however, after > defining the instruction in `mips.md`, GCC still won't generate `RINT.fmt` > instruction for MIPS, it generates following code instead: > > > lui $28,%hi(__gnu_local_gp) > > addiu $28,$28,%lo(__gnu_local_gp) > > lw $25,%call16(rint)($28) > > .reloc 1f,R_MIPS_JALR,rint
Why? Whis this: diff --git a/gcc/config/mips/mips.md b/gcc/config/mips/mips.md index f147667d63a..0c1ef77a816 100644 --- a/gcc/config/mips/mips.md +++ b/gcc/config/mips/mips.md @@ -100,6 +100,7 @@ (define_c_enum "unspec" [ ;; Floating-point unspecs. UNSPEC_FMIN UNSPEC_FMAX + UNSPEC_RINT ;; HI/LO moves. UNSPEC_MFHI @@ -8025,6 +8026,14 @@ (define_peephole2 (any_extend:SI (match_dup 3)))])] "") +(define_insn "rint<mode>2" + [(set (match_operand:SCALARF 0 "register_operand" "=f") + (unspec:SCALARF [(match_operand:SCALARF 1 "register_operand" " f")] + UNSPEC_RINT))] + "mips_isa_rev >= 6" + "rint.<fmt>\t%0,%1") + + ;; Synchronization instructions. it works for me: $ cat t.c double test(double x) { return __builtin_rint(x); } $ ./gcc/cc1 t.c -nostdinc -O2 -mips64r6 -mexplicit-relocs -mabi=64 $ grep rint t.s rint.d $f0,$f12 -- Xi Ruoyao <xry...@xry111.site> School of Aerospace Science and Technology, Xidian University