]> git.saurik.com Git - apple/dyld.git/blame - unit-tests/test-cases/lazy-binding-reg-params/main.c
dyld-96.2.tar.gz
[apple/dyld.git] / unit-tests / test-cases / lazy-binding-reg-params / main.c
CommitLineData
9e225d03
A
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>
d6f5f96d 27#include <sys/sysctl.h>
9e225d03
A
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
d6f5f96d
A
39#include "foo.h"
40
41
42static bool inttest()
43{
44 return dointtest(123,456,789,4444,55555);
45}
46
47static 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);
8bc9f0af 51#elif __i386__ || __x86_64__
d6f5f96d
A
52 return true;
53#else
54 #error unknown architecture
9e225d03 55#endif
d6f5f96d
A
56}
57
58static bool vectorSupport()
59{
60#if __ppc__
61 uint32_t value;
62 size_t size=sizeof(uint32_t);
63 int err = sysctlbyname("hw.optional.altivec", &value, &size, NULL, 0);
64 //fprintf(stderr, "sysctlbyname() = %d\n", err);
65 return ( err == 0 );
66#else
67 return true;
68#endif
69}
70
71
72static 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}
9e225d03
A
81
82int main()
83{
d6f5f96d 84 if ( ! inttest() ) {
9e225d03
A
85 FAIL("lazy-binding-reg-params int parameters");
86 return EXIT_SUCCESS;
87 }
d6f5f96d
A
88
89 if ( ! floattest() ) {
90 FAIL("lazy-binding-reg-params float parameters");
91 return EXIT_SUCCESS;
92 }
93
94 if ( vectorSupport() && ! vectortest() ) {
95 FAIL("lazy-binding-reg-params vector parameters");
96 return EXIT_SUCCESS;
97 }
98
9e225d03
A
99 PASS("lazy-binding-reg-params");
100 return EXIT_SUCCESS;
101}