]> git.saurik.com Git - apple/dyld.git/blob - unit-tests/test-cases/lazy-binding-reg-params/main.c
dyld-360.19.tar.gz
[apple/dyld.git] / unit-tests / test-cases / lazy-binding-reg-params / main.c
1 /*
2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 #include <stdbool.h>
24 #include <stdio.h> // fprintf(), NULL
25 #include <stdlib.h> // exit(), EXIT_SUCCESS
26 #include <dlfcn.h>
27 #include <sys/sysctl.h>
28
29 #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL()
30
31
32 ///
33 /// rdar://problem/4132378 support __attribute__((regparm()))
34 ///
35 /// The stub binding helper for dyld needs to preserve registers
36 ///
37
38
39 #include "foo.h"
40
41
42 static bool inttest()
43 {
44 return dointtest(123,456,789,4444,55555);
45 }
46
47 static bool floattest()
48 {
49 #if __ppc__ || __ppc64__
50 return dofloattest(1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0);
51 #elif __i386__ || __x86_64__ || __arm__
52 return true;
53 #else
54 #error unknown arch
55 #endif
56 }
57
58 #if __i386__ || __x86_64__ || __ppc__ || __ppc64__
59 static bool vectorSupport()
60 {
61 #if __ppc__
62 uint32_t value;
63 size_t size=sizeof(uint32_t);
64 int err = sysctlbyname("hw.optional.altivec", &value, &size, NULL, 0);
65 //fprintf(stderr, "sysctlbyname() = %d\n", err);
66 return ( err == 0 );
67 #else
68 return true;
69 #endif
70 }
71
72 static bool vectortest()
73 {
74 vFloat p1 = { 1.1, 1.2, 1.3, 1.4 };
75 vFloat p2 = { 2.1, 2.2, 2.3, 2.4 };
76 vFloat p3 = { 3.1, 3.2, 3.3, 3.4 };
77 vFloat p4 = { 4.1, 4.2, 4.3, 4.4 };
78 vFloat p5 = { 5.1, 5.2, 5.3, 5.4 };
79 return dovectortest(p1, p2, p3, p4, p5);
80 }
81 #endif
82
83 int main()
84 {
85 if ( ! inttest() ) {
86 FAIL("lazy-binding-reg-params int parameters");
87 return EXIT_SUCCESS;
88 }
89
90 if ( ! floattest() ) {
91 FAIL("lazy-binding-reg-params float parameters");
92 return EXIT_SUCCESS;
93 }
94
95 #if __i386__ || __x86_64__ || __ppc__ || __ppc64__
96 if ( vectorSupport() && ! vectortest() ) {
97 FAIL("lazy-binding-reg-params vector parameters");
98 return EXIT_SUCCESS;
99 }
100 #endif
101
102 PASS("lazy-binding-reg-params");
103 return EXIT_SUCCESS;
104 }