Skip to content

Commit c01bb2f

Browse files
author
Sebastien Bourdeauducq
committedDec 14, 2011
Remove dependency on libmath
1 parent 0ab45bf commit c01bb2f

File tree

4 files changed

+126
-7
lines changed

4 files changed

+126
-7
lines changed
 

‎src/Makefile

+3-6
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ OBJECTS = crt0.o $(COBJS)
77
SEGMENTS= -j .text -j .data -j .rodata
88

99
LDFLAGS+= -T linker.ld -N
10-
LDFLAGS+= -L$(MMDIR)/software/libbase -L$(MMDIR)/software/libmath -L$(MMDIR)/software/libnet -L$(MMDIR)/software/libhal
11-
LDLIBS= -lbase -lmath -lnet -lhal
12-
LIBS=$(MMDIR)/software/libbase/libbase.a $(MMDIR)/software/libmath/libmath.a \
10+
LDFLAGS+= -L$(MMDIR)/software/libbase -L$(MMDIR)/software/libnet -L$(MMDIR)/software/libhal
11+
LDLIBS= -lbase -lnet -lhal
12+
LIBS=$(MMDIR)/software/libbase/libbase.a \
1313
$(MMDIR)/software/libnet/libnet.a $(MMDIR)/software/libhal/libhal.a
1414

1515
CFLAGS+= -DVERSION='"$(GIT_VERSION)$(GIT_STATUS)"'
@@ -43,9 +43,6 @@ $(MMDIR)/software/libhal/libhal.a:
4343
$(MMDIR)/software/libnet/libnet.a:
4444
make -C $(MMDIR)/software/libnet/
4545

46-
$(MMDIR)/software/libmath/libmath.a:
47-
make -C $(MMDIR)/software/libmath/
48-
4946
.PHONY: clean depend load boot.crc.bin $(LIBS)
5047

5148
boot.crc.bin: boot.bin

‎src/sincos.c

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*/
18+
19+
union float_long
20+
{
21+
float f;
22+
long l;
23+
};
24+
25+
#define HALF_PI 1.5707963268
26+
#define iPI 0.3183098862
27+
#define EPS2 59.6046E-9
28+
29+
/* fabsf: Returns the absolute value of a 32-bit float. */
30+
static float fabsf(const float x)
31+
{
32+
union float_long fl;
33+
34+
fl.f = x;
35+
fl.l &= 0x7fffffff;
36+
return fl.f;
37+
}
38+
39+
/*
40+
sincosf: Computes sin or cos of a 32-bit float as outlined in
41+
[1] William James Cody and W. M. Waite. _Software manual for the
42+
elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980.
43+
*/
44+
#define r1 (-0.1666665668E+0)
45+
#define r2 (0.8333025139E-2)
46+
#define r3 (-0.1980741872E-3)
47+
#define r4 (0.2601903036E-5)
48+
49+
/* PI=C1+C2 */
50+
#define C1 3.140625
51+
#define C2 9.676535897E-4
52+
53+
/*A reasonable value for YMAX is the int part of PI*B**(t/2)=3.1416*2**(12)*/
54+
#define YMAX 12867.0
55+
56+
static float sincosf(float x, int iscos)
57+
{
58+
float y, f, r, g, XN;
59+
int N;
60+
char sign;
61+
62+
if(iscos)
63+
{
64+
y=fabsf(x)+HALF_PI;
65+
sign=0;
66+
}
67+
else
68+
{
69+
if(x<0.0)
70+
{ y=-x; sign=1; }
71+
else
72+
{ y=x; sign=0; }
73+
}
74+
75+
if(y>YMAX)
76+
{
77+
//errno=ERANGE;
78+
return 0.0;
79+
}
80+
81+
/*Round y/PI to the nearest integer*/
82+
N=((y*iPI)+0.5); /*y is positive*/
83+
84+
/*If N is odd change sign*/
85+
if(N&1) sign=!sign;
86+
87+
XN=N;
88+
/*Cosine required? (is done here to keep accuracy)*/
89+
if(iscos) XN-=0.5;
90+
91+
y=fabsf(x);
92+
r=(int)y;
93+
g=y-r;
94+
f=((r-XN*C1)+g)-XN*C2;
95+
96+
g=f*f;
97+
if(g>EPS2) //Used to be if(fabsf(f)>EPS)
98+
{
99+
r=(((r4*g+r3)*g+r2)*g+r1)*g;
100+
f+=f*r;
101+
}
102+
return (sign?-f:f);
103+
}
104+
105+
float sinf(float x)
106+
{
107+
if (x==0.0) return 0.0;
108+
return sincosf(x, 0);
109+
}
110+
111+
float cosf(float x)
112+
{
113+
if (x==0.0) return 1.0;
114+
return sincosf(x, 1);
115+
}

‎src/sincos.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef __SINCOS_H
2+
#define __SINCOS_H
3+
4+
float sinf(float x);
5+
float cosf(float x);
6+
7+
#endif /* __SINCOS_H */

‎src/tests_audio.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include <hw/ac97.h>
2020
#include <irq.h>
2121
#include <stdio.h>
22-
#include <math.h>
2322
#include <console.h>
23+
#include "sincos.h"
2424
#include "testdefs.h"
2525

2626
static unsigned int snd_ac97_read(unsigned int addr)

0 commit comments

Comments
 (0)
Please sign in to comment.