summaryrefslogtreecommitdiff
path: root/src/lib/openjp2/mqc_inl.h
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2017-06-02 11:52:16 +0200
committerEven Rouault <even.rouault@spatialys.com>2017-06-02 18:23:20 +0200
commit3d9940a35b8c566c1fb41db56018c91b511a976a (patch)
tree90c33abe4dc2cd077aa1a00ddd7552d6f9b599c3 /src/lib/openjp2/mqc_inl.h
parent7e8b502842075738c9a062a2f06dace3f35dd7cd (diff)
Force inlining of mqc decoding and pass steps through heavy use of macros, so as to get better register allocation
Diffstat (limited to 'src/lib/openjp2/mqc_inl.h')
-rw-r--r--src/lib/openjp2/mqc_inl.h201
1 files changed, 103 insertions, 98 deletions
diff --git a/src/lib/openjp2/mqc_inl.h b/src/lib/openjp2/mqc_inl.h
index 451ce02d..b2c7eef3 100644
--- a/src/lib/openjp2/mqc_inl.h
+++ b/src/lib/openjp2/mqc_inl.h
@@ -38,126 +38,131 @@
#ifndef __MQC_INL_H
#define __MQC_INL_H
-/**
-FIXME DOC
-@param mqc MQC handle
-@return
-*/
-static INLINE OPJ_UINT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc)
-{
- OPJ_UINT32 d;
- if (mqc->a < (*mqc->curctx)->qeval) {
- d = !((*mqc->curctx)->mps);
- *mqc->curctx = (*mqc->curctx)->nlps;
- } else {
- d = (*mqc->curctx)->mps;
- *mqc->curctx = (*mqc->curctx)->nmps;
- }
- return d;
+/* For internal use of opj_mqc_decode_macro() */
+#define opj_mqc_mpsexchange_macro(d, curctx, a) \
+{ \
+ if (a < (*curctx)->qeval) { \
+ d = !((*curctx)->mps); \
+ *curctx = (*curctx)->nlps; \
+ } else { \
+ d = (*curctx)->mps; \
+ *curctx = (*curctx)->nmps; \
+ } \
}
-/**
-FIXME DOC
-@param mqc MQC handle
-@return
-*/
-static INLINE OPJ_UINT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc)
-{
- OPJ_UINT32 d;
- if (mqc->a < (*mqc->curctx)->qeval) {
- mqc->a = (*mqc->curctx)->qeval;
- d = (*mqc->curctx)->mps;
- *mqc->curctx = (*mqc->curctx)->nmps;
- } else {
- mqc->a = (*mqc->curctx)->qeval;
- d = !((*mqc->curctx)->mps);
- *mqc->curctx = (*mqc->curctx)->nlps;
- }
+/* For internal use of opj_mqc_decode_macro() */
+#define opj_mqc_lpsexchange_macro(d, curctx, a) \
+{ \
+ if (a < (*curctx)->qeval) { \
+ a = (*curctx)->qeval; \
+ d = (*curctx)->mps; \
+ *curctx = (*curctx)->nmps; \
+ } else { \
+ a = (*curctx)->qeval; \
+ d = !((*curctx)->mps); \
+ *curctx = (*curctx)->nlps; \
+ } \
+}
+
+#define opj_mqc_bytein_macro(mqc, c, ct) \
+{ \
+ if (mqc->bp != mqc->end) { \
+ OPJ_UINT32 l_c; \
+ if (mqc->bp + 1 != mqc->end) { \
+ l_c = *(mqc->bp + 1); \
+ } else { \
+ l_c = 0xff; \
+ } \
+ if (*mqc->bp == 0xff) { \
+ if (l_c > 0x8f) { \
+ c += 0xff00; \
+ ct = 8; \
+ } else { \
+ mqc->bp++; \
+ c += l_c << 9; \
+ ct = 7; \
+ } \
+ } else { \
+ mqc->bp++; \
+ c += l_c << 8; \
+ ct = 8; \
+ } \
+ } else { \
+ c += 0xff00; \
+ ct = 8; \
+ } \
+}
+
+/* For internal use of opj_mqc_decode_macro() */
+#define opj_mqc_renormd_macro(mqc, a, c, ct) \
+{ \
+ do { \
+ if (ct == 0) { \
+ opj_mqc_bytein_macro(mqc, c, ct); \
+ } \
+ a <<= 1; \
+ c <<= 1; \
+ ct--; \
+ } while (a < 0x8000); \
+}
- return d;
+#define opj_mqc_decode_macro(d, mqc, curctx, a, c, ct) \
+{ \
+ /* Implements ISO 15444-1 C.3.2 Decoding a decision (DECODE) */ \
+ /* Note: alternate "J.2 - Decoding an MPS or an LPS in the */ \
+ /* software-conventions decoder" has been tried, but does not bring any */ \
+ /* improvement. See https://github.com/uclouvain/openjpeg/issues/921 */ \
+ a -= (*curctx)->qeval; \
+ if ((c >> 16) < (*curctx)->qeval) { \
+ opj_mqc_lpsexchange_macro(d, curctx, a); \
+ opj_mqc_renormd_macro(mqc, a, c, ct); \
+ } else { \
+ c -= (*curctx)->qeval << 16; \
+ if ((a & 0x8000) == 0) { \
+ opj_mqc_mpsexchange_macro(d, curctx, a); \
+ opj_mqc_renormd_macro(mqc, a, c, ct); \
+ } else { \
+ d = (*curctx)->mps; \
+ } \
+ } \
}
+#define DOWNLOAD_MQC_VARIABLES(mqc, curctx, c, a, ct) \
+ register opj_mqc_state_t **curctx = mqc->curctx; \
+ register OPJ_UINT32 c = mqc->c; \
+ register OPJ_UINT32 a = mqc->a; \
+ register OPJ_UINT32 ct = mqc->ct
+
+#define UPLOAD_MQC_VARIABLES(mqc, curctx, c, a, ct) \
+ mqc->curctx = curctx; \
+ mqc->c = c; \
+ mqc->a = a; \
+ mqc->ct = ct;
+
/**
Input a byte
@param mqc MQC handle
*/
static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc)
{
- /* Implements ISO 15444-1 C.3.4 Compressed image data input (BYTEIN) */
- /* Note: alternate "J.3 - Inserting a new byte into the C register in the */
- /* software-conventions decoder" has been tried, but does not bring any */
- /* improvement. See https://github.com/uclouvain/openjpeg/issues/921 */
- if (mqc->bp != mqc->end) {
- OPJ_UINT32 c;
- if (mqc->bp + 1 != mqc->end) {
- c = *(mqc->bp + 1);
- } else {
- c = 0xff;
- }
- if (*mqc->bp == 0xff) {
- if (c > 0x8f) {
- mqc->c += 0xff00;
- mqc->ct = 8;
- } else {
- mqc->bp++;
- mqc->c += c << 9;
- mqc->ct = 7;
- }
- } else {
- mqc->bp++;
- mqc->c += c << 8;
- mqc->ct = 8;
- }
- } else {
- mqc->c += 0xff00;
- mqc->ct = 8;
- }
+ opj_mqc_bytein_macro(mqc, mqc->c, mqc->ct);
}
/**
Renormalize mqc->a and mqc->c while decoding
@param mqc MQC handle
*/
-static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc)
-{
- do {
- if (mqc->ct == 0) {
- opj_mqc_bytein(mqc);
- }
- mqc->a <<= 1;
- mqc->c <<= 1;
- mqc->ct--;
- } while (mqc->a < 0x8000);
-}
+#define opj_mqc_renormd(mqc) \
+ opj_mqc_renormd_macro(mqc, mqc->a, mqc->c, mqc->ct)
/**
Decode a symbol
+@param d OPJ_UINT32 value where to store the decoded symbol
@param mqc MQC handle
-@return Returns the decoded symbol (0 or 1)
+@return Returns the decoded symbol (0 or 1) in d
*/
-static INLINE OPJ_UINT32 opj_mqc_decode(opj_mqc_t *const mqc)
-{
- /* Implements ISO 15444-1 C.3.2 Decoding a decision (DECODE) */
- /* Note: alternate "J.2 - Decoding an MPS or an LPS in the */
- /* software-conventions decoder" has been tried, but does not bring any */
- /* improvement. See https://github.com/uclouvain/openjpeg/issues/921 */
- OPJ_UINT32 d;
- mqc->a -= (*mqc->curctx)->qeval;
- if ((mqc->c >> 16) < (*mqc->curctx)->qeval) {
- d = opj_mqc_lpsexchange(mqc);
- opj_mqc_renormd(mqc);
- } else {
- mqc->c -= (*mqc->curctx)->qeval << 16;
- if ((mqc->a & 0x8000) == 0) {
- d = opj_mqc_mpsexchange(mqc);
- opj_mqc_renormd(mqc);
- } else {
- d = (*mqc->curctx)->mps;
- }
- }
-
- return d;
-}
+#define opj_mqc_decode(d, mqc) \
+ opj_mqc_decode_macro(d, mqc, mqc->curctx, mqc->a, mqc->c, mqc->ct)
#endif /* __MQC_INL_H */