Le clipping facile en 68000
Par Thomas Reiss le jeudi 12 mai 2005, 11:00 - Oldschool - Lien permanent
Sur le forum "Coding" de dhs.nu, Peter se demandais à quoi pouvait bien servir les instructions CHK et CHK2. Ces instructions ont l'air plus ou moins inutiles aux yeux de beaucoup (dont je fais partie)... Et pourtant... Leonard/OXG nous explique une utilité possible de ces instructions, notamment pour réaliser une routine de clipping optimisée. Je cite:
I don't know that game code, but these intructions "may" be usefull for special ultra-optimisation :-) Explain:
In my fast mandelbrot routine, I use the instruction TRAPV. TRAPV flush an exeption if overflow flag is set. If not, it only takes 4 cyles. In a standard mandelbrot set, you have to check an exit condition at each iteration, and generally do 30 to 100 iterations before one and only exit. So using trapv takes only 4 cycles per iterations, instead of 8 for a BVS branch.
Anyway, I don't know the CHK timing instruction but it may be 4 cycles if CHK dn,dn exist. So in a loop where the exit condition does not occur very often ( say a 2d dot clipping routine), CHK may be usefull. ( again, IF it takes 4 cycles. If not, it's useless)
<lèche-bottes>
Ô maître Leonard, tu es grand !
</lèche-bottes>
Edit
Voici le détail de l'instruction CHK:
CHK - Check Against Bounds
This instruction checks its first operand against a data register's word
contents. If the data register contains less than zero or greater than its
first operand, a trap to the address specified by vector 6 occurs. Thus, CHK
can be used to ensure that an element of an array is neither below nor above
its boundaries. Syntax: CHK bounds, Dn where bounds is anything except an
address register. Flags affected: All flags are undefined after this
operation.
En français et en clair, cette instruction est effectivement toute adaptée au clipping. L'instruction teste si le registre de données (apparemment la seconde opérande) est inférieur à zéro ou bien supérieur au premier opérande, si oui le 68000 va déclencher une interruption type CHK (vecteur en $18). Donc, si le point ne doit pas être clippé, l'instruction consomme 12 cycles en tout, mais s'il doit être clippé, c'est 44 cycles + le temps d'exécution de la routine d'interruption + le RTE. Merci Leonard !





Commentaires
Putain j'ai vécu sans savir ca! Vite je me cache... je m'exile au Népal :)