| 1 | /* |
| 2 | * |
| 3 | * mblock_sub44_sads.c |
| 4 | * Copyright (C) 2000 Andrew Stevens <[email protected]> |
| 5 | * |
| 6 | * Fast block sum-absolute difference computation for a rectangular area 4*x |
| 7 | * by y where y > h against a 4 by h block. |
| 8 | * |
| 9 | * Used for 4*4 sub-sampled motion compensation calculations. |
| 10 | * |
| 11 | * This is actually just a shell that uses templates from the included |
| 12 | * file "mblock_sub44_sads_x86_h.c". I didn't trust the compiler to do a good |
| 13 | * job on nested inlining. One day I'll experiment. |
| 14 | * |
| 15 | * |
| 16 | * This file is part of mpeg2enc, a free MPEG-2 video stream encoder |
| 17 | * based on the original MSSG reference design |
| 18 | * |
| 19 | * mpeg2enc is free software; you can redistribute new parts |
| 20 | * and/or modify under the terms of the GNU General Public License |
| 21 | * as published by |
| 22 | * the Free Software Foundation; either version 2 of the License, or |
| 23 | * (at your option) any later version. |
| 24 | * |
| 25 | * mpeg2dec is distributed in the hope that it will be useful, |
| 26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 | * GNU General Public License for more details. |
| 29 | * |
| 30 | * See the files for those sections (c) MSSG |
| 31 | * |
| 32 | * You should have received a copy of the GNU General Public License |
| 33 | * along with this program; if not, write to the Free Software |
| 34 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 35 | */ |
| 36 | |
| 37 | #include <config.h>cxx . . $ `<file>/config.h`/ |
| 38 | #include "mjpeg_types.h"cxx . . $ `<file>/utils/mjpeg_types.h`/ |
| 39 | #include "mmx.h"cxx . . $ `<file>/utils/mmx.h`/ |
| 40 | #include "fastintfns.h"cxx . . $ `<file>/utils/fastintfns.h`/ |
| 41 | #include "motionsearch.h"cxx . . $ `<file>/utils/motionsearch.h`/ |
| 42 | #include "mblock_sub44_sads_x86.h"cxx . . $ `<file>/utils/mmxsse/mblock_sub44_sads_x86.h`/ |
| 43 | |
| 44 | /* |
| 45 | * Load a 8*4 block of 4*4 sub-sampled pels (qpels) into the MMX |
| 46 | * registers |
| 47 | * |
| 48 | */ |
| 49 | static inline void load_blkcxx . . $ load_blk(24a4435ba77f1dc6).(uint8_tcxx . . $ uint8_t# *blk,uint32_tcxx . . $ uint32_t# rowstride,int h) |
| 50 | { |
| 51 | movq_m2rcxx . . $ `utils/mmx.h:81:9`!( *blk, mm0); |
| 52 | movq_m2rcxx . . $ `utils/mmx.h:81:9`!( *(blk+rowstride), mm1); |
| 53 | blk += 2*rowstride; |
| 54 | if( h == 2 ) |
| 55 | return; |
| 56 | movq_m2rcxx . . $ `utils/mmx.h:81:9`!( *blk, mm2); |
| 57 | movq_m2rcxx . . $ `utils/mmx.h:81:9`!( *(blk+rowstride), mm3); |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | * Do a shift right on the 4*4 block in the MMX registers |
| 62 | * We do this as a macro as otherwise we get warnings from the |
| 63 | * pre-optimised asm generated. |
| 64 | */ |
| 65 | #define shift_blkcxx . . $ `utils/mmxsse/mblock_sub44_sads_x86.c:65:9`!(shift)\ |
| 66 | psrlq_i2rcxx . . $ `utils/mmx.h:162:9`!( shift,mm0);\ |
| 67 | psrlq_i2rcxx . . $ `utils/mmx.h:162:9`!( shift,mm1);\ |
| 68 | psrlq_i2rcxx . . $ `utils/mmx.h:162:9`!( shift,mm2);\ |
| 69 | psrlq_i2rcxx . . $ `utils/mmx.h:162:9`!( shift,mm3); |
| 70 | |
| 71 | /* |
| 72 | * Compute the Sum absolute differences between the 4*h block in |
| 73 | * the MMX registers (4 least sig. bytes in mm0..mm3) |
| 74 | * |
| 75 | * and the 4*h block pointed to by refblk |
| 76 | * |
| 77 | * h == 2 || h == 4 |
| 78 | * |
| 79 | * TODO: Currently always loads and shifts 4*4 even if 4*2 is required. |
| 80 | * |
| 81 | */ |
| 82 | |
| 83 | static inline void init_qblock_sad_mmxecxx . . $ init_qblock_sad_mmxe(f63137c5d602553b).(uint8_tcxx . . $ uint8_t# *refblk,uint32_tcxx . . $ uint32_t# h,uint32_tcxx . . $ uint32_t# rowstride) |
| 84 | { |
| 85 | /* load refblk into mm6 and mm7 */ |
| 86 | |
| 87 | movd_m2rcxx . . $ `utils/mmx.h:75:9`!(refblk[0],mm6); |
| 88 | movd_m2rcxx . . $ `utils/mmx.h:75:9`!(refblk[rowstride],mm4); |
| 89 | punpcklbw_r2rcxx . . $ `utils/mmx.h:194:9`!(mm4,mm6); |
| 90 | |
| 91 | if( h == 4 ) { |
| 92 | refblk+=rowstride*2; |
| 93 | movd_m2rcxx . . $ `utils/mmx.h:75:9`!(refblk[0],mm7); |
| 94 | movd_m2rcxx . . $ `utils/mmx.h:75:9`!(refblk[rowstride],mm5); |
| 95 | punpcklbw_r2rcxx . . $ `utils/mmx.h:194:9`!(mm5,mm7); |
| 96 | } else { |
| 97 | pxor_r2rcxx . . $ `utils/mmx.h:201:9`!(mm7,mm7); |
| 98 | pxor_r2rcxx . . $ `utils/mmx.h:201:9`!(mm2,mm2); |
| 99 | pxor_r2rcxx . . $ `utils/mmx.h:201:9`!(mm3,mm3); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | static inline int qblock_sad_mmxecxx . . $ qblock_sad_mmxe(47d6add1f5feae6f).(uint8_tcxx . . $ uint8_t# *refblk, |
| 104 | uint32_tcxx . . $ uint32_t# h, |
| 105 | uint32_tcxx . . $ uint32_t# rowstride) |
| 106 | { |
| 107 | int res; |
| 108 | |
| 109 | /* On input, |
| 110 | mm0 = first row |
| 111 | mm1 = second row |
| 112 | mm2 = third row |
| 113 | mm3 = fourth row |
| 114 | |
| 115 | mm6 = refblk for first and second roww packed together (ala init_qblock_sad_mmxe) |
| 116 | mm7 = refblk for third and fourth rows packed together (ala init_qblock_sad_mmxe) |
| 117 | */ |
| 118 | |
| 119 | /* Do the first two rows together, by packing the two rows of 4 bytes |
| 120 | into one eight byte register; then perform only one SAD for both |
| 121 | rows at once. */ |
| 122 | |
| 123 | movq_r2rcxx . . $ `utils/mmx.h:83:9`! (mm0,mm4); |
| 124 | punpcklbw_r2rcxx . . $ `utils/mmx.h:194:9`!(mm1,mm4); |
| 125 | psadbw_r2rcxx . . $ `utils/mmx.h:297:9`! (mm6,mm4); |
| 126 | |
| 127 | movq_r2rcxx . . $ `utils/mmx.h:83:9`! (mm2,mm5); |
| 128 | punpcklbw_r2rcxx . . $ `utils/mmx.h:194:9`!(mm3,mm5); |
| 129 | psadbw_r2rcxx . . $ `utils/mmx.h:297:9`! (mm7,mm5); |
| 130 | paddw_r2rcxx . . $ `utils/mmx.h:98:9`! (mm5,mm4); |
| 131 | |
| 132 | movd_r2gcxx . . $ `utils/mmx.h:78:9`! ( mm4, res ); |
| 133 | |
| 134 | return res; |
| 135 | } |
| 136 | |
| 137 | |
| 138 | |
| 139 | /* |
| 140 | Register usage: |
| 141 | mm0-mm3 Hold the current row |
| 142 | mm4 Used for accumulating partial SAD |
| 143 | */ |
| 144 | |
| 145 | static inline void init_qblock_sad_mmxcxx . . $ init_qblock_sad_mmx(f63137c5d602553b).(uint8_tcxx . . $ uint8_t# *refblk,uint32_tcxx . . $ uint32_t# h,uint32_tcxx . . $ uint32_t# rowstride) |
| 146 | { |
| 147 | } |
| 148 | |
| 149 | static inline int qblock_sad_mmxcxx . . $ qblock_sad_mmx(47d6add1f5feae6f).(uint8_tcxx . . $ uint8_t# *refblk, uint32_tcxx . . $ uint32_t# h, uint32_tcxx . . $ uint32_t# rowstride) |
| 150 | { |
| 151 | int res; |
| 152 | pxor_r2rcxx . . $ `utils/mmx.h:201:9`! (mm4,mm4); |
| 153 | |
| 154 | movq_r2rcxx . . $ `utils/mmx.h:83:9`! (mm0,mm5); /* First row */ |
| 155 | movd_m2rcxx . . $ `utils/mmx.h:75:9`! (*refblk, mm6); |
| 156 | pxor_r2rcxx . . $ `utils/mmx.h:201:9`! ( mm7, mm7); |
| 157 | refblk += rowstride; |
| 158 | punpcklbw_r2rcxx . . $ `utils/mmx.h:194:9`! ( mm7, mm5); |
| 159 | |
| 160 | punpcklbw_r2rcxx . . $ `utils/mmx.h:194:9`! ( mm7, mm6); |
| 161 | |
| 162 | movq_r2rcxx . . $ `utils/mmx.h:83:9`! ( mm5, mm7); |
| 163 | psubusw_r2rcxx . . $ `utils/mmx.h:184:9`! ( mm6, mm5); |
| 164 | |
| 165 | psubusw_r2rcxx . . $ `utils/mmx.h:184:9`! ( mm7, mm6); |
| 166 | |
| 167 | paddw_r2rcxx . . $ `utils/mmx.h:98:9`! ( mm5, mm4); |
| 168 | paddw_r2rcxx . . $ `utils/mmx.h:98:9`! ( mm6, mm4 ); |
| 169 | |
| 170 | |
| 171 | |
| 172 | movq_r2rcxx . . $ `utils/mmx.h:83:9`! (mm1,mm5); /* Second row */ |
| 173 | movd_m2rcxx . . $ `utils/mmx.h:75:9`! (*refblk, mm6); |
| 174 | pxor_r2rcxx . . $ `utils/mmx.h:201:9`! ( mm7, mm7); |
| 175 | refblk += rowstride; |
| 176 | punpcklbw_r2rcxx . . $ `utils/mmx.h:194:9`! ( mm7, mm5); |
| 177 | punpcklbw_r2rcxx . . $ `utils/mmx.h:194:9`! ( mm7, mm6); |
| 178 | movq_r2rcxx . . $ `utils/mmx.h:83:9`! ( mm5, mm7); |
| 179 | psubusw_r2rcxx . . $ `utils/mmx.h:184:9`! ( mm6, mm5); |
| 180 | psubusw_r2rcxx . . $ `utils/mmx.h:184:9`! ( mm7, mm6); |
| 181 | paddw_r2rcxx . . $ `utils/mmx.h:98:9`! ( mm5, mm4); |
| 182 | paddw_r2rcxx . . $ `utils/mmx.h:98:9`! ( mm6, mm4 ); |
| 183 | |
| 184 | if( h == 4 ) |
| 185 | { |
| 186 | |
| 187 | movq_r2rcxx . . $ `utils/mmx.h:83:9`! (mm2,mm5); /* Third row */ |
| 188 | movd_m2rcxx . . $ `utils/mmx.h:75:9`! (*refblk, mm6); |
| 189 | pxor_r2rcxx . . $ `utils/mmx.h:201:9`! ( mm7, mm7); |
| 190 | refblk += rowstride; |
| 191 | punpcklbw_r2rcxx . . $ `utils/mmx.h:194:9`! ( mm7, mm5); |
| 192 | punpcklbw_r2rcxx . . $ `utils/mmx.h:194:9`! ( mm7, mm6); |
| 193 | movq_r2rcxx . . $ `utils/mmx.h:83:9`! ( mm5, mm7); |
| 194 | psubusw_r2rcxx . . $ `utils/mmx.h:184:9`! ( mm6, mm5); |
| 195 | psubusw_r2rcxx . . $ `utils/mmx.h:184:9`! ( mm7, mm6); |
| 196 | paddw_r2rcxx . . $ `utils/mmx.h:98:9`! ( mm5, mm4); |
| 197 | paddw_r2rcxx . . $ `utils/mmx.h:98:9`! ( mm6, mm4 ); |
| 198 | |
| 199 | movq_r2rcxx . . $ `utils/mmx.h:83:9`! (mm3,mm5); /* Fourth row */ |
| 200 | movd_m2rcxx . . $ `utils/mmx.h:75:9`! (*refblk, mm6); |
| 201 | pxor_r2rcxx . . $ `utils/mmx.h:201:9`! ( mm7, mm7); |
| 202 | punpcklbw_r2rcxx . . $ `utils/mmx.h:194:9`! ( mm7, mm5); |
| 203 | punpcklbw_r2rcxx . . $ `utils/mmx.h:194:9`! ( mm7, mm6); |
| 204 | movq_r2rcxx . . $ `utils/mmx.h:83:9`! ( mm5, mm7); |
| 205 | psubusw_r2rcxx . . $ `utils/mmx.h:184:9`! ( mm6, mm5); |
| 206 | psubusw_r2rcxx . . $ `utils/mmx.h:184:9`! ( mm7, mm6); |
| 207 | paddw_r2rcxx . . $ `utils/mmx.h:98:9`! ( mm5, mm4); |
| 208 | paddw_r2rcxx . . $ `utils/mmx.h:98:9`! ( mm6, mm4 ); |
| 209 | } |
| 210 | |
| 211 | |
| 212 | movq_r2rcxx . . $ `utils/mmx.h:83:9`! ( mm4, mm5 ); |
| 213 | psrlq_i2rcxx . . $ `utils/mmx.h:162:9`! ( 32, mm5 ); |
| 214 | paddw_r2rcxx . . $ `utils/mmx.h:98:9`! ( mm5, mm4 ); |
| 215 | movq_r2rcxx . . $ `utils/mmx.h:83:9`! ( mm4, mm6 ); |
| 216 | psrlq_i2rcxx . . $ `utils/mmx.h:162:9`! ( 16, mm6 ); |
| 217 | paddw_r2rcxx . . $ `utils/mmx.h:98:9`! ( mm6, mm4 ); |
| 218 | movd_r2gcxx . . $ `utils/mmx.h:78:9`! ( mm4, res ); |
| 219 | |
| 220 | return res & 0xffff; |
| 221 | } |
| 222 | |
| 223 | |
| 224 | /* |
| 225 | * Do the Extended MMX versions |
| 226 | */ |
| 227 | #define SIMD_SUFFIXcxx . . $ `utils/mmxsse/mblock_sub44_sads_x86.c:227:9`!(x) x##_mmxe |
| 228 | #include "mblock_sub44_sads_x86_h.c"cxx . . $ `<file>/utils/mmxsse/mblock_sub44_sads_x86_h.c`/ |
| 229 | #undef SIMD_SUFFIXcxx . . $ `utils/mmxsse/mblock_sub44_sads_x86.c:227:9`! |
| 230 | /* |
| 231 | * Do the original MMX versions |
| 232 | */ |
| 233 | #define SIMD_SUFFIXcxx . . $ `utils/mmxsse/mblock_sub44_sads_x86.c:233:9`!(x) x##_mmx |
| 234 | #include "mblock_sub44_sads_x86_h.c"cxx . . $ `<file>/utils/mmxsse/mblock_sub44_sads_x86_h.c`/ |
| 235 | #undef SIMD_SUFFIXcxx . . $ `utils/mmxsse/mblock_sub44_sads_x86.c:233:9`! |
| 236 | |
| 237 | |
| 238 | |
| 239 |