src/java.base/share/classes/java/lang/Long.java
changeset 49251 3c0a12972165
parent 47216 71c04702a3d5
child 49426 7f3986bad197
equal deleted inserted replaced
49250:7443b946694a 49251:3c0a12972165
     1 /*
     1 /*
     2  * Copyright (c) 1994, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1994, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
  1769      * @since 1.5
  1769      * @since 1.5
  1770      */
  1770      */
  1771     @HotSpotIntrinsicCandidate
  1771     @HotSpotIntrinsicCandidate
  1772     public static int numberOfLeadingZeros(long i) {
  1772     public static int numberOfLeadingZeros(long i) {
  1773         // HD, Figure 5-6
  1773         // HD, Figure 5-6
  1774          if (i == 0)
  1774          if (i <= 0)
  1775             return 64;
  1775             return i == 0 ? 64 : 0;
  1776         int n = 1;
  1776         int n = 1;
  1777         int x = (int)(i >>> 32);
  1777         int x = (int)(i >>> 32);
  1778         if (x == 0) { n += 32; x = (int)i; }
  1778         if (x == 0) { n += 32; x = (int)i; }
  1779         if (x >>> 16 == 0) { n += 16; x <<= 16; }
  1779         if (x >>> 16 == 0) { n += 16; x <<= 16; }
  1780         if (x >>> 24 == 0) { n +=  8; x <<=  8; }
  1780         if (x >>> 24 == 0) { n +=  8; x <<=  8; }