Home | History | Annotate | Download | only in x86
      1 
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 #include <assert.h>
      5 #include "tests/malloc.h"
      6 
      7 typedef  unsigned char           UChar;
      8 typedef  unsigned int            UInt;
      9 typedef  unsigned long int       UWord;
     10 typedef  unsigned long long int  ULong;
     11 
     12 
     13 typedef  struct { UChar cs[40]; }  Block;
     14 
     15 void showBlock ( char* msg, Block* b )
     16 {
     17    int i;
     18    printf("  %s ", msg);
     19    for (i = 0; i < 40; i++)
     20       printf("%02x", (UInt)b->cs[i]);
     21    printf("\n");
     22 }
     23 
     24 UChar randUChar ( void )
     25 {
     26    static UInt seed = 80021;
     27    seed = 1103515245 * seed + 12345;
     28    return (seed >> 17) & 0xFF;
     29 }
     30 
     31 void randBlock ( Block* b )
     32 {
     33    int i;
     34    UChar* p = (UChar*)b;
     35    for (i = 0; i < sizeof(Block); i++)
     36       p[i] = randUChar();
     37 }
     38 
     39 /* Generate a function test_NAME, that tests the given insn.
     40    The insn may only mention (%eax) and esi. */
     41 
     42 #define GEN_test_Monly(_name, _mem_form)   \
     43     \
     44     __attribute__ ((noinline)) static void test_##_name ( void )   \
     45     { \
     46        Block* b = memalign32(sizeof(Block)); \
     47        randBlock(b); \
     48        printf("%s\n", #_name); \
     49        showBlock("before", b); \
     50        __asm__ __volatile__( \
     51           "leal      16(%0),%%eax"  "\n\t" \
     52           "movl      24(%0),%%esi"   "\n\t" \
     53           _mem_form  "\n\t" \
     54           "movl      %%esi, 32(%0)"  "\n\t" \
     55           : /*OUT*/  \
     56           : /*IN*/"r"(b) \
     57           : /*TRASH*/"esi","eax","memory","cc" \
     58        ); \
     59        showBlock("after ", b); \
     60        printf("\n"); \
     61        free(b); \
     62     }
     63 
     64 GEN_test_Monly( MOVBE_RtoM_32, "movbel %%esi,1(%%eax)")
     65 GEN_test_Monly( MOVBE_RtoM_16, "movbew %%si,1(%%eax)")
     66 
     67 GEN_test_Monly( MOVBE_MtoR_32, "movbel 1(%%eax), %%esi")
     68 GEN_test_Monly( MOVBE_MtoR_16, "movbew 1(%%eax), %%si")
     69 
     70 int main ( void )
     71 {
     72    test_MOVBE_RtoM_32();
     73    test_MOVBE_RtoM_16();
     74    test_MOVBE_MtoR_32();
     75    test_MOVBE_MtoR_16();
     76    return 0;
     77 }
     78