001/*
002 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.jtt.optimize;
024
025import org.junit.*;
026
027import com.oracle.graal.jtt.*;
028
029/**
030 * inspired by java.security.SecureRandom.longToByteArray(long).
031 *
032 */
033public class LongToSomethingArray01 extends JTTTest {
034
035    public static byte[] longToByteArray(long arg) {
036        long l = arg;
037        byte[] ret = new byte[8];
038        for (int i = 0; i < 8; i++) {
039            ret[i] = (byte) (l & 0xff);
040            l = l >> 8;
041        }
042        return ret;
043    }
044
045    @Test
046    public void runB0() throws Throwable {
047        runTest("longToByteArray", 0x1122_3344_5566_7788L);
048    }
049
050    public static short[] longToShortArray(long arg) {
051        long l = arg;
052        short[] ret = new short[4];
053        for (int i = 0; i < 4; i++) {
054            ret[i] = (short) (l & 0xffff);
055            l = l >> 16;
056        }
057        return ret;
058    }
059
060    @Test
061    public void runS0() throws Throwable {
062        runTest("longToShortArray", 0x1122_3344_5566_7788L);
063    }
064
065    public static int[] longToIntArray(long arg) {
066        long l = arg;
067        int[] ret = new int[2];
068        for (int i = 0; i < 2; i++) {
069            ret[i] = (int) (l & 0xffff_ffff);
070            l = l >> 32;
071        }
072        return ret;
073    }
074
075    @Test
076    public void runI0() throws Throwable {
077        runTest("longToIntArray", 0x1122_3344_5566_7788L);
078    }
079
080    public static long[] longToLongArray(long arg) {
081        long l = arg;
082        long[] ret = new long[1];
083        for (int i = 0; i < 1; i++) {
084            ret[i] = l & 0xffff_ffff_ffff_ffffL;
085            l = l >> 64;
086        }
087        return ret;
088    }
089
090    @Test
091    public void runL0() throws Throwable {
092        runTest("longToLongArray", 0x1122_3344_5566_7788L);
093    }
094}