On Fri, Oct 02, 2015 at 11:18:32AM -0400, Rich Felker wrote: > > > +#ifdef __FDPIC__ > > > +#define udiv_qrnnd(q, r, n1, n0, d) \ > > > + do { > > > \ > > > + extern UWtype __udiv_qrnnd_16 (UWtype, UWtype) > > > \ > > > > It's really difficult to spot the subtle difference of the FDPIC version > > and the non-FDPIC version. At least there should be a comment. > > OK, I can add a comment; this is appropriate anyway since the way it's > making the FDPIC call is unconventional.
Before I add comments, can we discuss whether the approach I took is appropriate? The udiv_qrnnd asm block takes as an operand a function pointer for __udiv_qrnnd_16 which it calls from asm. The __udiv_qrnnd_16 function is itself written in asm has a special contract for register clobbers, and it doesn't need a GOT register. The non-FDPIC asm calls it via jsr @%5 (%5 is the function pointer) but on FDPIC the function pointer points to a function descriptor, not code, so an extra level of indirection is needed. This is actually inefficient to do in asm because we have to repeat it twice. Normally an FDPIC call would also require loading the GOT pointer from the function descriptor, but since this call is local, that can be skipped. Another option would be to pass (essentially) *(void**)__udiv_qrnnd_16 instead of __udiv_qrnnd_16 to the asm block; then the existing inline asm can be used as-is. This could be done via passing SH_CODE_ADDRESS(__udiv_qrnnd_16) instead of __udiv_qrnnd_16, where SH_CODE_ADDRESS would be a macro defined to pass through its argument for non-FDPIC and to extract the code address from the function descriptor for FDPIC. However I'm not convinced it's clean/safe to do the above punning. At the very least a may_alias attribute probably belongs in there somewhere. But an approach like this would reduce code duplication and slightly improve the size/performance of the resulting code. Opinions? Rich