001/*
002 * Copyright (c) 2007, 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 */
023/*
024 * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
025 */
026package com.oracle.graal.jtt.micro;
027
028import org.junit.*;
029
030import com.oracle.graal.jtt.*;
031
032/**
033 * Tests different alignment on the stack with extended parameters (index > 5).
034 */
035public class BigMixedParams04 extends JTTTest {
036
037    @SuppressWarnings("unused")
038    public static long test(int choice, int i0, int i1, int i2, int i3, double d1, double d2, boolean bo1, boolean bo2, byte by, short sh, char ch, int in) {
039        switch (choice) {
040            case 0:
041                return bo1 ? 1L : 2L;
042            case 1:
043                return bo2 ? 1L : 2L;
044            case 2:
045                return by;
046            case 3:
047                return sh;
048            case 4:
049                return ch;
050            case 5:
051                return in;
052        }
053        return 42;
054    }
055
056    /**
057     * Test SPARC mixed params with double/single float register overlapping.
058     *
059     * @param f1
060     * @param d2
061     * @param f3
062     * @return Must always return the argument d2
063     */
064    @SuppressWarnings("all")
065    public static double test2(int i1, float f1, double d2, float f3,
066    // @formatter:off
067                    double ad1,
068                    double ad2,
069                    double ad3,
070                    double ad4,
071                    double ad5,
072                    double ad6,
073                    double ad7,
074                    double ad8,
075                    double ad9,
076                    double ad10,
077                    double ad11,
078                    double ad12,
079                    double ad13,
080                    double ad14,
081                    double ad15,
082                    double ad16,
083                    float  af1,
084                    float  af2,
085                    float  af3,
086                    float  af4,
087                    float  af5,
088                    float  af6,
089                    float  af7,
090                    float  af8,
091                    float  af9,
092                    float  af10,
093                    float  af11,
094                    float  af12,
095                    float  af13,
096                    float  af14,
097                    float  af15,
098                    float  af16
099    // @formatter:on
100    ) {
101
102        // now do something with the locals to make sure the locals don't get optimized away.
103        for (int i = 0; i < i1; i++) {
104            af1 += f1;
105            af2 += f1;
106            af3 += f1;
107            af4 += f1;
108            af5 += f1;
109            af6 += f1;
110            af7 += f1;
111            af8 += f1;
112            af9 += f1;
113            af10 += f1;
114            af11 += f1;
115            af12 += f1;
116            af13 += f1;
117            af14 += f1;
118            af15 += f1;
119            af16 += f1;
120            ad1 += f1;
121            ad2 += f1;
122            ad3 += f1;
123            ad4 += f1;
124            ad5 += f1;
125            ad6 += f1;
126            ad7 += f1;
127            ad8 += f1;
128            ad9 += f1;
129            ad10 += f1;
130            ad11 += f1;
131            ad12 += f1;
132            ad13 += f1;
133            ad14 += f1;
134            ad15 += f1;
135            ad16 += f1;
136        }
137        // @formatter:off
138        boolean orderFloat =
139                        af1  < af2  &&
140                        af2  < af3  &&
141                        af3  < af4  &&
142                        af4  < af5  &&
143                        af5  < af6  &&
144                        af6  < af7  &&
145                        af7  < af8  &&
146                        af8  < af9  &&
147                        af9  < af10 &&
148                        af10 < af11 &&
149                        af11 < af12 &&
150                        af12 < af13 &&
151                        af13 < af14 &&
152                        af14 < af15 &&
153                        af15 < af16;
154        boolean orderDouble =
155                        ad1  < ad2  &&
156                        ad2  < ad3  &&
157                        ad3  < ad4  &&
158                        ad4  < ad5  &&
159                        ad5  < ad6  &&
160                        ad6  < ad7  &&
161                        ad7  < ad8  &&
162                        ad8  < ad9  &&
163                        ad9  < ad10 &&
164                        ad10 < ad11 &&
165                        ad11 < ad12 &&
166                        ad12 < ad13 &&
167                        ad13 < ad14 &&
168                        ad14 < ad15 &&
169                        ad15 < ad16;
170        // @formatter:on
171        if (orderDouble && orderFloat) {
172            return f1 + d2 + f3; // this should not be destroyed
173        }
174        Assert.fail();
175        return 0.0;
176    }
177
178    /**
179     * Test SPARC mixed params with double/single float register overlapping.
180     *
181     * @param f1
182     * @param d2
183     * @param f3
184     * @return Must always return the argument d2
185     */
186    @SuppressWarnings("all")
187    public static double test3(boolean f, int idx,
188    // @formatter:off
189                    double ad1,
190                    double ad2,
191                    double ad3,
192                    double ad4,
193                    double ad5,
194                    double ad6,
195                    double ad7,
196                    double ad8,
197                    double ad9,
198                    double ad10,
199                    double ad11,
200                    double ad12,
201                    double ad13,
202                    double ad14,
203                    double ad15,
204                    double ad16,
205                    float  af1,
206                    float  af2,
207                    float  af3,
208                    float  af4,
209                    float  af5,
210                    float  af6,
211                    float  af7,
212                    float  af8,
213                    float  af9,
214                    float  af10,
215                    float  af11,
216                    float  af12,
217                    float  af13,
218                    float  af14,
219                    float  af15,
220                    float  af16
221    ) {
222        switch(f ? idx + 16 : idx) {
223            case 1 : return ad1;
224            case 2 : return ad2;
225            case 3 : return ad3;
226            case 4 : return ad4;
227            case 5 : return ad5;
228            case 6 : return ad6;
229            case 7 : return ad7;
230            case 8 : return ad8;
231            case 9 : return ad9;
232            case 10: return ad10;
233            case 11: return ad11;
234            case 12: return ad12;
235            case 13: return ad13;
236            case 14: return ad14;
237            case 15: return ad15;
238            case 16: return ad16;
239            case 1  + 16: return af1;
240            case 2  + 16: return af2;
241            case 3  + 16: return af3;
242            case 4  + 16: return af4;
243            case 5  + 16: return af5;
244            case 6  + 16: return af6;
245            case 7  + 16: return af7;
246            case 8  + 16: return af8;
247            case 9  + 16: return af9;
248            case 10 + 16: return af10;
249            case 11 + 16: return af11;
250            case 12 + 16: return af12;
251            case 13 + 16: return af13;
252            case 14 + 16: return af14;
253            case 15 + 16: return af15;
254            case 16 + 16: return af16;
255        }
256        Assert.fail(); // should not reach here
257        return 0;
258
259    }
260    // @formatter:on
261
262    @Test
263    public void run0() throws Throwable {
264        runTest("test", 0, -1, -1, -1, -1, 1d, 2d, true, false, (byte) -128, (short) -0x7FFF, (char) 0xFFFF, -0x7FFFFFF);
265    }
266
267    @Test
268    public void run1() throws Throwable {
269        runTest("test", 1, -1, -1, -1, -1, 1d, 2d, true, false, (byte) -128, (short) -0x7FFF, (char) 0xFFFF, -0x7FFFFFF);
270    }
271
272    @Test
273    public void run2() throws Throwable {
274        runTest("test", 2, -1, -1, -1, -1, 1d, 2d, true, false, (byte) -128, (short) -0x7FFF, (char) 0xFFFF, -0x7FFFFFF);
275    }
276
277    @Test
278    public void run3() throws Throwable {
279        runTest("test", 3, -1, -1, -1, -1, 1d, 2d, true, false, (byte) -128, (short) -0x7FFF, (char) 0xFFFF, -0x7FFFFFF);
280    }
281
282    @Test
283    public void run4() throws Throwable {
284        runTest("test", 4, -1, -1, -1, -1, 1d, 2d, true, false, (byte) -128, (short) -0x7FFF, (char) 0xFFFF, -0x7FFFFFF);
285    }
286
287    @Test
288    public void run5() throws Throwable {
289        runTest("test", 5, -1, -1, -1, -1, 1d, 2d, true, false, (byte) -128, (short) -0x7FFF, (char) 0xFFFF, -0x7FFFFFF);
290    }
291
292    @Test
293    public void run6() throws Throwable {
294        // @formatter:off
295        runTest("test2", 20, 1.0f, -3.2912948246387967943231233d, 3.0f,
296                        1d,
297                        2d,
298                        3d,
299                        4d,
300                        5d,
301                        6d,
302                        7d,
303                        8d,
304                        9d,
305                        10d,
306                        11d,
307                        12d,
308                        13d,
309                        14d,
310                        15d,
311                        16d,
312                        1f,
313                        2f,
314                        3f,
315                        4f,
316                        5f,
317                        6f,
318                        7f,
319                        8f,
320                        9f,
321                        10f,
322                        11f,
323                        12f,
324                        13f,
325                        14f,
326                        15f,
327                        16f
328                        );
329        // @formatter:on
330    }
331
332    @Test
333    public void run7() throws Throwable {
334        // @formatter:off
335        for (int i = 0; i < 32 * 2; i++) {
336        runTest("test3", i % 2 == 0, i / 2,
337                        1d,
338                        2d,
339                        3d,
340                        4d,
341                        5d,
342                        6d,
343                        7d,
344                        8d,
345                        9d,
346                        10d,
347                        11d,
348                        12d,
349                        13d,
350                        14d,
351                        15d,
352                        16d,
353                        1f,
354                        2f,
355                        3f,
356                        4f,
357                        5f,
358                        6f,
359                        7f,
360                        8f,
361                        9f,
362                        10f,
363                        11f,
364                        12f,
365                        13f,
366                        14f,
367                        15f,
368                        16f
369                        );
370        }
371        // @formatter:on
372    }
373
374}