libhybris/libhybris — pull request #175 by sharpneli (2013-12-03 19:20:40+00:00)
Title: Optimized version of the glesv2.c

Size of the library is down from 31.8kB into 19.8kB

The functions themselves are far smaller.

Original version:
000056ec :
56ec: e59f3060 ldr r3, [pc, #96] ; 5754
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
570c: e59f4044 ldr r4, [pc, #68] ; 5758
5710: e08f4004 add r4, pc, r4
5714: e59431c0 ldr r3, [r4, #448] ; 0x1c0
5718: e3530000 cmp r3, #0
571c: 0a000003 beq 5730
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
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
574c: ebfff19e bl 1dcc <_init+0x128>
5750: eaffffed b 570c
5754: 00009fd0 ldrdeq r9, [r0], -r0
5758: 00009fb8 ; instruction: 0x00009fb8
575c: 00001944 andeq r1, r0, r4, asr #18

New version:

00003878 :
3878: e92d4008 push {r3, lr}
387c: ee101a10 vmov r1, s0
3880: e59f300c ldr r3, [pc, #12] ; 3894
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

In addition each function performs 2 loads less so it should be bit more cache friendly.

Based on tests in target device no measurable perfomance penalty was detected.