[Petit up]
alors voilà j'ai refait la fonction de rendu de mode7 en asm (et en changeant l'algo un peu) et j'aimerais savoir si vous voyez des moyen de gagner des cycles la dedans :
#define IN_MAP_ASM(SHIFT) \
asm("move.l %d4,%d5"); \
asm("asr.l %0,%%d5"::"g"(RENDER_SHARPNESS)); \
asm("add.w %d1,%d5"); \
asm("move.l %d3,%d6"); \
asm("asr.l %0,%%d6"::"g"(RENDER_SHARPNESS)); \
asm("add.w %d2,%d6"); \
\
asm("move.w %d5,%d7"); \
asm("swap %d7"); \
asm("move.w %d6,%d7"); \
asm("asr.w %0,%%d5"::"g"(TILES_SHIFT)); \
asm("asl.w %0,%%d5"::"g"(10-TILES_SHIFT)); \
asm("asr.w %0,%%d7"::"g"(TILES_SHIFT)); \
asm("add.w %d7,%d5"); \
asm("lsl.w #2,%d5"); \
asm("swap %d7"); \
asm("lea %a4@(%d5.w),%a5"); \
asm("and.w %0,%%d6"::"g"(TILES_SIZE - 1)); \
asm("and.w %0,%%d7"::"g"(TILES_SIZE - 1)); \
asm("asl.w %0,%%d7"::"g"(TILES_SHIFT)); \
asm("add.w %d6,%d7"); \
asm("movea.l %a5@,%a5"); \
asm("adda %d7,%a5"); \
asm("add.l %a3@,%d4"); \
asm("add.l %a3@(4),%d3"); \
\
asm("tst.b %a5@"); \
asm(".word 0x6704 | beq +4"); \
asm("or.w %0,%%a0@"::"g"(PIX >> SHIFT)); \
asm("adda.w %a6,%a5"); \
asm("tst.b %a5@"); \
asm(".word 0x6704 | beq +4"); \
asm("or.w %0,%%a1@"::"g"(PIX >> SHIFT));
static inline void m7_DrawFrame(void) {
asm("movem.l %d0-%d7/%a0-%a6,%a7@-"); // pushes all registers
asm("move.w Dir,%d0");
asm("lea SinTable,%a0");
asm("lea CosTable,%a1");
asm("moveq #0,%d3");
asm("moveq #0,%d4");
asm("move.b %a0@(%d0.w),%d3");
asm("ext.w %d3");
asm("move.b %a1@(%d0.w),%d4");
asm("ext.w %d4");
// computing of m7startsL
asm("lea m7starts,%a0");
asm("lea m7startsL,%a1");
asm("move.w Y,%a2");
asm("move.w X,%a3");
asm("moveq %0,%%d0"::"g"(SIZE_Y-1));
asm("loopM7S:");
asm("move.w %a0@+,%d1");
asm("move.w %d1,%d2");
asm("move.w %a0@+,%d5");
asm("move.w %d5,%d6");
asm("muls.w %d4,%d1");
asm("muls.w %d3,%d2");
asm("muls.w %d4,%d6");
asm("muls.w %d3,%d5");
asm("sub.l %d5,%d1");
asm("add.l %d6,%d2");
asm("add.l %a2,%d1");
asm("add.l %a3,%d2");
asm("asr.l %0,%%d1"::"g"(SINCOS + ZOOM));
asm("asr.l %0,%%d2"::"g"(SINCOS + ZOOM));
asm("move.w %d1,%a1@+");
asm("move.w %d2,%a1@+");
asm("dbra %d0,loopM7S");
// computing of m7vectorsL
asm("neg.w %d3");
asm("lea m7vectors,%a0");
asm("lea m7vectorsL,%a1");
asm("moveq %0,%%d0"::"g"(SIZE_Y-1));
asm("loopM7V:");
asm("move.w %a0@+,%d1");
asm("move.w %d1,%d2");
asm("muls.w %d3,%d1");
asm("muls.w %d4,%d2");
asm("asr.l %0,%%d1"::"g"(SINCOS + ZOOM));
asm("asr.l %0,%%d2"::"g"(SINCOS + ZOOM));
asm("move.l %d1,%a1@+");
asm("move.l %d2,%a1@+");
asm("dbra %d0,loopM7V");
asm("movea.l MapTiles,%a4");
asm("movea.w TilesOffset,%a6");
asm("movea.l Plane0,%a0");
asm("movea.l Plane1,%a1");
asm("lea %%a0@(%c0),%%a0"::"g"(2*(OFFSET_SCR_HORZ+ 15*OFFSET_SCR_VERT)));
asm("lea %%a1@(%c0),%%a1"::"g"(2*(OFFSET_SCR_HORZ+ 15*OFFSET_SCR_VERT)));
asm("lea m7startsL,%a2");
asm("lea m7vectorsL,%a3");
#if ENABLE_MULTI_RES == 1
asm("move.w %0,%%d0"::"g"(MULTI_RES_CUT-1));
#else
asm("move.w %0,%%d0"::"g"(SIZE_Y-1));
#endif
asm("loopj:");
asm("swap %d0");
asm("move.w %a2@+,%d1");
asm("move.w %a2@+,%d2");
asm("moveq #0,%d3");
asm("moveq #0,%d4");
asm("move.w %0,%%d0"::"g"((SIZE_X*ZOOM_SCR_HORZ/16)-1));
asm("loopi:");
asm("clr.w %a0@");
asm("clr.w %a1@");
#if ZOOM_SCR_HORZ <= 8
IN_MAP_ASM(0)
IN_MAP_ASM(ZOOM_SCR_HORZ)
#endif
#if ZOOM_SCR_HORZ <= 4
IN_MAP_ASM(ZOOM_SCR_HORZ * 2)
IN_MAP_ASM(ZOOM_SCR_HORZ * 3)
#endif
#if ZOOM_SCR_HORZ <= 2
IN_MAP_ASM(ZOOM_SCR_HORZ * 4)
IN_MAP_ASM(ZOOM_SCR_HORZ * 5)
IN_MAP_ASM(ZOOM_SCR_HORZ * 6)
IN_MAP_ASM(ZOOM_SCR_HORZ * 7)
#endif
#if ZOOM_SCR_HORZ == 1
IN_MAP_ASM(ZOOM_SCR_HORZ * 8)
IN_MAP_ASM(ZOOM_SCR_HORZ * 9)
IN_MAP_ASM(ZOOM_SCR_HORZ * 10)
IN_MAP_ASM(ZOOM_SCR_HORZ * 11)
IN_MAP_ASM(ZOOM_SCR_HORZ * 12)
IN_MAP_ASM(ZOOM_SCR_HORZ * 13)
IN_MAP_ASM(ZOOM_SCR_HORZ * 14)
IN_MAP_ASM(ZOOM_SCR_HORZ * 15)
#endif
#if ZOOM_SCR_VERT == 2
asm("move.w %a0@,%a0@(30)");
asm("move.w %a1@,%a1@(30)");
#endif
asm("addq.l #2,%a0");
asm("addq.l #2,%a1");
asm("dbra %d0,loopi");
asm("addq.l #8,%a3");
asm("swap %d0");
asm("lea %%a0@(%c0),%%a0"::"g"(2*(15*ZOOM_SCR_VERT-((ZOOM_SCR_HORZ*SIZE_X)/16))));
asm("lea %%a1@(%c0),%%a1"::"g"(2*(15*ZOOM_SCR_VERT-((ZOOM_SCR_HORZ*SIZE_X)/16))));
asm("dbra %d0,loopj");
#if ENABLE_MULTI_RES == 1
asm("move.w %0,%%d0"::"g"(((SIZE_Y-MULTI_RES_CUT)/2) - 1));
asm("loopj2:");
asm("swap %d0");
asm("move.w %a2@+,%d1");
asm("move.w %a2@,%d2");
asm("addq.l #6,%a2");
asm("moveq #0,%d3");
asm("moveq #0,%d4");
asm("move.w %0,%%d0"::"g"((SIZE_X*ZOOM_SCR_HORZ/16)-1));
asm("loopi2:");
asm("clr.w %a0@");
asm("clr.w %a1@");
#if ZOOM_SCR_HORZ <= 8
IN_MAP_ASM(0)
IN_MAP_ASM(ZOOM_SCR_HORZ)
#endif
#if ZOOM_SCR_HORZ <= 4
IN_MAP_ASM(ZOOM_SCR_HORZ * 2)
IN_MAP_ASM(ZOOM_SCR_HORZ * 3)
#endif
#if ZOOM_SCR_HORZ <= 2
IN_MAP_ASM(ZOOM_SCR_HORZ * 4)
IN_MAP_ASM(ZOOM_SCR_HORZ * 5)
IN_MAP_ASM(ZOOM_SCR_HORZ * 6)
IN_MAP_ASM(ZOOM_SCR_HORZ * 7)
#endif
#if ZOOM_SCR_HORZ == 1
IN_MAP_ASM(ZOOM_SCR_HORZ * 8)
IN_MAP_ASM(ZOOM_SCR_HORZ * 9)
IN_MAP_ASM(ZOOM_SCR_HORZ * 10)
IN_MAP_ASM(ZOOM_SCR_HORZ * 11)
IN_MAP_ASM(ZOOM_SCR_HORZ * 12)
IN_MAP_ASM(ZOOM_SCR_HORZ * 13)
IN_MAP_ASM(ZOOM_SCR_HORZ * 14)
IN_MAP_ASM(ZOOM_SCR_HORZ * 15)
#endif
asm("move.w %a0@,%a0@(30)");
asm("move.w %a1@,%a1@(30)");
asm("addq.l #2,%a0");
asm("addq.l #2,%a1");
asm("dbra %d0,loopi2");
asm("add.l #16,%a3");
asm("swap %d0");
asm("lea %%a0@(%c0),%%a0"::"g"(2*(15*2-((ZOOM_SCR_HORZ*SIZE_X)/16))));
asm("lea %%a1@(%c0),%%a1"::"g"(2*(15*2-((ZOOM_SCR_HORZ*SIZE_X)/16))));
asm("dbra %d0,loopj2");
#endif
asm("movem.l %a7@+,%d0-%d7/%a0-%a6"); // pops all registers
}
bon je sais que c'est de l'asm inline invalide (car je dit pas a gcc que je detruit les registres etc... Kevin m'a déjà expliqué pourquoi) mais bon en attendant que je modifie ca ca marche très bien
C'est surtout dans la macro que je dois optimiser au max.
Si vous avez le temps de regarder
Merci beaucoup