『楼 主』:
VGA12h模式下GUI界面设计的速度考虑
使用 LLM 解释/回答一下
VGA12h模式下GUI界面设计的速度考虑
1。 VGA12h模式下各种不同方式划线1满屏的耗时对比:
==============================================
划线方法 耗时(秒) 运行程序* 写次数 线性地址计算 REG设置
-----------------------------------------------------------------------------------------------------
扫描划块(REG) 0.046343422 lineff.com L*P/8 线间不重复 不重复
扫描划线(REG) 0.061104584 linehh.com L*P/8 线间重复 线间重复
垂直划线(REG) 0.326120375 linev.com L*P 点间不重复 线间重复
普通划线(REG) 0.823882125 linen.com L*P 点间重复 线间重复
-----------------------------------------------------------------------------------------------------
普通划点(BIOS) 3.899710625 lineb.com L*P 点间重复 点间重复
==============================================
注:REG--VGA寄存器 BIOS--BIOS中断 L--线条数 P--像素数
* --lineff.com、linehh.com划线100*16屏,其余.com划16屏
由此可见,BIOS描点划线速度太慢(耗时约为扫描线法的64倍),在GUI编程中不予考虑。即使是采用VGA寄存器编程,普通划线耗时约为扫描线法的13.5倍,普通划线耗时约为垂直线法的2.53倍。
注意:lineff.com和linehh.com的方式是都是划扫描线,而且因为线条的起止落在8的倍数的像素上,所以每次写8个像素,划块、划线速度最快,lineff.com因为线间不重复计算地址,所以更快,耗时是linehh.com的3分之2!linev.com是划竖线最快的方式,原因同扫描线划块--不重复计算地址!划非水平线、非竖线的其它线条,就只能采用普通划线方式。
所以,在要求速度的GUI设计中划块要用lineff.com方式,划框线要用linehh.com和linev.com方式,而不是用linen.com普通划线方式!
2。 绝对压榨速度的几点考虑:
在用VGA寄存器法划线时,必然要经历先①计算视频缓冲线性地址、②计算位屏蔽值、设置位屏蔽等寄存器,然后③描点划线,最后④恢复改动过的寄存器的默认值这几个阶段。
在第①环节中可能用到乘除法,但乘法和除法被公认为开销较大的运算,遇到需要反复执行的乘除法时,应该以移位和加法替代,左移1位相当于乘以2,右移2位相当于除以4。在许多绘图算法里计算地址时都要用到乘以80,可如下计算:
80*y=(64+16)*y=(y shl 6)+(y shl 4)
汇编代码为:
mov ax,y
mov cx,4
shl ax,cl ;y*16
mov bx,ax
shl bx,1
shl bx,1 ;y*64
add ax,bx ;(y*64)+(y*16)
在第②③④阶段必然用到的寄存器操作中,是用out dx,al还是out dx,ax,效率也是不一样的。如下程序段:
mov dx,3CEh
xor al,al
out dx,al
inc dx
mov ax,Color
out dx,al
dec dx
mov al,1
out dx,al
mov al,0Fh
out dx,al
可考虑改成:
mov dx,3CEh
xor al,al
mov ah,Color
out dx,ax
mov ax,0F01h
out dx,ax
在划线的各个阶段中,都可以注意一下此步操作有无必要重复,如有固定的增量关系等,可以简化,如无必要,则可省略。可参照line?.com中的程序代码。
### Speed Considerations in VGA12h Mode GUI Design
1. Time Consumption Comparison of Drawing Lines in Various Ways in VGA12h Mode:
==============================================
Line Drawing Method Time Consumption (seconds) Running Program* Number of Writes Linear Address Calculation REG Settings
-----------------------------------------------------------------------------------------------------
Scan Block Drawing (REG) 0.046343422 lineff.com L*P/8 Non-repetitive between lines Non-repetitive
Scan Line Drawing (REG) 0.061104584 linehh.com L*P/8 Repetitive between lines Repetitive between lines
Vertical Line Drawing (REG) 0.326120375 linev.com L*P Non-repetitive between points Repetitive between lines
Normal Line Drawing (REG) 0.823882125 linen.com L*P Repetitive between points Repetitive between lines
-----------------------------------------------------------------------------------------------------
Normal Point Drawing (BIOS) 3.899710625 lineb.com L*P Repetitive between points Repetitive between points
==============================================
Note: REG -- VGA registers BIOS -- BIOS interrupts L -- Number of lines P -- Number of pixels
* -- lineff.com, linehh.com draw 100*16 screen, others.com draw 16 screen
It can be seen that BIOS point drawing and line drawing are too slow (time consumption is about 64 times that of the scan line method), and are not considered in GUI programming. Even when using VGA register programming, the time consumption of normal line drawing is about 13.5 times that of the scan line method, and the time consumption of normal line drawing is about 2.53 times that of the vertical line method.
Note: The methods of lineff.com and linehh.com are both drawing scan lines, and because the start and end of the lines fall on pixels that are multiples of 8, each time 8 pixels are written, block drawing and line drawing are the fastest. lineff.com is faster because it does not repeat address calculation between lines, so it is faster, and the time consumption is 2/3 of linehh.com! linev.com is the fastest way to draw vertical lines, for the same reason as scan line block drawing -- no repeated address calculation! For other lines that are not horizontal or vertical, only the normal line drawing method can be used.
Therefore, in GUI design requiring speed, block drawing should use the lineff.com method, frame line drawing should use the linehh.com and linev.com methods, not the linen.com normal line drawing method!
2. Considerations for Absolute Speed Optimization:
When using the VGA register method to draw lines, it is necessary to go through several stages: first ① calculate the linear address of the video buffer, ② calculate the bit mask value, set the bit mask and other registers, then ③ draw points and lines, and finally ④ restore the default values of the modified registers.
In the first link ①, multiplication and division may be used, but multiplication and division are generally considered to be operations with high overhead. When encountering multiplication and division that need to be executed repeatedly, they should be replaced with shifts and additions. Shifting left by 1 bit is equivalent to multiplying by 2, and shifting right by 2 bits is equivalent to dividing by 4. In many drawing algorithms, calculating the address often requires multiplying by 80, which can be calculated as follows:
80*y=(64+16)*y=(y shl 6)+(y shl 4)
Assembly code:
mov ax,y
mov cx,4
shl ax,cl ;y*16
mov bx,ax
shl bx,1
shl bx,1 ;y*64
add ax,bx ;(y*64)+(y*16)
In the register operations that are necessarily used in stages ②③④, the efficiency is also different between using out dx,al or out dx,ax. The following code segment:
mov dx,3CEh
xor al,al
out dx,al
inc dx
mov ax,Color
out dx,al
dec dx
mov al,1
out dx,al
mov al,0Fh
out dx,al
Can be considered to be changed to:
mov dx,3CEh
xor al,al
mov ah,Color
out dx,ax
mov ax,0F01h
out dx,ax
In each stage of line drawing, you can pay attention to whether this operation is necessary to be repeated. If there is a fixed incremental relationship, etc., it can be simplified. If it is not necessary, it can be omitted. You can refer to the program code in line?.com.
附件
1: Linex.rar (2006-8-18 14:48, 14.5 KiB, 下载附件所需积分 1 点
,下载次数: 34)
|