blob: bac49c89d1169bfb1e2b8e049cfae1e752994968 [file] [log] [blame]
Matt Wala105b7042014-08-11 19:56:19 -07001//===- subzero/crosstest/test_calling_conv.cpp - Implementation for tests -===//
2//
3// The Subzero Code Generator
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the test functions used to check that Subzero
11// generates code compatible with the calling convention used by
12// llc. "Caller" functions test the handling of out-args, and "callee"
13// functions test the handling of in-args.
14//
15//===----------------------------------------------------------------------===//
16
17#include <cstring>
18
19#include "test_calling_conv.h"
John Porto1d235422015-08-12 12:37:53 -070020#include "xdefs.h"
Matt Wala105b7042014-08-11 19:56:19 -070021
22#define CALL_AS_TYPE(Ty, Func) (reinterpret_cast<Ty *>(Func))
23
24void caller_i(void) {
25 int arg1 = 0x12345678;
26 CALL_AS_TYPE(callee_i_Ty, Callee)(arg1);
27}
28
29void caller_vvvvv(void) {
30 v4si32 arg1 = {0, 1, 2, 3};
31 v4si32 arg2 = {4, 5, 6, 7};
32 v4si32 arg3 = {8, 9, 10, 11};
33 v4si32 arg4 = {12, 13, 14, 15};
34 v4si32 arg5 = {16, 17, 18, 19};
35
36 CALL_AS_TYPE(callee_vvvvv_Ty, Callee)(arg1, arg2, arg3, arg4, arg5);
37}
38
John Portoba6a67c2015-09-25 15:19:45 -070039void caller_vlvilvfvdviv(void) {
Matt Wala105b7042014-08-11 19:56:19 -070040 v4f32 arg1 = {0, 1, 2, 3};
John Porto1d235422015-08-12 12:37:53 -070041 int64 arg2 = 4;
Matt Wala105b7042014-08-11 19:56:19 -070042 v4f32 arg3 = {6, 7, 8, 9};
John Portoba6a67c2015-09-25 15:19:45 -070043 int arg4 = 10;
44 int64 arg5 = 11;
Matt Wala105b7042014-08-11 19:56:19 -070045 v4f32 arg6 = {12, 13, 14, 15};
46 float arg7 = 16;
47 v4f32 arg8 = {17, 18, 19, 20};
48 double arg9 = 21;
49 v4f32 arg10 = {22, 23, 24, 25};
50 int arg11 = 26;
51 v4f32 arg12 = {27, 28, 29, 30};
52
Antonio Maioranoca8a16e2020-11-10 16:56:20 -050053 CALL_AS_TYPE(callee_vlvilvfvdviv_Ty, Callee)
54 (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12);
Matt Wala105b7042014-08-11 19:56:19 -070055}
56
57#define HANDLE_ARG(ARGNUM) \
58 case ARGNUM: \
59 memcpy(&Buf[0], &arg##ARGNUM, sizeof(arg##ARGNUM)); \
60 break;
61
62void __attribute__((noinline)) callee_i(int arg1) {
63 switch (ArgNum) { HANDLE_ARG(1); }
64}
65
66void __attribute__((noinline))
67callee_vvvvv(v4si32 arg1, v4si32 arg2, v4si32 arg3, v4si32 arg4, v4si32 arg5) {
68 switch (ArgNum) {
69 HANDLE_ARG(1);
70 HANDLE_ARG(2);
71 HANDLE_ARG(3);
72 HANDLE_ARG(4);
73 HANDLE_ARG(5);
74 }
75}
76
77void __attribute__((noinline))
John Portoba6a67c2015-09-25 15:19:45 -070078callee_vlvilvfvdviv(v4f32 arg1, int64 arg2, v4f32 arg3, int arg4, int64 arg5,
John Porto1d235422015-08-12 12:37:53 -070079 v4f32 arg6, float arg7, v4f32 arg8, double arg9,
Jim Stichnothdd842db2015-01-27 12:53:53 -080080 v4f32 arg10, int arg11, v4f32 arg12) {
Matt Wala105b7042014-08-11 19:56:19 -070081 switch (ArgNum) {
82 HANDLE_ARG(1);
Matt Wala105b7042014-08-11 19:56:19 -070083 HANDLE_ARG(3);
John Portoba6a67c2015-09-25 15:19:45 -070084 HANDLE_ARG(6);
85 HANDLE_ARG(8);
86 HANDLE_ARG(10);
87 HANDLE_ARG(12);
John Portoba6a67c2015-09-25 15:19:45 -070088 HANDLE_ARG(2);
Matt Wala105b7042014-08-11 19:56:19 -070089 HANDLE_ARG(4);
90 HANDLE_ARG(5);
Matt Wala105b7042014-08-11 19:56:19 -070091 HANDLE_ARG(7);
Matt Wala105b7042014-08-11 19:56:19 -070092 HANDLE_ARG(9);
Matt Wala105b7042014-08-11 19:56:19 -070093 HANDLE_ARG(11);
Matt Wala105b7042014-08-11 19:56:19 -070094 }
95}