diff options
author | Josef 'Jeff' Sipek <josef.sipek@nexenta.com> | 2014-11-19 16:10:27 -0500 |
---|---|---|
committer | Dan McDonald <danmcd@omniti.com> | 2014-11-24 13:25:18 -0500 |
commit | fdb8cf8c1b80da286f448f5e748b65f9115d7043 (patch) | |
tree | 05065490e822cd22537c118e0e6abb7f97fe574c /usr/src/uts/intel/asm/bitmap.h | |
parent | 6f6a76adacda33b10633476dc6c5d66d7f17dd94 (diff) | |
download | illumos-joyent-fdb8cf8c1b80da286f448f5e748b65f9115d7043.tar.gz |
5291 x86 {high,low}bit rely on undefined behavior
Reviewed by: Keith Wesolowski <keith.wesolowski@joyent.com>
Approved by: Dan McDonald <danmcd@omniti.com>
Diffstat (limited to 'usr/src/uts/intel/asm/bitmap.h')
-rw-r--r-- | usr/src/uts/intel/asm/bitmap.h | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/usr/src/uts/intel/asm/bitmap.h b/usr/src/uts/intel/asm/bitmap.h index 6148277085..92020e39e3 100644 --- a/usr/src/uts/intel/asm/bitmap.h +++ b/usr/src/uts/intel/asm/bitmap.h @@ -48,29 +48,33 @@ extern "C" { extern __GNU_INLINE int highbit(ulong_t i) { - long value = -1l; + long value; + uint8_t zf; __asm__( - "bsr" __SUF " %1,%0" - : "+r" (value) - : "r" (i) + "bsr" __SUF " %2,%0;" + "setz %1" + : "=r" (value), "=q" (zf) + : "mr" (i) : "cc"); - return ((int)(value + 1)); + return (zf ? 0 : (value + 1)); } extern __GNU_INLINE int lowbit(ulong_t i) { - long value = -1l; + long value; + uint8_t zf; __asm__( - "bsf" __SUF " %1,%0" - : "+r" (value) - : "r" (i) + "bsf" __SUF " %2,%0;" + "setz %1" + : "=r" (value), "=q" (zf) + : "mr" (i) : "cc"); - return ((int)(value + 1)); + return (zf ? 0 : (value + 1)); } extern __GNU_INLINE uint_t |