/*
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */

/**
 * @test
 * @bug 6800154
 * @summary Add comments to long_by_long_mulhi() for better understandability
 *
 * @run main/othervm -Xcomp -XX:CompileOnly=Test6800154.divcomp Test6800154
 */

public class Test6800154 {
    public static void main(String[] args)
    {
        div(0);
        div(1);
        div(1423487);
        div(4444441);
        div(4918923241323L);
        div(-1);
        div(-24351);
        div(0x3333);
        div(0x0000000080000000L);
        div(0x7fffffffffffffffL);
        div(0x8000000000000000L);
    }

    static final int N = 11;

    static final long DIV1  = 2;
    static final long DIV2  = 17;
    static final long DIV3  = 24123;
    static final long DIV4  = -4423423234231423L;
    static final long DIV5  = -1;
    static final long DIV6  = 123444442344L;
    static final long DIV7  = 1;
    static final long DIV8  = 0x7fffffffffffffffL;
    static final long DIV9  = 143444;
    static final long DIV10 = 12342;
    static final long DIV11 = 0x0000000080000000L;

    static void div(long a)
    {
        // Element at 0 is left empty intentionally.
        long[] expected = new long[N + 1];
        long[] result   = new long[N + 1];

        divint(expected, a);
        divcomp(result, a);

        for (int i = 1; i <= N; i++) {
            if (result[i] != expected[i])
                throw new InternalError("Division of " + a + " failed at " + i + ": " + result + " != " + expected);
        }
    }

    static void divint(long[] la, long a)
    {
        // Element at 0 is left empty intentionally.
        la[1]  = a / DIV1;
        la[2]  = a / DIV2;
        la[3]  = a / DIV3;
        la[4]  = a / DIV4;
        la[5]  = a / DIV5;
        la[6]  = a / DIV6;
        la[7]  = a / DIV7;
        la[8]  = a / DIV8;
        la[9]  = a / DIV9;
        la[10] = a / DIV10;
        la[11] = a / DIV11;
    }

    static void divcomp(long[] la, long a)
    {
        // Element at 0 is left empty intentionally.
        la[1]  = a / DIV1;
        la[2]  = a / DIV2;
        la[3]  = a / DIV3;
        la[4]  = a / DIV4;
        la[5]  = a / DIV5;
        la[6]  = a / DIV6;
        la[7]  = a / DIV7;
        la[8]  = a / DIV8;
        la[9]  = a / DIV9;
        la[10] = a / DIV10;
        la[11] = a / DIV11;
    }
}
