#ifndef _VIDEO_ATAFB_UTILS_H
#define _VIDEO_ATAFB_UTILS_H
/* ================================================================= */
/* Utility Assembler Functions */
/* ================================================================= */
/* ====================================================================== */
/* Those of a delicate disposition might like to skip the next couple of
* pages.
*
* These functions are drop in replacements for memmove and
* memset(_, 0, _). However their five instances add at least a kilobyte
* to the object file. You have been warned.
*
* Not a great fan of assembler for the sake of it, but I think
* that these routines are at least 10 times faster than their C
* equivalents for large blits, and that's important to the lowest level of
* a graphics driver. Question is whether some scheme with the blitter
* would be faster. I suspect not for simple text system - not much
* asynchrony.
*
* Code is very simple, just gruesome expansion. Basic strategy is to
* increase data moved/cleared at each step to 16 bytes to reduce
* instruction per data move overhead. movem might be faster still
* For more than 15 bytes, we try to align the write direction on a
* longword boundary to get maximum speed. This is even more gruesome.
* Unaligned read/write used requires 68020+ - think this is a problem?
*
* Sorry!
*/
/* ++roman: I've optimized Robert's original versions in some minor
* aspects, e.g. moveq instead of movel, let gcc choose the registers,
* use movem in some places...
* For other modes than 1 plane, lots of more such assembler functions
* were needed (e.g. the ones using movep or expanding color values).
*/
/* ++andreas: more optimizations:
subl #65536,d0 replaced by clrw d0; subql #1,d0 for dbcc
addal is faster than addaw
movep is rather expensive compared to ordinary move's
some functions rewritten in C for clarity, no speed loss */
static inline void *fb_memclear_small(void *s, size_t count)
{
if (!count)
return 0;
asm volatile ("\n"
" lsr.l #1,%1 ; jcc 1f ; move.b %2,-(%0)\n"
"1: lsr.l #1,%1 ; jcc 1f ; move.w %2,-(%0)\n"
"1: lsr.l #1,%1 ; jcc 1f ; move.l %2,-(%0)\n"
"1: lsr.l #1,%1 ; jcc 1f ; move.l %2,-(%0) ; move.l %2,-(%0)\n"
"1:"
: "=a" (s), "=d" (count)
: "d" (0), "0" ((char *)s + count), "1" (count));
asm volatile ("\n"
" subq.l #1,%1\n"
" jcs 3f\n"
" move.l %2,%%d4; move.l %2,%%d5; move.l %2,%%d6\n"
"2: movem.l %2/%%d4/%%d5/%%d6,-(%0)\n"
" dbra %1,2b\n"
"3:"
: "=a" (s), "=d" (count)
: "d" (0), "0" (s), "1" (count)
: "d4", "d5", "d6"
);
return 0;
}
static inline void *fb_memclear(void *s, size_t count)
{
if (!count)
return 0;
if (count < 16) {
asm volatile ("\n"
" lsr.l #1,%1 ; jcc 1f ; clr.b (%0)+\n"
"1: lsr.l #1,%1 ; jcc 1f ; clr.w (%0)+\n"
"1: lsr.l #1,%1 ; jcc 1f ; clr.l (%0)+\n"
"1: lsr.l #1,%1 ; jcc 1f ; clr.l (%0)+ ; clr.l (%0)+\n"
"1:"
: "=a" (s), "=d" (count)
: "0" (s), "1" (count));
} else {
long tmp;
asm volatile ("\n"
" move.l %1,%2\n"
" lsr.l #1,%2 ; jcc 1f ; clr.b (%0)+ ; subq.w #1,%1\n"
" lsr.l #1,%2 ; jcs 2f\n" /* %0 increased=>bit 2 switched*/
" clr.w (%0)+ ; subq.w #2,%1 ; jra 2f\n"
"1: lsr.l #1,%2 ; jcc 2f\n"
" clr.w (%0)+ ; subq.w #2,%1\n"
"2: move.w %1,%2; lsr.l #2,%1 ; jeq 6f\n"
" lsr.l #1,%1 ; jcc 3f ; clr.l (%0)+\n"
"3: lsr.l #1,%1 ; jcc 4f ; clr.l (%0)+ ; clr.l (%0)+\n"
"4: subq.l #1,%1 ; jcs 6f\n"
"5: clr.l (%0)+; clr.l (%0)+ ; clr.l (%0)+ ; clr.l (%0)+\n"
" dbra %1,5b ; clr.w %1; subq.l #1,%1; jcc 5b\n"
"6: move.w %2,%1; btst #1,%1 ; jeq 7f ; clr.w (%0)+\n"
"7: btst #0,%1 ; jeq 8f ; clr.b (%0)+\n"
"8:"
: "=a" (s), "=d" (count), "=d" (tmp)
: "0" (s), "1" (count));
}
return 0;
}
static inline void *fb_memset255(void *s, size_t count)
{
if (!count)
return 0;
asm volatile ("\n"
" lsr.l #1,%1 ; jcc 1f ; move.b %2,-(%0)\n"
"1: lsr.l #1,%1 ; jcc 1f ; move.w %2,-(%0)\n"
"1: lsr.l #1,%1 ; jcc 1f ; move.l %2,-(%0)\n"
"1: lsr.l #1,%1 ; jcc 1f ; move.l %2,-(%0) ; move.l %2,-(%0)\n"
"1:"
: "=a" (s), "=d" (count)
: "d" (-1), "0" ((char *)s+count), "1" (count));
asm volatile ("\n"
" subq.l #1,%1 ; jcs 3f\n"
" move.l %2,%%d4; move.l %2,%%d5; move.l %2,%%d6\n"
"2: movem.l %2/%%d4/%%d5/%%d6,-(%0)\n"
" dbra %1,2b\n"
"3:"
: "=a" (s), "=d" (count)
: "d" (-1), "0" (s), "1" (count)
: "d4", "d5", "d6");
return 0;
}
static inline void *fb_memmove(void *d, const void *s, size_t count)
{
if (d < s) {
if (count < 16) {
asm volatile ("\n"
" lsr.l #1,%2 ; jcc 1f ; move.b (%1)+,(%0)+\n"
"1: lsr.l #1,%2 ; jcc 1f ; move.w (%1)+,(%0)+\n"
"1: lsr.l #1,%2 ; jcc 1f ; move.l (%1)+,(%0)+\n"
"1: lsr.l #1,%2 ; jcc 1f ; move.l (%1)+,(%0)+ ; move.l (%1)+,(%0)+\n"
"1:"
: "=a" (d), "=a" (s), "=d" (count)
: "0" (d), "1" (s), "2" (count));
} else {
long tmp;
asm volatile ("\n"
" move.l %0,%3\n"
" lsr.l #1,%3 ; jcc 1f ; move.b (%1)+,(%0)+ ; subqw #1,%2\n"
" lsr.l #1,%3 ; jcs 2f\n" /* %0 increased=>bit 2 switched*/
" move.w (%1)+,(%0)+ ; subqw #2,%2 ; jra 2f\n"
"1: lsr.l #1,%3 ; jcc 2f\n"
" move.w (%1)+,(%0)+ ; subqw #2,%2\n"
"2: move.w %2,%-; lsr.l #2,%2 ; jeq 6f\n"
" lsr.l #1,%2 ; jcc 3f ; move.l (%1)+,(%0)+\n"
"3: lsr.l #1,%2 ; jcc 4f ; move.l (%1)+,(%0)+ ; move.l (%1)+,(%0)+\n"
"4: subq.l #1,%2 ; jcs 6f\n"
"5: move.l (%1)+,(%0)+; move.l (%1)+,(%0)+\n"
" move.l (%1)+,(%0)+; move.l (%1)+,(%0)+\n"
" dbra %2,5b ; clr.w %2; subq.l #1,%2; jcc 5b\n"
"6: move.w %+,%2; btst #1,%2 ; jeq 7f ; move.w (%1)+,(%0)+\n"
"7: btst #0,%2 ; jeq 8f ; move.b (%1)+,(%0)+\n"
"8:"
: "=a" (d), "=a" (s), "=d" (count), "=d" (tmp)
: "0" (d), "1" (s), "2" (count));
}
} else {
if (count < 16) {
asm volatile ("\n"
" lsr.l #1,%2 ; jcc 1f ; move.b -(%1),-(%0)\n"
"1: lsr.l #1,%2 ; jcc 1f ; move.w -(%1),-(%0)\n"
"1: lsr.l #1,%2 ; jcc 1f ; move.l -(%1),-(%0)\n"
"1: lsr.l #1,%2 ; jcc 1f ; move.l -(%1),-(%0) ; move.l -(%1),-(%0)\n"
"1:"
: "=a" (d), "=a" (s), "=d" (count)
: "0" ((char *) d + count), "1" ((char *) s + count), "2" (count));
} else {
long tmp;
asm volatile ("\n"
" move.l %0,%3\n"
" lsr.l #1,%3 ; jcc 1f ; move.b -(%1),-(%0) ; subqw #1,%2\n"
" lsr.l #1,%3 ; jcs 2f\n" /* %0 increased=>bit 2 switched*/
" move.w -(%1),-(%0) ; subqw #2,%2 ; jra 2f\n"
"1: lsr.l #1,%3 ; jcc 2f\n"
" move.w -(%1),-(%0) ; subqw #2,%2\n"
"2: move.w %2,%-; lsr.l #2,%2 ; jeq 6f\n"
" lsr.l #1,%2 ; jcc 3f ; move.l -(%1),-(%0)\n"
"3: lsr.l #1,%2 ; jcc 4f ; move.l -(%1),-(%0) ; move.l -(%1),-(%0)\n"
"4: subq.l #1,%2 ; jcs 6f\n"
"5: move.l -(%1),-(%0); move.l -(%1),-(%0)\n"
" move.l -(%1),-(%0); move.l -(%1),-(%0)\n"
" dbra %2,5b ; clr.w %2; subq.l #1,%2; jcc 5b\n"
"6: move.w %+,%2; btst #1,%2 ; jeq 7f ; move.w -(%1),-(%0)\n"
"7: btst #0,%2 ; jeq 8f ; move.b -(%1),-(%0)\n"
"8:"
: "=a" (d), "=a" (s), "=d" (count), "=d" (tmp)
: "0" ((char *) d + count), "1" ((char *) s + count), "2" (count));
}
}
return 0;
}
/* ++andreas: Simple and fast version of memmove, assumes size is
divisible by 16, suitable for moving the whole screen bitplane */
static inline void fast_memmove(char *dst, const char *src, size_t size)
{
if (!size)
return;
if (dst < src)
asm volatile ("\n"
"1: movem.l (%0)+,%%d0/%%d1/%%a0/%%a1\n"
" movem.l %%d0/%%d1/%%a0/%%a1,%1@\n"
" addq.l #8,%1; addq.l #8,%1\n"
" dbra %2,1b\n"
" clr.w %2; subq.l #1,%2\n"
" jcc 1b"
: "=a" (src), "=a" (dst), "=d" (size)
: "0" (src), "1" (dst), "2" (size / 16 - 1)
: "d0", "d1", "a0", "a1", "memory");
else
asm volatile ("\n"
"1: subq.l #8,%0; subq.l #8,%0\n"
" movem.l %0@,%%d0/%%d1/%%a0/%%a1\n"
" movem.l %%d0/%%d1/%%a0/%%a1,-(%1)\n"
" dbra %2,1b\n"
" clr.w %2; subq.l #1,%2\n"
" jcc 1b"
: "=a" (sr
atmel_pdc.rar_The Next
版权申诉
162 浏览量
2022-09-24
20:25:46
上传
评论
收藏 4KB RAR 举报
林当时
- 粉丝: 97
- 资源: 1万+
最新资源
- 基于matlab实现夜间车牌识别程序(1).rar
- 基于matlab实现无线传感器网络无需测距定位算法matlab源代码 包括apit,dv-hop,amorphous在内的共7个
- 基于python的yolov5实现的旋转目标检测
- 基于matlab实现无线传感器网络 CAB定位仿真程序 这是无线传感器节点定位CAB算法的仿真程序,由matlab完成.rar
- 基于matlab实现图像处理,本程序使用背景差分法对来往车辆进行检测和跟踪.rar
- 基于matlab实现视频监控中车型识别代码,自己写的,希望和大家多多交流.rar
- springcodespringcodespringcodespringcode
- 基于matlab实现权值的MAXDEV无线传感器网络定位算法研究 MAXDEV 无线传感器 定位 算法.rar
- sdk.config
- 基于matlab实现配电网三相潮流计算方法,对几种常用的配电网潮流计算方法进行了对比分析.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈