Commit 6176a26d1d0fe40dea0fd6a4e1a437931cbdcb2d

Authored by aurel32
1 parent 182608d4

target-ppc: optimize popcntb

Suggested by Andrzej Zaborowski.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5592 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 8 additions and 14 deletions
target-ppc/op_helper.c
@@ -222,25 +222,19 @@ target_ulong helper_srad (target_ulong value, target_ulong shift) @@ -222,25 +222,19 @@ target_ulong helper_srad (target_ulong value, target_ulong shift)
222 222
223 target_ulong helper_popcntb (target_ulong val) 223 target_ulong helper_popcntb (target_ulong val)
224 { 224 {
225 - uint32_t ret;  
226 - int i;  
227 -  
228 - ret = 0;  
229 - for (i = 0; i < 32; i += 8)  
230 - ret |= ctpop8((val >> i) & 0xFF) << i;  
231 - return ret; 225 + val = (val & 0x55555555) + ((val >> 1) & 0x55555555);
  226 + val = (val & 0x33333333) + ((val >> 2) & 0x33333333);
  227 + val = (val & 0x0f0f0f0f) + ((val >> 4) & 0x0f0f0f0f);
  228 + return val;
232 } 229 }
233 230
234 #if defined(TARGET_PPC64) 231 #if defined(TARGET_PPC64)
235 target_ulong helper_popcntb_64 (target_ulong val) 232 target_ulong helper_popcntb_64 (target_ulong val)
236 { 233 {
237 - uint64_t ret;  
238 - int i;  
239 -  
240 - ret = 0;  
241 - for (i = 0; i < 64; i += 8)  
242 - ret |= ctpop8((val >> i) & 0xFF) << i;  
243 - return ret; 234 + val = (val & 0x5555555555555555ULL) + ((val >> 1) & 0x5555555555555555ULL);
  235 + val = (val & 0x3333333333333333ULL) + ((val >> 2) & 0x3333333333333333ULL);
  236 + val = (val & 0x0f0f0f0f0f0f0f0fULL) + ((val >> 4) & 0x0f0f0f0f0f0f0f0fULL);
  237 + return val;
244 } 238 }
245 #endif 239 #endif
246 240