Closed Bug 575534 Opened 14 years ago Closed 14 years ago

Use __builtin_ctz and __builtin_clz when ARM

Categories

(NSPR :: NSPR, defect)

ARM
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: m_kato, Assigned: m_kato)

References

Details

Attachments

(1 file)

Related to bug 356852.

GCC 4 with -march=armv5 or -march=armv6t2 has optimized __builtin_ctz and __builtin_clz using CLZ, RSB.

We should use this builtin function in prbit.h when ARMv5 or later.

Also, this code supports thumb2.
Original,
00000000 <PR_CeilingLog2>:
   0:   e2403001        sub     r3, r0, #1      ; 0x1
   4:   e1130000        tst     r3, r0
   8:   03a01000        moveq   r1, #0  ; 0x0
   c:   13a01001        movne   r1, #1  ; 0x1
  10:   e1b03820        lsrs    r3, r0, #16
  14:   01a03000        moveq   r3, r0
  18:   12811010        addne   r1, r1, #16     ; 0x10
  1c:   e1b02423        lsrs    r2, r3, #8
  20:   01a02003        moveq   r2, r3
  24:   12811008        addne   r1, r1, #8      ; 0x8
  28:   e1b03222        lsrs    r3, r2, #4
  2c:   01a03002        moveq   r3, r2
  30:   12811004        addne   r1, r1, #4      ; 0x4
  34:   e1b02123        lsrs    r2, r3, #2
  38:   01a02003        moveq   r2, r3
  3c:   12811002        addne   r1, r1, #2      ; 0x2
  40:   e1b020a2        lsrs    r2, r2, #1
  44:   12811001        addne   r1, r1, #1      ; 0x1
  48:   e1a00001        mov     r0, r1
  4c:   e12fff1e        bx      lr

after that,

00000000 <PR_FloorLog2>:
   0:   e3800001        orr     r0, r0, #1      ; 0x1
   4:   e16f0f10        clz     r0, r0
   8:   e260001f        rsb     r0, r0, #31     ; 0x1f
   c:   e12fff1e        bx      lr
Summary: Use __builtin_ctz and __builtin_clz when ARMv5 or later → Use __builtin_ctz and __builtin_clz when ARM
Attached patch patchSplinter Review
Attachment #454837 - Flags: review?(wtc)
Comment on attachment 454837 [details] [diff] [review]
patch

r=wtc.  Thanks for the patch.  I checked in the patch on
the NSPR trunk (NSPR 4.8.6).

Checking in prbit.h;
/cvsroot/mozilla/nsprpub/pr/include/prbit.h,v  <--  prbit.h
new revision: 3.14; previous revision: 3.13
done
Attachment #454837 - Flags: review?(wtc) → review+
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Target Milestone: --- → 4.8.6
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: