/*
* Copyright ( C ) 2016 The Android Open Source Project
*
* Licensed under the Apache License , Version 2 . 0 ( the " License " ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an " AS IS " BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
*/
public class Main {
/// CHECK-START: int Main.hi32(int) builder (after)
/// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerHighestOneBit
/// CHECK-DAG: Return [<<Result>>]
private static int hi32(int x) {
return Integer.highestOneBit(x);
}
/// CHECK-START: int Main.lo32(int) builder (after)
/// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerLowestOneBit
/// CHECK-DAG: Return [<<Result>>]
private static int lo32(int x) {
return Integer.lowestOneBit(x);
}
/// CHECK-START: long Main.hi64(long) builder (after)
/// CHECK-DAG: <<Result:j\d+>> InvokeStaticOrDirect intrinsic:LongHighestOneBit
/// CHECK-DAG: Return [<<Result>>]
private static long hi64(long x) {
return Long .highestOneBit(x);
}
/// CHECK-START: long Main.lo64(long) builder (after)
/// CHECK-DAG: <<Result:j\d+>> InvokeStaticOrDirect intrinsic:LongLowestOneBit
/// CHECK-DAG: Return [<<Result>>]
private static long lo64(long x) {
return Long .lowestOneBit(x);
}
public static void main(String args[]) {
// Hidden zeros.
int [] xi = new int [32 ];
long [] xj = new long [64 ];
expectEquals32(0 x00000000, hi32(0 x00000000));
expectEquals32(0 x00000000, lo32(0 x00000000));
expectEquals32(0 x00010000, hi32(0 x00010000));
expectEquals32(0 x00010000, lo32(0 x00010000));
expectEquals32(0 x00800000, hi32(0 x00FF0000));
expectEquals32(0 x00010000, lo32(0 x00FF0000));
expectEquals32(0 x80000000, hi32(0 xFFFFFFFF));
expectEquals32(0 x00000001, lo32(0 xFFFFFFFF));
for (int i = 0 ; i < 32 ; i++) {
expectEquals32(0 , hi32(xi[i]));
expectEquals32(0 , lo32(xi[i]));
expectEquals32(1 << i, hi32(1 << i));
expectEquals32(1 << i, lo32(1 << i));
int expected = i < 29 ? 0 x8 << i : 0 x80000000;
expectEquals32(expected, hi32(0 xF << i));
expectEquals32(0 x1 << i, lo32(0 xF << i));
}
expectEquals64(0 x0000000000000000L, hi64(0 x0000000000000000L));
expectEquals64(0 x0000000000000000L, lo64(0 x0000000000000000L));
expectEquals64(0 x0000000100000000L, hi64(0 x0000000100000000L));
expectEquals64(0 x0000000100000000L, lo64(0 x0000000100000000L));
expectEquals64(0 x0000008000000000L, hi64(0 x000000FF00000000L));
expectEquals64(0 x0000000100000000L, lo64(0 x000000FF00000000L));
expectEquals64(0 x8000000000000000L, hi64(0 xFFFFFFFFFFFFFFFFL));
expectEquals64(0 x0000000000000001L, lo64(0 xFFFFFFFFFFFFFFFFL));
for (int i = 0 ; i < 64 ; i++) {
expectEquals64(0 L, hi64(xj[i]));
expectEquals64(0 L, lo64(xj[i]));
expectEquals64(1 L << i, hi64(1 L << i));
expectEquals64(1 L << i, lo64(1 L << i));
long expected = i < 61 ? 0 x8L << i : 0 x8000000000000000L;
expectEquals64(expected, hi64(0 xFL << i));
expectEquals64(0 x1L << i, lo64(0 xFL << i));
}
System.out.println("passed" );
}
private static void expectEquals32(int expected, int result) {
if (expected != result) {
throw new Error("Expected: " + expected + ", found: " + result);
}
}
private static void expectEquals64(long expected, long result) {
if (expected != result) {
throw new Error("Expected: " + expected + ", found: " + result);
}
}
}
Messung V0.5 in Prozent C=80 H=92 G=86
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-29)
¤
*© Formatika GbR, Deutschland