This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: PowerPC gas/ immediate range checking?


Geoff Keating wrote:
> 

> 0xdead is the 32-bit value 0x0000dead.  You can't add this to a
> register in a single instruction.  Instead, you must do:
> 
> addis r3,r3,-1
> addi r3,r3,0x10000-0xdead
> 
> If you really meant to add -0x2153, it's probably better to write that.
> GAS performs this check mostly to catch machine-generated operands that
> overflow, for instance
> 
> Lbar:   addi r3,r3,Lfoo-Lbar
>         ...
> Lfoo:
> 
> or
> 
>         li r3,CO_APIC_LEVEL
> 
> where it isn't obvious that the operand would overflow.

That makes sense from a compiler-generated code point of view.  However, for
those that hand-code their asm, it's counter-intuitive.  Reading the arch
manual (and having experience working with in-house pseudo-assemblers that only
look at the lower 16 bits of the immediate), I'd expect the lower 16 bits to be
smashed into the assembled instruction regardless of what the upper bits were.
I can see, though, wanting to be able to error-check the value in generated
code.

The above option isn't an option for me, as I'm writing performance-oriented
code, and adding instructions is not a good thing.  Using signed integer
notation is also ugly and unreadable, as the number is an address that is
generated by a macro. I guess I'll change my macros that generate the
immediates to prepend the immediate with f's if it's meant to be negative.
Actually, I'd already begun doing this - I was just hoping there was some
option to disable the checking for non-generated code(the "-iknowwhatimdoing"
option ;-), or that there was some way to stipulate that the 16-bit hex
constant was meant to be treated as a signed 16-bit number.

Off to write *ugly* asm code not.

Thanks,
B


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]