1 #include <asm/processor.h>
2 #include <asm/ppc_asm.h>
4 #include <asm/asm-offsets.h>
5 #include <asm/cputable.h>
6 #include <asm/thread_info.h>
10 * load_up_altivec(unused, unused, tsk)
11 * Disable VMX for the task which had it previously,
12 * and save its vector registers in its thread_struct.
13 * Enables the VMX for use in the kernel on return.
14 * On SMP we know the VMX is free, since we give it up every
15 * switch (ie, no lazy save of the vector registers).
17 _GLOBAL(load_up_altivec)
18 mfmsr r5 /* grab the current MSR */
20 MTMSRD(r5) /* enable use of AltiVec now */
24 * For SMP, we don't do lazy VMX switching because it just gets too
25 * horrendously complex, especially when a task switches from one CPU
26 * to another. Instead we call giveup_altvec in switch_to.
27 * VRSAVE isn't dealt with here, that is done in the normal context
28 * switch code. Note that we could rely on vrsave value to eventually
29 * avoid saving all of the VREGs here...
32 LOAD_REG_ADDRBASE(r3, last_task_used_altivec)
34 PPC_LL r4,ADDROFF(last_task_used_altivec)(r3)
38 /* Save VMX state to last_task_used_altivec's THREAD struct */
45 /* Disable VMX for last_task_used_altivec */
48 PPC_LL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
51 PPC_STL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
53 #endif /* CONFIG_SMP */
55 /* Hack: if we get an altivec unavailable trap with VRSAVE
56 * set to all zeros, we assume this is a broken application
57 * that fails to set it properly, and thus we switch it to
66 /* enable use of VMX after return */
68 mfspr r5,SPRN_SPRG3 /* current task's THREAD (phys) */
71 ld r4,PACACURRENT(r13)
72 addi r5,r4,THREAD /* Get THREAD */
73 oris r12,r12,MSR_VEC@h
78 stw r4,THREAD_USED_VR(r5)
83 /* Update last_task_used_altivec to 'current' */
84 subi r4,r5,THREAD /* Back to 'current' */
86 PPC_STL r4,ADDROFF(last_task_used_altivec)(r3)
87 #endif /* CONFIG_SMP */
88 /* restore registers and return */
93 * Disable VMX for the task given as the argument,
94 * and save the vector registers in its thread_struct.
95 * Enables the VMX for use in the kernel on return.
97 _GLOBAL(giveup_altivec)
101 MTMSRD(r5) /* enable use of VMX now */
104 beqlr- /* if no previous owner, done */
105 addi r3,r3,THREAD /* want THREAD of task */
106 PPC_LL r5,PT_REGS(r3)
113 PPC_LL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
116 lis r3,(MSR_VEC|MSR_VSX)@h
119 ALT_FTR_SECTION_END_IFSET(CPU_FTR_VSX)
123 andc r4,r4,r3 /* disable FP for previous task */
124 PPC_STL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
128 LOAD_REG_ADDRBASE(r4,last_task_used_altivec)
129 PPC_STL r5,ADDROFF(last_task_used_altivec)(r4)
130 #endif /* CONFIG_SMP */
136 #error This asm code isn't ready for 32-bit kernels
140 * load_up_vsx(unused, unused, tsk)
141 * Disable VSX for the task which had it previously,
142 * and save its vector registers in its thread_struct.
143 * Reuse the fp and vsx saves, but first check to see if they have
144 * been saved already.
147 /* Load FP and VSX registers if they haven't been done yet */
149 beql+ load_up_fpu /* skip if already loaded */
150 andis. r5,r12,MSR_VEC@h
151 beql+ load_up_altivec /* skip if already loaded */
154 ld r3,last_task_used_vsx@got(r2)
158 /* Disable VSX for last_task_used_vsx */
161 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
164 std r6,_MSR-STACK_FRAME_OVERHEAD(r5)
166 #endif /* CONFIG_SMP */
167 ld r4,PACACURRENT(r13)
168 addi r4,r4,THREAD /* Get THREAD */
170 stw r6,THREAD_USED_VSR(r4) /* ... also set thread used vsr */
171 /* enable use of VSX after return */
172 oris r12,r12,MSR_VSX@h
175 /* Update last_task_used_vsx to 'current' */
176 ld r4,PACACURRENT(r13)
178 #endif /* CONFIG_SMP */
179 b fast_exception_return
183 * Disable VSX for the task given as the argument.
184 * Does NOT save vsx registers.
185 * Enables the VSX for use in the kernel on return.
187 _GLOBAL(__giveup_vsx)
190 mtmsrd r5 /* enable use of VSX now */
194 beqlr- /* if no previous owner, done */
195 addi r3,r3,THREAD /* want THREAD of task */
199 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
201 andc r4,r4,r3 /* disable VSX for previous task */
202 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
206 ld r4,last_task_used_vsx@got(r2)
208 #endif /* CONFIG_SMP */
211 #endif /* CONFIG_VSX */
215 * The routines below are in assembler so we can closely control the
216 * usage of floating-point registers. These routines must be called
217 * with preempt disabled.
224 .long 0x3f800000 /* 1.0 in single-precision FP */
226 .long 0x3f000000 /* 0.5 in single-precision FP */
228 #define LDCONST(fr, name) \
237 .tc FD_3ff00000_0[TC],0x3ff0000000000000 /* 1.0 */
239 .tc FD_3fe00000_0[TC],0x3fe0000000000000 /* 0.5 */
241 #define LDCONST(fr, name) \
247 * Internal routine to enable floating point and set FPSCR to 0.
248 * Don't call it from C; it doesn't use the normal calling convention.
280 * Vector add, floating point.
297 * Vector subtract, floating point.
314 * Vector multiply and add, floating point.
326 fmadds fr0,fr0,fr2,fr1
334 * Vector negative multiply and subtract, floating point.
346 fnmsubs fr0,fr0,fr2,fr1
354 * Vector reciprocal estimate. We just compute 1.0/x.
355 * r3 -> destination, r4 -> source.
372 * Vector reciprocal square-root estimate, floating point.
373 * We use the frsqrte instruction for the initial estimate followed
374 * by 2 iterations of Newton-Raphson to get sufficient accuracy.
375 * r3 -> destination, r4 -> source.
390 frsqrte fr1,fr0 /* r = frsqrte(s) */
391 fmuls fr3,fr1,fr0 /* r * s */
392 fmuls fr2,fr1,fr5 /* r * 0.5 */
393 fnmsubs fr3,fr1,fr3,fr4 /* 1 - s * r * r */
394 fmadds fr1,fr2,fr3,fr1 /* r = r + 0.5 * r * (1 - s * r * r) */
395 fmuls fr3,fr1,fr0 /* r * s */
396 fmuls fr2,fr1,fr5 /* r * 0.5 */
397 fnmsubs fr3,fr1,fr3,fr4 /* 1 - s * r * r */
398 fmadds fr1,fr2,fr3,fr1 /* r = r + 0.5 * r * (1 - s * r * r) */