[gfortran] Fix PR17631: intrinsic MVBITS missing

Paul Brook paul@codesourcery.com
Thu Sep 23 19:33:00 GMT 2004


On Thursday 23 September 2004 19:45, Tobias Schlüter wrote:
> This is an implmentation of the MVBITS intrinsic. It is not complete in
> that it doesn't support integer kinds besides integer*4, but since

In that case we should geneate an error (or fail to link) for the 
unimplemented cases. AFAICS your implementation will silently bad code for 
other type kinds.

> implementing this in the library isn't a really smart thing to do (MVBITS
> should take some 10 assembler instructions to implement) I didn't bother to
> either learn m4 or implement some preprocessor hackery to support other
> types as well.

I agree that implementing this inline is the right thing to do.

<...>

> void
> prefix (mvbits) (GFC_INTEGER_4 *from, GFC_INTEGER_4 *frompos,
>                  GFC_INTEGER_4 *len, GFC_INTEGER_4 *to,
>                  GFC_INTEGER_4 *topos)
> {
>   GFC_INTEGER_4 oldbits, newbits, lenmask;
>
>   lenmask = (1 << *len) - 1;

Doesn't work when len==32.

>   newbits = ((*from & (lenmask << *frompos)) >> *frompos) << *topos;

Doesn't work for negative numbers. Technically the bit representation of 
negative values is undefined, but we should make it work anyway. You probably 
need to use unsigned values to ensure logical shifts rather than arithmetic 
shifts.

Also, this can be written as
  newbits = ((*from >> *frompos) & lenmask) << *topos;
Though this still doesn't work for negative values.

Paul



More information about the Gcc-patches mailing list