Optimized version of the glesv2.c

All the symbol loading has been moved from the functions themselves into a constructor function that is executed when the library is loaded. Thus there is no need to do any checking in the function calls themselves. In addition the code that tests if the library has been loaded is present only once, instead of being included in every function call.

The actual overhead saving is just 2 loads and 9 instructions per call. Biggest saving is size of the library which is down from 31.8kB into 19.8kB when built using Sailfish SDK (and compared to one found in Jolla phone)


Original version of glUniform1f as used in Jolla phone:
000056ec glUniform1f:
    56ec:       e59f3060        ldr     r3, [pc, #96]   ; 5754 <glUniform1f+0x68>
    56f0:       e92d4070        push    {r4, r5, r6, lr}
    56f4:       ee105a10        vmov    r5, s0
    56f8:       e08f3003        add     r3, pc, r3
    56fc:       e1a06000        mov     r6, r0
    5700:       e5933000        ldr     r3, [r3]
    5704:       e3530000        cmp     r3, #0
    5708:       0a00000f        beq     574c <glUniform1f+0x60>
    570c:       e59f4044        ldr     r4, [pc, #68]   ; 5758 <glUniform1f+0x6c>
    5710:       e08f4004        add     r4, pc, r4
    5714:       e59431c0        ldr     r3, [r4, #448]  ; 0x1c0
    5718:       e3530000        cmp     r3, #0
    571c:       0a000003        beq     5730 <glUniform1f+0x44>
    5720:       e1a00006        mov     r0, r6
    5724:       e1a01005        mov     r1, r5
    5728:       e12fff33        blx     r3
    572c:       e8bd8070        pop     {r4, r5, r6, pc}
    5730:       e59f1024        ldr     r1, [pc, #36]   ; 575c <glUniform1f+0x70>
    5734:       e5940000        ldr     r0, [r4]
    5738:       e08f1001        add     r1, pc, r1
    573c:       ebfff163        bl      1cd0 <_init+0x2c>
    5740:       e1a03000        mov     r3, r0
    5744:       e58401c0        str     r0, [r4, #448]  ; 0x1c0
    5748:       eafffff4        b       5720 <glUniform1f+0x34>
    574c:       ebfff19e        bl      1dcc <_init+0x128>
    5750:       eaffffed        b       570c <glUniform1f+0x20>
    5754:       00009fd0        ldrdeq  r9, [r0], -r0
    5758:       00009fb8                        ; <UNDEFINED> instruction: 0x00009fb8
    575c:       00001944        andeq   r1, r0, r4, asr #18


Disassembly of the new version:

00003878 glUniform1f:
    3878:       e92d4008        push    {r3, lr}
    387c:       ee101a10        vmov    r1, s0
    3880:       e59f300c        ldr     r3, [pc, #12]   ; 3894 <glUniform1f+0x1c>
    3884:       e08f3003        add     r3, pc, r3
    3888:       e59331c0        ldr     r3, [r3, #448]  ; 0x1c0
    388c:       e12fff33        blx     r3
    3890:       e8bd8008        pop     {r3, pc}
    3894:       00008f40        andeq   r8, r0, r0, asr #30


Based on tests in Jolla phone no measurable perfomance penalty on loading the library was detected. The library retains all the properties of the original, such as crashing horribly if the function is not found from the target for some reason.