From 1744204cd84800636373a812a054489999805a1c Mon Sep 17 00:00:00 2001 From: XProger Date: Sat, 12 Feb 2022 16:13:16 +0300 Subject: [PATCH] #368 add divLUT macro --- src/platform/gba/asm/boxIsVisible.s | 7 +++---- src/platform/gba/asm/common_asm.inc | 5 +++++ src/platform/gba/asm/matrixLerp.s | 3 +-- src/platform/gba/asm/rasterizeF.s | 6 ++---- src/platform/gba/asm/rasterizeFT.s | 9 +++------ src/platform/gba/asm/rasterizeFTA.s | 9 +++------ src/platform/gba/asm/rasterizeGT.s | 9 +++------ src/platform/gba/asm/rasterizeGTA.s | 9 +++------ src/platform/gba/asm/rasterizeS.s | 6 ++---- src/platform/gba/asm/sphereIsVisible.s | 9 ++++----- src/platform/gba/asm/transformMesh.s | 7 +++---- src/platform/gba/asm/transformRoom.s | 7 +++---- src/platform/gba/asm/transformRoomUW.s | 7 +++---- 13 files changed, 38 insertions(+), 55 deletions(-) diff --git a/src/platform/gba/asm/boxIsVisible.s b/src/platform/gba/asm/boxIsVisible.s index a355d0c..d78aa8a 100644 --- a/src/platform/gba/asm/boxIsVisible.s +++ b/src/platform/gba/asm/boxIsVisible.s @@ -69,10 +69,9 @@ SIZE = (6 * 3 * 4) mov dz, z, lsr #(FIXED_SHIFT + 6) add dz, dz, z, lsr #(FIXED_SHIFT + 4) - add tmp, dz, #DIVLUT_ADDR - ldrh dz, [tmp, dz] - mul x, dz, x - mul y, dz, y + divLUT tmp, dz + mul x, tmp, x + mul y, tmp, y cmp x, rMinX movlt rMinX, x diff --git a/src/platform/gba/asm/common_asm.inc b/src/platform/gba/asm/common_asm.inc index 512d7c6..9adc050 100644 --- a/src/platform/gba/asm/common_asm.inc +++ b/src/platform/gba/asm/common_asm.inc @@ -92,6 +92,11 @@ .equ MIN_INT32, 0x80000000 .equ MAX_INT32, 0x7FFFFFFF +.macro divLUT res, x + add \res, \x, #DIVLUT_ADDR + ldrh \res, [\res, \x] +.endm + .macro CCW skip ldrsh vx0, [vp0, #VERTEX_X] ldrsh vy0, [vp0, #VERTEX_Y] diff --git a/src/platform/gba/asm/matrixLerp.s b/src/platform/gba/asm/matrixLerp.s index b38fb29..f309fd2 100644 --- a/src/platform/gba/asm/matrixLerp.s +++ b/src/platform/gba/asm/matrixLerp.s @@ -106,8 +106,7 @@ matrixLerp_asm: lerp _1_2 b .done .mX_dY: - add tmp, pdiv, #DIVLUT_ADDR - ldrh tmp, [tmp, pdiv] + divLUT tmp, pdiv mul tmp, pmul, tmp mov pmul, tmp, asr #8 lerp _X_Y diff --git a/src/platform/gba/asm/rasterizeF.s b/src/platform/gba/asm/rasterizeF.s index 98f0708..28cb217 100644 --- a/src/platform/gba/asm/rasterizeF.s +++ b/src/platform/gba/asm/rasterizeF.s @@ -55,8 +55,7 @@ rasterizeF_asm: cmp Lh, #1 // if (Lh == 1) skip Ldx calc beq .calc_left_end - add tmp, Lh, #DIVLUT_ADDR - ldrh tmp, [tmp, Lh] // tmp = FixedInvU(Lh) + divLUT tmp, Lh // tmp = FixedInvU(Lh) ldrsh Ldx, [L, #VERTEX_X] sub Ldx, Lx, asr #16 @@ -80,8 +79,7 @@ rasterizeF_asm: cmp Rh, #1 // if (Rh == 1) skip Rdx calc beq .calc_right_end - add tmp, Rh, #DIVLUT_ADDR - ldrh tmp, [tmp, Rh] // tmp = FixedInvU(Rh) + divLUT tmp, Rh // tmp = FixedInvU(Rh) ldrsh Rdx, [R, #VERTEX_X] sub Rdx, Rx, asr #16 diff --git a/src/platform/gba/asm/rasterizeFT.s b/src/platform/gba/asm/rasterizeFT.s index a9fc72b..8cca5ae 100644 --- a/src/platform/gba/asm/rasterizeFT.s +++ b/src/platform/gba/asm/rasterizeFT.s @@ -109,8 +109,7 @@ rasterizeFT_asm: cmp Lh, #1 // if (Lh <= 1) skip Ldx calc beq .calc_left_end - add tmp, Lh, #DIVLUT_ADDR - ldrh tmp, [tmp, Lh] // tmp = FixedInvU(Lh) + divLUT tmp, Lh // tmp = FixedInvU(Lh) ldrsh Ldx, [L, #VERTEX_X] sub Ldx, Lx, asr #16 @@ -142,8 +141,7 @@ rasterizeFT_asm: cmp Rh, #1 // if (Rh <= 1) skip Rdx calc beq .calc_right_end - add tmp, Rh, #DIVLUT_ADDR - ldrh tmp, [tmp, Rh] // tmp = FixedInvU(Rh) + divLUT tmp, Rh // tmp = FixedInvU(Rh) ldrsh Rdx, [R, #VERTEX_X] sub Rdx, Rx, asr #16 @@ -172,8 +170,7 @@ rasterizeFT_asm: add ptr, pixel, tmp // ptr = pixel + x1 - add inv, width, #DIVLUT_ADDR - ldrh inv, [inv, width] // inv = FixedInvU(width) + divLUT inv, width // inv = FixedInvU(width) sub dtdx, Rt, Lt // duv = Rt - Lt scaleUV dtdx, du, dv, inv diff --git a/src/platform/gba/asm/rasterizeFTA.s b/src/platform/gba/asm/rasterizeFTA.s index 111e5cb..20fe35b 100644 --- a/src/platform/gba/asm/rasterizeFTA.s +++ b/src/platform/gba/asm/rasterizeFTA.s @@ -109,8 +109,7 @@ rasterizeFTA_asm: cmp Lh, #1 // if (Lh <= 1) skip Ldx calc beq .calc_left_end - add tmp, Lh, #DIVLUT_ADDR - ldrh tmp, [tmp, Lh] // tmp = FixedInvU(Lh) + divLUT tmp, Lh // tmp = FixedInvU(Lh) ldrsh Ldx, [L, #VERTEX_X] sub Ldx, Lx, asr #16 @@ -142,8 +141,7 @@ rasterizeFTA_asm: cmp Rh, #1 // if (Rh <= 1) skip Rdx calc beq .calc_right_end - add tmp, Rh, #DIVLUT_ADDR - ldrh tmp, [tmp, Rh] // tmp = FixedInvU(Rh) + divLUT tmp, Rh // tmp = FixedInvU(Rh) ldrsh Rdx, [R, #VERTEX_X] sub Rdx, Rx, asr #16 @@ -172,8 +170,7 @@ rasterizeFTA_asm: add ptr, pixel, tmp // ptr = pixel + x1 - add inv, width, #DIVLUT_ADDR - ldrh inv, [inv, width] // inv = FixedInvU(width) + divLUT inv, width // inv = FixedInvU(width) sub dtdx, Rt, Lt // duv = Rt - Lt scaleUV dtdx, du, dv, inv diff --git a/src/platform/gba/asm/rasterizeGT.s b/src/platform/gba/asm/rasterizeGT.s index 1eb5dcb..0e4c9d7 100644 --- a/src/platform/gba/asm/rasterizeGT.s +++ b/src/platform/gba/asm/rasterizeGT.s @@ -130,8 +130,7 @@ rasterizeGT_asm: cmp Lh, #1 // if (Lh <= 1) skip Ldx calc beq .calc_left_end - add tmp, Lh, #DIVLUT_ADDR - ldrh tmp, [tmp, Lh] // tmp = FixedInvU(Lh) + divLUT tmp, Lh // tmp = FixedInvU(Lh) ldrsh Ldx, [L, #VERTEX_X] sub Ldx, Lx, asr #16 @@ -171,8 +170,7 @@ rasterizeGT_asm: cmp Rh, #1 // if (Rh <= 1) skip Rdx calc beq .calc_right_end - add tmp, Rh, #DIVLUT_ADDR - ldrh tmp, [tmp, Rh] // tmp = FixedInvU(Rh) + divLUT tmp, Rh // tmp = FixedInvU(Rh) ldrsh Rdx, [R, #VERTEX_X] sub Rdx, Rx, asr #16 @@ -214,8 +212,7 @@ rasterizeGT_asm: add ptr, pixel, Lx // ptr = pixel + x1 - add inv, width, #DIVLUT_ADDR - ldrh inv, [inv, width] // inv = FixedInvU(width) + divLUT inv, width // inv = FixedInvU(width) sub dtdx, Rt, Lt // dtdx = Rt - Lt scaleUV dtdx, du, dv, inv diff --git a/src/platform/gba/asm/rasterizeGTA.s b/src/platform/gba/asm/rasterizeGTA.s index 8b89fcd..5afd6be 100644 --- a/src/platform/gba/asm/rasterizeGTA.s +++ b/src/platform/gba/asm/rasterizeGTA.s @@ -132,8 +132,7 @@ rasterizeGTA_asm: cmp Lh, #1 // if (Lh <= 1) skip Ldx calc beq .calc_left_end - add tmp, Lh, #DIVLUT_ADDR - ldrh tmp, [tmp, Lh] // tmp = FixedInvU(Lh) + divLUT tmp, Lh // tmp = FixedInvU(Lh) ldrsh Ldx, [L, #VERTEX_X] sub Ldx, Lx, asr #16 @@ -173,8 +172,7 @@ rasterizeGTA_asm: cmp Rh, #1 // if (Rh <= 1) skip Rdx calc beq .calc_right_end - add tmp, Rh, #DIVLUT_ADDR - ldrh tmp, [tmp, Rh] // tmp = FixedInvU(Rh) + divLUT tmp, Rh // tmp = FixedInvU(Rh) ldrsh Rdx, [R, #VERTEX_X] sub Rdx, Rx, asr #16 @@ -216,8 +214,7 @@ rasterizeGTA_asm: add ptr, pixel, Lx // ptr = pixel + x1 - add inv, width, #DIVLUT_ADDR - ldrh inv, [inv, width] // inv = FixedInvU(width) + divLUT inv, width // inv = FixedInvU(width) sub dtdx, Rt, Lt // dtdx = Rt - Lt scaleUV dtdx, du, dv, inv diff --git a/src/platform/gba/asm/rasterizeS.s b/src/platform/gba/asm/rasterizeS.s index ca60adc..f232aad 100644 --- a/src/platform/gba/asm/rasterizeS.s +++ b/src/platform/gba/asm/rasterizeS.s @@ -51,8 +51,7 @@ rasterizeS_asm: cmp Lh, #1 // if (Lh == 1) skip Ldx calc beq .calc_left_end - add tmp, Lh, #DIVLUT_ADDR - ldrh tmp, [tmp, Lh] // tmp = FixedInvU(Lh) + divLUT tmp, Lh // tmp = FixedInvU(Lh) ldrsh Ldx, [L, #VERTEX_X] sub Ldx, Lx, asr #16 @@ -76,8 +75,7 @@ rasterizeS_asm: cmp Rh, #1 // if (Rh == 1) skip Rdx calc beq .calc_right_end - add tmp, Rh, #DIVLUT_ADDR - ldrh tmp, [tmp, Rh] // tmp = FixedInvU(Rh) + divLUT tmp, Rh // tmp = FixedInvU(Rh) ldrsh Rdx, [R, #VERTEX_X] sub Rdx, Rx, asr #16 diff --git a/src/platform/gba/asm/sphereIsVisible.s b/src/platform/gba/asm/sphereIsVisible.s index 9d5ee4f..1a343ee 100644 --- a/src/platform/gba/asm/sphereIsVisible.s +++ b/src/platform/gba/asm/sphereIsVisible.s @@ -49,11 +49,10 @@ sphereIsVisible_asm: mov z, vz, lsr #(FIXED_SHIFT + 6) add z, z, vz, lsr #(FIXED_SHIFT + 4) - add tmp, z, #DIVLUT_ADDR - ldrh z, [tmp, z] - mul x, z, x - mul y, z, y - mul r, z, r + divLUT tmp, z + mul x, tmp, x + mul y, tmp, y + mul r, tmp, r mov x, x, asr #(16 - PROJ_SHIFT) mov y, y, lsl #(PROJ_SHIFT) diff --git a/src/platform/gba/asm/transformMesh.s b/src/platform/gba/asm/transformMesh.s index af95133..e13f596 100644 --- a/src/platform/gba/asm/transformMesh.s +++ b/src/platform/gba/asm/transformMesh.s @@ -93,10 +93,9 @@ transformMesh_asm: // project mov dz, z, lsr #4 add dz, dz, z, lsr #6 - add tmp, dz, #DIVLUT_ADDR - ldrh dz, [tmp, dz] - mul x, dz, x - mul y, dz, y + divLUT tmp, dz + mul x, tmp, x + mul y, tmp, y mov x, x, asr #(16 - PROJ_SHIFT) mov y, y, asr #(16 - PROJ_SHIFT) diff --git a/src/platform/gba/asm/transformRoom.s b/src/platform/gba/asm/transformRoom.s index 9368e44..51e6040 100644 --- a/src/platform/gba/asm/transformRoom.s +++ b/src/platform/gba/asm/transformRoom.s @@ -110,10 +110,9 @@ transformRoom_asm: // project mov dz, z, lsr #6 add dz, dz, z, lsr #4 - add tmp, dz, #DIVLUT_ADDR - ldrh dz, [tmp, dz] - mul x, dz, x - mul y, dz, y + divLUT tmp, dz + mul x, tmp, x + mul y, tmp, y mov x, x, asr #(16 - PROJ_SHIFT) mov y, y, asr #(16 - PROJ_SHIFT) diff --git a/src/platform/gba/asm/transformRoomUW.s b/src/platform/gba/asm/transformRoomUW.s index bc74418..57d1e03 100644 --- a/src/platform/gba/asm/transformRoomUW.s +++ b/src/platform/gba/asm/transformRoomUW.s @@ -136,10 +136,9 @@ transformRoomUW_asm: // project mov dz, z, lsr #6 add dz, dz, z, lsr #4 - add tmp, dz, #DIVLUT_ADDR - ldrh dz, [tmp, dz] - mul x, dz, x - mul y, dz, y + divLUT tmp, dz + mul x, tmp, x + mul y, tmp, y mov x, x, asr #(16 - PROJ_SHIFT) mov y, y, asr #(16 - PROJ_SHIFT)