This is an archive of the discontinued LLVM Phabricator instance.

Clang: Define macro _MIPS_SPFPSET
ClosedPublic

Authored by wzssyqa on Aug 14 2023, 9:21 AM.

Details

Summary

GCC defines this macro for how many single-precision floating point registers
can be used.

If the -mno-odd-spreg option is given, it will be 16; if either -mno-odd-spreg
nor -modd-spreg are given, we set it to 16 for FPXX.

Diff Detail

Event Timeline

wzssyqa created this revision.Aug 14 2023, 9:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 14 2023, 9:21 AM
wzssyqa requested review of this revision.Aug 14 2023, 9:21 AM

In GCC, -mno-odd-spreg -modd-spreg affects code generation. If we don't implement the behavior, I am not sure we can define _MIPS_SPFPSET.

Actually, do we really want to define the macro? CodeSearch context:global _MIPS_SPFPSET -f:gcc|sysdeps/ (regex) gives no result.

In GCC, -mno-odd-spreg -modd-spreg affects code generation. If we don't implement the behavior, I am not sure we can define _MIPS_SPFPSET.

Actually, do we really want to define the macro? CodeSearch context:global _MIPS_SPFPSET -f:gcc|sysdeps/ (regex) gives no result.

I am working on libunwind. I'd plan to use this macro to

In GCC, -mno-odd-spreg -modd-spreg affects code generation. If we don't implement the behavior, I am not sure we can define _MIPS_SPFPSET.

We do implement this behavior. I test with this code

float x(float a, float b) {
	return a*3+b*4;
}

The objdump result of clang -O2 -mfpxx -mno-odd-spreg -target mipsel-linux-gnu -c xx.c

00000000 <x>:
   0:	3c020000 	lui	v0,0x0
   4:	24420000 	addiu	v0,v0,0
   8:	00590821 	addu	at,v0,t9
   c:	8c220000 	lw	v0,0(at)
  10:	c4400000 	lwc1	$f0,0(v0)
  14:	46007002 	mul.s	$f0,$f14,$f0
  18:	8c210000 	lw	at,0(at)
  1c:	c4220000 	lwc1	$f2,0(at)
  20:	46026082 	mul.s	$f2,$f12,$f2
  24:	03e00008 	jr	ra
  28:	46001000 	add.s	$f0,$f2,$f0

The objdump result of clang -O2 -mfpxx -modd-spreg -target mipsel-linux-gnu -c xx.c

00000000 <x>:
   0:	3c020000 	lui	v0,0x0
   4:	24420000 	addiu	v0,v0,0
   8:	00590821 	addu	at,v0,t9
   c:	8c220000 	lw	v0,0(at)
  10:	c4400000 	lwc1	$f0,0(v0)
  14:	46007002 	mul.s	$f0,$f14,$f0
  18:	8c210000 	lw	at,0(at)
  1c:	c4210000 	lwc1	$f1,0(at)
  20:	46016042 	mul.s	$f1,$f12,$f1
  24:	03e00008 	jr	ra
  28:	46000800 	add.s	$f0,$f1,$f0

Actually, do we really want to define the macro? CodeSearch context:global _MIPS_SPFPSET -f:gcc|sysdeps/ (regex) gives no result.

I am working on libunwind to support both FP64 (-mfp64), and FPXX (-mfpxx -mno-odd-spreg).
It will need this macro.

  1. if __mips_fpr == 64, all 32 64bit FPR can be read/write with getFloatRegister, setFloatRegister.
  2. if __mips_fpr != 64, and _MIPS_SPFPSET==32, which means -modd-spreg is used, we should just reject to compile.
  3. if __mips_fpr != 64 and _MIPS_SPFPSET==16, which means -mno-odd-spreg is used. we can support it. if the argument is even-FPR, we just do the request, and if it's odd-FPR, _LIBUNWIND_ABORT can be used to reject it.
theraven accepted this revision.Aug 30 2023, 11:54 PM

Looks fine to me, though I’ve never seen code using this macro. For a single (not yet implemented) consumer I’m not certain it’s worth putting in the compiler since the same place in the build system that adds the flag directing code generation can also add a -D flag.

This revision is now accepted and ready to land.Aug 30 2023, 11:54 PM

Looks fine to me, though I’ve never seen code using this macro. For a single (not yet implemented) consumer I’m not certain it’s worth putting in the compiler since the same place in the build system that adds the flag directing code generation can also add a -D flag.

I add this macro, as I plan to use it for libunwind.
Since the float point will quite different then.

brad edited the summary of this revision. (Show Details)Oct 21 2023, 4:14 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptOct 21 2023, 4:16 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript