Skip to content

Commit e088861

Browse files
committed
Unroll the loop
1 parent c42ea73 commit e088861

File tree

2 files changed

+21
-36
lines changed

2 files changed

+21
-36
lines changed

src/layer/arm/shufflechannel_arm.cpp

+14-24
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,14 @@ int ShuffleChannel_arm::forward(const Mat& bottom_blob, Mat& top_blob, const Opt
131131
outptr0 += 4;
132132
}
133133

134-
for (int i = 0; i < 4; i++)
135134
{
136-
if (i % 2)
137-
{
138-
*outptr0 = *ptr1;
139-
ptr1 += 1;
140-
}
141-
else
142-
{
143-
*outptr0 = *ptr0;
144-
ptr0 += 1;
145-
}
146-
outptr0 += 1;
135+
outptr0[0] = ptr0[0];
136+
outptr0[1] = ptr1[0];
137+
outptr0[2] = ptr0[1];
138+
outptr0[3] = ptr1[1];
139+
ptr0 += 2;
140+
ptr1 += 2;
141+
outptr0 += 4;
147142
}
148143
}
149144

@@ -642,19 +637,14 @@ int ShuffleChannel_arm::forward_bf16s_fp16s(const Mat& bottom_blob, Mat& top_blo
642637
outptr0 += 4;
643638
}
644639

645-
for (int i = 0; i < 4; i++)
646640
{
647-
if (i % 2)
648-
{
649-
*outptr0 = *ptr1;
650-
ptr1 += 1;
651-
}
652-
else
653-
{
654-
*outptr0 = *ptr0;
655-
ptr0 += 1;
656-
}
657-
outptr0 += 1;
641+
outptr0[0] = ptr0[0];
642+
outptr0[1] = ptr1[0];
643+
outptr0[2] = ptr0[1];
644+
outptr0[3] = ptr1[1];
645+
ptr0 += 2;
646+
ptr1 += 2;
647+
outptr0 += 4;
658648
}
659649
}
660650

src/layer/x86/shufflechannel_x86.cpp

+7-12
Original file line numberDiff line numberDiff line change
@@ -651,19 +651,14 @@ int ShuffleChannel_x86::forward(const Mat& bottom_blob, Mat& top_blob, const Opt
651651
outptr += 4;
652652
}
653653

654-
for (int i = 0; i < 4; i++)
655654
{
656-
if (i % 2)
657-
{
658-
*outptr = *ptr1;
659-
ptr1 += 1;
660-
}
661-
else
662-
{
663-
*outptr = *ptr0;
664-
ptr0 += 1;
665-
}
666-
outptr += 1;
655+
outptr[0] = ptr0[0];
656+
outptr[1] = ptr1[0];
657+
outptr[2] = ptr0[1];
658+
outptr[3] = ptr1[1];
659+
ptr0 += 2;
660+
ptr1 += 2;
661+
outptr += 4;
667662
}
668663
}
669664

0 commit comments

Comments
 (0)