VirtualBox

Changeset 102245 in vbox


Ignore:
Timestamp:
Nov 22, 2023 10:43:09 AM (12 months ago)
Author:
vboxsync
Message:

libs/xpcom: Make PR_CeilingLog2() and PR_FloorLog2() inline, bugref:10545

Location:
trunk/src/libs/xpcom18a4
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/Makefile.kmk

    r102243 r102245  
    429429        nsprpub/pr/src/io/prprf.c \
    430430        nsprpub/pr/src/misc/prinrval.c \
    431         nsprpub/pr/src/misc/prlog2.c \
    432431        nsprpub/pr/src/misc/prlong.c \
    433432        nsprpub/lib/ds/plarena.c \
  • trunk/src/libs/xpcom18a4/nsprpub/pr/include/prbit.h

    r11551 r102245  
    3939#define prbit_h___
    4040
     41#include <iprt/cdefs.h>
     42
    4143#include "prtypes.h"
    42 
    43 #ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
    44 #define PR_CeilingLog2 VBoxNsprPR_CeilingLog2
    45 #define PR_FloorLog2 VBoxNsprPR_FloorLog2
    46 #endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
    4744
    4845PR_BEGIN_EXTERN_C
     
    6360** Compute the log of the least power of 2 greater than or equal to n
    6461*/
    65 NSPR_API(PRIntn) PR_CeilingLog2(PRUint32 i);
     62DECL_FORCE_INLINE(PRIntn) PR_CeilingLog2(PRUint32 n)
     63{
     64    PRIntn log2 = 0;
     65
     66    if (n & (n-1))
     67  log2++;
     68    if (n >> 16)
     69  log2 += 16, n >>= 16;
     70    if (n >> 8)
     71  log2 += 8, n >>= 8;
     72    if (n >> 4)
     73  log2 += 4, n >>= 4;
     74    if (n >> 2)
     75  log2 += 2, n >>= 2;
     76    if (n >> 1)
     77  log2++;
     78    return log2;
     79}
    6680
    6781/*
    68 ** Compute the log of the greatest power of 2 less than or equal to n
     82** Compute the log of the greatest power of 2 less than or equal to n.
     83** This really just finds the highest set bit in the word.
    6984*/
    70 NSPR_API(PRIntn) PR_FloorLog2(PRUint32 i);
     85DECL_FORCE_INLINE(PRIntn) PR_FloorLog2(PRUint32 n)
     86{
     87    PRIntn log2 = 0;
     88
     89    if (n >> 16)
     90  log2 += 16, n >>= 16;
     91    if (n >> 8)
     92  log2 += 8, n >>= 8;
     93    if (n >> 4)
     94  log2 += 4, n >>= 4;
     95    if (n >> 2)
     96  log2 += 2, n >>= 2;
     97    if (n >> 1)
     98  log2++;
     99    return log2;
     100}
    71101
    72102/*
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette