1/*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. 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.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26
27#include <stdlib.h>
28#include <string.h>
29#ifdef MACOSX
30#include <unistd.h>
31#include <sys/param.h>
32#else
33#include <malloc.h>
34#endif
35#include <mlib_types.h>
36#include <mlib_sys_proto.h>
37#include "mlib_SysMath.h"
38
39/***************************************************************/
40
41#if ! defined ( __MEDIALIB_OLD_NAMES )
42#if defined ( __SUNPRO_C )
43
44#pragma weak mlib_memmove = __mlib_memmove
45#pragma weak mlib_malloc = __mlib_malloc
46#pragma weak mlib_realloc = __mlib_realloc
47#pragma weak mlib_free = __mlib_free
48#pragma weak mlib_memset = __mlib_memset
49#pragma weak mlib_memcpy = __mlib_memcpy
50
51#ifdef MLIB_NO_LIBSUNMATH
52#pragma weak mlib_sincosf = __mlib_sincosf
53#endif /* MLIB_NO_LIBSUNMATH */
54
55#elif defined ( __GNUC__ ) /* defined ( __SUNPRO_C ) */
56
57  __typeof__ ( __mlib_memmove) mlib_memmove
58    __attribute__ ((weak,alias("__mlib_memmove")));
59  __typeof__ ( __mlib_malloc) mlib_malloc
60    __attribute__ ((weak,alias("__mlib_malloc")));
61  __typeof__ ( __mlib_realloc) mlib_realloc
62    __attribute__ ((weak,alias("__mlib_realloc")));
63  __typeof__ ( __mlib_free) mlib_free
64    __attribute__ ((weak,alias("__mlib_free")));
65  __typeof__ ( __mlib_memset) mlib_memset
66    __attribute__ ((weak,alias("__mlib_memset")));
67  __typeof__ ( __mlib_memcpy) mlib_memcpy
68    __attribute__ ((weak,alias("__mlib_memcpy")));
69
70#ifdef MLIB_NO_LIBSUNMATH
71
72void __mlib_sincosf (float x, float *s, float *c);
73
74__typeof__ ( __mlib_sincosf) mlib_sincosf
75    __attribute__ ((weak,alias("__mlib_sincosf")));
76#endif /* MLIB_NO_LIBSUNMATH */
77
78#else /* defined ( __SUNPRO_C ) */
79
80#error  "unknown platform"
81
82#endif /* defined ( __SUNPRO_C ) */
83#endif /* ! defined ( __MEDIALIB_OLD_NAMES ) */
84
85/***************************************************************/
86
87void *__mlib_malloc(mlib_u32 size)
88{
89#if defined(_MSC_VER) || defined(AIX)
90  /*
91   * Currently, all MS C compilers for Win32 platforms default to 8 byte
92   * alignment. -- from stdlib.h of MS VC++5.0.
93   *
94   * On AIX, the malloc subroutine returns a pointer to space suitably
95   * aligned for the storage of any type of object (see 'man malloc').
96   */
97  return (void *) malloc(size);
98#elif defined(MACOSX)
99  return valloc(size);
100#else
101  return (void *) memalign(8, size);
102#endif /* _MSC_VER */
103}
104
105void *__mlib_realloc(void *ptr, mlib_u32 size)
106{
107  return realloc(ptr, size);
108}
109
110void __mlib_free(void *ptr)
111{
112  free(ptr);
113}
114
115void *__mlib_memset(void *s, mlib_s32 c, mlib_u32 n)
116{
117  return memset(s, c, n);
118}
119
120void *__mlib_memcpy(void *s1, void *s2, mlib_u32 n)
121{
122  return memcpy(s1, s2, n);
123}
124
125void *__mlib_memmove(void *s1, void *s2, mlib_u32 n)
126{
127  return memmove(s1, s2, n);
128}
129
130#ifdef MLIB_NO_LIBSUNMATH
131
132void __mlib_sincosf (mlib_f32 x, mlib_f32 *s, mlib_f32 *c)
133{
134  *s = (mlib_f32)sin(x);
135  *c = (mlib_f32)cos(x);
136}
137
138#endif /* MLIB_NO_LIBSUNMATH */
139