Skip to content

Commit bb0d8c5

Browse files
committed
Human-based optimization of LLM-provided code: +10% in rendition performance
1 parent 11218e5 commit bb0d8c5

1 file changed

Lines changed: 10 additions & 34 deletions

File tree

src/agge/blenders_arm.cpp

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,45 +38,21 @@ namespace agge
3838

3939
void blender_solid_color::blend4(pixel *pixels, uint16x8_t color_u16, uint16x8_t alpha_u16, unsigned int covers_packed)
4040
{
41-
uint8x8_t covers = vdup_n_u8(0);
42-
covers = vset_lane_u8(static_cast<uint8_t>(covers_packed >> 0), covers, 0);
43-
covers = vset_lane_u8(static_cast<uint8_t>(covers_packed >> 8), covers, 1);
44-
covers = vset_lane_u8(static_cast<uint8_t>(covers_packed >> 16), covers, 2);
45-
covers = vset_lane_u8(static_cast<uint8_t>(covers_packed >> 24), covers, 3);
41+
const uint16x4_t covers_u16 = vget_low_u16(vshlq_n_u16(vmovl_u8(vcreate_u8(covers_packed)), 8));
42+
const int16x4_t alpha = vreinterpret_s16_u16(vshrn_n_u32(vmull_u16(covers_u16, vget_low_u16(alpha_u16)), 16));
4643

47-
const uint16x4_t covers_u16 = vget_low_u16(vshlq_n_u16(vmovl_u8(covers), 8));
48-
const uint16x4_t alpha = vshrn_n_u32(vmull_u16(covers_u16, vget_low_u16(alpha_u16)), 16);
49-
50-
const uint16_t a0 = vget_lane_u16(alpha, 0);
51-
const uint16_t a1 = vget_lane_u16(alpha, 1);
52-
const uint16_t a2 = vget_lane_u16(alpha, 2);
53-
const uint16_t a3 = vget_lane_u16(alpha, 3);
54-
55-
const int16x8_t alpha10 = vreinterpretq_s16_u16(vcombine_u16(vdup_n_u16(a0), vdup_n_u16(a1)));
56-
const int16x8_t alpha32 = vreinterpretq_s16_u16(vcombine_u16(vdup_n_u16(a2), vdup_n_u16(a3)));
44+
const int16x8_t alpha10 = vcombine_s16(vdup_lane_s16(alpha, 0), vdup_lane_s16(alpha, 1));
45+
const int16x8_t alpha32 = vcombine_s16(vdup_lane_s16(alpha, 2), vdup_lane_s16(alpha, 3));
5746

5847
const uint8x16_t source_u8 = vld1q_u8(reinterpret_cast<uint8_t *>(pixels));
59-
const int16x8_t source10 = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(source_u8)));
60-
const int16x8_t source32 = vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(source_u8)));
61-
62-
const int16x8_t d10 = vshlq_n_s16(vsubq_s16(source10, vreinterpretq_s16_u16(color_u16)), 2);
63-
const int16x8_t d32 = vshlq_n_s16(vsubq_s16(source32, vreinterpretq_s16_u16(color_u16)), 2);
64-
65-
const int32x4_t m10l = vmull_s16(vget_low_s16(d10), vget_low_s16(alpha10));
66-
const int32x4_t m10h = vmull_s16(vget_high_s16(d10), vget_high_s16(alpha10));
67-
const int32x4_t m32l = vmull_s16(vget_low_s16(d32), vget_low_s16(alpha32));
68-
const int32x4_t m32h = vmull_s16(vget_high_s16(d32), vget_high_s16(alpha32));
69-
70-
const int16x8_t c10 = vcombine_s16(vshrn_n_s32(m10l, 16), vshrn_n_s32(m10h, 16));
71-
const int16x8_t c32 = vcombine_s16(vshrn_n_s32(m32l, 16), vshrn_n_s32(m32h, 16));
72-
73-
const int16x8_t r10 = vsubq_s16(source10, c10);
74-
const int16x8_t r32 = vsubq_s16(source32, c32);
48+
int16x8_t source10 = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(source_u8)));
49+
int16x8_t source32 = vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(source_u8)));
7550

76-
const uint8x8_t result10 = vqmovun_s16(r10);
77-
const uint8x8_t result32 = vqmovun_s16(r32);
51+
// source -= ((source - color) << 2 * alpha) >> 16
52+
source10 = vsubq_s16(source10, vqdmulhq_s16(vshlq_n_s16(vsubq_s16(source10, vreinterpretq_s16_u16(color_u16)), 1), alpha10));
53+
source32 = vsubq_s16(source32, vqdmulhq_s16(vshlq_n_s16(vsubq_s16(source32, vreinterpretq_s16_u16(color_u16)), 1), alpha32));
7854

79-
vst1q_u8(reinterpret_cast<uint8_t *>(pixels), vcombine_u8(result10, result32));
55+
vst1q_u8(reinterpret_cast<uint8_t *>(pixels), vcombine_u8(vqmovun_s16(source10), vqmovun_s16(source32)));
8056
}
8157
}
8258
}

0 commit comments

Comments
 (0)