SHARE
TWEET

Untitled

a guest Oct 3rd, 2017 112 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.    
  3.     static __inline__ int MIN(int a, int b){
  4.     int result =a;
  5.     __asm__ ("pminsw %1, %0" : "+x" (result) : "x" (b));
  6.     return result;
  7.     }
  8.     static __inline__ int MAX(int a, int b){
  9.     int result = a;
  10.     __asm__ ("pmaxsw %1, %0" : "+x" (result) : "x" (b));
  11.     return result;
  12.     }
  13.     static __inline__ unsigned long long rdtsc(void){
  14.       unsigned long long int x;
  15.     __asm__ volatile (".byte 0x0f, 0x31" :
  16.       "=A" (x));
  17.       return x;
  18.     }
  19.    
  20.     #define MIN3(a, b, c) (MIN(MIN(a,b),c))
  21.     #define MIN4(a, b, c, d) (MIN(MIN(a,b),MIN(c,d)))
  22.    
  23.     static __inline__ void sort6(int * in) {
  24.       const int A=in[0], B=in[1], C=in[2], D=in[3], E=in[4], F=in[5];
  25.    
  26.       in[0] = MIN( MIN4(A,B,C,D),MIN(E,F) );
  27.    
  28.       const int
  29.       AB = MAX(A, B),
  30.       AC = MAX(A, C),
  31.       AD = MAX(A, D),
  32.       AE = MAX(A, E),
  33.       AF = MAX(A, F),
  34.       BC = MAX(B, C),
  35.       BD = MAX(B, D),
  36.       BE = MAX(B, E),
  37.       BF = MAX(B, F),
  38.       CD = MAX(C, D),
  39.       CE = MAX(C, E),
  40.       CF = MAX(C, F),
  41.       DE = MAX(D, E),
  42.       DF = MAX(D, F),
  43.       EF = MAX(E, F);
  44.    
  45.       in[1] = MIN4 (
  46.       MIN4( AB, AC, AD, AE ),
  47.       MIN4( AF, BC, BD, BE ),
  48.       MIN4( BF, CD, CE, CF ),
  49.       MIN3( DE, DF, EF)
  50.       );
  51.    
  52.       const int
  53.       ABCD = MAX(AB,CD),
  54.       ABCE = MAX(AB,CE),
  55.       ABCF = MAX(AB,CF),
  56.       ABDE = MAX(AB,DE),
  57.       ABDF = MAX(AB,DF),
  58.       ABEF = MAX(AB,EF),
  59.       ACDE = MAX(AC,DE),
  60.       ACDF = MAX(AC,DF),
  61.       ACEF = MAX(AC,EF),
  62.       ADEF = MAX(AD,EF),
  63.       BCDE = MAX(BC,DE),
  64.       BCDF = MAX(BC,DF),
  65.       BCEF = MAX(BC,EF),
  66.       BDEF = MAX(BD,EF),
  67.       CDEF = MAX(CD,EF);
  68.    
  69.       in[3] = MIN4 (
  70.       MIN4( ABCD, ABCE, ABCF, ABDE ),
  71.       MIN4( ABDF, ABEF, ACDE, ACDF ),
  72.       MIN4( ACEF, ADEF, BCDE, BCDF ),
  73.       MIN3( BCEF, BDEF, CDEF )
  74.       );
  75.    
  76.       const int
  77.       ABCDE= MAX(ABCD,E),
  78.       ABCDF= MAX(ABCD,F),
  79.       ABCEF= MAX(ABCE,F),
  80.       ABDEF= MAX(ABDE,F),
  81.       ACDEF= MAX(ACDE,F),
  82.       BCDEF= MAX(BCDE,F);
  83.    
  84.       in[4]= MIN (
  85.       MIN4( ABCDE, ABCDF, ABCEF, ABDEF ),
  86.       MIN ( ACDEF, BCDEF )
  87.       );
  88.    
  89.       in[5] = MAX(ABCDE,F);
  90.      
  91.       in[2] = A+B+C+D+E+F-(in[0]+in[1]+in[3]+in[4]+in[5]);
  92.     }
  93.    
  94.     int main(int argc, char ** argv) {
  95.       int d[6][6] = {
  96.         {1, 2, 3, 4, 5, 6},
  97.         {6, 5, 4, 3, 2, 1},
  98.         {100, 2, 300, 4, 500, 6},
  99.         {100, 2, 3, 4, 500, 6},
  100.         {1, 200, 3, 4, 5, 600},
  101.         {1, 1, 2, 1, 2, 1}
  102.       };
  103.    
  104.       unsigned long long cycles = rdtsc();
  105.       for (int i = 0; i < 6; i++) {
  106.         sort6(d[i]);
  107.       }
  108.       cycles = rdtsc() - cycles;
  109.       printf("Time is %d\n", (unsigned)cycles);
  110.    
  111.       for (int i = 0; i < 6; i++) {
  112.         printf("d%d : %d %d %d %d %d %d\n", i,
  113.          d[i][0], d[i][1], d[i][2],
  114.          d[i][3], d[i][4], d[i][5]);
  115.       }
  116.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top