Files
gcc/libjava/testsuite/libjava.lang/BuiltinReverseBytes.java
T
Roger Sayle a1293f402a builtins.c (java_builtins): Use popcount* and bswap* builtins to implement bitCount() and reverseBytes()...
2016-05-31  Roger Sayle  <roger@nextmovesoftware.com>

gcc/java:
	* builtins.c (java_builtins): Use popcount* and bswap* builtins to
	implement bitCount() and reverseBytes() methods in java.lang.Integer
	and friends.
	(initialize_builtins): Annotate math builtins with ECF_LEAF.  Call
	define_builtin for the new popcount* and bswap* builtins.

libjava:
	* testsuite/libjava.lang/BuiltinBitCount.java: New test case.
	* testsuite/libjava.lang/BuiltinReverseBytes.java: Likewise.

From-SVN: r236919
2016-05-31 11:30:56 +00:00

63 lines
1.5 KiB
Java

class BuiltinReverseBytes
{
public static short bswap16(short x)
{
return Short.reverseBytes(x);
}
public static int bswap32(int x)
{
return Integer.reverseBytes(x);
}
public static long bswap64(long x)
{
return Long.reverseBytes(x);
}
public static void main(String[] args)
{
if (Short.reverseBytes((short)0) != (short)0)
throw new Error();
if (Short.reverseBytes((short)0x1234) != (short)0x3412)
throw new Error();
if (Short.reverseBytes((short)-1) != (short)-1)
throw new Error();
if (Integer.reverseBytes(0) != 0)
throw new Error();
if (Integer.reverseBytes(0x12345678) != 0x78563412)
throw new Error();
if (Integer.reverseBytes(-1) != -1)
throw new Error();
if (Long.reverseBytes(0L) != 0L)
throw new Error();
if (Long.reverseBytes(0x123456789abcde0fL) != 0x0fdebc9a78563412L)
throw new Error();
if (Long.reverseBytes(-1L) != -1L)
throw new Error();
if (bswap16((short)0) != (short)0)
throw new Error();
if (bswap16((short)0x1234) != (short)0x3412)
throw new Error();
if (bswap16((short)-1) != (short)-1)
throw new Error();
if (bswap32(0) != 0)
throw new Error();
if (bswap32(0x12345678) != 0x78563412)
throw new Error();
if (bswap32(-1) != -1)
throw new Error();
if (bswap64(0L) != 0L)
throw new Error();
if (bswap64(0x123456789abcde0fL) != 0x0fdebc9a78563412L)
throw new Error();
if (bswap64(-1L) != -1L)
throw new Error();
}
}