-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add loongarch 256-bit LASX SIMD optimization #1458
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1786,6 +1786,34 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) | |
} | ||
} | ||
#endif | ||
|
||
#ifdef __loongarch_asx | ||
{ | ||
asm volatile | ||
( | ||
"srli.w $t0, %[cblk], 4 \n\t" | ||
"xvldrepl.w $xr0, %[step], 0 \n\t" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason not to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch, will update. |
||
"beqz $t0, 999f \n\t" | ||
"16: \n\t" | ||
"xvld $xr1, %[data], 0 \n\t" | ||
"xvld $xr2, %[data], 32 \n\t" | ||
"xvffint.s.w $xr1, $xr1 \n\t" | ||
"xvffint.s.w $xr2, $xr2 \n\t" | ||
"xvfmul.s $xr1, $xr1, $xr0 \n\t" | ||
"xvfmul.s $xr2, $xr2, $xr0 \n\t" | ||
"xvst $xr1, %[data], 0 \n\t" | ||
"xvst $xr2, %[data], 32 \n\t" | ||
"addi.d %[data], %[data], 64 \n\t" | ||
"addi.w $t0, $t0, -1 \n\t" | ||
"bnez $t0, 16b \n\t" | ||
"999: \n\t" | ||
: [data]"+r"(datap) | ||
: [step]"r"(&stepsize), [cblk]"r"(cblk_size) | ||
: "$t0", "$xr0", "$xr1", "$xr2", "memory" | ||
); | ||
i = cblk_size & ~15U; | ||
} | ||
#endif | ||
for (; i < cblk_size; ++i) { | ||
OPJ_FLOAT32 tmp = ((OPJ_FLOAT32)(*datap)) * stepsize; | ||
memcpy(datap, &tmp, sizeof(tmp)); | ||
|
@@ -1797,6 +1825,34 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) | |
(OPJ_SIZE_T)x]; | ||
for (j = 0; j < cblk_h; ++j) { | ||
i = 0; | ||
#ifdef __loongarch_asx | ||
{ | ||
OPJ_INT32* ptr1 = datap + j * cblk_w; | ||
OPJ_INT32* ptr2 = tiledp + j * (OPJ_SIZE_T)tile_w; | ||
OPJ_UINT32 step_size = 0; | ||
asm volatile | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise, try to avoid |
||
( | ||
"srli.w $t0, %[cblk], 3 \n\t" | ||
"xvxor.v $xr1, $xr1, $xr1 \n\t" | ||
"xvaddi.wu $xr1, $xr1, 2 \n\t" | ||
"beqz $t0, 999f \n\t" | ||
"8: \n\t" | ||
"xvldx $xr0, %[ptr1], %[step] \n\t" | ||
"xvdiv.w $xr0, $xr0, $xr1 \n\t" | ||
"xvstx $xr0, %[ptr2], %[step] \n\t" | ||
"addi.w %[step], %[step], 32 \n\t" | ||
"addi.w $t0, $t0, -1 \n\t" | ||
"bnez $t0, 8b \n\t" | ||
"999: \n\t" | ||
: [step]"+r"(step_size) | ||
: [ptr1]"r"(ptr1), | ||
[ptr2]"r"(ptr2), | ||
[cblk]"r"(cblk_w) | ||
: "$t0", "$xr0", "memory" | ||
); | ||
i = cblk_w & ~7U; | ||
} | ||
#endif | ||
for (; i < (cblk_w & ~(OPJ_UINT32)3U); i += 4U) { | ||
OPJ_INT32 tmp0 = datap[(j * cblk_w) + i + 0U]; | ||
OPJ_INT32 tmp1 = datap[(j * cblk_w) + i + 1U]; | ||
|
@@ -1807,6 +1863,7 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) | |
((OPJ_INT32*)tiledp)[(j * (OPJ_SIZE_T)tile_w) + i + 2U] = tmp2 / 2; | ||
((OPJ_INT32*)tiledp)[(j * (OPJ_SIZE_T)tile_w) + i + 3U] = tmp3 / 2; | ||
} | ||
|
||
for (; i < cblk_w; ++i) { | ||
OPJ_INT32 tmp = datap[(j * cblk_w) + i]; | ||
((OPJ_INT32*)tiledp)[(j * (OPJ_SIZE_T)tile_w) + i] = tmp / 2; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using "volatile" is generally a bad idea (unless there is a side-effect not explainable by the input/output/clobber). If it does not work w/o "volatile", you've likely missed some register input/output/clobber.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
affect performance or something else ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because "if it's a chicken, don't model it as a duck".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please , provide helpful suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it broken after if we remove
volatile
? If it's not broken, just removevolatile
. Otherwise try to figure out why the compiler breaks it and fix the input/output/clobber list.volatile
means there is some unexplainable side effect, for example writing/reading some CSRs, invoking hardware memory barriers, etc. These just do not apply for a SIMD optimization.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just want to tell compiler not to optimize or modify the asm block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't modify the asm block because the compiler does not parse asm at all.
The only possible optimizations are:
If the input/output/clobber lists are correct, 2 should be disabled, and 1 should be performed in a constrained way not to break the code.
Again
volatile
means "there is unexplainable side effect", not "don't modify the asm block".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, and maybe