Home | History | Annotate | Download | only in Ia32
      1 ;/*++
      2 ;
      3 ;Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
      4 ;This program and the accompanying materials                          
      5 ;are licensed and made available under the terms and conditions of the BSD License         
      6 ;which accompanies this distribution.  The full text of the license may be found at        
      7 ;http://opensource.org/licenses/bsd-license.php                                            
      8 ;                                                                                          
      9 ;THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
     10 ;WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             
     11 ;
     12 ;Module Name:
     13 ;
     14 ;  Log2.c
     15 ;
     16 ;Abstract:
     17 ;
     18 ;  64-bit integer logarithm function for IA-32
     19 ;
     20 ;--*/
     21 ;
     22 ;---------------------------------------------------------------------------
     23     .686
     24     .model  flat,C
     25     .code
     26 
     27 ;---------------------------------------------------------------------------
     28 
     29 ;UINT8
     30 ;Log2 (
     31 ;  IN UINT64   Operand
     32 ;  )
     33 ;/*++
     34 ;
     35 ;Routine Description:
     36 ; 
     37 ;  Calculates and floors logarithms based on 2
     38 ;
     39 ;Arguments:
     40 ;
     41 ;  Operand - value to calculate logarithm
     42 ;  
     43 ;Returns:
     44 ;
     45 ;  The largest integer that is less than or equal
     46 ;  to the logarithm of Operand based on 2 
     47 ;
     48 ;--*/
     49 Log2 PROC
     50   mov    ecx, 64
     51   
     52   cmp    dword ptr [esp + 4], 0  ; (UINT32 *(&Operand))
     53   jne    _Log2_Wend 
     54   cmp    dword ptr [esp + 8], 0  ; (UINT32 *(&Operand)) + 1
     55   jne    _Log2_Wend 
     56   mov    cl, 0FFH
     57   jmp    _Log2_Done
     58   
     59 _Log2_Wend:
     60   dec    ecx
     61   cmp    ecx, 32
     62   jae    _Log2_Higher
     63   bt     [esp + 4], ecx ; (UINT32 *(&Operand))
     64   jmp    _Log2_Bit
     65   
     66 _Log2_Higher:
     67   mov    eax, ecx
     68   sub    eax, 32
     69   bt     [esp + 8], eax ; (UINT32 *(&Operand)) + 1
     70   
     71 _Log2_Bit:
     72   jc     _Log2_Done
     73   jmp    _Log2_Wend
     74       
     75 _Log2_Done:
     76   mov    al, cl
     77 
     78   ret
     79 
     80 	Log2 ENDP
     81 	END
     82