1  /* { dg-do run } */
       2  
       3  #include <stdio.h>
       4  
       5  /* Test A/L, B/H, C, D, d, e, f, g operand modifiers on 32-bit, 64-bit and,
       6     where appropriate, 16-bit values.  */
       7  
       8  #define MEM16_VAL 0x2345
       9  #define MEM32_VAL 0x89abcdef
      10  #define MEM64_VAL 0xfedcba9876543210
      11  
      12  #define CONST16_VAL 0xbcde
      13  #define CONST32_VAL 0x99aabbcc
      14  #define CONST64_VAL 0x8899aabbccddeeff
      15  
      16  #define REG32_VAL 0x12345678
      17  #define REG64_VAL 0x123456789abcdef
      18  
      19  volatile unsigned long mem16 = MEM16_VAL;
      20  volatile unsigned long mem32 = MEM32_VAL;
      21  volatile unsigned long long mem64 = MEM64_VAL;
      22  
      23  unsigned int word0, word1, word2, word3;
      24  unsigned char byte0, byte1, byte2, byte3, byte4, byte5, byte6, byte7;
      25  
      26  #define CHECK_BYTES_IN_16BIT_VAL(VAL)		\
      27    if (byte0 != ((unsigned char)VAL)			\
      28        || byte1 != ((unsigned char)(VAL >> 8)))	\
      29      return 1;
      30  
      31  #define CHECK_WORDS_IN_32BIT_VAL(VAL)		\
      32    if (word0 != ((unsigned)VAL)			\
      33        || word1 != ((unsigned)(VAL >> 16)))	\
      34      return 1;
      35  
      36  #define CHECK_WORDS_IN_64BIT_VAL(VAL)		\
      37    if (word0 != ((unsigned)VAL)		\
      38        || word1 != ((unsigned)(VAL >> 16))	\
      39        || word2 != ((unsigned)(VAL >> 32))	\
      40        || word3 != ((unsigned)(VAL >> 48)))	\
      41      return 1;
      42  
      43  #define CHECK_BYTES_IN_32BIT_VAL(VAL)		\
      44    if (byte0 != ((unsigned char)VAL)		\
      45        || byte1 != ((unsigned char)(VAL >> 8))	\
      46        || byte2 != ((unsigned char)(VAL >> 16))	\
      47        || byte3 != ((unsigned char)(VAL >> 24)))	\
      48      return 1;
      49  
      50  #define CHECK_BYTES_IN_64BIT_VAL(VAL)		\
      51    if (byte0 != ((unsigned char)VAL)		\
      52        || byte1 != ((unsigned char)(VAL >> 8))	\
      53        || byte2 != ((unsigned char)(VAL >> 16))	\
      54        || byte3 != ((unsigned char)(VAL >> 24))	\
      55        || byte4 != ((unsigned char)(VAL >> 32))	\
      56        || byte5 != ((unsigned char)(VAL >> 40))	\
      57        || byte6 != ((unsigned char)(VAL >> 48))	\
      58        || byte7 != ((unsigned char)(VAL >> 56)))	\
      59      return 1;
      60  
      61  int
      62  main (void)
      63  {
      64    unsigned long register reg32 = REG32_VAL;
      65    unsigned long long register reg64 = REG64_VAL;
      66  
      67    /* *** MEMORY OPERAND TESTS *** */
      68    /* Test byte extraction of a 16-bit value.  */
      69    __asm__("mov.b %A1, %0\n" : "=m" (byte0) : "m" (mem16));
      70    __asm__("mov.b %d1, %0\n" : "=m" (byte1) : "m" (mem16));
      71    CHECK_BYTES_IN_16BIT_VAL (MEM16_VAL);
      72  
      73    /* Test extraction of high and low words from 32-bit value.  */
      74    __asm__("mov %A1, %0\n" : "=m" (word0) : "m" (mem32));
      75    __asm__("mov %B1, %0\n" : "=m" (word1) : "m" (mem32));
      76    CHECK_WORDS_IN_32BIT_VAL (MEM32_VAL);
      77  
      78    /* Test extraction of each word of a 64-bit value.  */
      79    __asm__("mov %A1, %0\n" : "=m" (word0) : "m" (mem64));
      80    __asm__("mov %B1, %0\n" : "=m" (word1) : "m" (mem64));
      81    __asm__("mov %C1, %0\n" : "=m" (word2) : "m" (mem64));
      82    __asm__("mov %D1, %0\n" : "=m" (word3) : "m" (mem64));
      83    CHECK_WORDS_IN_64BIT_VAL (MEM64_VAL);
      84  
      85    /* Test extraction of each byte of a 32-bit value.  */
      86    __asm__("mov.b %A1, %0\n" : "=m" (byte0) : "m" (mem32));
      87    __asm__("mov.b %d1, %0\n" : "=m" (byte1) : "m" (mem32));
      88    __asm__("mov.b %B1, %0\n" : "=m" (byte2) : "m" (mem32));
      89    __asm__("mov.b %e1, %0\n" : "=m" (byte3) : "m" (mem32));
      90    CHECK_BYTES_IN_32BIT_VAL (MEM32_VAL);
      91  
      92    /* Test extraction of each byte of a 64-bit value.  */
      93    __asm__("mov.b %A1, %0\n" : "=m" (byte0) : "m" (mem64));
      94    __asm__("mov.b %d1, %0\n" : "=m" (byte1) : "m" (mem64));
      95    __asm__("mov.b %B1, %0\n" : "=m" (byte2) : "m" (mem64));
      96    __asm__("mov.b %e1, %0\n" : "=m" (byte3) : "m" (mem64));
      97    __asm__("mov.b %C1, %0\n" : "=m" (byte4) : "m" (mem64));
      98    __asm__("mov.b %f1, %0\n" : "=m" (byte5) : "m" (mem64));
      99    __asm__("mov.b %D1, %0\n" : "=m" (byte6) : "m" (mem64));
     100    __asm__("mov.b %g1, %0\n" : "=m" (byte7) : "m" (mem64));
     101    CHECK_BYTES_IN_64BIT_VAL (MEM64_VAL);
     102  
     103    /* *** IMMEDIATE OPERAND TESTS *** */
     104    /* Test byte extraction of a 16-bit value.  */
     105    __asm__("mov.b %A1, %0\n" : "=m" (byte0) : "i" (CONST16_VAL));
     106    __asm__("mov.b %d1, %0\n" : "=m" (byte1) : "i" (CONST16_VAL));
     107    CHECK_BYTES_IN_16BIT_VAL (CONST16_VAL);
     108  
     109    /* Test extraction of high and low words from 32-bit value.  */
     110    __asm__("mov %A1, %0\n" : "=m" (word0) : "i" (CONST32_VAL));
     111    __asm__("mov %B1, %0\n" : "=m" (word1) : "i" (CONST32_VAL));
     112    CHECK_WORDS_IN_32BIT_VAL (CONST32_VAL);
     113  
     114    /* Test extraction of each word of a 64-bit value.  */
     115    __asm__("mov %A1, %0\n" : "=m" (word0) : "i" (CONST64_VAL));
     116    __asm__("mov %B1, %0\n" : "=m" (word1) : "i" (CONST64_VAL));
     117    __asm__("mov %C1, %0\n" : "=m" (word2) : "i" (CONST64_VAL));
     118    __asm__("mov %D1, %0\n" : "=m" (word3) : "i" (CONST64_VAL));
     119    CHECK_WORDS_IN_64BIT_VAL (CONST64_VAL);
     120  
     121    /* Test extraction of each byte of a 32-bit value.  */
     122    __asm__("mov.b %A1, %0\n" : "=m" (byte0) : "i" (CONST32_VAL));
     123    __asm__("mov.b %d1, %0\n" : "=m" (byte1) : "i" (CONST32_VAL));
     124    __asm__("mov.b %B1, %0\n" : "=m" (byte2) : "i" (CONST32_VAL));
     125    __asm__("mov.b %e1, %0\n" : "=m" (byte3) : "i" (CONST32_VAL));
     126    CHECK_BYTES_IN_32BIT_VAL (CONST32_VAL);
     127  
     128    /* Test extraction of each byte of a 64-bit value.  */
     129    __asm__("mov.b %A1, %0\n" : "=m" (byte0) : "i" (CONST64_VAL));
     130    __asm__("mov.b %d1, %0\n" : "=m" (byte1) : "i" (CONST64_VAL));
     131    __asm__("mov.b %B1, %0\n" : "=m" (byte2) : "i" (CONST64_VAL));
     132    __asm__("mov.b %e1, %0\n" : "=m" (byte3) : "i" (CONST64_VAL));
     133    __asm__("mov.b %C1, %0\n" : "=m" (byte4) : "i" (CONST64_VAL));
     134    __asm__("mov.b %f1, %0\n" : "=m" (byte5) : "i" (CONST64_VAL));
     135    __asm__("mov.b %D1, %0\n" : "=m" (byte6) : "i" (CONST64_VAL));
     136    __asm__("mov.b %g1, %0\n" : "=m" (byte7) : "i" (CONST64_VAL));
     137    CHECK_BYTES_IN_64BIT_VAL (CONST64_VAL);
     138  
     139    /* *** REGISTER OPERAND TESTS *** */
     140    /* No extraction of bytes from a single register.  */
     141  
     142    /* Test extraction of high and low words from 32-bit value.  */
     143    __asm__("mov %A1, %0\n" : "=m" (word0) : "r" (reg32));
     144    __asm__("mov %B1, %0\n" : "=m" (word1) : "r" (reg32));
     145    CHECK_WORDS_IN_32BIT_VAL (REG32_VAL);
     146  
     147    /* Test extraction of each word of a 64-bit value.  */
     148    __asm__("mov %A1, %0\n" : "=m" (word0) : "r" (reg64));
     149    __asm__("mov %B1, %0\n" : "=m" (word1) : "r" (reg64));
     150    __asm__("mov %C1, %0\n" : "=m" (word2) : "r" (reg64));
     151    __asm__("mov %D1, %0\n" : "=m" (word3) : "r" (reg64));
     152    CHECK_WORDS_IN_64BIT_VAL (REG64_VAL);
     153  
     154    return 0;
     155  }