fix x86 build
[pcsx_rearmed.git] / plugins / gpu_senquack / gpu_inner_light_arm.h
1 #ifndef _OP_LIGHT_ARM_H_
2 #define _OP_LIGHT_ARM_H_
3
4 ////////////////////////////////////////////////////////////////////////////////
5 // Extract bgr555 color from Gouraud u32 fixed-pt 8.3:8.3:8.2 rgb triplet
6 //
7 // INPUT:
8 //  'gCol' input:  rrrrrrrrXXXggggggggXXXbbbbbbbbXX
9 //                 ^ bit 31
10 // RETURNS:
11 //    u16 output:  0bbbbbgggggrrrrr
12 //                 ^ bit 16
13 // Where 'r,g,b' are integer bits of colors, 'X' fixed-pt, and '0' zero
14 ////////////////////////////////////////////////////////////////////////////////
15 GPU_INLINE uint_fast16_t gpuLightingRGBARM(u32 gCol)
16 {
17         uint_fast16_t out = 0x03E0; // don't need the mask after starting to write output
18         u32 tmp;
19   
20         asm ("and %[tmp], %[gCol], %[out]\n\t"              // tmp holds 0x000000bbbbb00000
21              "and %[out], %[out],  %[gCol], lsr #0x0B\n\t"  // out holds 0x000000ggggg00000
22              "orr %[tmp], %[out],  %[tmp],  lsl #0x05\n\t"  // tmp holds 0x0bbbbbggggg00000
23              "orr %[out], %[tmp],  %[gCol], lsr #0x1B\n\t"  // out holds 0x0bbbbbgggggrrrrr
24              : [out] "+&r" (out), [tmp] "=&r" (tmp)
25              : [gCol] "r"  (gCol)
26              );
27
28         return out;
29 }
30
31 ////////////////////////////////////////////////////////////////////////////////
32 // Apply fast (low-precision) 5-bit lighting to bgr555 texture color:
33 //
34 // INPUT:
35 //        'r5','g5','b5' are unsigned 5-bit color values, value of 15
36 //          is midpoint that doesn't modify that component of texture
37 //        'uSrc' input:  mbbbbbgggggrrrrr
38 //                       ^ bit 16
39 // RETURNS:
40 //          u16 output:  mbbbbbgggggrrrrr
41 // Where 'X' are fixed-pt bits.
42 ////////////////////////////////////////////////////////////////////////////////
43 GPU_INLINE uint_fast16_t gpuLightingTXTARM(uint_fast16_t uSrc, u8 r5, u8 g5, u8 b5)
44 {
45         uint_fast16_t out = 0x03E0;
46         u32 db, dg;
47
48         // Using `g` for src, `G` for dest
49         asm ("and    %[dg],  %[out],    %[src]  \n\t"             // dg holds 0x000000ggggg00000
50              "orr    %[dg],  %[dg],     %[g5]   \n\t"             // dg holds 0x000000gggggGGGGG
51              "and    %[db],  %[out],    %[src], lsr #0x05 \n\t"   // db holds 0x000000bbbbb00000
52              "ldrb   %[dg],  [%[lut],   %[dg]]  \n\t"             // dg holds result 0x00000000000ggggg
53              "and    %[out], %[out],    %[src], lsl #0x05 \n\t"   // out holds 0x000000rrrrr00000
54              "orr    %[out], %[out],    %[r5]   \n\t"             // out holds 0x000000rrrrrRRRRR
55              "orr    %[db],  %[db],     %[b5]   \n\t"             // db holds 0x000000bbbbbBBBBB
56              "ldrb   %[out], [%[lut],   %[out]] \n\t"             // out holds result 0x00000000000rrrrr
57              "ldrb   %[db],  [%[lut],   %[db]]  \n\t"             // db holds result 0x00000000000bbbbb
58              "tst    %[src], #0x8000\n\t"                         // check whether msb was set on uSrc
59              "orr    %[out], %[out],    %[dg],  lsl #0x05   \n\t" // out holds 0x000000gggggrrrrr
60              "orrne  %[out], %[out],    #0x8000\n\t"              // add msb to out if set on uSrc
61              "orr    %[out], %[out],    %[db],  lsl #0x0A   \n\t" // out holds 0xmbbbbbgggggrrrrr
62              : [out] "=&r" (out), [db] "=&r" (db), [dg] "=&r" (dg)
63              : [r5] "r" (r5), [g5] "r" (g5),  [b5] "r" (b5),
64                [lut] "r" (gpu_senquack.LightLUT), [src] "r" (uSrc), "0" (out)
65              : "cc");
66         return out;
67 }
68
69 ////////////////////////////////////////////////////////////////////////////////
70 // Apply fast (low-precision) 5-bit Gouraud lighting to bgr555 texture color:
71 //
72 // INPUT:
73 //  'gCol' is a packed Gouraud u32 fixed-pt 8.3:8.3:8.2 rgb triplet, value of
74 //     15.0 is midpoint that does not modify color of texture
75 //         gCol input :  rrrrrXXXXXXgggggXXXXXXbbbbbXXXXX
76 //                       ^ bit 31
77 //        'uSrc' input:  mbbbbbgggggrrrrr
78 //                       ^ bit 16
79 // RETURNS:
80 //          u16 output:  mbbbbbgggggrrrrr
81 // Where 'X' are fixed-pt bits, '0' is zero-padding, and '-' is don't care
82 ////////////////////////////////////////////////////////////////////////////////
83 GPU_INLINE uint_fast16_t gpuLightingTXTGouraudARM(uint_fast16_t uSrc, u32 gCol)
84 {
85         uint_fast16_t out = 0x03E0; // don't need the mask after starting to write output
86         u32 db,dg,gtmp;
87
88         // Using `g` for src, `G` for dest
89         asm ("and    %[dg],  %[out],  %[src]   \n\t"           // dg holds 0x000000ggggg00000
90              "and    %[gtmp],%[out],  %[gCol], lsr #0x0B \n\t" // gtmp holds 0x000000GGGGG00000
91              "and    %[db],  %[out],  %[src],  lsr #0x05 \n\t" // db holds 0x000000bbbbb00000
92              "orr    %[dg],  %[dg],   %[gtmp], lsr #0x05 \n\t" // dg holds 0x000000gggggGGGGG
93              "and    %[gtmp],%[out],  %[gCol]  \n\t"           // gtmp holds 0x000000BBBBB00000
94              "ldrb   %[dg],  [%[lut], %[dg]]   \n\t"           // dg holds result 0x00000000000ggggg
95              "and    %[out], %[out],  %[src],  lsl #0x05 \n\t" // out holds 0x000000rrrrr00000
96              "orr    %[out], %[out],  %[gCol], lsr #0x1B \n\t" // out holds 0x000000rrrrrRRRRR
97              "orr    %[db],  %[db],   %[gtmp], lsr #0x05 \n\t" // db holds 0x000000bbbbbBBBBB
98              "ldrb   %[out], [%[lut], %[out]]  \n\t"           // out holds result 0x00000000000rrrrr
99              "ldrb   %[db],  [%[lut], %[db]]   \n\t"           // db holds result 0x00000000000bbbbb
100              "tst    %[src], #0x8000\n\t"                      // check whether msb was set on uSrc
101              "orr    %[out], %[out],  %[dg],   lsl #0x05 \n\t" // out holds 0x000000gggggrrrrr
102              "orrne  %[out], %[out],  #0x8000\n\t"             // add msb to out if set on uSrc
103              "orr    %[out], %[out],  %[db],   lsl #0x0A \n\t" // out holds 0xmbbbbbgggggrrrrr
104              : [out] "=&r" (out), [db] "=&r" (db), [dg] "=&r" (dg),
105                [gtmp] "=&r" (gtmp) \
106              : [gCol] "r" (gCol), [lut] "r" (gpu_senquack.LightLUT), "0" (out), [src] "r" (uSrc)
107              : "cc");
108
109         return out;
110 }
111
112 #endif  //_OP_LIGHT_ARM_H_