|
| 1 | +/* |
| 2 | + * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. |
| 3 | + * |
| 4 | + * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product |
| 5 | + * that is described in this document. In particular, and without limitation, these intellectual property |
| 6 | + * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or |
| 7 | + * more additional patents or pending patent applications in the U.S. and in other countries. |
| 8 | + * |
| 9 | + * U.S. Government Rights - Commercial software. Government users are subject to the Sun |
| 10 | + * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its |
| 11 | + * supplements. |
| 12 | + * |
| 13 | + * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or |
| 14 | + * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks |
| 15 | + * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the |
| 16 | + * U.S. and other countries. |
| 17 | + * |
| 18 | + * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open |
| 19 | + * Company, Ltd. |
| 20 | + */ |
| 21 | +package com.sun.max.vm.compiler.builtin; |
| 22 | + |
| 23 | +import com.sun.max.unsafe.Word; |
| 24 | + |
| 25 | +/** |
| 26 | + * @author Bernd Mathiske |
| 27 | + */ |
| 28 | +public abstract class SpecialBuiltin { |
| 29 | + |
| 30 | + /** |
| 31 | + * Returns the index of the least significant bit set in a given value. |
| 32 | + * |
| 33 | + * @param value the value to scan for the least significant bit |
| 34 | + * @return the index of the least significant bit within {@code value} or {@code -1} if {@code value == 0} |
| 35 | + */ |
| 36 | + public static int leastSignificantBit(Word value) { |
| 37 | + long l = value.asAddress().toLong(); |
| 38 | + if (l == 0) { |
| 39 | + return -1; |
| 40 | + } |
| 41 | + return Long.numberOfTrailingZeros(l); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Returns the index to the most significant bit set in a given value. |
| 46 | + * |
| 47 | + * @param value the value to scan for the most significant bit |
| 48 | + * @return the index to the most significant bit within {@code value} or {@code -1} if {@code value == 0} |
| 49 | + */ |
| 50 | + public static int mostSignificantBit(Word value) { |
| 51 | + long l = value.asAddress().toLong(); |
| 52 | + if (l == 0) { |
| 53 | + return -1; |
| 54 | + } |
| 55 | + return Long.numberOfTrailingZeros(l); |
| 56 | + } |
| 57 | +} |
0 commit comments