mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 14:02:46 +00:00 
			
		
		
		
	UserspaceEmulator: Remove an unnecessary step in some instructions
We don't need to move the result of shifts around like this, we can just use inline assembly outputs to make it end up in the right place.
This commit is contained in:
		
							parent
							
								
									80d3306840
								
							
						
					
					
						commit
						a9f92e5d75
					
				
					 1 changed files with 45 additions and 33 deletions
				
			
		|  | @ -472,20 +472,24 @@ static T op_shr(SoftCPU& cpu, T data, u8 steps) | |||
|     u32 result = 0; | ||||
|     u32 new_flags = 0; | ||||
| 
 | ||||
|     if constexpr (sizeof(T) == 4) | ||||
|         asm volatile("shrl %%cl, %%eax\n" ::"a"(data), "c"(steps)); | ||||
|     else if constexpr (sizeof(T) == 2) | ||||
|         asm volatile("shrw %%cl, %%ax\n" ::"a"(data), "c"(steps)); | ||||
|     else if constexpr (sizeof(T) == 1) | ||||
|         asm volatile("shrb %%cl, %%al\n" ::"a"(data), "c"(steps)); | ||||
|     if constexpr (sizeof(T) == 4) { | ||||
|         asm volatile("shrl %%cl, %%eax\n" | ||||
|                      : "=a"(result) | ||||
|                      : "a"(data), "c"(steps)); | ||||
|     } else if constexpr (sizeof(T) == 2) { | ||||
|         asm volatile("shrw %%cl, %%ax\n" | ||||
|                      : "=a"(result) | ||||
|                      : "a"(data), "c"(steps)); | ||||
|     } else if constexpr (sizeof(T) == 1) { | ||||
|         asm volatile("shrb %%cl, %%al\n" | ||||
|                      : "=a"(result) | ||||
|                      : "a"(data), "c"(steps)); | ||||
|     } | ||||
| 
 | ||||
|     asm volatile( | ||||
|         "mov %%eax, %%ebx\n" | ||||
|         : "=b"(result)); | ||||
|     asm volatile( | ||||
|         "pushf\n" | ||||
|         "pop %%eax" | ||||
|         : "=a"(new_flags)); | ||||
|         "pop %%ebx" | ||||
|         : "=b"(new_flags)); | ||||
| 
 | ||||
|     cpu.set_flags_oszapc(new_flags); | ||||
|     return result; | ||||
|  | @ -500,20 +504,24 @@ static T op_shl(SoftCPU& cpu, T data, u8 steps) | |||
|     u32 result = 0; | ||||
|     u32 new_flags = 0; | ||||
| 
 | ||||
|     if constexpr (sizeof(T) == 4) | ||||
|         asm volatile("shll %%cl, %%eax\n" ::"a"(data), "c"(steps)); | ||||
|     else if constexpr (sizeof(T) == 2) | ||||
|         asm volatile("shlw %%cl, %%ax\n" ::"a"(data), "c"(steps)); | ||||
|     else if constexpr (sizeof(T) == 1) | ||||
|         asm volatile("shlb %%cl, %%al\n" ::"a"(data), "c"(steps)); | ||||
|     if constexpr (sizeof(T) == 4) { | ||||
|         asm volatile("shll %%cl, %%eax\n" | ||||
|                      : "=a"(result) | ||||
|                      : "a"(data), "c"(steps)); | ||||
|     } else if constexpr (sizeof(T) == 2) { | ||||
|         asm volatile("shlw %%cl, %%ax\n" | ||||
|                      : "=a"(result) | ||||
|                      : "a"(data), "c"(steps)); | ||||
|     } else if constexpr (sizeof(T) == 1) { | ||||
|         asm volatile("shlb %%cl, %%al\n" | ||||
|                      : "=a"(result) | ||||
|                      : "a"(data), "c"(steps)); | ||||
|     } | ||||
| 
 | ||||
|     asm volatile( | ||||
|         "mov %%eax, %%ebx\n" | ||||
|         : "=b"(result)); | ||||
|     asm volatile( | ||||
|         "pushf\n" | ||||
|         "pop %%eax" | ||||
|         : "=a"(new_flags)); | ||||
|         "pop %%ebx" | ||||
|         : "=b"(new_flags)); | ||||
| 
 | ||||
|     cpu.set_flags_oszapc(new_flags); | ||||
|     return result; | ||||
|  | @ -1355,20 +1363,24 @@ static T op_sar(SoftCPU& cpu, T data, u8 steps) | |||
|     u32 result = 0; | ||||
|     u32 new_flags = 0; | ||||
| 
 | ||||
|     if constexpr (sizeof(T) == 4) | ||||
|         asm volatile("sarl %%cl, %%eax\n" ::"a"(data), "c"(steps)); | ||||
|     else if constexpr (sizeof(T) == 2) | ||||
|         asm volatile("sarw %%cl, %%ax\n" ::"a"(data), "c"(steps)); | ||||
|     else if constexpr (sizeof(T) == 1) | ||||
|         asm volatile("sarb %%cl, %%al\n" ::"a"(data), "c"(steps)); | ||||
|     if constexpr (sizeof(T) == 4) { | ||||
|         asm volatile("sarl %%cl, %%eax\n" | ||||
|                      : "=a"(result) | ||||
|                      : "a"(data), "c"(steps)); | ||||
|     } else if constexpr (sizeof(T) == 2) { | ||||
|         asm volatile("sarw %%cl, %%ax\n" | ||||
|                      : "=a"(result) | ||||
|                      : "a"(data), "c"(steps)); | ||||
|     } else if constexpr (sizeof(T) == 1) { | ||||
|         asm volatile("sarb %%cl, %%al\n" | ||||
|                      : "=a"(result) | ||||
|                      : "a"(data), "c"(steps)); | ||||
|     } | ||||
| 
 | ||||
|     asm volatile( | ||||
|         "mov %%eax, %%ebx\n" | ||||
|         : "=b"(result)); | ||||
|     asm volatile( | ||||
|         "pushf\n" | ||||
|         "pop %%eax" | ||||
|         : "=a"(new_flags)); | ||||
|         "pop %%ebx" | ||||
|         : "=b"(new_flags)); | ||||
| 
 | ||||
|     cpu.set_flags_oszapc(new_flags); | ||||
|     return result; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling