1 /* 2 * Copyright © 2024, VideoLAN and dav1d authors 3 * Copyright © 2024, Luca Barbato 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright notice, this 10 * list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright notice, 13 * this list of conditions and the following disclaimer in the documentation 14 * and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #ifndef DAV1D_SRC_PPC_UTILS_H 29 #define DAV1D_SRC_PPC_UTILS_H 30 31 #include "src/ppc/dav1d_types.h" 32 33 #define assert_eq(a, b) \ 34 if ((a) != (b)) \ 35 printf("%d: %d vs %d\n", __LINE__, a, b); \ 36 assert((a) == (b)); 37 38 #define MERGE_I32(a, b, h, l) \ 39 { \ 40 h = vec_mergeh(a, b); \ 41 l = vec_mergel(a, b); \ 42 } 43 44 #define DECLARE_MERGE_I32(a, b, h, l) \ 45 i32x4 h, l; \ 46 MERGE_I32(a, b, h, l) 47 48 49 // Transpose a 4x4 matrix of i32x4 vectors 50 #define TRANSPOSE4_I32(c0, c1, c2, c3) \ 51 { \ 52 DECLARE_MERGE_I32(c0, c2, m02h, m02l) \ 53 DECLARE_MERGE_I32(c1, c3, m13h, m13l) \ 54 \ 55 MERGE_I32(m02h, m13h, c0, c1) \ 56 MERGE_I32(m02l, m13l, c2, c3) \ 57 } 58 59 // Transpose a 8x8 matrix of i32x4 vectors 60 #define TRANSPOSE8_I32(c0, c1, c2, c3, c4, c5, c6, c7, \ 61 c8, c9, cA, cB, cC, cD, cE, cF) \ 62 { \ 63 DECLARE_MERGE_I32(c0, c2, m02h, m02l) \ 64 DECLARE_MERGE_I32(c1, c3, m13h, m13l) \ 65 DECLARE_MERGE_I32(c4, c6, m46h, m46l) \ 66 DECLARE_MERGE_I32(c5, c7, m57h, m57l) \ 67 DECLARE_MERGE_I32(c8, cA, m8Ah, m8Al) \ 68 DECLARE_MERGE_I32(c9, cB, m9Bh, m9Bl) \ 69 DECLARE_MERGE_I32(cC, cE, mCEh, mCEl) \ 70 DECLARE_MERGE_I32(cD, cF, mDFh, mDFl) \ 71 \ 72 MERGE_I32(m02h, m13h, c0, c1) \ 73 MERGE_I32(m02l, m13l, c2, c3) \ 74 MERGE_I32(m46h, m57h, c8, c9) \ 75 MERGE_I32(m46l, m57l, cA, cB) \ 76 MERGE_I32(m8Ah, m9Bh, c4, c5) \ 77 MERGE_I32(m8Al, m9Bl, c6, c7) \ 78 MERGE_I32(mCEh, mDFh, cC, cD) \ 79 MERGE_I32(mCEl, mDFl, cE, cF) \ 80 } 81 82 // Transpose a 4x16 matrix of i32x4 vectors 83 #define TRANSPOSE4x16_I32(c0, c1, c2, c3, c4, c5, c6, c7, \ 84 c8, c9, cA, cB, cC, cD, cE, cF) \ 85 { \ 86 DECLARE_MERGE_I32(c0, c2, m02h, m02l) \ 87 DECLARE_MERGE_I32(c1, c3, m13h, m13l) \ 88 DECLARE_MERGE_I32(c4, c6, m46h, m46l) \ 89 DECLARE_MERGE_I32(c5, c7, m57h, m57l) \ 90 DECLARE_MERGE_I32(c8, cA, m8Ah, m8Al) \ 91 DECLARE_MERGE_I32(c9, cB, m9Bh, m9Bl) \ 92 DECLARE_MERGE_I32(cC, cE, mCEh, mCEl) \ 93 DECLARE_MERGE_I32(cD, cF, mDFh, mDFl) \ 94 \ 95 MERGE_I32(m02h, m13h, c0, c1) \ 96 MERGE_I32(m02l, m13l, c2, c3) \ 97 MERGE_I32(m46h, m57h, c4, c5) \ 98 MERGE_I32(m46l, m57l, c6, c7) \ 99 MERGE_I32(m8Ah, m9Bh, c8, c9) \ 100 MERGE_I32(m8Al, m9Bl, cA, cB) \ 101 MERGE_I32(mCEh, mDFh, cC, cD) \ 102 MERGE_I32(mCEl, mDFl, cE, cF) \ 103 } 104 105 #endif // DAV1D_SRC_PPC_UTILS_H 106