[RFC] imgrel/imagerel operator from the clang integrated assembler and the Microsoft assembler

Jan Beulich jbeulich@suse.com
Wed Nov 13 08:39:05 GMT 2024


On 13.11.2024 05:49, Julian Waters wrote:
> The reply from Intel mentions that it has to do with the addressing
> mode, to quote:
> 
> In case of vmovupd that you show below, the addressing mode used has
> base (rdx), index (rcx), and displacement
> (imagerel(__jsvml_dtanh_ha_data_internal)+2624). The base/index are
> registers and displacement is the constant. The displacement in this
> addressing mode can only be 32bits so the 64-bit base is loaded into
> rdx first.
> 
> The assembly we were talking about was this:
> 
> lea       rdx, QWORD PTR [__ImageBase]
> ...
> vmovupd   xmm2, XMMWORD PTR
> [imagerel(__jsvml_dtanh_ha_data_internal)+2624+rdx+rcx]

While I follow what they're saying, I don't see why

	lea       rdx, [__jsvml_dtanh_ha_data_internal]
	...
	vmovupd   xmm2, XMMWORD PTR [2624+rdx+rcx]

wouldn't achieve the same (with the MASM implication that the LEA actually
uses RIP-relative addressing, unlike gas would do when the operand doesn't
explicitly say so).

Or wait, I think I can finally see why their approach is preferable in the
common case (perhaps not in the specific function we did look at). If more
than one variable wants using in this same way inside the same function,
then holding the (common) image base in a register is more efficient. So
yes, even leaving aside Michael's arguments it looks like we want to gain
support for this.

Jan


More information about the Binutils mailing list