Is this SSE-performance test program(C++, __asm) logical in terms of data-alignment and cache-management?
===

i am learning C++ and assembly. I created some intense calculation functions to test my SSE-capable CPU. Can anyone try this program? 
More importantly can you convert xmm parameters to ymm parameters and run the program and get the results?
    
    This program uses SSE and some SSE2 instructions.

    I appreciate anyone who can try and show the results.

Thanks.
My computer: laptop-centrino CPU(pentium-M)

On my computer, general results:

    x=1.0/sqrt(1+x): __asm is nearly 60x faster than unoptimized C++ code
    conversion of number-system: __asm is only 2x faster
    increment-decrement of vector: __asm is 35x faster
    String copying: __asm using aligned code is 60x faster. unaligned is 20x faster than copying 1 byte by 1
    pushing general-purpose registers to stack: storing in xmm is %50 faster
    128-bit logical binary operations: __asm is %50 faster
    empty loops: __asmp is 3x fast
    4D distance: __asm %100 faster

To start, here is the declaration of aligned and unaligned variables,fields:

    	//I put these arrays at the beginning, so they are aligned
	//for the movaps instructions(x2 speed for reading and writing memory)
	float v1[16];
	float v2[16];
	char counters[32];
 	char array_of_ones[32];
	char source_array[4096];
	char destination_array[4096];	
 	struct bit_field
	{
		bf1:32;	//too bad that maximum width is 32 bit per element
		bf2:32;
		bf3:32;
		bf4:32;
	}some_area;
	struct bit_mask_x
	{
		bf1:32;
		bf2:32;
		bf3:32;
		bf4:32;
	}some_mask;
	float var_fast[4];
	char alignment_purge[5];	//for the unalignment tests
	char unaligned_source_array[4096];
	char unaligned_destination_array[4096];
    


Here is test 1-a that is getting x(i)=1.0/sqrt(1.0+x(i)) of 4 variables for 30 million times.: just testing the "rsqrtps" instruction performance/error level.

    t1=clock();
	__asm
	{
		pushf					//save registers	
		push eax
	
		mov eax,[counter]		//start counting from 30 Million
		pxor xmm2,xmm2			//Shortcut to make xmm2 = zero
		movss xmm2,[one]		//make Lowest-Order float of mm2 = one (zero,zero,zero,one)
		shufps xmm2,xmm2,0h		//copy lowest-order to all higher orders(one,one,one,one)
		movaps xmm0,[var_fast]	//save var_fast array into xmm0
		loop1:					//begin the loop
		sub eax,01h				//counter counts down
		cmp eax,0h				//compare counter to zero
		addps xmm0,xmm2			//add one to each element of aray
		rsqrtps xmm0,xmm0		//reciprocal of square root of array elements
		jne loop1				//jump to loop beginning
		movaps [var_fast],xmm0	//when done, load array from xmm0

		pop eax					//load registers
		popf
	}
	t2=clock();
result: 0.11s, error level=%0.1

test 1-b is doing the same thing with using sqrt function and simple division:

     t1=clock();
	for(int i=0;i<30000000;i++)
	{		
		var_slow[0]=1.0/sqrt(var_slow[0]+1.0);	
		var_slow[1]=1.0/sqrt(var_slow[1]+1.0);
		var_slow[2]=1.0/sqrt(var_slow[2]+1.0);
		var_slow[3]=1.0/sqrt(var_slow[3]+1.0);
	}
	t2=clock();
result:6.48 s<--------nearly x60 time of the __asm code above.
********************************************************************************
********************************************************************************
test 2-a is about converting a decimal value to another number-system(2-10)

    t1=clock();
  	for(int i=0;i<10000000;i++)
  	{
  		digits_total=get_digits(variable_x,number_system,digits);
 	}
  	t2=clock(); 

declaration of get_digits:

    unsigned int get_digits(unsigned int y,unsigned int n_s,unsigned int digits[32])
	{
		unsigned char d_t=0;
		while(y>n_s)
		{
			digits[d_t]=y%n_s;
			y/=n_s;
			d_t++;			

		}
		digits[d_t]=y%n_s;
		d_t++;
		return d_t;		
	}

result: converting 32000001(decimal) to 111101....01(in binary) for 10M times took 7.53 seconds.

test 2-b is doing same as above in __asm code

     t1=clock();
 	for(int i=0;i<10000000;i++)
 	{
	 	get_digits_asm();	
	
 	}
	t2=clock();
declaration of get_digits_asm()

    void get_digits_asm()
	{
		__asm
  		{
  			
		 	pushf		//couldnt store this in other registers	
			movd xmm0,eax//storing in xmm registers instead of pushing
			movd xmm1,ebx//
			movd xmm2,ecx//
			movd xmm3,edx//
			movd xmm4,edi//end of push backups
			
			mov eax,[variable_x]
			mov ebx,[number_system]
			mov ecx,0h
			mov edi,0h
			
			begin_loop:
			mov edx,0h
			div ebx				
			lea edi,digits	 
							
			mov [edi+ecx*4],edx
			add ecx,01h
			cmp eax,ebx
			ja begin_loop
			
			mov edx,0
			div ebx
			lea edi,digits
			mov [edi+ecx*4],edx
			inc ecx
			mov [digits_total],ecx
			
			
			movd edi,xmm4//pop edi
			movd edx,xmm3//pop edx
			movd ecx,xmm2//pop ecx
			movd ebx,xmm1//pop ebx
			movd eax,xmm0//pop eax
			popf 			
	 	}
	
	}
result: 3.56 s (half of other code)(maybe because of parameterless-function?)
********************************************************************************
********************************************************************************
test 3-a just adds and subtracts one from each element of an array(32 element)

    t1=clock();
	for(int i=0;i<20000000;i++)//20M is divisible by 256. so i added 1
	{
		for(int j=0;j<32;j++)
		{
			counters[j]++;
			counters[j]--;
		}	
	}
	t2=clock();
result: 5.16 s

test 3-b is doing same with using sse instructions in parallel

    t1=clock();
	for(int i=0;i<20000000;i++)
	{
	__asm
	{
		movaps xmm0,[counters]		//block-read
		movaps xmm2,[counters+16]
		movaps xmm1,[array_of_ones]	//block-read
		movaps xmm3,[array_of_ones+16]
		
		paddb xmm0,xmm1
		psubb xmm0,xmm1
		paddb xmm2,xmm3
		psubb xmm2,xmm3
		
		 
		movaps [counters],xmm0		//block-write
		movaps [counters+16],xmm2	
	}
	}
	t2=clock(); 
result:0.14s<----------this is less than 1/35 of time taken in other code.

********************************************************************************
********************************************************************************
test 4-a copies a 4096-element array to another 100k times.

    t1=clock();
 	for(int i=0;i<100000;i++)
 	{
 		for(int j=0;j<4096;j++){destination_array[j]=source_array[j];}
 		
 	}
 	t2=clock();
result: 2.29 s. Does copying element-wise 1 by 1 inefficient.

test 4-b: same thing in __asm code for an "aligned" array of same size, same repeat count.

    t1=clock();
 	for(int i=0;i<100000;i++)
 	{
 		__asm
 		{
			movd xmm0,ecx			//quicker than pushing
			movd xmm1,edi
			movd xmm5,edx
			
			mov ecx,0h				//just an init
			
			copy_loop:			 	//will loop for 4096/64=64 times	
			
			movd xmm3,ecx			//ecx backup
			imul ecx,ecx,040h		//multiply by 64
			
			lea edi,source_array	//reding 64 bytes
			movaps xmm2,[edi+ecx]
			add ecx,010h
			movaps xmm4,[edi+ecx]
			add ecx,010h
			movaps xmm6,[edi+ecx]
			add ecx,010h
			movaps xmm7,[edi+ecx]
			
			
			lea edi,destination_array	//writing 64 bytes
			sub ecx,030h
			movaps [edi+ecx],xmm2
			add ecx,010h
			movaps [edi+ecx],xmm4
			add ecx,010h
			movaps [edi+ecx],xmm6
			add ecx,010h
			movaps [edi+ecx],xmm7
			
			
			
			movd ecx,xmm3		//continue from ecx old value
			add ecx,01h			//loop counter ++
			cmp ecx,40h 		//loop 64 times
			jne copy_loop
			
			
			movd edx,xmm5		
			movd edi,xmm1		//quicker than pop
			movd ecx,xmm0
			 	
	 	}
 	}
 	t2=clock();
result: 0.032 s <----- other code took 60x time of this.

test 4-c is doing the same with using "unaligned array"

    t1=clock();
 	for(int i=0;i<100000;i++)
 	{
 		__asm
 		{
			movd xmm0,ecx			//quicker than pushing
			movd xmm1,edi
			movd xmm5,edx
			
			mov ecx,0h				//just an init
			
			copy_loop_u:			 	//will loop for 4096/64=64 times	
			
			movd xmm3,ecx			//ecx backup
			imul ecx,ecx,040h		//multiply by 64
			
			lea edi,unaligned_source_array	//reding 64 bytes
			movups xmm2,[edi+ecx]
			add ecx,010h
			movups xmm4,[edi+ecx]
			add ecx,010h
			movups xmm6,[edi+ecx]
			add ecx,010h
			movups xmm7,[edi+ecx]
			
			
			lea edi,unaligned_destination_array	//writing 64 bytes
			sub ecx,030h
			movups [edi+ecx],xmm2
			add ecx,010h
			movups [edi+ecx],xmm4
			add ecx,010h
			movups [edi+ecx],xmm6
			add ecx,010h
			movups [edi+ecx],xmm7
			
			
			
			movd ecx,xmm3		//continue from ecx old value
			add ecx,01h			//loop counter ++
			cmp ecx,40h 		//loop 64 times
			jne copy_loop_u
			
			
			movd edx,xmm5		
			movd edi,xmm1		//quicker than pop
			movd ecx,xmm0
			 	
	 	}
 	}
 	t2=clock();
result:0.093 s. this is triple of time taken for aligned copying.
*******************************************************************************
*******************************************************************************
test 5-a and 5-b compares time of pushing general pupose registers to stack versus saving them in xmm registers

5-a:

    t1=clock();
	for(int i=0;i<100000000;i++)
	{
		__asm
		{
			pushf
			push eax	
			push ebx
			push ecx
			push edx
			push edi
			
		
			push eax
			push eax
			push eax
			pop eax
			pop eax
			pop eax
			
			
			pop edi
			pop edx
			pop ecx
			pop ebx
			pop eax
			popf
		}
	}
	t2=clock();
result: 3.39s

test 5-b:

     t1=clock();
	for(int i=0;i<100000000;i++)
	{
		__asm
		{
			pushf
			movd xmm0,eax	
			movd xmm1,ebx
			movd xmm2,ecx
			movd xmm3,edx
			movd xmm4,edi
			
			movd xmm5,eax
			movd xmm6,eax
			movd xmm7,eax
			movd eax,xmm7
			movd eax,xmm6
			movd eax,xmm5
			
			movd edi,xmm4
			movd edx,xmm3
			movd ecx,xmm2
			movd ebx,xmm1
			movd eax,xmm0
			popf
		}
	}
	t2=clock();
result: 2.20s. a little faster than other. is this useful for small functions?
*******************************************************************************
*******************************************************************************
test 6-a,b,c,d,e,f compares logical xor,or,and operations between a 128 bit bit-field and a 128-bit bitmask: 

this is declaration of bitfield:

    struct bit_field
	{
		bf1:32;	//too bad that maximum width is 32 bit per element
		bf2:32;
		bf3:32;
		bf4:32;
	}some_area;
	struct bit_mask_x
	{
		bf1:32;
		bf2:32;
		bf3:32;
		bf4:32;
	}some_mask;

test 6-a: (C++ or) 0.56 s

    t1=clock();
	for(int i=0;i<100000000;i++)
	{
		some_area.bf1=some_area.bf1|	some_mask.bf1;
		some_area.bf2=some_area.bf2|	some_mask.bf2;
		some_area.bf3=some_area.bf3|	some_mask.bf3;
		some_area.bf4=some_area.bf4|	some_mask.bf4;
	}
	t2=clock();

test 6-b: (C++ and) 0.59 s

     t1=clock();
	for(int i=0;i<100000000;i++)
	{
		some_area.bf1=some_area.bf1&	some_mask.bf1;
		some_area.bf2=some_area.bf2&	some_mask.bf2;
		some_area.bf3=some_area.bf3&	some_mask.bf3;
		some_area.bf4=some_area.bf4&	some_mask.bf4;
	}
	t2=clock();

test 6-c: (C++ xor) 0.56 s

     t1=clock();
	for(int i=0;i<100000000;i++)
	{
		some_area.bf1=some_area.bf1^	some_mask.bf1;
		some_area.bf2=some_area.bf2^	some_mask.bf2;
		some_area.bf3=some_area.bf3^	some_mask.bf3;
		some_area.bf4=some_area.bf4^	some_mask.bf4;
	}
	t2=clock();

test 6-d: __asm pxor 0.35s

     t1=clock();
	for(int i=0;i<100000000;i++)
	{
		__asm
		{
			movaps xmm0,[some_area]
			movaps xmm1,[some_mask]
			pxor xmm0,xmm1
			movaps [some_area],xmm0
		}
	
	}
	t2=clock();

test 6-e: __asm pand 0.36 s

    t1=clock();
	for(int i=0;i<100000000;i++)
	{
		__asm
		{
			movaps xmm0,[some_area]
			movaps xmm1,[some_mask]
			pand xmm0,xmm1
			movaps [some_area],xmm0
		}
	
	}
	t2=clock();

test 6-f: __asm por 0.35 s

    t1=clock();
	for(int i=0;i<100000000;i++)
	{
		__asm
		{
			movaps xmm0,[some_area]
			movaps xmm1,[some_mask]
			por xmm0,xmm1
			movaps [some_area],xmm0
		}
	
	}
	t2=clock();
*******************************************************************************
*******************************************************************************
theres a test-7 section whis show totally unoptimized empty loops taking 3x time of optimized __asm codes
*******************************************************************************
*******************************************************************************
test 8-a: calculating 4Dimensioned distance calculation(10M times) in C++

    t1=clock();
	for(int i=0;i<10000000;i++)
	{
		distance[0]=sqrt((v1[0]-v2[0])*(v1[0]-v2[0])+(v1[1]-v2[1])*(v1[1]-v2[1])+(v1[2]-v2[2])*(v1[2]-v2[2])+(v1[3]-v1[3])*(v1[3]-v2[3]));
	}
	t2=clock();
result: 0.359 s

test 8-b:

    t1=clock();
	for(int i=0;i<10000000;i++)
	{
	
		
		__asm
		{	
			
		
			movaps xmm0,[v1]	
			movaps xmm1,[v2]
			subps xmm0,xmm1	//getting deltas
			mulps xmm0,xmm0 //getting squares
			
			
			shufps xmm2,xmm0,0h
			shufps xmm3,xmm0,055h
			shufps xmm4,xmm0,0aah
			shufps xmm5,xmm0,0ffh
			
			addss xmm2,xmm3
			addss xmm2,xmm4
			addss xmm2,xmm5
			sqrtss xmm6,xmm2
			
			movss [distance],xmm6
			
		}
	}
	t2=clock();
result: 0.141 s. (only %100 faster)

Thank you for your attention. Plz replace all xmm with ymm and give the results?
    

    

    





Here is full code:

    	//I put these arrays at the beginning, so they are aligned
	//for the movaps instructions(x2 speed for reading and writing memory)
	float v1[16];
	float v2[16];
	char counters[32];
 	char array_of_ones[32];
	char source_array[4096];
	char destination_array[4096];	
 	struct bit_field
	{
		bf1:32;	//too bad that maximum width is 32 bit per element
		bf2:32;
		bf3:32;
		bf4:32;
	}some_area;
	struct bit_mask_x
	{
		bf1:32;
		bf2:32;
		bf3:32;
		bf4:32;
	}some_mask;
	float var_fast[4];
	char alignment_purge[5];	//for the unalignment tests
	char unaligned_source_array[4096];
	char unaligned_destination_array[4096];

	
    #include <iostream.h>
    #include <math.h>
    #include<stdlib.h>
    #include<stdio.h>
    #include<time.h>
    //assumption: this machines long variable is 64 bits. int is 32 bits.
    //assumption: this machines float is 32 bits



  	unsigned int variable_x=32000001;
  	unsigned int number_system=2;
  	unsigned int y=0;
  	unsigned int digits[32];//32-bit variable is maximum 32 digits (even in binary) 
  	unsigned int digits_total=0;
	
	
	unsigned int get_digits(unsigned int y,unsigned int n_s,unsigned int digits[32])
	{
		unsigned char d_t=0;
		while(y>n_s)
		{
			digits[d_t]=y%n_s;
			y/=n_s;
			d_t++;			

		}
		digits[d_t]=y%n_s;
		d_t++;
		return d_t;		
	}
	void get_digits_asm()
	{
		__asm
  		{
  			
		 	pushf		//couldnt store this in other registers	
			movd xmm0,eax//storing in xmm registers instead of pushing
			movd xmm1,ebx//
			movd xmm2,ecx//
			movd xmm3,edx//
			movd xmm4,edi//end of push backups
			
			mov eax,[variable_x]
			mov ebx,[number_system]
			mov ecx,0h
			mov edi,0h
			
			begin_loop:
			mov edx,0h
			div ebx				
			lea edi,digits	//my compiler doesnt allow me to add 4*edi 
							//so i add 4 times
			mov [edi+ecx*4],edx
			add ecx,01h
			cmp eax,ebx
			ja begin_loop
			
			mov edx,0
			div ebx
			lea edi,digits
			mov [edi+ecx*4],edx
			inc ecx
			mov [digits_total],ecx
			
			
			movd edi,xmm4//pop edi
			movd edx,xmm3//pop edx
			movd ecx,xmm2//pop ecx
			movd ebx,xmm1//pop ebx
			movd eax,xmm0//pop eax
			popf 			
	 	}
	
	}
	

    unsigned long zero=0;	
    unsigned long one=1;
    unsigned long two=2;


	int main()
    {
	
	srand(time(0));
	for(int i=0;i<32;i++)
	{
		counters[i]=100;	//init of some variables
		array_of_ones[i]=1;
	}
	

	
	clock_t t1=0;
	clock_t t2=0;
	int counter=30000000;	
	for(int i=0;i<4;i++)
	{
		var_fast[i]=0;
	}
	
	//test 1
	printf("****taking reciprocal square root of four variables(30 Millon times):****\n\n");
	float one=1.0;
	t1=clock();
	__asm
	{
		pushf					//save registers	
		push eax
	
		mov eax,[counter]		//start counting from 30 Million
		pxor xmm2,xmm2			//Shortcut to make xmm2 = zero
		movss xmm2,[one]		//make Lowest-Order float of mm2 = one (zero,zero,zero,one)
		shufps xmm2,xmm2,0h		//copy lowest-order to all higher orders(one,one,one,one)
		movaps xmm0,[var_fast]	//save var_fast array into xmm0
		loop1:					//begin the loop
		sub eax,01h				//counter counts down
		cmp eax,0h				//compare counter to zero
		addps xmm0,xmm2			//add one to each element of aray
		rsqrtps xmm0,xmm0		//reciprocal of square root of array elements
		jne loop1				//jump to loop beginning
		movaps [var_fast],xmm0	//when done, load array from xmm0

		pop eax					//load registers
		popf
	}
	t2=clock();
	
	printf("        __asm-inlining of addps + rsqrtps instruction time:%3.3f seconds\n        %2.3f     %2.3f     %2.3f     %2.3f   \n\n",(float)(t2-t1)/(float)CLOCKS_PER_SEC,var_fast[0],var_fast[1],var_fast[2],var_fast[3]);
	
		 
	
	float var_slow[4]={0.0,0.0,0.0,0.0};
	
	
	t1=clock();
	for(int i=0;i<30000000;i++)
	{
		
		var_slow[0]=1.0/sqrt(var_slow[0]+1.0);	
		var_slow[1]=1.0/sqrt(var_slow[1]+1.0);
		var_slow[2]=1.0/sqrt(var_slow[2]+1.0);
		var_slow[3]=1.0/sqrt(var_slow[3]+1.0);
	}
	t2=clock();
	printf("        C++ style var=1.0/sqrt(var+1.0) (from array):  time: %3.3f seconds \n        %2.3f     %2.3f     %2.3f     %2.3f     \n\n",(float)(t2-t1)/(float)CLOCKS_PER_SEC,var_slow[0],var_slow[1],var_slow[2],var_slow[3]);
  	

	  
	  
 	
	 
	 
	 //test 2
	 
 	printf("representing of a 32bit integer variable in a x-number system(10 Millon times):\n\n");
  	
  	t1=clock();
  	for(int i=0;i<10000000;i++)
  	{
  		digits_total=get_digits(variable_x,number_system,digits);
 	}
  	t2=clock();
  	printf("        C++ : %3.3f seconds\n        %i is  ",(float)(t2-t1)/(float)CLOCKS_PER_SEC,variable_x);
  	for(int i=0;i<digits_total;i++)
  	{
		printf("%i",digits[digits_total-(i+1)]);  	
  	}
  	printf(" in the system-%i \n\n",number_system); 
  	for(int i=0;i<32;i++){digits[i]=0;}
	t1=clock();
 	for(int i=0;i<10000000;i++)
 	{
	 	get_digits_asm();	
	
 	}
	t2=clock();
  		printf("        __asm(not inlined) : %3.3f seconds\n        %i is  ",(float)(t2-t1)/(float)CLOCKS_PER_SEC,variable_x);
  	for(int i=0;i<digits_total;i++)
  	{
		printf("%i",digits[digits_total-(i+1)]);  	
  	}
  	printf(" in the system-%i \n\n",number_system); 
  	
  	
	//  	test 3
	
	t1=clock();
	for(int i=0;i<20000000;i++)//20M is divisible by 256. so i added 1
	{
		for(int j=0;j<32;j++)
		{
			counters[j]++;
			counters[j]--;
		}	
	}
	t2=clock();
	
	
	printf("***********increment + decrement of 32 integers(8-bit)(20M times):********\n\n        ");
 	printf("C++ 32-element array: %3.3f seconds\n",(float)(t2-t1)/(float)CLOCKS_PER_SEC) ; 
	printf("        testing array: ");
	for(int i=0;i<32;i++){printf("%c",counters[i]);}
	printf("\n\n        ");
	t1=clock();
	for(int i=0;i<20000000;i++)
	{
	__asm
	{
		movaps xmm0,[counters]		//block-read
		movaps xmm2,[counters+16]
		movaps xmm1,[array_of_ones]	//block-read
		movaps xmm3,[array_of_ones+16]
		
		paddb xmm0,xmm1
		psubb xmm0,xmm1
		paddb xmm2,xmm3
		psubb xmm2,xmm3
		
		 
		movaps [counters],xmm0		//block-write
		movaps [counters+16],xmm2	
	}
	}
	t2=clock();  
	printf("__asm (aligned 32-element) movaps, paddb, psubb, movaps: %3.3f seconds",(float)(t2-t1)/(float)CLOCKS_PER_SEC);
	printf(" \n");   
	printf("        testing array: ");
	for(int i=0;i<32;i++){printf("%c",counters[i]);}
	printf("\n\n        ");  
	
	
	for(int i=0;i<4096;i++)
	{
		source_array[i]=i;
	}  
 	printf("\n**************array(4096 elements) copying(100k times):****************\n\n        ");
 	
 	
 	t1=clock();
 	for(int i=0;i<100000;i++)
 	{
 		for(int j=0;j<4096;j++){destination_array[j]=source_array[j];}
 		
 	}
 	t2=clock();
  	printf("C++ iterating 1 by 1: %3.3f seconds\n\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);
	
	
	for(int i=0;i<4096;i++)
	{
		source_array[i]=i+1;	//inter-initialization
	}  
	
	
	t1=clock();
 	for(int i=0;i<100000;i++)
 	{
 		__asm
 		{
			movd xmm0,ecx			//quicker than pushing
			movd xmm1,edi
			movd xmm5,edx
			
			mov ecx,0h				//just an init
			
			copy_loop:			 	//will loop for 4096/64=64 times	
			
			movd xmm3,ecx			//ecx backup
			imul ecx,ecx,040h		//multiply by 64
			
			lea edi,source_array	//reding 64 bytes
			movaps xmm2,[edi+ecx]
			add ecx,010h
			movaps xmm4,[edi+ecx]
			add ecx,010h
			movaps xmm6,[edi+ecx]
			add ecx,010h
			movaps xmm7,[edi+ecx]
			
			
			lea edi,destination_array	//writing 64 bytes
			sub ecx,030h
			movaps [edi+ecx],xmm2
			add ecx,010h
			movaps [edi+ecx],xmm4
			add ecx,010h
			movaps [edi+ecx],xmm6
			add ecx,010h
			movaps [edi+ecx],xmm7
			
			
			
			movd ecx,xmm3		//continue from ecx old value
			add ecx,01h			//loop counter ++
			cmp ecx,40h 		//loop 64 times
			jne copy_loop
			
			
			movd edx,xmm5		
			movd edi,xmm1		//quicker than pop
			movd ecx,xmm0
			 	
	 	}
 	}
 	t2=clock();
  	printf("__asm movaps(aligned): %3.3f seconds\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);
	
	t1=clock();
 	for(int i=0;i<100000;i++)
 	{
 		__asm
 		{
			movd xmm0,ecx			//quicker than pushing
			movd xmm1,edi
			movd xmm5,edx
			
			mov ecx,0h				//just an init
			
			copy_loop_u:			 	//will loop for 4096/64=64 times	
			
			movd xmm3,ecx			//ecx backup
			imul ecx,ecx,040h		//multiply by 64
			
			lea edi,unaligned_source_array	//reding 64 bytes
			movups xmm2,[edi+ecx]
			add ecx,010h
			movups xmm4,[edi+ecx]
			add ecx,010h
			movups xmm6,[edi+ecx]
			add ecx,010h
			movups xmm7,[edi+ecx]
			
			
			lea edi,unaligned_destination_array	//writing 64 bytes
			sub ecx,030h
			movups [edi+ecx],xmm2
			add ecx,010h
			movups [edi+ecx],xmm4
			add ecx,010h
			movups [edi+ecx],xmm6
			add ecx,010h
			movups [edi+ecx],xmm7
			
			
			
			movd ecx,xmm3		//continue from ecx old value
			add ecx,01h			//loop counter ++
			cmp ecx,40h 		//loop 64 times
			jne copy_loop_u
			
			
			movd edx,xmm5		
			movd edi,xmm1		//quicker than pop
			movd ecx,xmm0
			 	
	 	}
 	}
 	t2=clock();
  	printf("__asm movups(unaligned): %3.3f seconds\n\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);
	
	
	printf("\n************** push+pop to stack VS push+pop to xmm ******************\n\n        ");
	
	t1=clock();
	for(int i=0;i<100000000;i++)
	{
		__asm
		{
			pushf
			push eax	
			push ebx
			push ecx
			push edx
			push edi
			
		
			push eax
			push eax
			push eax
			pop eax
			pop eax
			pop eax
			
			
			pop edi
			pop edx
			pop ecx
			pop ebx
			pop eax
			popf
		}
	}
	t2=clock();
	printf("stack: %3.3f seconds\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);	
	t1=clock();
	for(int i=0;i<100000000;i++)
	{
		__asm
		{
			pushf
			movd xmm0,eax	
			movd xmm1,ebx
			movd xmm2,ecx
			movd xmm3,edx
			movd xmm4,edi
			
			movd xmm5,eax
			movd xmm6,eax
			movd xmm7,eax
			movd eax,xmm7
			movd eax,xmm6
			movd eax,xmm5
			
			movd edi,xmm4
			movd edx,xmm3
			movd ecx,xmm2
			movd ebx,xmm1
			movd eax,xmm0
			popf
		}
	}
	t2=clock();
	printf("xmm: %3.3f seconds\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);	
	
	printf("\n***********128bit logical xor-or-and (100M times):****************\n        ");
	
	
	
	t1=clock();
	for(int i=0;i<100000000;i++)
	{
		some_area.bf1=some_area.bf1|	some_mask.bf1;
		some_area.bf2=some_area.bf2|	some_mask.bf2;
		some_area.bf3=some_area.bf3|	some_mask.bf3;
		some_area.bf4=some_area.bf4|	some_mask.bf4;
	}
	t2=clock();
	printf("C++ (128bit)bitfield of a struct(or): %3.3f seconds\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);	
	t1=clock();
	for(int i=0;i<100000000;i++)
	{
		some_area.bf1=some_area.bf1&	some_mask.bf1;
		some_area.bf2=some_area.bf2&	some_mask.bf2;
		some_area.bf3=some_area.bf3&	some_mask.bf3;
		some_area.bf4=some_area.bf4&	some_mask.bf4;
	}
	t2=clock();
	printf("C++ (128bit)bitfield of a struct(and): %3.3f seconds\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);	
	t1=clock();
	for(int i=0;i<100000000;i++)
	{
		some_area.bf1=some_area.bf1^	some_mask.bf1;
		some_area.bf2=some_area.bf2^	some_mask.bf2;
		some_area.bf3=some_area.bf3^	some_mask.bf3;
		some_area.bf4=some_area.bf4^	some_mask.bf4;
	}
	t2=clock();
	printf("C++ (128bit)bitfield of a struct(xor): %3.3f seconds\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);	
	t1=clock();
	for(int i=0;i<100000000;i++)
	{
		__asm
		{
			movaps xmm0,[some_area]
			movaps xmm1,[some_mask]
			pxor xmm0,xmm1
			movaps [some_area],xmm0
		}
	
	}
	t2=clock();
	printf("__asm pxor xmm: %3.3f seconds\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);	
	t1=clock();
	for(int i=0;i<100000000;i++)
	{
		__asm
		{
			movaps xmm0,[some_area]
			movaps xmm1,[some_mask]
			pand xmm0,xmm1
			movaps [some_area],xmm0
		}
	
	}
	t2=clock();
	printf("__asm pand xmm: %3.3f seconds\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);	
	t1=clock();
	for(int i=0;i<100000000;i++)
	{
		__asm
		{
			movaps xmm0,[some_area]
			movaps xmm1,[some_mask]
			por xmm0,xmm1
			movaps [some_area],xmm0
		}
	
	}
	t2=clock();
	printf("__asm por xmm: %3.3f seconds\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);	
	
	printf("\n*****empty loops 1G (C++ for vs while) VS __asm(jne vs je vs ja)*****\n\n        ");
	t1=clock();
	for(int i=0;i<1000000000;i++)
	{
		
	}
	t2=clock();
	printf("C++ for: %3.3f seconds\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);	
	int w_v=0;
	t1=clock();
	while(w_v<1000000000)
	{
		w_v++;	
	}
	t2=clock();
	printf("C++ while: %3.3f seconds\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);	
	
	
	
	
	t1=clock();
	__asm
	{
		pushf
		movd xmm0,ecx
		
		mov ecx,0h
		
		loop_jne:
		inc ecx
		cmp ecx,03B9ACA00h
		jne loop_jne
		
		movd ecx,xmm0
		popf
	}
	t2=clock();
	printf("__asm jne(inc): %3.3f seconds\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);	
	
	
	t1=clock();
	__asm
	{
		pushf
		movd xmm0,ecx
		
		mov ecx,0h
		
		loop_inf:
		inc ecx
		cmp ecx,03B9ACA00h
		je loop_je
		jmp loop_inf
		loop_je:
		movd ecx,xmm0
		popf
	}
	t2=clock();
	printf("__asm je(inc): %3.3f seconds\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);	
	


	t1=clock();
	__asm
	{
		pushf
		movd xmm0,ecx
		
		mov ecx,03B9ACA00h
		
		loop_ja:
		sub ecx,01h
		cmp ecx,0h
		ja loop_ja
		movd ecx,xmm0
		popf
	}
	t2=clock();
	printf("__asm ja(sub): %3.3f seconds\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);	
	
	printf("\n***** 4Dimensioned distance calculations (10M times)*****\n        ");
	
	v1[0]=10,v1[1]=20,v1[2]=30,v1[3]=1;
	v2[0]=33,v2[1]=45,v2[2]=45,v2[3]=-1;
	double distance[4];
	t1=clock();
	for(int i=0;i<10000000;i++)
	{
		distance[0]=sqrt((v1[0]-v2[0])*(v1[0]-v2[0])+(v1[1]-v2[1])*(v1[1]-v2[1])+(v1[2]-v2[2])*(v1[2]-v2[2])+(v1[3]-v1[3])*(v1[3]-v2[3]));
	}
	t2=clock();
	printf("C++ sqrt(sum of square-deltas) : %3.3f seconds\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);
	printf("distance=%8.3f\n        ",distance[0]);
	
	t1=clock();
	for(int i=0;i<10000000;i++)
	{
	
		
		__asm
		{	
			
		
			movaps xmm0,[v1]	
			movaps xmm1,[v2]
			subps xmm0,xmm1	//getting deltas
			mulps xmm0,xmm0 //getting squares
			
			
			shufps xmm2,xmm0,0h
			shufps xmm3,xmm0,055h
			shufps xmm4,xmm0,0aah
			shufps xmm5,xmm0,0ffh
			
			addss xmm2,xmm3
			addss xmm2,xmm4
			addss xmm2,xmm5
			sqrtss xmm6,xmm2
			
			movss [distance],xmm6
			
		}
	}
	t2=clock();
	printf("__asm sqrt(sum of square-deltas) : %3.3f seconds\n        ",(float)(t2-t1)/(float)CLOCKS_PER_SEC);
	printf("distance=%8.3f\n        ",distance[0]);
		
	return 0;
}