- 首页 > it技术 > >
ARM-高效C编程|第四篇 ARM C 高效编程 - 多条件判断
armc语言ARM-高效C编程
/**
* 结论:
*1. 编译器对多个条件处理为依次计算每个条件,条件不符合就执行跳转
*2. 尽量将多个条件合为一个条件,减少比较指令以及跳转指令
* compile with arm-linux-gnueabihf-gcc v8.3
* flags: -O3 -mcpu=cortex-a7 -mtune=cortex-a7 -mfloat-abi=hard -mfpu=neon
* 000103d8 :
* 103d8:e24dd008subsp, sp, #8
* 103dc:e28d3008addr3, sp, #8
* 103e0:e9030003stmdbr3, {r0, r1}
* 103e4:e5921000ldrr1, [r2]
* 103e8:e59d3000ldrr3, [sp]
* 103ec:e1510003cmpr1, r3
* 103f0:83a00000movhir0, #0
* 103f4:8a000003bhi10408
* 103f8:e5920004ldrr0, [r2, #4]
* 103fc:e1500003cmpr0, r3
* 10400:93a00000movlsr0, #0
* 10404:83a00001movhir0, #1
* 10408:e28dd008addsp, sp, #8
* 1040c:e12fff1ebxlr
* 00010410 :
* 10410:e24dd008subsp, sp, #8
* 10414:e28d3008addr3, sp, #8
* 10418:e9030003stmdbr3, {r0, r1}
* 1041c:e5921000ldrr1, [r2]
* 10420:e59d3000ldrr3, [sp]
* 10424:e5920004ldrr0, [r2, #4]
* 10428:e0433001subr3, r3, r1
* 1042c:e1530000cmpr3, r0
* 10430:23a00000movcsr0, #0
* 10434:33a00001movccr0, #1
* 10438:e28dd008addsp, sp, #8
* 1043c:e12fff1ebxlr
*/typedef struct point {
uint32_t x;
uint32_t y;
} point_t;
typedef struct rect {
uint32_t x;
uint32_t x_max;
} rect_t;
uint32_t x_in_rect(point_t p, rect_t *r)
{
return (p.x >= r->x && p.x < r->x_max);
}uint32_t x_in_rect1(point_t p, rect_t *r)
{
return (uint32_t)(p.x - r->x) x_max;
}
推荐阅读