Using gcc inline assembly to Shift Right fails with "Error: operand type mismatch for `shr'"

Solution Verified - Updated -

Issue

  • Using gcc inline assembly to Shift Right fails with
asmshift.c: Assembler messages:
asmshift.c:8: Error: operand type mismatch for `shr'
  • Example code uses SHR Shift Right instruction, eg:
     1  #include <stdio.h>
     2  #include <stdint.h>
     3
     4  static inline int atna_shrc64pu(uint64_t *d, uint64_t b, int crin, int *cr)
     5  {
     6    // assumed *d = a;
     7    asm("neg %1\n\t"
     8        "shrq %3,%0\n\t"
     9        :"+r"(d), "+&r"(crin), "=@ccc"(*cr)
    10        :"r"(b));
    11    return 1;
    12  }

Environment

  • Red Hat Enterprise Linux 8.5
  • GNU C compiler (gcc-8.5.0-4.el8_5)
  • GNU GAS assembler (binutils-2.30-108.el8_5.1)

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content