Page 289 - ARM 64 Bit Assembly Language
P. 289
278 Chapter 8
145 blt sloop // Repeat for every table entry
146 // convert from S(2,61) to S(3,28) and return
147 asr x0,x0,#33
148 ret // return the result
149
150
151 //-------------------------------------------------------------
152 // cos(x) NOTE: The cos(x) function does not return.
153 // It is an alternate entry point to sin(x).
154 // input: x -> S(3,28)
155 // returns cos(x) -> S(3,28)
156 .global fixed_cos
157 fixed_cos:
158 cmp x0,#0 // Add 2*pi to x if needed, to make
159 bge cosgood // sure x does not become too negative.
160 ldr x1,=pi_x2 // load pointer to 2*pi
161 ldrsw x1,[x1] // load 2*pi
162 add x0,x0,x1
163 cosgood:ldr x1,=pi_2 // load pointer to pi/2
164 ldrsw x1,[x1] // load pi/2
165 sub x0,x1,x0 // cos(x) = sin(pi/2-x)
166 // now we just fall through into the sin function
167
168 //-------------------------------------------------------------
169 // sin(x)
170 // input: x -> S(3,28)
171 // returns sin(x) -> S(3,28)
172 .global fixed_sin
173 fixed_sin:
174 stp x29,x30,[sp, #-16]! // push FP & LR
175
176 // load w1, w2 and w3 with constants
177 mov w1,#PI_2_LO
178 movk w1,#PI_2_HI,lsl #16
179 mov w2,#PI_LO
180 movk w2,#PI_HI,lsl #16
181 mov w3,#PI_X2_LO
182 movk w3,#PI_X2_HI,lsl #16
183
184 // step 1: make sure x>=0.0 and x<=2pi
185 negl: cmp x0,#0 // while(x < 0)
186 bge nonneg
187 add x0,x0,x3 // x=x+2*pi
188 b negl // end while
189 nonneg: cmp x0,x3 // while(x > pi/2)
190 ble inrange
191 sub x0,x0,x3 // x=x-2*pi
192 b nonneg // end while
193 // step 2: find the quadrant and call sinq appropriately