blob: e63cf420008ee748be35e94cec0cc074ad820233 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1997-2003 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26
27#include <stdlib.h>
28#include <string.h>
29#include <mlib_types.h>
30#include <mlib_sys_proto.h>
31#include "mlib_SysMath.h"
32
33/***************************************************************/
34
35#if ! defined ( __MEDIALIB_OLD_NAMES )
36#if defined ( __SUNPRO_C )
37
38#pragma weak mlib_memmove = __mlib_memmove
39#pragma weak mlib_malloc = __mlib_malloc
40#pragma weak mlib_realloc = __mlib_realloc
41#pragma weak mlib_free = __mlib_free
42#pragma weak mlib_memset = __mlib_memset
43#pragma weak mlib_memcpy = __mlib_memcpy
44
45#ifdef MLIB_NO_LIBSUNMATH
46#pragma weak mlib_sincosf = __mlib_sincosf
47#endif /* MLIB_NO_LIBSUNMATH */
48
49#elif defined ( __GNUC__ ) /* defined ( __SUNPRO_C ) */
50
51 __typeof__ ( __mlib_memmove) mlib_memmove
52 __attribute__ ((weak,alias("__mlib_memmove")));
53 __typeof__ ( __mlib_malloc) mlib_malloc
54 __attribute__ ((weak,alias("__mlib_malloc")));
55 __typeof__ ( __mlib_realloc) mlib_realloc
56 __attribute__ ((weak,alias("__mlib_realloc")));
57 __typeof__ ( __mlib_free) mlib_free
58 __attribute__ ((weak,alias("__mlib_free")));
59 __typeof__ ( __mlib_memset) mlib_memset
60 __attribute__ ((weak,alias("__mlib_memset")));
61 __typeof__ ( __mlib_memcpy) mlib_memcpy
62 __attribute__ ((weak,alias("__mlib_memcpy")));
63
64#ifdef MLIB_NO_LIBSUNMATH
65
66void __mlib_sincosf (float x, float *s, float *c);
67
68__typeof__ ( __mlib_sincosf) mlib_sincosf
69 __attribute__ ((weak,alias("__mlib_sincosf")));
70#endif /* MLIB_NO_LIBSUNMATH */
71
72#else /* defined ( __SUNPRO_C ) */
73
74#error "unknown platform"
75
76#endif /* defined ( __SUNPRO_C ) */
77#endif /* ! defined ( __MEDIALIB_OLD_NAMES ) */
78
79/***************************************************************/
80
81void *__mlib_malloc(mlib_u32 size)
82{
83#ifdef _MSC_VER
84 /*
85 * Currently, all MS C compilers for Win32 platforms default to 8 byte
86 * alignment. -- from stdlib.h of MS VC++5.0.
87 */
88 return (void *) malloc(size);
89#else /* _MSC_VER */
90 return (void *) memalign(8, size);
91#endif /* _MSC_VER */
92}
93
94void *__mlib_realloc(void *ptr, mlib_u32 size)
95{
96 return realloc(ptr, size);
97}
98
99void __mlib_free(void *ptr)
100{
101 free(ptr);
102}
103
104void *__mlib_memset(void *s, mlib_s32 c, mlib_u32 n)
105{
106 return memset(s, c, n);
107}
108
109void *__mlib_memcpy(void *s1, void *s2, mlib_u32 n)
110{
111 return memcpy(s1, s2, n);
112}
113
114void *__mlib_memmove(void *s1, void *s2, mlib_u32 n)
115{
116 return memmove(s1, s2, n);
117}
118
119#ifdef MLIB_NO_LIBSUNMATH
120
121void __mlib_sincosf (mlib_f32 x, mlib_f32 *s, mlib_f32 *c)
122{
123 *s = (mlib_f32)sin(x);
124 *c = (mlib_f32)cos(x);
125}
126
127#endif /* MLIB_NO_LIBSUNMATH */