2 #include <proto/exec.h>
3 #include <proto/utility.h>
4 #include <exec/resident.h>
5 #include <exec/system.h>
11 void setupAVExceptions(void)
13 ULONG a
[ 4 ] __attribute((aligned( 16 )));
14 vector
unsigned short b
;
16 vec_st(b
, 0, (unsigned short *) a
);
18 b
= vec_ld(0, (unsigned short *)a
);
23 void AltivecInit( void )
25 struct Resident
*MyResident
;
27 MyResident
= FindResident("MorphOS");
29 /* Altivec/VMX detection */
31 if (MyResident
&& (MyResident
->rt_Version
> 1 || ((MyResident
->rt_Flags
& RTF_EXTENDED
) && MyResident
->rt_Version
== 1 && MyResident
->rt_Revision
>= 5)))
33 struct TagItem MyTag
= {TAG_DONE
, 0};
34 NewGetSystemAttrsA(&hasAltivec
, sizeof(hasAltivec
), SYSTEMINFOTYPE_PPC_ALTIVEC
, &MyTag
);
43 /// Altivec cache prewarming stuff
46 * blockcount: number of blocks (from 0 to 255, 0 = 256 blocks)
47 * blocksize: number of 16-byte chunks (from 0 to 31, 0 = 32 * 16-byte chunks)
48 * blockstride: 16-bit value from -32768 to 32767 (0 = 32768), denotes the address
49 * increment from the beginning of one block to the beginning of the next.
52 static void cpu_vec_dst(CONST_APTR ptr
, ULONG opts
, ULONG channel
)
57 vec_dst((VECTOR_UBYTE
*)ptr
, opts
, 0);
61 vec_dst((VECTOR_UBYTE
*)ptr
, opts
, 1);
65 vec_dst((VECTOR_UBYTE
*)ptr
, opts
, 2);
69 vec_dst((VECTOR_UBYTE
*)ptr
, opts
, 3);
74 static void cpu_vec_dstt(CONST_APTR ptr
, ULONG opts
, ULONG channel
)
79 vec_dstt((VECTOR_UBYTE
*)ptr
, opts
, 0);
83 vec_dstt((VECTOR_UBYTE
*)ptr
, opts
, 1);
87 vec_dstt((VECTOR_UBYTE
*)ptr
, opts
, 2);
91 vec_dstt((VECTOR_UBYTE
*)ptr
, opts
, 3);
97 static void cpu_vec_dstst(CONST_APTR ptr
, ULONG opts
, ULONG channel
)
102 vec_dstst((VECTOR_UBYTE
*)ptr
, opts
, 0);
106 vec_dstst((VECTOR_UBYTE
*)ptr
, opts
, 1);
110 vec_dstst((VECTOR_UBYTE
*)ptr
, opts
, 2);
114 vec_dstst((VECTOR_UBYTE
*)ptr
, opts
, 3);
120 static void cpu_vec_dststt(CONST_APTR ptr
, ULONG opts
, ULONG channel
)
125 vec_dststt((VECTOR_UBYTE
*)ptr
, opts
, 0);
129 vec_dststt((VECTOR_UBYTE
*)ptr
, opts
, 1);
133 vec_dststt((VECTOR_UBYTE
*)ptr
, opts
, 2);
137 vec_dststt((VECTOR_UBYTE
*)ptr
, opts
, 3);
143 static void cpu_vec_dss(ULONG channel
)
165 void cpu_cache_stream_start(CONST_APTR ptr
, ULONG blockcount
, ULONG blocksize
, LONG stride
, ULONG flags
)
172 opts
= (blocksize
<< 24) | (blockcount
<< 16) | stride
;
174 if (flags
& CCSSF_CHANNEL1
)
178 else if (flags
& CCSSF_CHANNEL2
)
182 else if (flags
& CCSSF_CHANNEL3
)
187 if (flags
& CCSSF_WRITES
)
189 if (flags
& CCSSF_TRANSCIENT
)
191 cpu_vec_dststt(ptr
, opts
, channel
);
195 cpu_vec_dstst(ptr
, opts
, channel
);
200 if (flags
& CCSSF_TRANSCIENT
)
202 cpu_vec_dstt(ptr
, opts
, channel
);
206 cpu_vec_dst(ptr
, opts
, channel
);
212 //kprintf("[Altivec]: Not available\n");
214 /* XXX: fallback to dtst etc.. ? */
218 void cpu_cache_stream_stop(ULONG channel
)
222 cpu_vec_dss(channel
);
227 * Function using simple heuristics to determine caching.
230 void cpu_cache_image_start(void *ptr
, int rowbytes
, int width
, int lines
)
232 /* blocksize 0...31, 0 == 32 */
241 blocksize
= width
/ (blocks
* 16); /* size of block in 16byte units */
249 blocksize
= (rowbytes
* lines
) / (blocks
* 16);
259 cpu_cache_stream_start((void*)((unsigned int)ptr
& ~0xf), blocks
, blocksize
, blocksize
* 16, CCSSF_CHANNEL1
);
262 void cpu_cache_image_stop(void)
264 cpu_cache_stream_stop(1);