inv_txfm.c 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701
  1. /*
  2. * Copyright (c) 2015 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include <math.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include "./vpx_dsp_rtcd.h"
  14. #include "vpx_dsp/inv_txfm.h"
  15. void vpx_iwht4x4_16_add_c(const tran_low_t *input, uint8_t *dest, int stride) {
  16. /* 4-point reversible, orthonormal inverse Walsh-Hadamard in 3.5 adds,
  17. 0.5 shifts per pixel. */
  18. int i;
  19. tran_low_t output[16];
  20. tran_high_t a1, b1, c1, d1, e1;
  21. const tran_low_t *ip = input;
  22. tran_low_t *op = output;
  23. for (i = 0; i < 4; i++) {
  24. a1 = ip[0] >> UNIT_QUANT_SHIFT;
  25. c1 = ip[1] >> UNIT_QUANT_SHIFT;
  26. d1 = ip[2] >> UNIT_QUANT_SHIFT;
  27. b1 = ip[3] >> UNIT_QUANT_SHIFT;
  28. a1 += c1;
  29. d1 -= b1;
  30. e1 = (a1 - d1) >> 1;
  31. b1 = e1 - b1;
  32. c1 = e1 - c1;
  33. a1 -= b1;
  34. d1 += c1;
  35. op[0] = WRAPLOW(a1);
  36. op[1] = WRAPLOW(b1);
  37. op[2] = WRAPLOW(c1);
  38. op[3] = WRAPLOW(d1);
  39. ip += 4;
  40. op += 4;
  41. }
  42. ip = output;
  43. for (i = 0; i < 4; i++) {
  44. a1 = ip[4 * 0];
  45. c1 = ip[4 * 1];
  46. d1 = ip[4 * 2];
  47. b1 = ip[4 * 3];
  48. a1 += c1;
  49. d1 -= b1;
  50. e1 = (a1 - d1) >> 1;
  51. b1 = e1 - b1;
  52. c1 = e1 - c1;
  53. a1 -= b1;
  54. d1 += c1;
  55. dest[stride * 0] = clip_pixel_add(dest[stride * 0], WRAPLOW(a1));
  56. dest[stride * 1] = clip_pixel_add(dest[stride * 1], WRAPLOW(b1));
  57. dest[stride * 2] = clip_pixel_add(dest[stride * 2], WRAPLOW(c1));
  58. dest[stride * 3] = clip_pixel_add(dest[stride * 3], WRAPLOW(d1));
  59. ip++;
  60. dest++;
  61. }
  62. }
  63. void vpx_iwht4x4_1_add_c(const tran_low_t *input, uint8_t *dest, int stride) {
  64. int i;
  65. tran_high_t a1, e1;
  66. tran_low_t tmp[4];
  67. const tran_low_t *ip = input;
  68. tran_low_t *op = tmp;
  69. a1 = ip[0] >> UNIT_QUANT_SHIFT;
  70. e1 = a1 >> 1;
  71. a1 -= e1;
  72. op[0] = WRAPLOW(a1);
  73. op[1] = op[2] = op[3] = WRAPLOW(e1);
  74. ip = tmp;
  75. for (i = 0; i < 4; i++) {
  76. e1 = ip[0] >> 1;
  77. a1 = ip[0] - e1;
  78. dest[stride * 0] = clip_pixel_add(dest[stride * 0], a1);
  79. dest[stride * 1] = clip_pixel_add(dest[stride * 1], e1);
  80. dest[stride * 2] = clip_pixel_add(dest[stride * 2], e1);
  81. dest[stride * 3] = clip_pixel_add(dest[stride * 3], e1);
  82. ip++;
  83. dest++;
  84. }
  85. }
  86. void iadst4_c(const tran_low_t *input, tran_low_t *output) {
  87. tran_high_t s0, s1, s2, s3, s4, s5, s6, s7;
  88. tran_low_t x0 = input[0];
  89. tran_low_t x1 = input[1];
  90. tran_low_t x2 = input[2];
  91. tran_low_t x3 = input[3];
  92. if (!(x0 | x1 | x2 | x3)) {
  93. memset(output, 0, 4 * sizeof(*output));
  94. return;
  95. }
  96. // 32-bit result is enough for the following multiplications.
  97. s0 = sinpi_1_9 * x0;
  98. s1 = sinpi_2_9 * x0;
  99. s2 = sinpi_3_9 * x1;
  100. s3 = sinpi_4_9 * x2;
  101. s4 = sinpi_1_9 * x2;
  102. s5 = sinpi_2_9 * x3;
  103. s6 = sinpi_4_9 * x3;
  104. s7 = WRAPLOW(x0 - x2 + x3);
  105. s0 = s0 + s3 + s5;
  106. s1 = s1 - s4 - s6;
  107. s3 = s2;
  108. s2 = sinpi_3_9 * s7;
  109. // 1-D transform scaling factor is sqrt(2).
  110. // The overall dynamic range is 14b (input) + 14b (multiplication scaling)
  111. // + 1b (addition) = 29b.
  112. // Hence the output bit depth is 15b.
  113. output[0] = WRAPLOW(dct_const_round_shift(s0 + s3));
  114. output[1] = WRAPLOW(dct_const_round_shift(s1 + s3));
  115. output[2] = WRAPLOW(dct_const_round_shift(s2));
  116. output[3] = WRAPLOW(dct_const_round_shift(s0 + s1 - s3));
  117. }
  118. void idct4_c(const tran_low_t *input, tran_low_t *output) {
  119. int16_t step[4];
  120. tran_high_t temp1, temp2;
  121. // stage 1
  122. temp1 = ((int16_t)input[0] + (int16_t)input[2]) * cospi_16_64;
  123. temp2 = ((int16_t)input[0] - (int16_t)input[2]) * cospi_16_64;
  124. step[0] = WRAPLOW(dct_const_round_shift(temp1));
  125. step[1] = WRAPLOW(dct_const_round_shift(temp2));
  126. temp1 = (int16_t)input[1] * cospi_24_64 - (int16_t)input[3] * cospi_8_64;
  127. temp2 = (int16_t)input[1] * cospi_8_64 + (int16_t)input[3] * cospi_24_64;
  128. step[2] = WRAPLOW(dct_const_round_shift(temp1));
  129. step[3] = WRAPLOW(dct_const_round_shift(temp2));
  130. // stage 2
  131. output[0] = WRAPLOW(step[0] + step[3]);
  132. output[1] = WRAPLOW(step[1] + step[2]);
  133. output[2] = WRAPLOW(step[1] - step[2]);
  134. output[3] = WRAPLOW(step[0] - step[3]);
  135. }
  136. void vpx_idct4x4_16_add_c(const tran_low_t *input, uint8_t *dest, int stride) {
  137. int i, j;
  138. tran_low_t out[4 * 4];
  139. tran_low_t *outptr = out;
  140. tran_low_t temp_in[4], temp_out[4];
  141. // Rows
  142. for (i = 0; i < 4; ++i) {
  143. idct4_c(input, outptr);
  144. input += 4;
  145. outptr += 4;
  146. }
  147. // Columns
  148. for (i = 0; i < 4; ++i) {
  149. for (j = 0; j < 4; ++j) temp_in[j] = out[j * 4 + i];
  150. idct4_c(temp_in, temp_out);
  151. for (j = 0; j < 4; ++j) {
  152. dest[j * stride + i] = clip_pixel_add(dest[j * stride + i],
  153. ROUND_POWER_OF_TWO(temp_out[j], 4));
  154. }
  155. }
  156. }
  157. void vpx_idct4x4_1_add_c(const tran_low_t *input, uint8_t *dest, int stride) {
  158. int i;
  159. tran_high_t a1;
  160. tran_low_t out =
  161. WRAPLOW(dct_const_round_shift((int16_t)input[0] * cospi_16_64));
  162. out = WRAPLOW(dct_const_round_shift(out * cospi_16_64));
  163. a1 = ROUND_POWER_OF_TWO(out, 4);
  164. for (i = 0; i < 4; i++) {
  165. dest[0] = clip_pixel_add(dest[0], a1);
  166. dest[1] = clip_pixel_add(dest[1], a1);
  167. dest[2] = clip_pixel_add(dest[2], a1);
  168. dest[3] = clip_pixel_add(dest[3], a1);
  169. dest += stride;
  170. }
  171. }
  172. void iadst8_c(const tran_low_t *input, tran_low_t *output) {
  173. int s0, s1, s2, s3, s4, s5, s6, s7;
  174. tran_high_t x0 = input[7];
  175. tran_high_t x1 = input[0];
  176. tran_high_t x2 = input[5];
  177. tran_high_t x3 = input[2];
  178. tran_high_t x4 = input[3];
  179. tran_high_t x5 = input[4];
  180. tran_high_t x6 = input[1];
  181. tran_high_t x7 = input[6];
  182. if (!(x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7)) {
  183. memset(output, 0, 8 * sizeof(*output));
  184. return;
  185. }
  186. // stage 1
  187. s0 = (int)(cospi_2_64 * x0 + cospi_30_64 * x1);
  188. s1 = (int)(cospi_30_64 * x0 - cospi_2_64 * x1);
  189. s2 = (int)(cospi_10_64 * x2 + cospi_22_64 * x3);
  190. s3 = (int)(cospi_22_64 * x2 - cospi_10_64 * x3);
  191. s4 = (int)(cospi_18_64 * x4 + cospi_14_64 * x5);
  192. s5 = (int)(cospi_14_64 * x4 - cospi_18_64 * x5);
  193. s6 = (int)(cospi_26_64 * x6 + cospi_6_64 * x7);
  194. s7 = (int)(cospi_6_64 * x6 - cospi_26_64 * x7);
  195. x0 = WRAPLOW(dct_const_round_shift(s0 + s4));
  196. x1 = WRAPLOW(dct_const_round_shift(s1 + s5));
  197. x2 = WRAPLOW(dct_const_round_shift(s2 + s6));
  198. x3 = WRAPLOW(dct_const_round_shift(s3 + s7));
  199. x4 = WRAPLOW(dct_const_round_shift(s0 - s4));
  200. x5 = WRAPLOW(dct_const_round_shift(s1 - s5));
  201. x6 = WRAPLOW(dct_const_round_shift(s2 - s6));
  202. x7 = WRAPLOW(dct_const_round_shift(s3 - s7));
  203. // stage 2
  204. s0 = (int)x0;
  205. s1 = (int)x1;
  206. s2 = (int)x2;
  207. s3 = (int)x3;
  208. s4 = (int)(cospi_8_64 * x4 + cospi_24_64 * x5);
  209. s5 = (int)(cospi_24_64 * x4 - cospi_8_64 * x5);
  210. s6 = (int)(-cospi_24_64 * x6 + cospi_8_64 * x7);
  211. s7 = (int)(cospi_8_64 * x6 + cospi_24_64 * x7);
  212. x0 = WRAPLOW(s0 + s2);
  213. x1 = WRAPLOW(s1 + s3);
  214. x2 = WRAPLOW(s0 - s2);
  215. x3 = WRAPLOW(s1 - s3);
  216. x4 = WRAPLOW(dct_const_round_shift(s4 + s6));
  217. x5 = WRAPLOW(dct_const_round_shift(s5 + s7));
  218. x6 = WRAPLOW(dct_const_round_shift(s4 - s6));
  219. x7 = WRAPLOW(dct_const_round_shift(s5 - s7));
  220. // stage 3
  221. s2 = (int)(cospi_16_64 * (x2 + x3));
  222. s3 = (int)(cospi_16_64 * (x2 - x3));
  223. s6 = (int)(cospi_16_64 * (x6 + x7));
  224. s7 = (int)(cospi_16_64 * (x6 - x7));
  225. x2 = WRAPLOW(dct_const_round_shift(s2));
  226. x3 = WRAPLOW(dct_const_round_shift(s3));
  227. x6 = WRAPLOW(dct_const_round_shift(s6));
  228. x7 = WRAPLOW(dct_const_round_shift(s7));
  229. output[0] = WRAPLOW(x0);
  230. output[1] = WRAPLOW(-x4);
  231. output[2] = WRAPLOW(x6);
  232. output[3] = WRAPLOW(-x2);
  233. output[4] = WRAPLOW(x3);
  234. output[5] = WRAPLOW(-x7);
  235. output[6] = WRAPLOW(x5);
  236. output[7] = WRAPLOW(-x1);
  237. }
  238. void idct8_c(const tran_low_t *input, tran_low_t *output) {
  239. int16_t step1[8], step2[8];
  240. tran_high_t temp1, temp2;
  241. // stage 1
  242. step1[0] = (int16_t)input[0];
  243. step1[2] = (int16_t)input[4];
  244. step1[1] = (int16_t)input[2];
  245. step1[3] = (int16_t)input[6];
  246. temp1 = (int16_t)input[1] * cospi_28_64 - (int16_t)input[7] * cospi_4_64;
  247. temp2 = (int16_t)input[1] * cospi_4_64 + (int16_t)input[7] * cospi_28_64;
  248. step1[4] = WRAPLOW(dct_const_round_shift(temp1));
  249. step1[7] = WRAPLOW(dct_const_round_shift(temp2));
  250. temp1 = (int16_t)input[5] * cospi_12_64 - (int16_t)input[3] * cospi_20_64;
  251. temp2 = (int16_t)input[5] * cospi_20_64 + (int16_t)input[3] * cospi_12_64;
  252. step1[5] = WRAPLOW(dct_const_round_shift(temp1));
  253. step1[6] = WRAPLOW(dct_const_round_shift(temp2));
  254. // stage 2
  255. temp1 = (step1[0] + step1[2]) * cospi_16_64;
  256. temp2 = (step1[0] - step1[2]) * cospi_16_64;
  257. step2[0] = WRAPLOW(dct_const_round_shift(temp1));
  258. step2[1] = WRAPLOW(dct_const_round_shift(temp2));
  259. temp1 = step1[1] * cospi_24_64 - step1[3] * cospi_8_64;
  260. temp2 = step1[1] * cospi_8_64 + step1[3] * cospi_24_64;
  261. step2[2] = WRAPLOW(dct_const_round_shift(temp1));
  262. step2[3] = WRAPLOW(dct_const_round_shift(temp2));
  263. step2[4] = WRAPLOW(step1[4] + step1[5]);
  264. step2[5] = WRAPLOW(step1[4] - step1[5]);
  265. step2[6] = WRAPLOW(-step1[6] + step1[7]);
  266. step2[7] = WRAPLOW(step1[6] + step1[7]);
  267. // stage 3
  268. step1[0] = WRAPLOW(step2[0] + step2[3]);
  269. step1[1] = WRAPLOW(step2[1] + step2[2]);
  270. step1[2] = WRAPLOW(step2[1] - step2[2]);
  271. step1[3] = WRAPLOW(step2[0] - step2[3]);
  272. step1[4] = step2[4];
  273. temp1 = (step2[6] - step2[5]) * cospi_16_64;
  274. temp2 = (step2[5] + step2[6]) * cospi_16_64;
  275. step1[5] = WRAPLOW(dct_const_round_shift(temp1));
  276. step1[6] = WRAPLOW(dct_const_round_shift(temp2));
  277. step1[7] = step2[7];
  278. // stage 4
  279. output[0] = WRAPLOW(step1[0] + step1[7]);
  280. output[1] = WRAPLOW(step1[1] + step1[6]);
  281. output[2] = WRAPLOW(step1[2] + step1[5]);
  282. output[3] = WRAPLOW(step1[3] + step1[4]);
  283. output[4] = WRAPLOW(step1[3] - step1[4]);
  284. output[5] = WRAPLOW(step1[2] - step1[5]);
  285. output[6] = WRAPLOW(step1[1] - step1[6]);
  286. output[7] = WRAPLOW(step1[0] - step1[7]);
  287. }
  288. void vpx_idct8x8_64_add_c(const tran_low_t *input, uint8_t *dest, int stride) {
  289. int i, j;
  290. tran_low_t out[8 * 8];
  291. tran_low_t *outptr = out;
  292. tran_low_t temp_in[8], temp_out[8];
  293. // First transform rows
  294. for (i = 0; i < 8; ++i) {
  295. idct8_c(input, outptr);
  296. input += 8;
  297. outptr += 8;
  298. }
  299. // Then transform columns
  300. for (i = 0; i < 8; ++i) {
  301. for (j = 0; j < 8; ++j) temp_in[j] = out[j * 8 + i];
  302. idct8_c(temp_in, temp_out);
  303. for (j = 0; j < 8; ++j) {
  304. dest[j * stride + i] = clip_pixel_add(dest[j * stride + i],
  305. ROUND_POWER_OF_TWO(temp_out[j], 5));
  306. }
  307. }
  308. }
  309. void vpx_idct8x8_12_add_c(const tran_low_t *input, uint8_t *dest, int stride) {
  310. int i, j;
  311. tran_low_t out[8 * 8] = { 0 };
  312. tran_low_t *outptr = out;
  313. tran_low_t temp_in[8], temp_out[8];
  314. // First transform rows
  315. // Only first 4 row has non-zero coefs
  316. for (i = 0; i < 4; ++i) {
  317. idct8_c(input, outptr);
  318. input += 8;
  319. outptr += 8;
  320. }
  321. // Then transform columns
  322. for (i = 0; i < 8; ++i) {
  323. for (j = 0; j < 8; ++j) temp_in[j] = out[j * 8 + i];
  324. idct8_c(temp_in, temp_out);
  325. for (j = 0; j < 8; ++j) {
  326. dest[j * stride + i] = clip_pixel_add(dest[j * stride + i],
  327. ROUND_POWER_OF_TWO(temp_out[j], 5));
  328. }
  329. }
  330. }
  331. void vpx_idct8x8_1_add_c(const tran_low_t *input, uint8_t *dest, int stride) {
  332. int i, j;
  333. tran_high_t a1;
  334. tran_low_t out =
  335. WRAPLOW(dct_const_round_shift((int16_t)input[0] * cospi_16_64));
  336. out = WRAPLOW(dct_const_round_shift(out * cospi_16_64));
  337. a1 = ROUND_POWER_OF_TWO(out, 5);
  338. for (j = 0; j < 8; ++j) {
  339. for (i = 0; i < 8; ++i) dest[i] = clip_pixel_add(dest[i], a1);
  340. dest += stride;
  341. }
  342. }
  343. void iadst16_c(const tran_low_t *input, tran_low_t *output) {
  344. tran_high_t s0, s1, s2, s3, s4, s5, s6, s7, s8;
  345. tran_high_t s9, s10, s11, s12, s13, s14, s15;
  346. tran_high_t x0 = input[15];
  347. tran_high_t x1 = input[0];
  348. tran_high_t x2 = input[13];
  349. tran_high_t x3 = input[2];
  350. tran_high_t x4 = input[11];
  351. tran_high_t x5 = input[4];
  352. tran_high_t x6 = input[9];
  353. tran_high_t x7 = input[6];
  354. tran_high_t x8 = input[7];
  355. tran_high_t x9 = input[8];
  356. tran_high_t x10 = input[5];
  357. tran_high_t x11 = input[10];
  358. tran_high_t x12 = input[3];
  359. tran_high_t x13 = input[12];
  360. tran_high_t x14 = input[1];
  361. tran_high_t x15 = input[14];
  362. if (!(x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 | x10 | x11 | x12 |
  363. x13 | x14 | x15)) {
  364. memset(output, 0, 16 * sizeof(*output));
  365. return;
  366. }
  367. // stage 1
  368. s0 = x0 * cospi_1_64 + x1 * cospi_31_64;
  369. s1 = x0 * cospi_31_64 - x1 * cospi_1_64;
  370. s2 = x2 * cospi_5_64 + x3 * cospi_27_64;
  371. s3 = x2 * cospi_27_64 - x3 * cospi_5_64;
  372. s4 = x4 * cospi_9_64 + x5 * cospi_23_64;
  373. s5 = x4 * cospi_23_64 - x5 * cospi_9_64;
  374. s6 = x6 * cospi_13_64 + x7 * cospi_19_64;
  375. s7 = x6 * cospi_19_64 - x7 * cospi_13_64;
  376. s8 = x8 * cospi_17_64 + x9 * cospi_15_64;
  377. s9 = x8 * cospi_15_64 - x9 * cospi_17_64;
  378. s10 = x10 * cospi_21_64 + x11 * cospi_11_64;
  379. s11 = x10 * cospi_11_64 - x11 * cospi_21_64;
  380. s12 = x12 * cospi_25_64 + x13 * cospi_7_64;
  381. s13 = x12 * cospi_7_64 - x13 * cospi_25_64;
  382. s14 = x14 * cospi_29_64 + x15 * cospi_3_64;
  383. s15 = x14 * cospi_3_64 - x15 * cospi_29_64;
  384. x0 = WRAPLOW(dct_const_round_shift(s0 + s8));
  385. x1 = WRAPLOW(dct_const_round_shift(s1 + s9));
  386. x2 = WRAPLOW(dct_const_round_shift(s2 + s10));
  387. x3 = WRAPLOW(dct_const_round_shift(s3 + s11));
  388. x4 = WRAPLOW(dct_const_round_shift(s4 + s12));
  389. x5 = WRAPLOW(dct_const_round_shift(s5 + s13));
  390. x6 = WRAPLOW(dct_const_round_shift(s6 + s14));
  391. x7 = WRAPLOW(dct_const_round_shift(s7 + s15));
  392. x8 = WRAPLOW(dct_const_round_shift(s0 - s8));
  393. x9 = WRAPLOW(dct_const_round_shift(s1 - s9));
  394. x10 = WRAPLOW(dct_const_round_shift(s2 - s10));
  395. x11 = WRAPLOW(dct_const_round_shift(s3 - s11));
  396. x12 = WRAPLOW(dct_const_round_shift(s4 - s12));
  397. x13 = WRAPLOW(dct_const_round_shift(s5 - s13));
  398. x14 = WRAPLOW(dct_const_round_shift(s6 - s14));
  399. x15 = WRAPLOW(dct_const_round_shift(s7 - s15));
  400. // stage 2
  401. s0 = x0;
  402. s1 = x1;
  403. s2 = x2;
  404. s3 = x3;
  405. s4 = x4;
  406. s5 = x5;
  407. s6 = x6;
  408. s7 = x7;
  409. s8 = x8 * cospi_4_64 + x9 * cospi_28_64;
  410. s9 = x8 * cospi_28_64 - x9 * cospi_4_64;
  411. s10 = x10 * cospi_20_64 + x11 * cospi_12_64;
  412. s11 = x10 * cospi_12_64 - x11 * cospi_20_64;
  413. s12 = -x12 * cospi_28_64 + x13 * cospi_4_64;
  414. s13 = x12 * cospi_4_64 + x13 * cospi_28_64;
  415. s14 = -x14 * cospi_12_64 + x15 * cospi_20_64;
  416. s15 = x14 * cospi_20_64 + x15 * cospi_12_64;
  417. x0 = WRAPLOW(s0 + s4);
  418. x1 = WRAPLOW(s1 + s5);
  419. x2 = WRAPLOW(s2 + s6);
  420. x3 = WRAPLOW(s3 + s7);
  421. x4 = WRAPLOW(s0 - s4);
  422. x5 = WRAPLOW(s1 - s5);
  423. x6 = WRAPLOW(s2 - s6);
  424. x7 = WRAPLOW(s3 - s7);
  425. x8 = WRAPLOW(dct_const_round_shift(s8 + s12));
  426. x9 = WRAPLOW(dct_const_round_shift(s9 + s13));
  427. x10 = WRAPLOW(dct_const_round_shift(s10 + s14));
  428. x11 = WRAPLOW(dct_const_round_shift(s11 + s15));
  429. x12 = WRAPLOW(dct_const_round_shift(s8 - s12));
  430. x13 = WRAPLOW(dct_const_round_shift(s9 - s13));
  431. x14 = WRAPLOW(dct_const_round_shift(s10 - s14));
  432. x15 = WRAPLOW(dct_const_round_shift(s11 - s15));
  433. // stage 3
  434. s0 = x0;
  435. s1 = x1;
  436. s2 = x2;
  437. s3 = x3;
  438. s4 = x4 * cospi_8_64 + x5 * cospi_24_64;
  439. s5 = x4 * cospi_24_64 - x5 * cospi_8_64;
  440. s6 = -x6 * cospi_24_64 + x7 * cospi_8_64;
  441. s7 = x6 * cospi_8_64 + x7 * cospi_24_64;
  442. s8 = x8;
  443. s9 = x9;
  444. s10 = x10;
  445. s11 = x11;
  446. s12 = x12 * cospi_8_64 + x13 * cospi_24_64;
  447. s13 = x12 * cospi_24_64 - x13 * cospi_8_64;
  448. s14 = -x14 * cospi_24_64 + x15 * cospi_8_64;
  449. s15 = x14 * cospi_8_64 + x15 * cospi_24_64;
  450. x0 = WRAPLOW(s0 + s2);
  451. x1 = WRAPLOW(s1 + s3);
  452. x2 = WRAPLOW(s0 - s2);
  453. x3 = WRAPLOW(s1 - s3);
  454. x4 = WRAPLOW(dct_const_round_shift(s4 + s6));
  455. x5 = WRAPLOW(dct_const_round_shift(s5 + s7));
  456. x6 = WRAPLOW(dct_const_round_shift(s4 - s6));
  457. x7 = WRAPLOW(dct_const_round_shift(s5 - s7));
  458. x8 = WRAPLOW(s8 + s10);
  459. x9 = WRAPLOW(s9 + s11);
  460. x10 = WRAPLOW(s8 - s10);
  461. x11 = WRAPLOW(s9 - s11);
  462. x12 = WRAPLOW(dct_const_round_shift(s12 + s14));
  463. x13 = WRAPLOW(dct_const_round_shift(s13 + s15));
  464. x14 = WRAPLOW(dct_const_round_shift(s12 - s14));
  465. x15 = WRAPLOW(dct_const_round_shift(s13 - s15));
  466. // stage 4
  467. s2 = (-cospi_16_64) * (x2 + x3);
  468. s3 = cospi_16_64 * (x2 - x3);
  469. s6 = cospi_16_64 * (x6 + x7);
  470. s7 = cospi_16_64 * (-x6 + x7);
  471. s10 = cospi_16_64 * (x10 + x11);
  472. s11 = cospi_16_64 * (-x10 + x11);
  473. s14 = (-cospi_16_64) * (x14 + x15);
  474. s15 = cospi_16_64 * (x14 - x15);
  475. x2 = WRAPLOW(dct_const_round_shift(s2));
  476. x3 = WRAPLOW(dct_const_round_shift(s3));
  477. x6 = WRAPLOW(dct_const_round_shift(s6));
  478. x7 = WRAPLOW(dct_const_round_shift(s7));
  479. x10 = WRAPLOW(dct_const_round_shift(s10));
  480. x11 = WRAPLOW(dct_const_round_shift(s11));
  481. x14 = WRAPLOW(dct_const_round_shift(s14));
  482. x15 = WRAPLOW(dct_const_round_shift(s15));
  483. output[0] = WRAPLOW(x0);
  484. output[1] = WRAPLOW(-x8);
  485. output[2] = WRAPLOW(x12);
  486. output[3] = WRAPLOW(-x4);
  487. output[4] = WRAPLOW(x6);
  488. output[5] = WRAPLOW(x14);
  489. output[6] = WRAPLOW(x10);
  490. output[7] = WRAPLOW(x2);
  491. output[8] = WRAPLOW(x3);
  492. output[9] = WRAPLOW(x11);
  493. output[10] = WRAPLOW(x15);
  494. output[11] = WRAPLOW(x7);
  495. output[12] = WRAPLOW(x5);
  496. output[13] = WRAPLOW(-x13);
  497. output[14] = WRAPLOW(x9);
  498. output[15] = WRAPLOW(-x1);
  499. }
  500. void idct16_c(const tran_low_t *input, tran_low_t *output) {
  501. int16_t step1[16], step2[16];
  502. tran_high_t temp1, temp2;
  503. // stage 1
  504. step1[0] = (int16_t)input[0 / 2];
  505. step1[1] = (int16_t)input[16 / 2];
  506. step1[2] = (int16_t)input[8 / 2];
  507. step1[3] = (int16_t)input[24 / 2];
  508. step1[4] = (int16_t)input[4 / 2];
  509. step1[5] = (int16_t)input[20 / 2];
  510. step1[6] = (int16_t)input[12 / 2];
  511. step1[7] = (int16_t)input[28 / 2];
  512. step1[8] = (int16_t)input[2 / 2];
  513. step1[9] = (int16_t)input[18 / 2];
  514. step1[10] = (int16_t)input[10 / 2];
  515. step1[11] = (int16_t)input[26 / 2];
  516. step1[12] = (int16_t)input[6 / 2];
  517. step1[13] = (int16_t)input[22 / 2];
  518. step1[14] = (int16_t)input[14 / 2];
  519. step1[15] = (int16_t)input[30 / 2];
  520. // stage 2
  521. step2[0] = step1[0];
  522. step2[1] = step1[1];
  523. step2[2] = step1[2];
  524. step2[3] = step1[3];
  525. step2[4] = step1[4];
  526. step2[5] = step1[5];
  527. step2[6] = step1[6];
  528. step2[7] = step1[7];
  529. temp1 = step1[8] * cospi_30_64 - step1[15] * cospi_2_64;
  530. temp2 = step1[8] * cospi_2_64 + step1[15] * cospi_30_64;
  531. step2[8] = WRAPLOW(dct_const_round_shift(temp1));
  532. step2[15] = WRAPLOW(dct_const_round_shift(temp2));
  533. temp1 = step1[9] * cospi_14_64 - step1[14] * cospi_18_64;
  534. temp2 = step1[9] * cospi_18_64 + step1[14] * cospi_14_64;
  535. step2[9] = WRAPLOW(dct_const_round_shift(temp1));
  536. step2[14] = WRAPLOW(dct_const_round_shift(temp2));
  537. temp1 = step1[10] * cospi_22_64 - step1[13] * cospi_10_64;
  538. temp2 = step1[10] * cospi_10_64 + step1[13] * cospi_22_64;
  539. step2[10] = WRAPLOW(dct_const_round_shift(temp1));
  540. step2[13] = WRAPLOW(dct_const_round_shift(temp2));
  541. temp1 = step1[11] * cospi_6_64 - step1[12] * cospi_26_64;
  542. temp2 = step1[11] * cospi_26_64 + step1[12] * cospi_6_64;
  543. step2[11] = WRAPLOW(dct_const_round_shift(temp1));
  544. step2[12] = WRAPLOW(dct_const_round_shift(temp2));
  545. // stage 3
  546. step1[0] = step2[0];
  547. step1[1] = step2[1];
  548. step1[2] = step2[2];
  549. step1[3] = step2[3];
  550. temp1 = step2[4] * cospi_28_64 - step2[7] * cospi_4_64;
  551. temp2 = step2[4] * cospi_4_64 + step2[7] * cospi_28_64;
  552. step1[4] = WRAPLOW(dct_const_round_shift(temp1));
  553. step1[7] = WRAPLOW(dct_const_round_shift(temp2));
  554. temp1 = step2[5] * cospi_12_64 - step2[6] * cospi_20_64;
  555. temp2 = step2[5] * cospi_20_64 + step2[6] * cospi_12_64;
  556. step1[5] = WRAPLOW(dct_const_round_shift(temp1));
  557. step1[6] = WRAPLOW(dct_const_round_shift(temp2));
  558. step1[8] = WRAPLOW(step2[8] + step2[9]);
  559. step1[9] = WRAPLOW(step2[8] - step2[9]);
  560. step1[10] = WRAPLOW(-step2[10] + step2[11]);
  561. step1[11] = WRAPLOW(step2[10] + step2[11]);
  562. step1[12] = WRAPLOW(step2[12] + step2[13]);
  563. step1[13] = WRAPLOW(step2[12] - step2[13]);
  564. step1[14] = WRAPLOW(-step2[14] + step2[15]);
  565. step1[15] = WRAPLOW(step2[14] + step2[15]);
  566. // stage 4
  567. temp1 = (step1[0] + step1[1]) * cospi_16_64;
  568. temp2 = (step1[0] - step1[1]) * cospi_16_64;
  569. step2[0] = WRAPLOW(dct_const_round_shift(temp1));
  570. step2[1] = WRAPLOW(dct_const_round_shift(temp2));
  571. temp1 = step1[2] * cospi_24_64 - step1[3] * cospi_8_64;
  572. temp2 = step1[2] * cospi_8_64 + step1[3] * cospi_24_64;
  573. step2[2] = WRAPLOW(dct_const_round_shift(temp1));
  574. step2[3] = WRAPLOW(dct_const_round_shift(temp2));
  575. step2[4] = WRAPLOW(step1[4] + step1[5]);
  576. step2[5] = WRAPLOW(step1[4] - step1[5]);
  577. step2[6] = WRAPLOW(-step1[6] + step1[7]);
  578. step2[7] = WRAPLOW(step1[6] + step1[7]);
  579. step2[8] = step1[8];
  580. step2[15] = step1[15];
  581. temp1 = -step1[9] * cospi_8_64 + step1[14] * cospi_24_64;
  582. temp2 = step1[9] * cospi_24_64 + step1[14] * cospi_8_64;
  583. step2[9] = WRAPLOW(dct_const_round_shift(temp1));
  584. step2[14] = WRAPLOW(dct_const_round_shift(temp2));
  585. temp1 = -step1[10] * cospi_24_64 - step1[13] * cospi_8_64;
  586. temp2 = -step1[10] * cospi_8_64 + step1[13] * cospi_24_64;
  587. step2[10] = WRAPLOW(dct_const_round_shift(temp1));
  588. step2[13] = WRAPLOW(dct_const_round_shift(temp2));
  589. step2[11] = step1[11];
  590. step2[12] = step1[12];
  591. // stage 5
  592. step1[0] = WRAPLOW(step2[0] + step2[3]);
  593. step1[1] = WRAPLOW(step2[1] + step2[2]);
  594. step1[2] = WRAPLOW(step2[1] - step2[2]);
  595. step1[3] = WRAPLOW(step2[0] - step2[3]);
  596. step1[4] = step2[4];
  597. temp1 = (step2[6] - step2[5]) * cospi_16_64;
  598. temp2 = (step2[5] + step2[6]) * cospi_16_64;
  599. step1[5] = WRAPLOW(dct_const_round_shift(temp1));
  600. step1[6] = WRAPLOW(dct_const_round_shift(temp2));
  601. step1[7] = step2[7];
  602. step1[8] = WRAPLOW(step2[8] + step2[11]);
  603. step1[9] = WRAPLOW(step2[9] + step2[10]);
  604. step1[10] = WRAPLOW(step2[9] - step2[10]);
  605. step1[11] = WRAPLOW(step2[8] - step2[11]);
  606. step1[12] = WRAPLOW(-step2[12] + step2[15]);
  607. step1[13] = WRAPLOW(-step2[13] + step2[14]);
  608. step1[14] = WRAPLOW(step2[13] + step2[14]);
  609. step1[15] = WRAPLOW(step2[12] + step2[15]);
  610. // stage 6
  611. step2[0] = WRAPLOW(step1[0] + step1[7]);
  612. step2[1] = WRAPLOW(step1[1] + step1[6]);
  613. step2[2] = WRAPLOW(step1[2] + step1[5]);
  614. step2[3] = WRAPLOW(step1[3] + step1[4]);
  615. step2[4] = WRAPLOW(step1[3] - step1[4]);
  616. step2[5] = WRAPLOW(step1[2] - step1[5]);
  617. step2[6] = WRAPLOW(step1[1] - step1[6]);
  618. step2[7] = WRAPLOW(step1[0] - step1[7]);
  619. step2[8] = step1[8];
  620. step2[9] = step1[9];
  621. temp1 = (-step1[10] + step1[13]) * cospi_16_64;
  622. temp2 = (step1[10] + step1[13]) * cospi_16_64;
  623. step2[10] = WRAPLOW(dct_const_round_shift(temp1));
  624. step2[13] = WRAPLOW(dct_const_round_shift(temp2));
  625. temp1 = (-step1[11] + step1[12]) * cospi_16_64;
  626. temp2 = (step1[11] + step1[12]) * cospi_16_64;
  627. step2[11] = WRAPLOW(dct_const_round_shift(temp1));
  628. step2[12] = WRAPLOW(dct_const_round_shift(temp2));
  629. step2[14] = step1[14];
  630. step2[15] = step1[15];
  631. // stage 7
  632. output[0] = WRAPLOW(step2[0] + step2[15]);
  633. output[1] = WRAPLOW(step2[1] + step2[14]);
  634. output[2] = WRAPLOW(step2[2] + step2[13]);
  635. output[3] = WRAPLOW(step2[3] + step2[12]);
  636. output[4] = WRAPLOW(step2[4] + step2[11]);
  637. output[5] = WRAPLOW(step2[5] + step2[10]);
  638. output[6] = WRAPLOW(step2[6] + step2[9]);
  639. output[7] = WRAPLOW(step2[7] + step2[8]);
  640. output[8] = WRAPLOW(step2[7] - step2[8]);
  641. output[9] = WRAPLOW(step2[6] - step2[9]);
  642. output[10] = WRAPLOW(step2[5] - step2[10]);
  643. output[11] = WRAPLOW(step2[4] - step2[11]);
  644. output[12] = WRAPLOW(step2[3] - step2[12]);
  645. output[13] = WRAPLOW(step2[2] - step2[13]);
  646. output[14] = WRAPLOW(step2[1] - step2[14]);
  647. output[15] = WRAPLOW(step2[0] - step2[15]);
  648. }
  649. void vpx_idct16x16_256_add_c(const tran_low_t *input, uint8_t *dest,
  650. int stride) {
  651. int i, j;
  652. tran_low_t out[16 * 16];
  653. tran_low_t *outptr = out;
  654. tran_low_t temp_in[16], temp_out[16];
  655. // First transform rows
  656. for (i = 0; i < 16; ++i) {
  657. idct16_c(input, outptr);
  658. input += 16;
  659. outptr += 16;
  660. }
  661. // Then transform columns
  662. for (i = 0; i < 16; ++i) {
  663. for (j = 0; j < 16; ++j) temp_in[j] = out[j * 16 + i];
  664. idct16_c(temp_in, temp_out);
  665. for (j = 0; j < 16; ++j) {
  666. dest[j * stride + i] = clip_pixel_add(dest[j * stride + i],
  667. ROUND_POWER_OF_TWO(temp_out[j], 6));
  668. }
  669. }
  670. }
  671. void vpx_idct16x16_38_add_c(const tran_low_t *input, uint8_t *dest,
  672. int stride) {
  673. int i, j;
  674. tran_low_t out[16 * 16] = { 0 };
  675. tran_low_t *outptr = out;
  676. tran_low_t temp_in[16], temp_out[16];
  677. // First transform rows. Since all non-zero dct coefficients are in
  678. // upper-left 8x8 area, we only need to calculate first 8 rows here.
  679. for (i = 0; i < 8; ++i) {
  680. idct16_c(input, outptr);
  681. input += 16;
  682. outptr += 16;
  683. }
  684. // Then transform columns
  685. for (i = 0; i < 16; ++i) {
  686. for (j = 0; j < 16; ++j) temp_in[j] = out[j * 16 + i];
  687. idct16_c(temp_in, temp_out);
  688. for (j = 0; j < 16; ++j) {
  689. dest[j * stride + i] = clip_pixel_add(dest[j * stride + i],
  690. ROUND_POWER_OF_TWO(temp_out[j], 6));
  691. }
  692. }
  693. }
  694. void vpx_idct16x16_10_add_c(const tran_low_t *input, uint8_t *dest,
  695. int stride) {
  696. int i, j;
  697. tran_low_t out[16 * 16] = { 0 };
  698. tran_low_t *outptr = out;
  699. tran_low_t temp_in[16], temp_out[16];
  700. // First transform rows. Since all non-zero dct coefficients are in
  701. // upper-left 4x4 area, we only need to calculate first 4 rows here.
  702. for (i = 0; i < 4; ++i) {
  703. idct16_c(input, outptr);
  704. input += 16;
  705. outptr += 16;
  706. }
  707. // Then transform columns
  708. for (i = 0; i < 16; ++i) {
  709. for (j = 0; j < 16; ++j) temp_in[j] = out[j * 16 + i];
  710. idct16_c(temp_in, temp_out);
  711. for (j = 0; j < 16; ++j) {
  712. dest[j * stride + i] = clip_pixel_add(dest[j * stride + i],
  713. ROUND_POWER_OF_TWO(temp_out[j], 6));
  714. }
  715. }
  716. }
  717. void vpx_idct16x16_1_add_c(const tran_low_t *input, uint8_t *dest, int stride) {
  718. int i, j;
  719. tran_high_t a1;
  720. tran_low_t out =
  721. WRAPLOW(dct_const_round_shift((int16_t)input[0] * cospi_16_64));
  722. out = WRAPLOW(dct_const_round_shift(out * cospi_16_64));
  723. a1 = ROUND_POWER_OF_TWO(out, 6);
  724. for (j = 0; j < 16; ++j) {
  725. for (i = 0; i < 16; ++i) dest[i] = clip_pixel_add(dest[i], a1);
  726. dest += stride;
  727. }
  728. }
  729. void idct32_c(const tran_low_t *input, tran_low_t *output) {
  730. int16_t step1[32], step2[32];
  731. tran_high_t temp1, temp2;
  732. // stage 1
  733. step1[0] = (int16_t)input[0];
  734. step1[1] = (int16_t)input[16];
  735. step1[2] = (int16_t)input[8];
  736. step1[3] = (int16_t)input[24];
  737. step1[4] = (int16_t)input[4];
  738. step1[5] = (int16_t)input[20];
  739. step1[6] = (int16_t)input[12];
  740. step1[7] = (int16_t)input[28];
  741. step1[8] = (int16_t)input[2];
  742. step1[9] = (int16_t)input[18];
  743. step1[10] = (int16_t)input[10];
  744. step1[11] = (int16_t)input[26];
  745. step1[12] = (int16_t)input[6];
  746. step1[13] = (int16_t)input[22];
  747. step1[14] = (int16_t)input[14];
  748. step1[15] = (int16_t)input[30];
  749. temp1 = (int16_t)input[1] * cospi_31_64 - (int16_t)input[31] * cospi_1_64;
  750. temp2 = (int16_t)input[1] * cospi_1_64 + (int16_t)input[31] * cospi_31_64;
  751. step1[16] = WRAPLOW(dct_const_round_shift(temp1));
  752. step1[31] = WRAPLOW(dct_const_round_shift(temp2));
  753. temp1 = (int16_t)input[17] * cospi_15_64 - (int16_t)input[15] * cospi_17_64;
  754. temp2 = (int16_t)input[17] * cospi_17_64 + (int16_t)input[15] * cospi_15_64;
  755. step1[17] = WRAPLOW(dct_const_round_shift(temp1));
  756. step1[30] = WRAPLOW(dct_const_round_shift(temp2));
  757. temp1 = (int16_t)input[9] * cospi_23_64 - (int16_t)input[23] * cospi_9_64;
  758. temp2 = (int16_t)input[9] * cospi_9_64 + (int16_t)input[23] * cospi_23_64;
  759. step1[18] = WRAPLOW(dct_const_round_shift(temp1));
  760. step1[29] = WRAPLOW(dct_const_round_shift(temp2));
  761. temp1 = (int16_t)input[25] * cospi_7_64 - (int16_t)input[7] * cospi_25_64;
  762. temp2 = (int16_t)input[25] * cospi_25_64 + (int16_t)input[7] * cospi_7_64;
  763. step1[19] = WRAPLOW(dct_const_round_shift(temp1));
  764. step1[28] = WRAPLOW(dct_const_round_shift(temp2));
  765. temp1 = (int16_t)input[5] * cospi_27_64 - (int16_t)input[27] * cospi_5_64;
  766. temp2 = (int16_t)input[5] * cospi_5_64 + (int16_t)input[27] * cospi_27_64;
  767. step1[20] = WRAPLOW(dct_const_round_shift(temp1));
  768. step1[27] = WRAPLOW(dct_const_round_shift(temp2));
  769. temp1 = (int16_t)input[21] * cospi_11_64 - (int16_t)input[11] * cospi_21_64;
  770. temp2 = (int16_t)input[21] * cospi_21_64 + (int16_t)input[11] * cospi_11_64;
  771. step1[21] = WRAPLOW(dct_const_round_shift(temp1));
  772. step1[26] = WRAPLOW(dct_const_round_shift(temp2));
  773. temp1 = (int16_t)input[13] * cospi_19_64 - (int16_t)input[19] * cospi_13_64;
  774. temp2 = (int16_t)input[13] * cospi_13_64 + (int16_t)input[19] * cospi_19_64;
  775. step1[22] = WRAPLOW(dct_const_round_shift(temp1));
  776. step1[25] = WRAPLOW(dct_const_round_shift(temp2));
  777. temp1 = (int16_t)input[29] * cospi_3_64 - (int16_t)input[3] * cospi_29_64;
  778. temp2 = (int16_t)input[29] * cospi_29_64 + (int16_t)input[3] * cospi_3_64;
  779. step1[23] = WRAPLOW(dct_const_round_shift(temp1));
  780. step1[24] = WRAPLOW(dct_const_round_shift(temp2));
  781. // stage 2
  782. step2[0] = step1[0];
  783. step2[1] = step1[1];
  784. step2[2] = step1[2];
  785. step2[3] = step1[3];
  786. step2[4] = step1[4];
  787. step2[5] = step1[5];
  788. step2[6] = step1[6];
  789. step2[7] = step1[7];
  790. temp1 = step1[8] * cospi_30_64 - step1[15] * cospi_2_64;
  791. temp2 = step1[8] * cospi_2_64 + step1[15] * cospi_30_64;
  792. step2[8] = WRAPLOW(dct_const_round_shift(temp1));
  793. step2[15] = WRAPLOW(dct_const_round_shift(temp2));
  794. temp1 = step1[9] * cospi_14_64 - step1[14] * cospi_18_64;
  795. temp2 = step1[9] * cospi_18_64 + step1[14] * cospi_14_64;
  796. step2[9] = WRAPLOW(dct_const_round_shift(temp1));
  797. step2[14] = WRAPLOW(dct_const_round_shift(temp2));
  798. temp1 = step1[10] * cospi_22_64 - step1[13] * cospi_10_64;
  799. temp2 = step1[10] * cospi_10_64 + step1[13] * cospi_22_64;
  800. step2[10] = WRAPLOW(dct_const_round_shift(temp1));
  801. step2[13] = WRAPLOW(dct_const_round_shift(temp2));
  802. temp1 = step1[11] * cospi_6_64 - step1[12] * cospi_26_64;
  803. temp2 = step1[11] * cospi_26_64 + step1[12] * cospi_6_64;
  804. step2[11] = WRAPLOW(dct_const_round_shift(temp1));
  805. step2[12] = WRAPLOW(dct_const_round_shift(temp2));
  806. step2[16] = WRAPLOW(step1[16] + step1[17]);
  807. step2[17] = WRAPLOW(step1[16] - step1[17]);
  808. step2[18] = WRAPLOW(-step1[18] + step1[19]);
  809. step2[19] = WRAPLOW(step1[18] + step1[19]);
  810. step2[20] = WRAPLOW(step1[20] + step1[21]);
  811. step2[21] = WRAPLOW(step1[20] - step1[21]);
  812. step2[22] = WRAPLOW(-step1[22] + step1[23]);
  813. step2[23] = WRAPLOW(step1[22] + step1[23]);
  814. step2[24] = WRAPLOW(step1[24] + step1[25]);
  815. step2[25] = WRAPLOW(step1[24] - step1[25]);
  816. step2[26] = WRAPLOW(-step1[26] + step1[27]);
  817. step2[27] = WRAPLOW(step1[26] + step1[27]);
  818. step2[28] = WRAPLOW(step1[28] + step1[29]);
  819. step2[29] = WRAPLOW(step1[28] - step1[29]);
  820. step2[30] = WRAPLOW(-step1[30] + step1[31]);
  821. step2[31] = WRAPLOW(step1[30] + step1[31]);
  822. // stage 3
  823. step1[0] = step2[0];
  824. step1[1] = step2[1];
  825. step1[2] = step2[2];
  826. step1[3] = step2[3];
  827. temp1 = step2[4] * cospi_28_64 - step2[7] * cospi_4_64;
  828. temp2 = step2[4] * cospi_4_64 + step2[7] * cospi_28_64;
  829. step1[4] = WRAPLOW(dct_const_round_shift(temp1));
  830. step1[7] = WRAPLOW(dct_const_round_shift(temp2));
  831. temp1 = step2[5] * cospi_12_64 - step2[6] * cospi_20_64;
  832. temp2 = step2[5] * cospi_20_64 + step2[6] * cospi_12_64;
  833. step1[5] = WRAPLOW(dct_const_round_shift(temp1));
  834. step1[6] = WRAPLOW(dct_const_round_shift(temp2));
  835. step1[8] = WRAPLOW(step2[8] + step2[9]);
  836. step1[9] = WRAPLOW(step2[8] - step2[9]);
  837. step1[10] = WRAPLOW(-step2[10] + step2[11]);
  838. step1[11] = WRAPLOW(step2[10] + step2[11]);
  839. step1[12] = WRAPLOW(step2[12] + step2[13]);
  840. step1[13] = WRAPLOW(step2[12] - step2[13]);
  841. step1[14] = WRAPLOW(-step2[14] + step2[15]);
  842. step1[15] = WRAPLOW(step2[14] + step2[15]);
  843. step1[16] = step2[16];
  844. step1[31] = step2[31];
  845. temp1 = -step2[17] * cospi_4_64 + step2[30] * cospi_28_64;
  846. temp2 = step2[17] * cospi_28_64 + step2[30] * cospi_4_64;
  847. step1[17] = WRAPLOW(dct_const_round_shift(temp1));
  848. step1[30] = WRAPLOW(dct_const_round_shift(temp2));
  849. temp1 = -step2[18] * cospi_28_64 - step2[29] * cospi_4_64;
  850. temp2 = -step2[18] * cospi_4_64 + step2[29] * cospi_28_64;
  851. step1[18] = WRAPLOW(dct_const_round_shift(temp1));
  852. step1[29] = WRAPLOW(dct_const_round_shift(temp2));
  853. step1[19] = step2[19];
  854. step1[20] = step2[20];
  855. temp1 = -step2[21] * cospi_20_64 + step2[26] * cospi_12_64;
  856. temp2 = step2[21] * cospi_12_64 + step2[26] * cospi_20_64;
  857. step1[21] = WRAPLOW(dct_const_round_shift(temp1));
  858. step1[26] = WRAPLOW(dct_const_round_shift(temp2));
  859. temp1 = -step2[22] * cospi_12_64 - step2[25] * cospi_20_64;
  860. temp2 = -step2[22] * cospi_20_64 + step2[25] * cospi_12_64;
  861. step1[22] = WRAPLOW(dct_const_round_shift(temp1));
  862. step1[25] = WRAPLOW(dct_const_round_shift(temp2));
  863. step1[23] = step2[23];
  864. step1[24] = step2[24];
  865. step1[27] = step2[27];
  866. step1[28] = step2[28];
  867. // stage 4
  868. temp1 = (step1[0] + step1[1]) * cospi_16_64;
  869. temp2 = (step1[0] - step1[1]) * cospi_16_64;
  870. step2[0] = WRAPLOW(dct_const_round_shift(temp1));
  871. step2[1] = WRAPLOW(dct_const_round_shift(temp2));
  872. temp1 = step1[2] * cospi_24_64 - step1[3] * cospi_8_64;
  873. temp2 = step1[2] * cospi_8_64 + step1[3] * cospi_24_64;
  874. step2[2] = WRAPLOW(dct_const_round_shift(temp1));
  875. step2[3] = WRAPLOW(dct_const_round_shift(temp2));
  876. step2[4] = WRAPLOW(step1[4] + step1[5]);
  877. step2[5] = WRAPLOW(step1[4] - step1[5]);
  878. step2[6] = WRAPLOW(-step1[6] + step1[7]);
  879. step2[7] = WRAPLOW(step1[6] + step1[7]);
  880. step2[8] = step1[8];
  881. step2[15] = step1[15];
  882. temp1 = -step1[9] * cospi_8_64 + step1[14] * cospi_24_64;
  883. temp2 = step1[9] * cospi_24_64 + step1[14] * cospi_8_64;
  884. step2[9] = WRAPLOW(dct_const_round_shift(temp1));
  885. step2[14] = WRAPLOW(dct_const_round_shift(temp2));
  886. temp1 = -step1[10] * cospi_24_64 - step1[13] * cospi_8_64;
  887. temp2 = -step1[10] * cospi_8_64 + step1[13] * cospi_24_64;
  888. step2[10] = WRAPLOW(dct_const_round_shift(temp1));
  889. step2[13] = WRAPLOW(dct_const_round_shift(temp2));
  890. step2[11] = step1[11];
  891. step2[12] = step1[12];
  892. step2[16] = WRAPLOW(step1[16] + step1[19]);
  893. step2[17] = WRAPLOW(step1[17] + step1[18]);
  894. step2[18] = WRAPLOW(step1[17] - step1[18]);
  895. step2[19] = WRAPLOW(step1[16] - step1[19]);
  896. step2[20] = WRAPLOW(-step1[20] + step1[23]);
  897. step2[21] = WRAPLOW(-step1[21] + step1[22]);
  898. step2[22] = WRAPLOW(step1[21] + step1[22]);
  899. step2[23] = WRAPLOW(step1[20] + step1[23]);
  900. step2[24] = WRAPLOW(step1[24] + step1[27]);
  901. step2[25] = WRAPLOW(step1[25] + step1[26]);
  902. step2[26] = WRAPLOW(step1[25] - step1[26]);
  903. step2[27] = WRAPLOW(step1[24] - step1[27]);
  904. step2[28] = WRAPLOW(-step1[28] + step1[31]);
  905. step2[29] = WRAPLOW(-step1[29] + step1[30]);
  906. step2[30] = WRAPLOW(step1[29] + step1[30]);
  907. step2[31] = WRAPLOW(step1[28] + step1[31]);
  908. // stage 5
  909. step1[0] = WRAPLOW(step2[0] + step2[3]);
  910. step1[1] = WRAPLOW(step2[1] + step2[2]);
  911. step1[2] = WRAPLOW(step2[1] - step2[2]);
  912. step1[3] = WRAPLOW(step2[0] - step2[3]);
  913. step1[4] = step2[4];
  914. temp1 = (step2[6] - step2[5]) * cospi_16_64;
  915. temp2 = (step2[5] + step2[6]) * cospi_16_64;
  916. step1[5] = WRAPLOW(dct_const_round_shift(temp1));
  917. step1[6] = WRAPLOW(dct_const_round_shift(temp2));
  918. step1[7] = step2[7];
  919. step1[8] = WRAPLOW(step2[8] + step2[11]);
  920. step1[9] = WRAPLOW(step2[9] + step2[10]);
  921. step1[10] = WRAPLOW(step2[9] - step2[10]);
  922. step1[11] = WRAPLOW(step2[8] - step2[11]);
  923. step1[12] = WRAPLOW(-step2[12] + step2[15]);
  924. step1[13] = WRAPLOW(-step2[13] + step2[14]);
  925. step1[14] = WRAPLOW(step2[13] + step2[14]);
  926. step1[15] = WRAPLOW(step2[12] + step2[15]);
  927. step1[16] = step2[16];
  928. step1[17] = step2[17];
  929. temp1 = -step2[18] * cospi_8_64 + step2[29] * cospi_24_64;
  930. temp2 = step2[18] * cospi_24_64 + step2[29] * cospi_8_64;
  931. step1[18] = WRAPLOW(dct_const_round_shift(temp1));
  932. step1[29] = WRAPLOW(dct_const_round_shift(temp2));
  933. temp1 = -step2[19] * cospi_8_64 + step2[28] * cospi_24_64;
  934. temp2 = step2[19] * cospi_24_64 + step2[28] * cospi_8_64;
  935. step1[19] = WRAPLOW(dct_const_round_shift(temp1));
  936. step1[28] = WRAPLOW(dct_const_round_shift(temp2));
  937. temp1 = -step2[20] * cospi_24_64 - step2[27] * cospi_8_64;
  938. temp2 = -step2[20] * cospi_8_64 + step2[27] * cospi_24_64;
  939. step1[20] = WRAPLOW(dct_const_round_shift(temp1));
  940. step1[27] = WRAPLOW(dct_const_round_shift(temp2));
  941. temp1 = -step2[21] * cospi_24_64 - step2[26] * cospi_8_64;
  942. temp2 = -step2[21] * cospi_8_64 + step2[26] * cospi_24_64;
  943. step1[21] = WRAPLOW(dct_const_round_shift(temp1));
  944. step1[26] = WRAPLOW(dct_const_round_shift(temp2));
  945. step1[22] = step2[22];
  946. step1[23] = step2[23];
  947. step1[24] = step2[24];
  948. step1[25] = step2[25];
  949. step1[30] = step2[30];
  950. step1[31] = step2[31];
  951. // stage 6
  952. step2[0] = WRAPLOW(step1[0] + step1[7]);
  953. step2[1] = WRAPLOW(step1[1] + step1[6]);
  954. step2[2] = WRAPLOW(step1[2] + step1[5]);
  955. step2[3] = WRAPLOW(step1[3] + step1[4]);
  956. step2[4] = WRAPLOW(step1[3] - step1[4]);
  957. step2[5] = WRAPLOW(step1[2] - step1[5]);
  958. step2[6] = WRAPLOW(step1[1] - step1[6]);
  959. step2[7] = WRAPLOW(step1[0] - step1[7]);
  960. step2[8] = step1[8];
  961. step2[9] = step1[9];
  962. temp1 = (-step1[10] + step1[13]) * cospi_16_64;
  963. temp2 = (step1[10] + step1[13]) * cospi_16_64;
  964. step2[10] = WRAPLOW(dct_const_round_shift(temp1));
  965. step2[13] = WRAPLOW(dct_const_round_shift(temp2));
  966. temp1 = (-step1[11] + step1[12]) * cospi_16_64;
  967. temp2 = (step1[11] + step1[12]) * cospi_16_64;
  968. step2[11] = WRAPLOW(dct_const_round_shift(temp1));
  969. step2[12] = WRAPLOW(dct_const_round_shift(temp2));
  970. step2[14] = step1[14];
  971. step2[15] = step1[15];
  972. step2[16] = WRAPLOW(step1[16] + step1[23]);
  973. step2[17] = WRAPLOW(step1[17] + step1[22]);
  974. step2[18] = WRAPLOW(step1[18] + step1[21]);
  975. step2[19] = WRAPLOW(step1[19] + step1[20]);
  976. step2[20] = WRAPLOW(step1[19] - step1[20]);
  977. step2[21] = WRAPLOW(step1[18] - step1[21]);
  978. step2[22] = WRAPLOW(step1[17] - step1[22]);
  979. step2[23] = WRAPLOW(step1[16] - step1[23]);
  980. step2[24] = WRAPLOW(-step1[24] + step1[31]);
  981. step2[25] = WRAPLOW(-step1[25] + step1[30]);
  982. step2[26] = WRAPLOW(-step1[26] + step1[29]);
  983. step2[27] = WRAPLOW(-step1[27] + step1[28]);
  984. step2[28] = WRAPLOW(step1[27] + step1[28]);
  985. step2[29] = WRAPLOW(step1[26] + step1[29]);
  986. step2[30] = WRAPLOW(step1[25] + step1[30]);
  987. step2[31] = WRAPLOW(step1[24] + step1[31]);
  988. // stage 7
  989. step1[0] = WRAPLOW(step2[0] + step2[15]);
  990. step1[1] = WRAPLOW(step2[1] + step2[14]);
  991. step1[2] = WRAPLOW(step2[2] + step2[13]);
  992. step1[3] = WRAPLOW(step2[3] + step2[12]);
  993. step1[4] = WRAPLOW(step2[4] + step2[11]);
  994. step1[5] = WRAPLOW(step2[5] + step2[10]);
  995. step1[6] = WRAPLOW(step2[6] + step2[9]);
  996. step1[7] = WRAPLOW(step2[7] + step2[8]);
  997. step1[8] = WRAPLOW(step2[7] - step2[8]);
  998. step1[9] = WRAPLOW(step2[6] - step2[9]);
  999. step1[10] = WRAPLOW(step2[5] - step2[10]);
  1000. step1[11] = WRAPLOW(step2[4] - step2[11]);
  1001. step1[12] = WRAPLOW(step2[3] - step2[12]);
  1002. step1[13] = WRAPLOW(step2[2] - step2[13]);
  1003. step1[14] = WRAPLOW(step2[1] - step2[14]);
  1004. step1[15] = WRAPLOW(step2[0] - step2[15]);
  1005. step1[16] = step2[16];
  1006. step1[17] = step2[17];
  1007. step1[18] = step2[18];
  1008. step1[19] = step2[19];
  1009. temp1 = (-step2[20] + step2[27]) * cospi_16_64;
  1010. temp2 = (step2[20] + step2[27]) * cospi_16_64;
  1011. step1[20] = WRAPLOW(dct_const_round_shift(temp1));
  1012. step1[27] = WRAPLOW(dct_const_round_shift(temp2));
  1013. temp1 = (-step2[21] + step2[26]) * cospi_16_64;
  1014. temp2 = (step2[21] + step2[26]) * cospi_16_64;
  1015. step1[21] = WRAPLOW(dct_const_round_shift(temp1));
  1016. step1[26] = WRAPLOW(dct_const_round_shift(temp2));
  1017. temp1 = (-step2[22] + step2[25]) * cospi_16_64;
  1018. temp2 = (step2[22] + step2[25]) * cospi_16_64;
  1019. step1[22] = WRAPLOW(dct_const_round_shift(temp1));
  1020. step1[25] = WRAPLOW(dct_const_round_shift(temp2));
  1021. temp1 = (-step2[23] + step2[24]) * cospi_16_64;
  1022. temp2 = (step2[23] + step2[24]) * cospi_16_64;
  1023. step1[23] = WRAPLOW(dct_const_round_shift(temp1));
  1024. step1[24] = WRAPLOW(dct_const_round_shift(temp2));
  1025. step1[28] = step2[28];
  1026. step1[29] = step2[29];
  1027. step1[30] = step2[30];
  1028. step1[31] = step2[31];
  1029. // final stage
  1030. output[0] = WRAPLOW(step1[0] + step1[31]);
  1031. output[1] = WRAPLOW(step1[1] + step1[30]);
  1032. output[2] = WRAPLOW(step1[2] + step1[29]);
  1033. output[3] = WRAPLOW(step1[3] + step1[28]);
  1034. output[4] = WRAPLOW(step1[4] + step1[27]);
  1035. output[5] = WRAPLOW(step1[5] + step1[26]);
  1036. output[6] = WRAPLOW(step1[6] + step1[25]);
  1037. output[7] = WRAPLOW(step1[7] + step1[24]);
  1038. output[8] = WRAPLOW(step1[8] + step1[23]);
  1039. output[9] = WRAPLOW(step1[9] + step1[22]);
  1040. output[10] = WRAPLOW(step1[10] + step1[21]);
  1041. output[11] = WRAPLOW(step1[11] + step1[20]);
  1042. output[12] = WRAPLOW(step1[12] + step1[19]);
  1043. output[13] = WRAPLOW(step1[13] + step1[18]);
  1044. output[14] = WRAPLOW(step1[14] + step1[17]);
  1045. output[15] = WRAPLOW(step1[15] + step1[16]);
  1046. output[16] = WRAPLOW(step1[15] - step1[16]);
  1047. output[17] = WRAPLOW(step1[14] - step1[17]);
  1048. output[18] = WRAPLOW(step1[13] - step1[18]);
  1049. output[19] = WRAPLOW(step1[12] - step1[19]);
  1050. output[20] = WRAPLOW(step1[11] - step1[20]);
  1051. output[21] = WRAPLOW(step1[10] - step1[21]);
  1052. output[22] = WRAPLOW(step1[9] - step1[22]);
  1053. output[23] = WRAPLOW(step1[8] - step1[23]);
  1054. output[24] = WRAPLOW(step1[7] - step1[24]);
  1055. output[25] = WRAPLOW(step1[6] - step1[25]);
  1056. output[26] = WRAPLOW(step1[5] - step1[26]);
  1057. output[27] = WRAPLOW(step1[4] - step1[27]);
  1058. output[28] = WRAPLOW(step1[3] - step1[28]);
  1059. output[29] = WRAPLOW(step1[2] - step1[29]);
  1060. output[30] = WRAPLOW(step1[1] - step1[30]);
  1061. output[31] = WRAPLOW(step1[0] - step1[31]);
  1062. }
  1063. void vpx_idct32x32_1024_add_c(const tran_low_t *input, uint8_t *dest,
  1064. int stride) {
  1065. int i, j;
  1066. tran_low_t out[32 * 32];
  1067. tran_low_t *outptr = out;
  1068. tran_low_t temp_in[32], temp_out[32];
  1069. // Rows
  1070. for (i = 0; i < 32; ++i) {
  1071. int16_t zero_coeff = 0;
  1072. for (j = 0; j < 32; ++j) zero_coeff |= input[j];
  1073. if (zero_coeff)
  1074. idct32_c(input, outptr);
  1075. else
  1076. memset(outptr, 0, sizeof(tran_low_t) * 32);
  1077. input += 32;
  1078. outptr += 32;
  1079. }
  1080. // Columns
  1081. for (i = 0; i < 32; ++i) {
  1082. for (j = 0; j < 32; ++j) temp_in[j] = out[j * 32 + i];
  1083. idct32_c(temp_in, temp_out);
  1084. for (j = 0; j < 32; ++j) {
  1085. dest[j * stride + i] = clip_pixel_add(dest[j * stride + i],
  1086. ROUND_POWER_OF_TWO(temp_out[j], 6));
  1087. }
  1088. }
  1089. }
  1090. void vpx_idct32x32_135_add_c(const tran_low_t *input, uint8_t *dest,
  1091. int stride) {
  1092. int i, j;
  1093. tran_low_t out[32 * 32] = { 0 };
  1094. tran_low_t *outptr = out;
  1095. tran_low_t temp_in[32], temp_out[32];
  1096. // Rows
  1097. // Only upper-left 16x16 has non-zero coeff
  1098. for (i = 0; i < 16; ++i) {
  1099. idct32_c(input, outptr);
  1100. input += 32;
  1101. outptr += 32;
  1102. }
  1103. // Columns
  1104. for (i = 0; i < 32; ++i) {
  1105. for (j = 0; j < 32; ++j) temp_in[j] = out[j * 32 + i];
  1106. idct32_c(temp_in, temp_out);
  1107. for (j = 0; j < 32; ++j) {
  1108. dest[j * stride + i] = clip_pixel_add(dest[j * stride + i],
  1109. ROUND_POWER_OF_TWO(temp_out[j], 6));
  1110. }
  1111. }
  1112. }
  1113. void vpx_idct32x32_34_add_c(const tran_low_t *input, uint8_t *dest,
  1114. int stride) {
  1115. int i, j;
  1116. tran_low_t out[32 * 32] = { 0 };
  1117. tran_low_t *outptr = out;
  1118. tran_low_t temp_in[32], temp_out[32];
  1119. // Rows
  1120. // Only upper-left 8x8 has non-zero coeff
  1121. for (i = 0; i < 8; ++i) {
  1122. idct32_c(input, outptr);
  1123. input += 32;
  1124. outptr += 32;
  1125. }
  1126. // Columns
  1127. for (i = 0; i < 32; ++i) {
  1128. for (j = 0; j < 32; ++j) temp_in[j] = out[j * 32 + i];
  1129. idct32_c(temp_in, temp_out);
  1130. for (j = 0; j < 32; ++j) {
  1131. dest[j * stride + i] = clip_pixel_add(dest[j * stride + i],
  1132. ROUND_POWER_OF_TWO(temp_out[j], 6));
  1133. }
  1134. }
  1135. }
  1136. void vpx_idct32x32_1_add_c(const tran_low_t *input, uint8_t *dest, int stride) {
  1137. int i, j;
  1138. tran_high_t a1;
  1139. tran_low_t out =
  1140. WRAPLOW(dct_const_round_shift((int16_t)input[0] * cospi_16_64));
  1141. out = WRAPLOW(dct_const_round_shift(out * cospi_16_64));
  1142. a1 = ROUND_POWER_OF_TWO(out, 6);
  1143. for (j = 0; j < 32; ++j) {
  1144. for (i = 0; i < 32; ++i) dest[i] = clip_pixel_add(dest[i], a1);
  1145. dest += stride;
  1146. }
  1147. }
  1148. #if CONFIG_VP9_HIGHBITDEPTH
  1149. // 12 signal input bits + 7 2D forward transform amplify bits + 5 1D inverse
  1150. // transform amplify bits + 1 bit for contingency in rounding and quantizing
  1151. #define HIGHBD_VALID_TXFM_MAGNITUDE_RANGE (1 << 25)
  1152. static INLINE int detect_invalid_highbd_input(const tran_low_t *input,
  1153. int size) {
  1154. int i;
  1155. for (i = 0; i < size; ++i)
  1156. if (abs(input[i]) >= HIGHBD_VALID_TXFM_MAGNITUDE_RANGE) return 1;
  1157. return 0;
  1158. }
  1159. void vpx_highbd_iwht4x4_16_add_c(const tran_low_t *input, uint16_t *dest,
  1160. int stride, int bd) {
  1161. /* 4-point reversible, orthonormal inverse Walsh-Hadamard in 3.5 adds,
  1162. 0.5 shifts per pixel. */
  1163. int i;
  1164. tran_low_t output[16];
  1165. tran_high_t a1, b1, c1, d1, e1;
  1166. const tran_low_t *ip = input;
  1167. tran_low_t *op = output;
  1168. for (i = 0; i < 4; i++) {
  1169. a1 = ip[0] >> UNIT_QUANT_SHIFT;
  1170. c1 = ip[1] >> UNIT_QUANT_SHIFT;
  1171. d1 = ip[2] >> UNIT_QUANT_SHIFT;
  1172. b1 = ip[3] >> UNIT_QUANT_SHIFT;
  1173. a1 += c1;
  1174. d1 -= b1;
  1175. e1 = (a1 - d1) >> 1;
  1176. b1 = e1 - b1;
  1177. c1 = e1 - c1;
  1178. a1 -= b1;
  1179. d1 += c1;
  1180. op[0] = HIGHBD_WRAPLOW(a1, bd);
  1181. op[1] = HIGHBD_WRAPLOW(b1, bd);
  1182. op[2] = HIGHBD_WRAPLOW(c1, bd);
  1183. op[3] = HIGHBD_WRAPLOW(d1, bd);
  1184. ip += 4;
  1185. op += 4;
  1186. }
  1187. ip = output;
  1188. for (i = 0; i < 4; i++) {
  1189. a1 = ip[4 * 0];
  1190. c1 = ip[4 * 1];
  1191. d1 = ip[4 * 2];
  1192. b1 = ip[4 * 3];
  1193. a1 += c1;
  1194. d1 -= b1;
  1195. e1 = (a1 - d1) >> 1;
  1196. b1 = e1 - b1;
  1197. c1 = e1 - c1;
  1198. a1 -= b1;
  1199. d1 += c1;
  1200. dest[stride * 0] =
  1201. highbd_clip_pixel_add(dest[stride * 0], HIGHBD_WRAPLOW(a1, bd), bd);
  1202. dest[stride * 1] =
  1203. highbd_clip_pixel_add(dest[stride * 1], HIGHBD_WRAPLOW(b1, bd), bd);
  1204. dest[stride * 2] =
  1205. highbd_clip_pixel_add(dest[stride * 2], HIGHBD_WRAPLOW(c1, bd), bd);
  1206. dest[stride * 3] =
  1207. highbd_clip_pixel_add(dest[stride * 3], HIGHBD_WRAPLOW(d1, bd), bd);
  1208. ip++;
  1209. dest++;
  1210. }
  1211. }
  1212. void vpx_highbd_iwht4x4_1_add_c(const tran_low_t *input, uint16_t *dest,
  1213. int stride, int bd) {
  1214. int i;
  1215. tran_high_t a1, e1;
  1216. tran_low_t tmp[4];
  1217. const tran_low_t *ip = input;
  1218. tran_low_t *op = tmp;
  1219. (void)bd;
  1220. a1 = ip[0] >> UNIT_QUANT_SHIFT;
  1221. e1 = a1 >> 1;
  1222. a1 -= e1;
  1223. op[0] = HIGHBD_WRAPLOW(a1, bd);
  1224. op[1] = op[2] = op[3] = HIGHBD_WRAPLOW(e1, bd);
  1225. ip = tmp;
  1226. for (i = 0; i < 4; i++) {
  1227. e1 = ip[0] >> 1;
  1228. a1 = ip[0] - e1;
  1229. dest[stride * 0] = highbd_clip_pixel_add(dest[stride * 0], a1, bd);
  1230. dest[stride * 1] = highbd_clip_pixel_add(dest[stride * 1], e1, bd);
  1231. dest[stride * 2] = highbd_clip_pixel_add(dest[stride * 2], e1, bd);
  1232. dest[stride * 3] = highbd_clip_pixel_add(dest[stride * 3], e1, bd);
  1233. ip++;
  1234. dest++;
  1235. }
  1236. }
  1237. void vpx_highbd_iadst4_c(const tran_low_t *input, tran_low_t *output, int bd) {
  1238. tran_high_t s0, s1, s2, s3, s4, s5, s6, s7;
  1239. tran_low_t x0 = input[0];
  1240. tran_low_t x1 = input[1];
  1241. tran_low_t x2 = input[2];
  1242. tran_low_t x3 = input[3];
  1243. (void)bd;
  1244. if (detect_invalid_highbd_input(input, 4)) {
  1245. #if CONFIG_COEFFICIENT_RANGE_CHECKING
  1246. assert(0 && "invalid highbd txfm input");
  1247. #endif // CONFIG_COEFFICIENT_RANGE_CHECKING
  1248. memset(output, 0, sizeof(*output) * 4);
  1249. return;
  1250. }
  1251. if (!(x0 | x1 | x2 | x3)) {
  1252. memset(output, 0, 4 * sizeof(*output));
  1253. return;
  1254. }
  1255. s0 = (tran_high_t)sinpi_1_9 * x0;
  1256. s1 = (tran_high_t)sinpi_2_9 * x0;
  1257. s2 = (tran_high_t)sinpi_3_9 * x1;
  1258. s3 = (tran_high_t)sinpi_4_9 * x2;
  1259. s4 = (tran_high_t)sinpi_1_9 * x2;
  1260. s5 = (tran_high_t)sinpi_2_9 * x3;
  1261. s6 = (tran_high_t)sinpi_4_9 * x3;
  1262. s7 = (tran_high_t)HIGHBD_WRAPLOW(x0 - x2 + x3, bd);
  1263. s0 = s0 + s3 + s5;
  1264. s1 = s1 - s4 - s6;
  1265. s3 = s2;
  1266. s2 = sinpi_3_9 * s7;
  1267. // 1-D transform scaling factor is sqrt(2).
  1268. // The overall dynamic range is 14b (input) + 14b (multiplication scaling)
  1269. // + 1b (addition) = 29b.
  1270. // Hence the output bit depth is 15b.
  1271. output[0] = HIGHBD_WRAPLOW(dct_const_round_shift(s0 + s3), bd);
  1272. output[1] = HIGHBD_WRAPLOW(dct_const_round_shift(s1 + s3), bd);
  1273. output[2] = HIGHBD_WRAPLOW(dct_const_round_shift(s2), bd);
  1274. output[3] = HIGHBD_WRAPLOW(dct_const_round_shift(s0 + s1 - s3), bd);
  1275. }
  1276. void vpx_highbd_idct4_c(const tran_low_t *input, tran_low_t *output, int bd) {
  1277. tran_low_t step[4];
  1278. tran_high_t temp1, temp2;
  1279. (void)bd;
  1280. if (detect_invalid_highbd_input(input, 4)) {
  1281. #if CONFIG_COEFFICIENT_RANGE_CHECKING
  1282. assert(0 && "invalid highbd txfm input");
  1283. #endif // CONFIG_COEFFICIENT_RANGE_CHECKING
  1284. memset(output, 0, sizeof(*output) * 4);
  1285. return;
  1286. }
  1287. // stage 1
  1288. temp1 = (input[0] + input[2]) * (tran_high_t)cospi_16_64;
  1289. temp2 = (input[0] - input[2]) * (tran_high_t)cospi_16_64;
  1290. step[0] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1291. step[1] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1292. temp1 =
  1293. input[1] * (tran_high_t)cospi_24_64 - input[3] * (tran_high_t)cospi_8_64;
  1294. temp2 =
  1295. input[1] * (tran_high_t)cospi_8_64 + input[3] * (tran_high_t)cospi_24_64;
  1296. step[2] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1297. step[3] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1298. // stage 2
  1299. output[0] = HIGHBD_WRAPLOW(step[0] + step[3], bd);
  1300. output[1] = HIGHBD_WRAPLOW(step[1] + step[2], bd);
  1301. output[2] = HIGHBD_WRAPLOW(step[1] - step[2], bd);
  1302. output[3] = HIGHBD_WRAPLOW(step[0] - step[3], bd);
  1303. }
  1304. void vpx_highbd_idct4x4_16_add_c(const tran_low_t *input, uint16_t *dest,
  1305. int stride, int bd) {
  1306. int i, j;
  1307. tran_low_t out[4 * 4];
  1308. tran_low_t *outptr = out;
  1309. tran_low_t temp_in[4], temp_out[4];
  1310. // Rows
  1311. for (i = 0; i < 4; ++i) {
  1312. vpx_highbd_idct4_c(input, outptr, bd);
  1313. input += 4;
  1314. outptr += 4;
  1315. }
  1316. // Columns
  1317. for (i = 0; i < 4; ++i) {
  1318. for (j = 0; j < 4; ++j) temp_in[j] = out[j * 4 + i];
  1319. vpx_highbd_idct4_c(temp_in, temp_out, bd);
  1320. for (j = 0; j < 4; ++j) {
  1321. dest[j * stride + i] = highbd_clip_pixel_add(
  1322. dest[j * stride + i], ROUND_POWER_OF_TWO(temp_out[j], 4), bd);
  1323. }
  1324. }
  1325. }
  1326. void vpx_highbd_idct4x4_1_add_c(const tran_low_t *input, uint16_t *dest,
  1327. int stride, int bd) {
  1328. int i;
  1329. tran_high_t a1;
  1330. tran_low_t out = HIGHBD_WRAPLOW(
  1331. dct_const_round_shift(input[0] * (tran_high_t)cospi_16_64), bd);
  1332. out =
  1333. HIGHBD_WRAPLOW(dct_const_round_shift(out * (tran_high_t)cospi_16_64), bd);
  1334. a1 = ROUND_POWER_OF_TWO(out, 4);
  1335. for (i = 0; i < 4; i++) {
  1336. dest[0] = highbd_clip_pixel_add(dest[0], a1, bd);
  1337. dest[1] = highbd_clip_pixel_add(dest[1], a1, bd);
  1338. dest[2] = highbd_clip_pixel_add(dest[2], a1, bd);
  1339. dest[3] = highbd_clip_pixel_add(dest[3], a1, bd);
  1340. dest += stride;
  1341. }
  1342. }
  1343. void vpx_highbd_iadst8_c(const tran_low_t *input, tran_low_t *output, int bd) {
  1344. tran_high_t s0, s1, s2, s3, s4, s5, s6, s7;
  1345. tran_low_t x0 = input[7];
  1346. tran_low_t x1 = input[0];
  1347. tran_low_t x2 = input[5];
  1348. tran_low_t x3 = input[2];
  1349. tran_low_t x4 = input[3];
  1350. tran_low_t x5 = input[4];
  1351. tran_low_t x6 = input[1];
  1352. tran_low_t x7 = input[6];
  1353. (void)bd;
  1354. if (detect_invalid_highbd_input(input, 8)) {
  1355. #if CONFIG_COEFFICIENT_RANGE_CHECKING
  1356. assert(0 && "invalid highbd txfm input");
  1357. #endif // CONFIG_COEFFICIENT_RANGE_CHECKING
  1358. memset(output, 0, sizeof(*output) * 8);
  1359. return;
  1360. }
  1361. if (!(x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7)) {
  1362. memset(output, 0, 8 * sizeof(*output));
  1363. return;
  1364. }
  1365. // stage 1
  1366. s0 = (tran_high_t)cospi_2_64 * x0 + (tran_high_t)cospi_30_64 * x1;
  1367. s1 = (tran_high_t)cospi_30_64 * x0 - (tran_high_t)cospi_2_64 * x1;
  1368. s2 = (tran_high_t)cospi_10_64 * x2 + (tran_high_t)cospi_22_64 * x3;
  1369. s3 = (tran_high_t)cospi_22_64 * x2 - (tran_high_t)cospi_10_64 * x3;
  1370. s4 = (tran_high_t)cospi_18_64 * x4 + (tran_high_t)cospi_14_64 * x5;
  1371. s5 = (tran_high_t)cospi_14_64 * x4 - (tran_high_t)cospi_18_64 * x5;
  1372. s6 = (tran_high_t)cospi_26_64 * x6 + (tran_high_t)cospi_6_64 * x7;
  1373. s7 = (tran_high_t)cospi_6_64 * x6 - (tran_high_t)cospi_26_64 * x7;
  1374. x0 = HIGHBD_WRAPLOW(dct_const_round_shift(s0 + s4), bd);
  1375. x1 = HIGHBD_WRAPLOW(dct_const_round_shift(s1 + s5), bd);
  1376. x2 = HIGHBD_WRAPLOW(dct_const_round_shift(s2 + s6), bd);
  1377. x3 = HIGHBD_WRAPLOW(dct_const_round_shift(s3 + s7), bd);
  1378. x4 = HIGHBD_WRAPLOW(dct_const_round_shift(s0 - s4), bd);
  1379. x5 = HIGHBD_WRAPLOW(dct_const_round_shift(s1 - s5), bd);
  1380. x6 = HIGHBD_WRAPLOW(dct_const_round_shift(s2 - s6), bd);
  1381. x7 = HIGHBD_WRAPLOW(dct_const_round_shift(s3 - s7), bd);
  1382. // stage 2
  1383. s0 = x0;
  1384. s1 = x1;
  1385. s2 = x2;
  1386. s3 = x3;
  1387. s4 = (tran_high_t)cospi_8_64 * x4 + (tran_high_t)cospi_24_64 * x5;
  1388. s5 = (tran_high_t)cospi_24_64 * x4 - (tran_high_t)cospi_8_64 * x5;
  1389. s6 = (tran_high_t)(-cospi_24_64) * x6 + (tran_high_t)cospi_8_64 * x7;
  1390. s7 = (tran_high_t)cospi_8_64 * x6 + (tran_high_t)cospi_24_64 * x7;
  1391. x0 = HIGHBD_WRAPLOW(s0 + s2, bd);
  1392. x1 = HIGHBD_WRAPLOW(s1 + s3, bd);
  1393. x2 = HIGHBD_WRAPLOW(s0 - s2, bd);
  1394. x3 = HIGHBD_WRAPLOW(s1 - s3, bd);
  1395. x4 = HIGHBD_WRAPLOW(dct_const_round_shift(s4 + s6), bd);
  1396. x5 = HIGHBD_WRAPLOW(dct_const_round_shift(s5 + s7), bd);
  1397. x6 = HIGHBD_WRAPLOW(dct_const_round_shift(s4 - s6), bd);
  1398. x7 = HIGHBD_WRAPLOW(dct_const_round_shift(s5 - s7), bd);
  1399. // stage 3
  1400. s2 = (tran_high_t)cospi_16_64 * (x2 + x3);
  1401. s3 = (tran_high_t)cospi_16_64 * (x2 - x3);
  1402. s6 = (tran_high_t)cospi_16_64 * (x6 + x7);
  1403. s7 = (tran_high_t)cospi_16_64 * (x6 - x7);
  1404. x2 = HIGHBD_WRAPLOW(dct_const_round_shift(s2), bd);
  1405. x3 = HIGHBD_WRAPLOW(dct_const_round_shift(s3), bd);
  1406. x6 = HIGHBD_WRAPLOW(dct_const_round_shift(s6), bd);
  1407. x7 = HIGHBD_WRAPLOW(dct_const_round_shift(s7), bd);
  1408. output[0] = HIGHBD_WRAPLOW(x0, bd);
  1409. output[1] = HIGHBD_WRAPLOW(-x4, bd);
  1410. output[2] = HIGHBD_WRAPLOW(x6, bd);
  1411. output[3] = HIGHBD_WRAPLOW(-x2, bd);
  1412. output[4] = HIGHBD_WRAPLOW(x3, bd);
  1413. output[5] = HIGHBD_WRAPLOW(-x7, bd);
  1414. output[6] = HIGHBD_WRAPLOW(x5, bd);
  1415. output[7] = HIGHBD_WRAPLOW(-x1, bd);
  1416. }
  1417. void vpx_highbd_idct8_c(const tran_low_t *input, tran_low_t *output, int bd) {
  1418. tran_low_t step1[8], step2[8];
  1419. tran_high_t temp1, temp2;
  1420. if (detect_invalid_highbd_input(input, 8)) {
  1421. #if CONFIG_COEFFICIENT_RANGE_CHECKING
  1422. assert(0 && "invalid highbd txfm input");
  1423. #endif // CONFIG_COEFFICIENT_RANGE_CHECKING
  1424. memset(output, 0, sizeof(*output) * 8);
  1425. return;
  1426. }
  1427. // stage 1
  1428. step1[0] = input[0];
  1429. step1[2] = input[4];
  1430. step1[1] = input[2];
  1431. step1[3] = input[6];
  1432. temp1 =
  1433. input[1] * (tran_high_t)cospi_28_64 - input[7] * (tran_high_t)cospi_4_64;
  1434. temp2 =
  1435. input[1] * (tran_high_t)cospi_4_64 + input[7] * (tran_high_t)cospi_28_64;
  1436. step1[4] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1437. step1[7] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1438. temp1 =
  1439. input[5] * (tran_high_t)cospi_12_64 - input[3] * (tran_high_t)cospi_20_64;
  1440. temp2 =
  1441. input[5] * (tran_high_t)cospi_20_64 + input[3] * (tran_high_t)cospi_12_64;
  1442. step1[5] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1443. step1[6] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1444. // stage 2 & stage 3 - even half
  1445. vpx_highbd_idct4_c(step1, step1, bd);
  1446. // stage 2 - odd half
  1447. step2[4] = HIGHBD_WRAPLOW(step1[4] + step1[5], bd);
  1448. step2[5] = HIGHBD_WRAPLOW(step1[4] - step1[5], bd);
  1449. step2[6] = HIGHBD_WRAPLOW(-step1[6] + step1[7], bd);
  1450. step2[7] = HIGHBD_WRAPLOW(step1[6] + step1[7], bd);
  1451. // stage 3 - odd half
  1452. step1[4] = step2[4];
  1453. temp1 = (step2[6] - step2[5]) * (tran_high_t)cospi_16_64;
  1454. temp2 = (step2[5] + step2[6]) * (tran_high_t)cospi_16_64;
  1455. step1[5] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1456. step1[6] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1457. step1[7] = step2[7];
  1458. // stage 4
  1459. output[0] = HIGHBD_WRAPLOW(step1[0] + step1[7], bd);
  1460. output[1] = HIGHBD_WRAPLOW(step1[1] + step1[6], bd);
  1461. output[2] = HIGHBD_WRAPLOW(step1[2] + step1[5], bd);
  1462. output[3] = HIGHBD_WRAPLOW(step1[3] + step1[4], bd);
  1463. output[4] = HIGHBD_WRAPLOW(step1[3] - step1[4], bd);
  1464. output[5] = HIGHBD_WRAPLOW(step1[2] - step1[5], bd);
  1465. output[6] = HIGHBD_WRAPLOW(step1[1] - step1[6], bd);
  1466. output[7] = HIGHBD_WRAPLOW(step1[0] - step1[7], bd);
  1467. }
  1468. void vpx_highbd_idct8x8_64_add_c(const tran_low_t *input, uint16_t *dest,
  1469. int stride, int bd) {
  1470. int i, j;
  1471. tran_low_t out[8 * 8];
  1472. tran_low_t *outptr = out;
  1473. tran_low_t temp_in[8], temp_out[8];
  1474. // First transform rows
  1475. for (i = 0; i < 8; ++i) {
  1476. vpx_highbd_idct8_c(input, outptr, bd);
  1477. input += 8;
  1478. outptr += 8;
  1479. }
  1480. // Then transform columns
  1481. for (i = 0; i < 8; ++i) {
  1482. for (j = 0; j < 8; ++j) temp_in[j] = out[j * 8 + i];
  1483. vpx_highbd_idct8_c(temp_in, temp_out, bd);
  1484. for (j = 0; j < 8; ++j) {
  1485. dest[j * stride + i] = highbd_clip_pixel_add(
  1486. dest[j * stride + i], ROUND_POWER_OF_TWO(temp_out[j], 5), bd);
  1487. }
  1488. }
  1489. }
  1490. void vpx_highbd_idct8x8_12_add_c(const tran_low_t *input, uint16_t *dest,
  1491. int stride, int bd) {
  1492. int i, j;
  1493. tran_low_t out[8 * 8] = { 0 };
  1494. tran_low_t *outptr = out;
  1495. tran_low_t temp_in[8], temp_out[8];
  1496. // First transform rows
  1497. // Only first 4 row has non-zero coefs
  1498. for (i = 0; i < 4; ++i) {
  1499. vpx_highbd_idct8_c(input, outptr, bd);
  1500. input += 8;
  1501. outptr += 8;
  1502. }
  1503. // Then transform columns
  1504. for (i = 0; i < 8; ++i) {
  1505. for (j = 0; j < 8; ++j) temp_in[j] = out[j * 8 + i];
  1506. vpx_highbd_idct8_c(temp_in, temp_out, bd);
  1507. for (j = 0; j < 8; ++j) {
  1508. dest[j * stride + i] = highbd_clip_pixel_add(
  1509. dest[j * stride + i], ROUND_POWER_OF_TWO(temp_out[j], 5), bd);
  1510. }
  1511. }
  1512. }
  1513. void vpx_highbd_idct8x8_1_add_c(const tran_low_t *input, uint16_t *dest,
  1514. int stride, int bd) {
  1515. int i, j;
  1516. tran_high_t a1;
  1517. tran_low_t out = HIGHBD_WRAPLOW(
  1518. dct_const_round_shift(input[0] * (tran_high_t)cospi_16_64), bd);
  1519. out =
  1520. HIGHBD_WRAPLOW(dct_const_round_shift(out * (tran_high_t)cospi_16_64), bd);
  1521. a1 = ROUND_POWER_OF_TWO(out, 5);
  1522. for (j = 0; j < 8; ++j) {
  1523. for (i = 0; i < 8; ++i) dest[i] = highbd_clip_pixel_add(dest[i], a1, bd);
  1524. dest += stride;
  1525. }
  1526. }
  1527. void vpx_highbd_iadst16_c(const tran_low_t *input, tran_low_t *output, int bd) {
  1528. tran_high_t s0, s1, s2, s3, s4, s5, s6, s7, s8;
  1529. tran_high_t s9, s10, s11, s12, s13, s14, s15;
  1530. tran_low_t x0 = input[15];
  1531. tran_low_t x1 = input[0];
  1532. tran_low_t x2 = input[13];
  1533. tran_low_t x3 = input[2];
  1534. tran_low_t x4 = input[11];
  1535. tran_low_t x5 = input[4];
  1536. tran_low_t x6 = input[9];
  1537. tran_low_t x7 = input[6];
  1538. tran_low_t x8 = input[7];
  1539. tran_low_t x9 = input[8];
  1540. tran_low_t x10 = input[5];
  1541. tran_low_t x11 = input[10];
  1542. tran_low_t x12 = input[3];
  1543. tran_low_t x13 = input[12];
  1544. tran_low_t x14 = input[1];
  1545. tran_low_t x15 = input[14];
  1546. (void)bd;
  1547. if (detect_invalid_highbd_input(input, 16)) {
  1548. #if CONFIG_COEFFICIENT_RANGE_CHECKING
  1549. assert(0 && "invalid highbd txfm input");
  1550. #endif // CONFIG_COEFFICIENT_RANGE_CHECKING
  1551. memset(output, 0, sizeof(*output) * 16);
  1552. return;
  1553. }
  1554. if (!(x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 | x10 | x11 | x12 |
  1555. x13 | x14 | x15)) {
  1556. memset(output, 0, 16 * sizeof(*output));
  1557. return;
  1558. }
  1559. // stage 1
  1560. s0 = x0 * (tran_high_t)cospi_1_64 + x1 * (tran_high_t)cospi_31_64;
  1561. s1 = x0 * (tran_high_t)cospi_31_64 - x1 * (tran_high_t)cospi_1_64;
  1562. s2 = x2 * (tran_high_t)cospi_5_64 + x3 * (tran_high_t)cospi_27_64;
  1563. s3 = x2 * (tran_high_t)cospi_27_64 - x3 * (tran_high_t)cospi_5_64;
  1564. s4 = x4 * (tran_high_t)cospi_9_64 + x5 * (tran_high_t)cospi_23_64;
  1565. s5 = x4 * (tran_high_t)cospi_23_64 - x5 * (tran_high_t)cospi_9_64;
  1566. s6 = x6 * (tran_high_t)cospi_13_64 + x7 * (tran_high_t)cospi_19_64;
  1567. s7 = x6 * (tran_high_t)cospi_19_64 - x7 * (tran_high_t)cospi_13_64;
  1568. s8 = x8 * (tran_high_t)cospi_17_64 + x9 * (tran_high_t)cospi_15_64;
  1569. s9 = x8 * (tran_high_t)cospi_15_64 - x9 * (tran_high_t)cospi_17_64;
  1570. s10 = x10 * (tran_high_t)cospi_21_64 + x11 * (tran_high_t)cospi_11_64;
  1571. s11 = x10 * (tran_high_t)cospi_11_64 - x11 * (tran_high_t)cospi_21_64;
  1572. s12 = x12 * (tran_high_t)cospi_25_64 + x13 * (tran_high_t)cospi_7_64;
  1573. s13 = x12 * (tran_high_t)cospi_7_64 - x13 * (tran_high_t)cospi_25_64;
  1574. s14 = x14 * (tran_high_t)cospi_29_64 + x15 * (tran_high_t)cospi_3_64;
  1575. s15 = x14 * (tran_high_t)cospi_3_64 - x15 * (tran_high_t)cospi_29_64;
  1576. x0 = HIGHBD_WRAPLOW(dct_const_round_shift(s0 + s8), bd);
  1577. x1 = HIGHBD_WRAPLOW(dct_const_round_shift(s1 + s9), bd);
  1578. x2 = HIGHBD_WRAPLOW(dct_const_round_shift(s2 + s10), bd);
  1579. x3 = HIGHBD_WRAPLOW(dct_const_round_shift(s3 + s11), bd);
  1580. x4 = HIGHBD_WRAPLOW(dct_const_round_shift(s4 + s12), bd);
  1581. x5 = HIGHBD_WRAPLOW(dct_const_round_shift(s5 + s13), bd);
  1582. x6 = HIGHBD_WRAPLOW(dct_const_round_shift(s6 + s14), bd);
  1583. x7 = HIGHBD_WRAPLOW(dct_const_round_shift(s7 + s15), bd);
  1584. x8 = HIGHBD_WRAPLOW(dct_const_round_shift(s0 - s8), bd);
  1585. x9 = HIGHBD_WRAPLOW(dct_const_round_shift(s1 - s9), bd);
  1586. x10 = HIGHBD_WRAPLOW(dct_const_round_shift(s2 - s10), bd);
  1587. x11 = HIGHBD_WRAPLOW(dct_const_round_shift(s3 - s11), bd);
  1588. x12 = HIGHBD_WRAPLOW(dct_const_round_shift(s4 - s12), bd);
  1589. x13 = HIGHBD_WRAPLOW(dct_const_round_shift(s5 - s13), bd);
  1590. x14 = HIGHBD_WRAPLOW(dct_const_round_shift(s6 - s14), bd);
  1591. x15 = HIGHBD_WRAPLOW(dct_const_round_shift(s7 - s15), bd);
  1592. // stage 2
  1593. s0 = x0;
  1594. s1 = x1;
  1595. s2 = x2;
  1596. s3 = x3;
  1597. s4 = x4;
  1598. s5 = x5;
  1599. s6 = x6;
  1600. s7 = x7;
  1601. s8 = x8 * (tran_high_t)cospi_4_64 + x9 * (tran_high_t)cospi_28_64;
  1602. s9 = x8 * (tran_high_t)cospi_28_64 - x9 * (tran_high_t)cospi_4_64;
  1603. s10 = x10 * (tran_high_t)cospi_20_64 + x11 * (tran_high_t)cospi_12_64;
  1604. s11 = x10 * (tran_high_t)cospi_12_64 - x11 * (tran_high_t)cospi_20_64;
  1605. s12 = -x12 * (tran_high_t)cospi_28_64 + x13 * (tran_high_t)cospi_4_64;
  1606. s13 = x12 * (tran_high_t)cospi_4_64 + x13 * (tran_high_t)cospi_28_64;
  1607. s14 = -x14 * (tran_high_t)cospi_12_64 + x15 * (tran_high_t)cospi_20_64;
  1608. s15 = x14 * (tran_high_t)cospi_20_64 + x15 * (tran_high_t)cospi_12_64;
  1609. x0 = HIGHBD_WRAPLOW(s0 + s4, bd);
  1610. x1 = HIGHBD_WRAPLOW(s1 + s5, bd);
  1611. x2 = HIGHBD_WRAPLOW(s2 + s6, bd);
  1612. x3 = HIGHBD_WRAPLOW(s3 + s7, bd);
  1613. x4 = HIGHBD_WRAPLOW(s0 - s4, bd);
  1614. x5 = HIGHBD_WRAPLOW(s1 - s5, bd);
  1615. x6 = HIGHBD_WRAPLOW(s2 - s6, bd);
  1616. x7 = HIGHBD_WRAPLOW(s3 - s7, bd);
  1617. x8 = HIGHBD_WRAPLOW(dct_const_round_shift(s8 + s12), bd);
  1618. x9 = HIGHBD_WRAPLOW(dct_const_round_shift(s9 + s13), bd);
  1619. x10 = HIGHBD_WRAPLOW(dct_const_round_shift(s10 + s14), bd);
  1620. x11 = HIGHBD_WRAPLOW(dct_const_round_shift(s11 + s15), bd);
  1621. x12 = HIGHBD_WRAPLOW(dct_const_round_shift(s8 - s12), bd);
  1622. x13 = HIGHBD_WRAPLOW(dct_const_round_shift(s9 - s13), bd);
  1623. x14 = HIGHBD_WRAPLOW(dct_const_round_shift(s10 - s14), bd);
  1624. x15 = HIGHBD_WRAPLOW(dct_const_round_shift(s11 - s15), bd);
  1625. // stage 3
  1626. s0 = x0;
  1627. s1 = x1;
  1628. s2 = x2;
  1629. s3 = x3;
  1630. s4 = x4 * (tran_high_t)cospi_8_64 + x5 * (tran_high_t)cospi_24_64;
  1631. s5 = x4 * (tran_high_t)cospi_24_64 - x5 * (tran_high_t)cospi_8_64;
  1632. s6 = -x6 * (tran_high_t)cospi_24_64 + x7 * (tran_high_t)cospi_8_64;
  1633. s7 = x6 * (tran_high_t)cospi_8_64 + x7 * (tran_high_t)cospi_24_64;
  1634. s8 = x8;
  1635. s9 = x9;
  1636. s10 = x10;
  1637. s11 = x11;
  1638. s12 = x12 * (tran_high_t)cospi_8_64 + x13 * (tran_high_t)cospi_24_64;
  1639. s13 = x12 * (tran_high_t)cospi_24_64 - x13 * (tran_high_t)cospi_8_64;
  1640. s14 = -x14 * (tran_high_t)cospi_24_64 + x15 * (tran_high_t)cospi_8_64;
  1641. s15 = x14 * (tran_high_t)cospi_8_64 + x15 * (tran_high_t)cospi_24_64;
  1642. x0 = HIGHBD_WRAPLOW(s0 + s2, bd);
  1643. x1 = HIGHBD_WRAPLOW(s1 + s3, bd);
  1644. x2 = HIGHBD_WRAPLOW(s0 - s2, bd);
  1645. x3 = HIGHBD_WRAPLOW(s1 - s3, bd);
  1646. x4 = HIGHBD_WRAPLOW(dct_const_round_shift(s4 + s6), bd);
  1647. x5 = HIGHBD_WRAPLOW(dct_const_round_shift(s5 + s7), bd);
  1648. x6 = HIGHBD_WRAPLOW(dct_const_round_shift(s4 - s6), bd);
  1649. x7 = HIGHBD_WRAPLOW(dct_const_round_shift(s5 - s7), bd);
  1650. x8 = HIGHBD_WRAPLOW(s8 + s10, bd);
  1651. x9 = HIGHBD_WRAPLOW(s9 + s11, bd);
  1652. x10 = HIGHBD_WRAPLOW(s8 - s10, bd);
  1653. x11 = HIGHBD_WRAPLOW(s9 - s11, bd);
  1654. x12 = HIGHBD_WRAPLOW(dct_const_round_shift(s12 + s14), bd);
  1655. x13 = HIGHBD_WRAPLOW(dct_const_round_shift(s13 + s15), bd);
  1656. x14 = HIGHBD_WRAPLOW(dct_const_round_shift(s12 - s14), bd);
  1657. x15 = HIGHBD_WRAPLOW(dct_const_round_shift(s13 - s15), bd);
  1658. // stage 4
  1659. s2 = (tran_high_t)(-cospi_16_64) * (x2 + x3);
  1660. s3 = (tran_high_t)cospi_16_64 * (x2 - x3);
  1661. s6 = (tran_high_t)cospi_16_64 * (x6 + x7);
  1662. s7 = (tran_high_t)cospi_16_64 * (-x6 + x7);
  1663. s10 = (tran_high_t)cospi_16_64 * (x10 + x11);
  1664. s11 = (tran_high_t)cospi_16_64 * (-x10 + x11);
  1665. s14 = (tran_high_t)(-cospi_16_64) * (x14 + x15);
  1666. s15 = (tran_high_t)cospi_16_64 * (x14 - x15);
  1667. x2 = HIGHBD_WRAPLOW(dct_const_round_shift(s2), bd);
  1668. x3 = HIGHBD_WRAPLOW(dct_const_round_shift(s3), bd);
  1669. x6 = HIGHBD_WRAPLOW(dct_const_round_shift(s6), bd);
  1670. x7 = HIGHBD_WRAPLOW(dct_const_round_shift(s7), bd);
  1671. x10 = HIGHBD_WRAPLOW(dct_const_round_shift(s10), bd);
  1672. x11 = HIGHBD_WRAPLOW(dct_const_round_shift(s11), bd);
  1673. x14 = HIGHBD_WRAPLOW(dct_const_round_shift(s14), bd);
  1674. x15 = HIGHBD_WRAPLOW(dct_const_round_shift(s15), bd);
  1675. output[0] = HIGHBD_WRAPLOW(x0, bd);
  1676. output[1] = HIGHBD_WRAPLOW(-x8, bd);
  1677. output[2] = HIGHBD_WRAPLOW(x12, bd);
  1678. output[3] = HIGHBD_WRAPLOW(-x4, bd);
  1679. output[4] = HIGHBD_WRAPLOW(x6, bd);
  1680. output[5] = HIGHBD_WRAPLOW(x14, bd);
  1681. output[6] = HIGHBD_WRAPLOW(x10, bd);
  1682. output[7] = HIGHBD_WRAPLOW(x2, bd);
  1683. output[8] = HIGHBD_WRAPLOW(x3, bd);
  1684. output[9] = HIGHBD_WRAPLOW(x11, bd);
  1685. output[10] = HIGHBD_WRAPLOW(x15, bd);
  1686. output[11] = HIGHBD_WRAPLOW(x7, bd);
  1687. output[12] = HIGHBD_WRAPLOW(x5, bd);
  1688. output[13] = HIGHBD_WRAPLOW(-x13, bd);
  1689. output[14] = HIGHBD_WRAPLOW(x9, bd);
  1690. output[15] = HIGHBD_WRAPLOW(-x1, bd);
  1691. }
  1692. void vpx_highbd_idct16_c(const tran_low_t *input, tran_low_t *output, int bd) {
  1693. tran_low_t step1[16], step2[16];
  1694. tran_high_t temp1, temp2;
  1695. (void)bd;
  1696. if (detect_invalid_highbd_input(input, 16)) {
  1697. #if CONFIG_COEFFICIENT_RANGE_CHECKING
  1698. assert(0 && "invalid highbd txfm input");
  1699. #endif // CONFIG_COEFFICIENT_RANGE_CHECKING
  1700. memset(output, 0, sizeof(*output) * 16);
  1701. return;
  1702. }
  1703. // stage 1
  1704. step1[0] = input[0 / 2];
  1705. step1[1] = input[16 / 2];
  1706. step1[2] = input[8 / 2];
  1707. step1[3] = input[24 / 2];
  1708. step1[4] = input[4 / 2];
  1709. step1[5] = input[20 / 2];
  1710. step1[6] = input[12 / 2];
  1711. step1[7] = input[28 / 2];
  1712. step1[8] = input[2 / 2];
  1713. step1[9] = input[18 / 2];
  1714. step1[10] = input[10 / 2];
  1715. step1[11] = input[26 / 2];
  1716. step1[12] = input[6 / 2];
  1717. step1[13] = input[22 / 2];
  1718. step1[14] = input[14 / 2];
  1719. step1[15] = input[30 / 2];
  1720. // stage 2
  1721. step2[0] = step1[0];
  1722. step2[1] = step1[1];
  1723. step2[2] = step1[2];
  1724. step2[3] = step1[3];
  1725. step2[4] = step1[4];
  1726. step2[5] = step1[5];
  1727. step2[6] = step1[6];
  1728. step2[7] = step1[7];
  1729. temp1 =
  1730. step1[8] * (tran_high_t)cospi_30_64 - step1[15] * (tran_high_t)cospi_2_64;
  1731. temp2 =
  1732. step1[8] * (tran_high_t)cospi_2_64 + step1[15] * (tran_high_t)cospi_30_64;
  1733. step2[8] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1734. step2[15] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1735. temp1 = step1[9] * (tran_high_t)cospi_14_64 -
  1736. step1[14] * (tran_high_t)cospi_18_64;
  1737. temp2 = step1[9] * (tran_high_t)cospi_18_64 +
  1738. step1[14] * (tran_high_t)cospi_14_64;
  1739. step2[9] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1740. step2[14] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1741. temp1 = step1[10] * (tran_high_t)cospi_22_64 -
  1742. step1[13] * (tran_high_t)cospi_10_64;
  1743. temp2 = step1[10] * (tran_high_t)cospi_10_64 +
  1744. step1[13] * (tran_high_t)cospi_22_64;
  1745. step2[10] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1746. step2[13] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1747. temp1 = step1[11] * (tran_high_t)cospi_6_64 -
  1748. step1[12] * (tran_high_t)cospi_26_64;
  1749. temp2 = step1[11] * (tran_high_t)cospi_26_64 +
  1750. step1[12] * (tran_high_t)cospi_6_64;
  1751. step2[11] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1752. step2[12] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1753. // stage 3
  1754. step1[0] = step2[0];
  1755. step1[1] = step2[1];
  1756. step1[2] = step2[2];
  1757. step1[3] = step2[3];
  1758. temp1 =
  1759. step2[4] * (tran_high_t)cospi_28_64 - step2[7] * (tran_high_t)cospi_4_64;
  1760. temp2 =
  1761. step2[4] * (tran_high_t)cospi_4_64 + step2[7] * (tran_high_t)cospi_28_64;
  1762. step1[4] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1763. step1[7] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1764. temp1 =
  1765. step2[5] * (tran_high_t)cospi_12_64 - step2[6] * (tran_high_t)cospi_20_64;
  1766. temp2 =
  1767. step2[5] * (tran_high_t)cospi_20_64 + step2[6] * (tran_high_t)cospi_12_64;
  1768. step1[5] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1769. step1[6] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1770. step1[8] = HIGHBD_WRAPLOW(step2[8] + step2[9], bd);
  1771. step1[9] = HIGHBD_WRAPLOW(step2[8] - step2[9], bd);
  1772. step1[10] = HIGHBD_WRAPLOW(-step2[10] + step2[11], bd);
  1773. step1[11] = HIGHBD_WRAPLOW(step2[10] + step2[11], bd);
  1774. step1[12] = HIGHBD_WRAPLOW(step2[12] + step2[13], bd);
  1775. step1[13] = HIGHBD_WRAPLOW(step2[12] - step2[13], bd);
  1776. step1[14] = HIGHBD_WRAPLOW(-step2[14] + step2[15], bd);
  1777. step1[15] = HIGHBD_WRAPLOW(step2[14] + step2[15], bd);
  1778. // stage 4
  1779. temp1 = (step1[0] + step1[1]) * (tran_high_t)cospi_16_64;
  1780. temp2 = (step1[0] - step1[1]) * (tran_high_t)cospi_16_64;
  1781. step2[0] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1782. step2[1] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1783. temp1 =
  1784. step1[2] * (tran_high_t)cospi_24_64 - step1[3] * (tran_high_t)cospi_8_64;
  1785. temp2 =
  1786. step1[2] * (tran_high_t)cospi_8_64 + step1[3] * (tran_high_t)cospi_24_64;
  1787. step2[2] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1788. step2[3] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1789. step2[4] = HIGHBD_WRAPLOW(step1[4] + step1[5], bd);
  1790. step2[5] = HIGHBD_WRAPLOW(step1[4] - step1[5], bd);
  1791. step2[6] = HIGHBD_WRAPLOW(-step1[6] + step1[7], bd);
  1792. step2[7] = HIGHBD_WRAPLOW(step1[6] + step1[7], bd);
  1793. step2[8] = step1[8];
  1794. step2[15] = step1[15];
  1795. temp1 = -step1[9] * (tran_high_t)cospi_8_64 +
  1796. step1[14] * (tran_high_t)cospi_24_64;
  1797. temp2 =
  1798. step1[9] * (tran_high_t)cospi_24_64 + step1[14] * (tran_high_t)cospi_8_64;
  1799. step2[9] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1800. step2[14] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1801. temp1 = -step1[10] * (tran_high_t)cospi_24_64 -
  1802. step1[13] * (tran_high_t)cospi_8_64;
  1803. temp2 = -step1[10] * (tran_high_t)cospi_8_64 +
  1804. step1[13] * (tran_high_t)cospi_24_64;
  1805. step2[10] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1806. step2[13] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1807. step2[11] = step1[11];
  1808. step2[12] = step1[12];
  1809. // stage 5
  1810. step1[0] = HIGHBD_WRAPLOW(step2[0] + step2[3], bd);
  1811. step1[1] = HIGHBD_WRAPLOW(step2[1] + step2[2], bd);
  1812. step1[2] = HIGHBD_WRAPLOW(step2[1] - step2[2], bd);
  1813. step1[3] = HIGHBD_WRAPLOW(step2[0] - step2[3], bd);
  1814. step1[4] = step2[4];
  1815. temp1 = (step2[6] - step2[5]) * (tran_high_t)cospi_16_64;
  1816. temp2 = (step2[5] + step2[6]) * (tran_high_t)cospi_16_64;
  1817. step1[5] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1818. step1[6] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1819. step1[7] = step2[7];
  1820. step1[8] = HIGHBD_WRAPLOW(step2[8] + step2[11], bd);
  1821. step1[9] = HIGHBD_WRAPLOW(step2[9] + step2[10], bd);
  1822. step1[10] = HIGHBD_WRAPLOW(step2[9] - step2[10], bd);
  1823. step1[11] = HIGHBD_WRAPLOW(step2[8] - step2[11], bd);
  1824. step1[12] = HIGHBD_WRAPLOW(-step2[12] + step2[15], bd);
  1825. step1[13] = HIGHBD_WRAPLOW(-step2[13] + step2[14], bd);
  1826. step1[14] = HIGHBD_WRAPLOW(step2[13] + step2[14], bd);
  1827. step1[15] = HIGHBD_WRAPLOW(step2[12] + step2[15], bd);
  1828. // stage 6
  1829. step2[0] = HIGHBD_WRAPLOW(step1[0] + step1[7], bd);
  1830. step2[1] = HIGHBD_WRAPLOW(step1[1] + step1[6], bd);
  1831. step2[2] = HIGHBD_WRAPLOW(step1[2] + step1[5], bd);
  1832. step2[3] = HIGHBD_WRAPLOW(step1[3] + step1[4], bd);
  1833. step2[4] = HIGHBD_WRAPLOW(step1[3] - step1[4], bd);
  1834. step2[5] = HIGHBD_WRAPLOW(step1[2] - step1[5], bd);
  1835. step2[6] = HIGHBD_WRAPLOW(step1[1] - step1[6], bd);
  1836. step2[7] = HIGHBD_WRAPLOW(step1[0] - step1[7], bd);
  1837. step2[8] = step1[8];
  1838. step2[9] = step1[9];
  1839. temp1 = (-step1[10] + step1[13]) * (tran_high_t)cospi_16_64;
  1840. temp2 = (step1[10] + step1[13]) * (tran_high_t)cospi_16_64;
  1841. step2[10] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1842. step2[13] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1843. temp1 = (-step1[11] + step1[12]) * (tran_high_t)cospi_16_64;
  1844. temp2 = (step1[11] + step1[12]) * (tran_high_t)cospi_16_64;
  1845. step2[11] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1846. step2[12] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1847. step2[14] = step1[14];
  1848. step2[15] = step1[15];
  1849. // stage 7
  1850. output[0] = HIGHBD_WRAPLOW(step2[0] + step2[15], bd);
  1851. output[1] = HIGHBD_WRAPLOW(step2[1] + step2[14], bd);
  1852. output[2] = HIGHBD_WRAPLOW(step2[2] + step2[13], bd);
  1853. output[3] = HIGHBD_WRAPLOW(step2[3] + step2[12], bd);
  1854. output[4] = HIGHBD_WRAPLOW(step2[4] + step2[11], bd);
  1855. output[5] = HIGHBD_WRAPLOW(step2[5] + step2[10], bd);
  1856. output[6] = HIGHBD_WRAPLOW(step2[6] + step2[9], bd);
  1857. output[7] = HIGHBD_WRAPLOW(step2[7] + step2[8], bd);
  1858. output[8] = HIGHBD_WRAPLOW(step2[7] - step2[8], bd);
  1859. output[9] = HIGHBD_WRAPLOW(step2[6] - step2[9], bd);
  1860. output[10] = HIGHBD_WRAPLOW(step2[5] - step2[10], bd);
  1861. output[11] = HIGHBD_WRAPLOW(step2[4] - step2[11], bd);
  1862. output[12] = HIGHBD_WRAPLOW(step2[3] - step2[12], bd);
  1863. output[13] = HIGHBD_WRAPLOW(step2[2] - step2[13], bd);
  1864. output[14] = HIGHBD_WRAPLOW(step2[1] - step2[14], bd);
  1865. output[15] = HIGHBD_WRAPLOW(step2[0] - step2[15], bd);
  1866. }
  1867. void vpx_highbd_idct16x16_256_add_c(const tran_low_t *input, uint16_t *dest,
  1868. int stride, int bd) {
  1869. int i, j;
  1870. tran_low_t out[16 * 16];
  1871. tran_low_t *outptr = out;
  1872. tran_low_t temp_in[16], temp_out[16];
  1873. // First transform rows
  1874. for (i = 0; i < 16; ++i) {
  1875. vpx_highbd_idct16_c(input, outptr, bd);
  1876. input += 16;
  1877. outptr += 16;
  1878. }
  1879. // Then transform columns
  1880. for (i = 0; i < 16; ++i) {
  1881. for (j = 0; j < 16; ++j) temp_in[j] = out[j * 16 + i];
  1882. vpx_highbd_idct16_c(temp_in, temp_out, bd);
  1883. for (j = 0; j < 16; ++j) {
  1884. dest[j * stride + i] = highbd_clip_pixel_add(
  1885. dest[j * stride + i], ROUND_POWER_OF_TWO(temp_out[j], 6), bd);
  1886. }
  1887. }
  1888. }
  1889. void vpx_highbd_idct16x16_38_add_c(const tran_low_t *input, uint16_t *dest,
  1890. int stride, int bd) {
  1891. int i, j;
  1892. tran_low_t out[16 * 16] = { 0 };
  1893. tran_low_t *outptr = out;
  1894. tran_low_t temp_in[16], temp_out[16];
  1895. // First transform rows. Since all non-zero dct coefficients are in
  1896. // upper-left 8x8 area, we only need to calculate first 8 rows here.
  1897. for (i = 0; i < 8; ++i) {
  1898. vpx_highbd_idct16_c(input, outptr, bd);
  1899. input += 16;
  1900. outptr += 16;
  1901. }
  1902. // Then transform columns
  1903. for (i = 0; i < 16; ++i) {
  1904. uint16_t *destT = dest;
  1905. for (j = 0; j < 16; ++j) temp_in[j] = out[j * 16 + i];
  1906. vpx_highbd_idct16_c(temp_in, temp_out, bd);
  1907. for (j = 0; j < 16; ++j) {
  1908. destT[i] = highbd_clip_pixel_add(destT[i],
  1909. ROUND_POWER_OF_TWO(temp_out[j], 6), bd);
  1910. destT += stride;
  1911. }
  1912. }
  1913. }
  1914. void vpx_highbd_idct16x16_10_add_c(const tran_low_t *input, uint16_t *dest,
  1915. int stride, int bd) {
  1916. int i, j;
  1917. tran_low_t out[16 * 16] = { 0 };
  1918. tran_low_t *outptr = out;
  1919. tran_low_t temp_in[16], temp_out[16];
  1920. // First transform rows. Since all non-zero dct coefficients are in
  1921. // upper-left 4x4 area, we only need to calculate first 4 rows here.
  1922. for (i = 0; i < 4; ++i) {
  1923. vpx_highbd_idct16_c(input, outptr, bd);
  1924. input += 16;
  1925. outptr += 16;
  1926. }
  1927. // Then transform columns
  1928. for (i = 0; i < 16; ++i) {
  1929. for (j = 0; j < 16; ++j) temp_in[j] = out[j * 16 + i];
  1930. vpx_highbd_idct16_c(temp_in, temp_out, bd);
  1931. for (j = 0; j < 16; ++j) {
  1932. dest[j * stride + i] = highbd_clip_pixel_add(
  1933. dest[j * stride + i], ROUND_POWER_OF_TWO(temp_out[j], 6), bd);
  1934. }
  1935. }
  1936. }
  1937. void vpx_highbd_idct16x16_1_add_c(const tran_low_t *input, uint16_t *dest,
  1938. int stride, int bd) {
  1939. int i, j;
  1940. tran_high_t a1;
  1941. tran_low_t out = HIGHBD_WRAPLOW(
  1942. dct_const_round_shift(input[0] * (tran_high_t)cospi_16_64), bd);
  1943. out =
  1944. HIGHBD_WRAPLOW(dct_const_round_shift(out * (tran_high_t)cospi_16_64), bd);
  1945. a1 = ROUND_POWER_OF_TWO(out, 6);
  1946. for (j = 0; j < 16; ++j) {
  1947. for (i = 0; i < 16; ++i) dest[i] = highbd_clip_pixel_add(dest[i], a1, bd);
  1948. dest += stride;
  1949. }
  1950. }
  1951. static void highbd_idct32_c(const tran_low_t *input, tran_low_t *output,
  1952. int bd) {
  1953. tran_low_t step1[32], step2[32];
  1954. tran_high_t temp1, temp2;
  1955. (void)bd;
  1956. if (detect_invalid_highbd_input(input, 32)) {
  1957. #if CONFIG_COEFFICIENT_RANGE_CHECKING
  1958. assert(0 && "invalid highbd txfm input");
  1959. #endif // CONFIG_COEFFICIENT_RANGE_CHECKING
  1960. memset(output, 0, sizeof(*output) * 32);
  1961. return;
  1962. }
  1963. // stage 1
  1964. step1[0] = input[0];
  1965. step1[1] = input[16];
  1966. step1[2] = input[8];
  1967. step1[3] = input[24];
  1968. step1[4] = input[4];
  1969. step1[5] = input[20];
  1970. step1[6] = input[12];
  1971. step1[7] = input[28];
  1972. step1[8] = input[2];
  1973. step1[9] = input[18];
  1974. step1[10] = input[10];
  1975. step1[11] = input[26];
  1976. step1[12] = input[6];
  1977. step1[13] = input[22];
  1978. step1[14] = input[14];
  1979. step1[15] = input[30];
  1980. temp1 =
  1981. input[1] * (tran_high_t)cospi_31_64 - input[31] * (tran_high_t)cospi_1_64;
  1982. temp2 =
  1983. input[1] * (tran_high_t)cospi_1_64 + input[31] * (tran_high_t)cospi_31_64;
  1984. step1[16] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1985. step1[31] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1986. temp1 = input[17] * (tran_high_t)cospi_15_64 -
  1987. input[15] * (tran_high_t)cospi_17_64;
  1988. temp2 = input[17] * (tran_high_t)cospi_17_64 +
  1989. input[15] * (tran_high_t)cospi_15_64;
  1990. step1[17] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1991. step1[30] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1992. temp1 =
  1993. input[9] * (tran_high_t)cospi_23_64 - input[23] * (tran_high_t)cospi_9_64;
  1994. temp2 =
  1995. input[9] * (tran_high_t)cospi_9_64 + input[23] * (tran_high_t)cospi_23_64;
  1996. step1[18] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  1997. step1[29] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  1998. temp1 =
  1999. input[25] * (tran_high_t)cospi_7_64 - input[7] * (tran_high_t)cospi_25_64;
  2000. temp2 =
  2001. input[25] * (tran_high_t)cospi_25_64 + input[7] * (tran_high_t)cospi_7_64;
  2002. step1[19] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2003. step1[28] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2004. temp1 =
  2005. input[5] * (tran_high_t)cospi_27_64 - input[27] * (tran_high_t)cospi_5_64;
  2006. temp2 =
  2007. input[5] * (tran_high_t)cospi_5_64 + input[27] * (tran_high_t)cospi_27_64;
  2008. step1[20] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2009. step1[27] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2010. temp1 = input[21] * (tran_high_t)cospi_11_64 -
  2011. input[11] * (tran_high_t)cospi_21_64;
  2012. temp2 = input[21] * (tran_high_t)cospi_21_64 +
  2013. input[11] * (tran_high_t)cospi_11_64;
  2014. step1[21] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2015. step1[26] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2016. temp1 = input[13] * (tran_high_t)cospi_19_64 -
  2017. input[19] * (tran_high_t)cospi_13_64;
  2018. temp2 = input[13] * (tran_high_t)cospi_13_64 +
  2019. input[19] * (tran_high_t)cospi_19_64;
  2020. step1[22] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2021. step1[25] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2022. temp1 =
  2023. input[29] * (tran_high_t)cospi_3_64 - input[3] * (tran_high_t)cospi_29_64;
  2024. temp2 =
  2025. input[29] * (tran_high_t)cospi_29_64 + input[3] * (tran_high_t)cospi_3_64;
  2026. step1[23] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2027. step1[24] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2028. // stage 2
  2029. step2[0] = step1[0];
  2030. step2[1] = step1[1];
  2031. step2[2] = step1[2];
  2032. step2[3] = step1[3];
  2033. step2[4] = step1[4];
  2034. step2[5] = step1[5];
  2035. step2[6] = step1[6];
  2036. step2[7] = step1[7];
  2037. temp1 =
  2038. step1[8] * (tran_high_t)cospi_30_64 - step1[15] * (tran_high_t)cospi_2_64;
  2039. temp2 =
  2040. step1[8] * (tran_high_t)cospi_2_64 + step1[15] * (tran_high_t)cospi_30_64;
  2041. step2[8] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2042. step2[15] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2043. temp1 = step1[9] * (tran_high_t)cospi_14_64 -
  2044. step1[14] * (tran_high_t)cospi_18_64;
  2045. temp2 = step1[9] * (tran_high_t)cospi_18_64 +
  2046. step1[14] * (tran_high_t)cospi_14_64;
  2047. step2[9] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2048. step2[14] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2049. temp1 = step1[10] * (tran_high_t)cospi_22_64 -
  2050. step1[13] * (tran_high_t)cospi_10_64;
  2051. temp2 = step1[10] * (tran_high_t)cospi_10_64 +
  2052. step1[13] * (tran_high_t)cospi_22_64;
  2053. step2[10] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2054. step2[13] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2055. temp1 = step1[11] * (tran_high_t)cospi_6_64 -
  2056. step1[12] * (tran_high_t)cospi_26_64;
  2057. temp2 = step1[11] * (tran_high_t)cospi_26_64 +
  2058. step1[12] * (tran_high_t)cospi_6_64;
  2059. step2[11] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2060. step2[12] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2061. step2[16] = HIGHBD_WRAPLOW(step1[16] + step1[17], bd);
  2062. step2[17] = HIGHBD_WRAPLOW(step1[16] - step1[17], bd);
  2063. step2[18] = HIGHBD_WRAPLOW(-step1[18] + step1[19], bd);
  2064. step2[19] = HIGHBD_WRAPLOW(step1[18] + step1[19], bd);
  2065. step2[20] = HIGHBD_WRAPLOW(step1[20] + step1[21], bd);
  2066. step2[21] = HIGHBD_WRAPLOW(step1[20] - step1[21], bd);
  2067. step2[22] = HIGHBD_WRAPLOW(-step1[22] + step1[23], bd);
  2068. step2[23] = HIGHBD_WRAPLOW(step1[22] + step1[23], bd);
  2069. step2[24] = HIGHBD_WRAPLOW(step1[24] + step1[25], bd);
  2070. step2[25] = HIGHBD_WRAPLOW(step1[24] - step1[25], bd);
  2071. step2[26] = HIGHBD_WRAPLOW(-step1[26] + step1[27], bd);
  2072. step2[27] = HIGHBD_WRAPLOW(step1[26] + step1[27], bd);
  2073. step2[28] = HIGHBD_WRAPLOW(step1[28] + step1[29], bd);
  2074. step2[29] = HIGHBD_WRAPLOW(step1[28] - step1[29], bd);
  2075. step2[30] = HIGHBD_WRAPLOW(-step1[30] + step1[31], bd);
  2076. step2[31] = HIGHBD_WRAPLOW(step1[30] + step1[31], bd);
  2077. // stage 3
  2078. step1[0] = step2[0];
  2079. step1[1] = step2[1];
  2080. step1[2] = step2[2];
  2081. step1[3] = step2[3];
  2082. temp1 =
  2083. step2[4] * (tran_high_t)cospi_28_64 - step2[7] * (tran_high_t)cospi_4_64;
  2084. temp2 =
  2085. step2[4] * (tran_high_t)cospi_4_64 + step2[7] * (tran_high_t)cospi_28_64;
  2086. step1[4] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2087. step1[7] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2088. temp1 =
  2089. step2[5] * (tran_high_t)cospi_12_64 - step2[6] * (tran_high_t)cospi_20_64;
  2090. temp2 =
  2091. step2[5] * (tran_high_t)cospi_20_64 + step2[6] * (tran_high_t)cospi_12_64;
  2092. step1[5] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2093. step1[6] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2094. step1[8] = HIGHBD_WRAPLOW(step2[8] + step2[9], bd);
  2095. step1[9] = HIGHBD_WRAPLOW(step2[8] - step2[9], bd);
  2096. step1[10] = HIGHBD_WRAPLOW(-step2[10] + step2[11], bd);
  2097. step1[11] = HIGHBD_WRAPLOW(step2[10] + step2[11], bd);
  2098. step1[12] = HIGHBD_WRAPLOW(step2[12] + step2[13], bd);
  2099. step1[13] = HIGHBD_WRAPLOW(step2[12] - step2[13], bd);
  2100. step1[14] = HIGHBD_WRAPLOW(-step2[14] + step2[15], bd);
  2101. step1[15] = HIGHBD_WRAPLOW(step2[14] + step2[15], bd);
  2102. step1[16] = step2[16];
  2103. step1[31] = step2[31];
  2104. temp1 = -step2[17] * (tran_high_t)cospi_4_64 +
  2105. step2[30] * (tran_high_t)cospi_28_64;
  2106. temp2 = step2[17] * (tran_high_t)cospi_28_64 +
  2107. step2[30] * (tran_high_t)cospi_4_64;
  2108. step1[17] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2109. step1[30] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2110. temp1 = -step2[18] * (tran_high_t)cospi_28_64 -
  2111. step2[29] * (tran_high_t)cospi_4_64;
  2112. temp2 = -step2[18] * (tran_high_t)cospi_4_64 +
  2113. step2[29] * (tran_high_t)cospi_28_64;
  2114. step1[18] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2115. step1[29] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2116. step1[19] = step2[19];
  2117. step1[20] = step2[20];
  2118. temp1 = -step2[21] * (tran_high_t)cospi_20_64 +
  2119. step2[26] * (tran_high_t)cospi_12_64;
  2120. temp2 = step2[21] * (tran_high_t)cospi_12_64 +
  2121. step2[26] * (tran_high_t)cospi_20_64;
  2122. step1[21] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2123. step1[26] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2124. temp1 = -step2[22] * (tran_high_t)cospi_12_64 -
  2125. step2[25] * (tran_high_t)cospi_20_64;
  2126. temp2 = -step2[22] * (tran_high_t)cospi_20_64 +
  2127. step2[25] * (tran_high_t)cospi_12_64;
  2128. step1[22] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2129. step1[25] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2130. step1[23] = step2[23];
  2131. step1[24] = step2[24];
  2132. step1[27] = step2[27];
  2133. step1[28] = step2[28];
  2134. // stage 4
  2135. temp1 = (step1[0] + step1[1]) * (tran_high_t)cospi_16_64;
  2136. temp2 = (step1[0] - step1[1]) * (tran_high_t)cospi_16_64;
  2137. step2[0] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2138. step2[1] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2139. temp1 =
  2140. step1[2] * (tran_high_t)cospi_24_64 - step1[3] * (tran_high_t)cospi_8_64;
  2141. temp2 =
  2142. step1[2] * (tran_high_t)cospi_8_64 + step1[3] * (tran_high_t)cospi_24_64;
  2143. step2[2] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2144. step2[3] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2145. step2[4] = HIGHBD_WRAPLOW(step1[4] + step1[5], bd);
  2146. step2[5] = HIGHBD_WRAPLOW(step1[4] - step1[5], bd);
  2147. step2[6] = HIGHBD_WRAPLOW(-step1[6] + step1[7], bd);
  2148. step2[7] = HIGHBD_WRAPLOW(step1[6] + step1[7], bd);
  2149. step2[8] = step1[8];
  2150. step2[15] = step1[15];
  2151. temp1 = -step1[9] * (tran_high_t)cospi_8_64 +
  2152. step1[14] * (tran_high_t)cospi_24_64;
  2153. temp2 =
  2154. step1[9] * (tran_high_t)cospi_24_64 + step1[14] * (tran_high_t)cospi_8_64;
  2155. step2[9] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2156. step2[14] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2157. temp1 = -step1[10] * (tran_high_t)cospi_24_64 -
  2158. step1[13] * (tran_high_t)cospi_8_64;
  2159. temp2 = -step1[10] * (tran_high_t)cospi_8_64 +
  2160. step1[13] * (tran_high_t)cospi_24_64;
  2161. step2[10] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2162. step2[13] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2163. step2[11] = step1[11];
  2164. step2[12] = step1[12];
  2165. step2[16] = HIGHBD_WRAPLOW(step1[16] + step1[19], bd);
  2166. step2[17] = HIGHBD_WRAPLOW(step1[17] + step1[18], bd);
  2167. step2[18] = HIGHBD_WRAPLOW(step1[17] - step1[18], bd);
  2168. step2[19] = HIGHBD_WRAPLOW(step1[16] - step1[19], bd);
  2169. step2[20] = HIGHBD_WRAPLOW(-step1[20] + step1[23], bd);
  2170. step2[21] = HIGHBD_WRAPLOW(-step1[21] + step1[22], bd);
  2171. step2[22] = HIGHBD_WRAPLOW(step1[21] + step1[22], bd);
  2172. step2[23] = HIGHBD_WRAPLOW(step1[20] + step1[23], bd);
  2173. step2[24] = HIGHBD_WRAPLOW(step1[24] + step1[27], bd);
  2174. step2[25] = HIGHBD_WRAPLOW(step1[25] + step1[26], bd);
  2175. step2[26] = HIGHBD_WRAPLOW(step1[25] - step1[26], bd);
  2176. step2[27] = HIGHBD_WRAPLOW(step1[24] - step1[27], bd);
  2177. step2[28] = HIGHBD_WRAPLOW(-step1[28] + step1[31], bd);
  2178. step2[29] = HIGHBD_WRAPLOW(-step1[29] + step1[30], bd);
  2179. step2[30] = HIGHBD_WRAPLOW(step1[29] + step1[30], bd);
  2180. step2[31] = HIGHBD_WRAPLOW(step1[28] + step1[31], bd);
  2181. // stage 5
  2182. step1[0] = HIGHBD_WRAPLOW(step2[0] + step2[3], bd);
  2183. step1[1] = HIGHBD_WRAPLOW(step2[1] + step2[2], bd);
  2184. step1[2] = HIGHBD_WRAPLOW(step2[1] - step2[2], bd);
  2185. step1[3] = HIGHBD_WRAPLOW(step2[0] - step2[3], bd);
  2186. step1[4] = step2[4];
  2187. temp1 = (step2[6] - step2[5]) * (tran_high_t)cospi_16_64;
  2188. temp2 = (step2[5] + step2[6]) * (tran_high_t)cospi_16_64;
  2189. step1[5] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2190. step1[6] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2191. step1[7] = step2[7];
  2192. step1[8] = HIGHBD_WRAPLOW(step2[8] + step2[11], bd);
  2193. step1[9] = HIGHBD_WRAPLOW(step2[9] + step2[10], bd);
  2194. step1[10] = HIGHBD_WRAPLOW(step2[9] - step2[10], bd);
  2195. step1[11] = HIGHBD_WRAPLOW(step2[8] - step2[11], bd);
  2196. step1[12] = HIGHBD_WRAPLOW(-step2[12] + step2[15], bd);
  2197. step1[13] = HIGHBD_WRAPLOW(-step2[13] + step2[14], bd);
  2198. step1[14] = HIGHBD_WRAPLOW(step2[13] + step2[14], bd);
  2199. step1[15] = HIGHBD_WRAPLOW(step2[12] + step2[15], bd);
  2200. step1[16] = step2[16];
  2201. step1[17] = step2[17];
  2202. temp1 = -step2[18] * (tran_high_t)cospi_8_64 +
  2203. step2[29] * (tran_high_t)cospi_24_64;
  2204. temp2 = step2[18] * (tran_high_t)cospi_24_64 +
  2205. step2[29] * (tran_high_t)cospi_8_64;
  2206. step1[18] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2207. step1[29] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2208. temp1 = -step2[19] * (tran_high_t)cospi_8_64 +
  2209. step2[28] * (tran_high_t)cospi_24_64;
  2210. temp2 = step2[19] * (tran_high_t)cospi_24_64 +
  2211. step2[28] * (tran_high_t)cospi_8_64;
  2212. step1[19] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2213. step1[28] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2214. temp1 = -step2[20] * (tran_high_t)cospi_24_64 -
  2215. step2[27] * (tran_high_t)cospi_8_64;
  2216. temp2 = -step2[20] * (tran_high_t)cospi_8_64 +
  2217. step2[27] * (tran_high_t)cospi_24_64;
  2218. step1[20] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2219. step1[27] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2220. temp1 = -step2[21] * (tran_high_t)cospi_24_64 -
  2221. step2[26] * (tran_high_t)cospi_8_64;
  2222. temp2 = -step2[21] * (tran_high_t)cospi_8_64 +
  2223. step2[26] * (tran_high_t)cospi_24_64;
  2224. step1[21] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2225. step1[26] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2226. step1[22] = step2[22];
  2227. step1[23] = step2[23];
  2228. step1[24] = step2[24];
  2229. step1[25] = step2[25];
  2230. step1[30] = step2[30];
  2231. step1[31] = step2[31];
  2232. // stage 6
  2233. step2[0] = HIGHBD_WRAPLOW(step1[0] + step1[7], bd);
  2234. step2[1] = HIGHBD_WRAPLOW(step1[1] + step1[6], bd);
  2235. step2[2] = HIGHBD_WRAPLOW(step1[2] + step1[5], bd);
  2236. step2[3] = HIGHBD_WRAPLOW(step1[3] + step1[4], bd);
  2237. step2[4] = HIGHBD_WRAPLOW(step1[3] - step1[4], bd);
  2238. step2[5] = HIGHBD_WRAPLOW(step1[2] - step1[5], bd);
  2239. step2[6] = HIGHBD_WRAPLOW(step1[1] - step1[6], bd);
  2240. step2[7] = HIGHBD_WRAPLOW(step1[0] - step1[7], bd);
  2241. step2[8] = step1[8];
  2242. step2[9] = step1[9];
  2243. temp1 = (-step1[10] + step1[13]) * (tran_high_t)cospi_16_64;
  2244. temp2 = (step1[10] + step1[13]) * (tran_high_t)cospi_16_64;
  2245. step2[10] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2246. step2[13] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2247. temp1 = (-step1[11] + step1[12]) * (tran_high_t)cospi_16_64;
  2248. temp2 = (step1[11] + step1[12]) * (tran_high_t)cospi_16_64;
  2249. step2[11] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2250. step2[12] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2251. step2[14] = step1[14];
  2252. step2[15] = step1[15];
  2253. step2[16] = HIGHBD_WRAPLOW(step1[16] + step1[23], bd);
  2254. step2[17] = HIGHBD_WRAPLOW(step1[17] + step1[22], bd);
  2255. step2[18] = HIGHBD_WRAPLOW(step1[18] + step1[21], bd);
  2256. step2[19] = HIGHBD_WRAPLOW(step1[19] + step1[20], bd);
  2257. step2[20] = HIGHBD_WRAPLOW(step1[19] - step1[20], bd);
  2258. step2[21] = HIGHBD_WRAPLOW(step1[18] - step1[21], bd);
  2259. step2[22] = HIGHBD_WRAPLOW(step1[17] - step1[22], bd);
  2260. step2[23] = HIGHBD_WRAPLOW(step1[16] - step1[23], bd);
  2261. step2[24] = HIGHBD_WRAPLOW(-step1[24] + step1[31], bd);
  2262. step2[25] = HIGHBD_WRAPLOW(-step1[25] + step1[30], bd);
  2263. step2[26] = HIGHBD_WRAPLOW(-step1[26] + step1[29], bd);
  2264. step2[27] = HIGHBD_WRAPLOW(-step1[27] + step1[28], bd);
  2265. step2[28] = HIGHBD_WRAPLOW(step1[27] + step1[28], bd);
  2266. step2[29] = HIGHBD_WRAPLOW(step1[26] + step1[29], bd);
  2267. step2[30] = HIGHBD_WRAPLOW(step1[25] + step1[30], bd);
  2268. step2[31] = HIGHBD_WRAPLOW(step1[24] + step1[31], bd);
  2269. // stage 7
  2270. step1[0] = HIGHBD_WRAPLOW(step2[0] + step2[15], bd);
  2271. step1[1] = HIGHBD_WRAPLOW(step2[1] + step2[14], bd);
  2272. step1[2] = HIGHBD_WRAPLOW(step2[2] + step2[13], bd);
  2273. step1[3] = HIGHBD_WRAPLOW(step2[3] + step2[12], bd);
  2274. step1[4] = HIGHBD_WRAPLOW(step2[4] + step2[11], bd);
  2275. step1[5] = HIGHBD_WRAPLOW(step2[5] + step2[10], bd);
  2276. step1[6] = HIGHBD_WRAPLOW(step2[6] + step2[9], bd);
  2277. step1[7] = HIGHBD_WRAPLOW(step2[7] + step2[8], bd);
  2278. step1[8] = HIGHBD_WRAPLOW(step2[7] - step2[8], bd);
  2279. step1[9] = HIGHBD_WRAPLOW(step2[6] - step2[9], bd);
  2280. step1[10] = HIGHBD_WRAPLOW(step2[5] - step2[10], bd);
  2281. step1[11] = HIGHBD_WRAPLOW(step2[4] - step2[11], bd);
  2282. step1[12] = HIGHBD_WRAPLOW(step2[3] - step2[12], bd);
  2283. step1[13] = HIGHBD_WRAPLOW(step2[2] - step2[13], bd);
  2284. step1[14] = HIGHBD_WRAPLOW(step2[1] - step2[14], bd);
  2285. step1[15] = HIGHBD_WRAPLOW(step2[0] - step2[15], bd);
  2286. step1[16] = step2[16];
  2287. step1[17] = step2[17];
  2288. step1[18] = step2[18];
  2289. step1[19] = step2[19];
  2290. temp1 = (-step2[20] + step2[27]) * (tran_high_t)cospi_16_64;
  2291. temp2 = (step2[20] + step2[27]) * (tran_high_t)cospi_16_64;
  2292. step1[20] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2293. step1[27] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2294. temp1 = (-step2[21] + step2[26]) * (tran_high_t)cospi_16_64;
  2295. temp2 = (step2[21] + step2[26]) * (tran_high_t)cospi_16_64;
  2296. step1[21] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2297. step1[26] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2298. temp1 = (-step2[22] + step2[25]) * (tran_high_t)cospi_16_64;
  2299. temp2 = (step2[22] + step2[25]) * (tran_high_t)cospi_16_64;
  2300. step1[22] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2301. step1[25] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2302. temp1 = (-step2[23] + step2[24]) * (tran_high_t)cospi_16_64;
  2303. temp2 = (step2[23] + step2[24]) * (tran_high_t)cospi_16_64;
  2304. step1[23] = HIGHBD_WRAPLOW(dct_const_round_shift(temp1), bd);
  2305. step1[24] = HIGHBD_WRAPLOW(dct_const_round_shift(temp2), bd);
  2306. step1[28] = step2[28];
  2307. step1[29] = step2[29];
  2308. step1[30] = step2[30];
  2309. step1[31] = step2[31];
  2310. // final stage
  2311. output[0] = HIGHBD_WRAPLOW(step1[0] + step1[31], bd);
  2312. output[1] = HIGHBD_WRAPLOW(step1[1] + step1[30], bd);
  2313. output[2] = HIGHBD_WRAPLOW(step1[2] + step1[29], bd);
  2314. output[3] = HIGHBD_WRAPLOW(step1[3] + step1[28], bd);
  2315. output[4] = HIGHBD_WRAPLOW(step1[4] + step1[27], bd);
  2316. output[5] = HIGHBD_WRAPLOW(step1[5] + step1[26], bd);
  2317. output[6] = HIGHBD_WRAPLOW(step1[6] + step1[25], bd);
  2318. output[7] = HIGHBD_WRAPLOW(step1[7] + step1[24], bd);
  2319. output[8] = HIGHBD_WRAPLOW(step1[8] + step1[23], bd);
  2320. output[9] = HIGHBD_WRAPLOW(step1[9] + step1[22], bd);
  2321. output[10] = HIGHBD_WRAPLOW(step1[10] + step1[21], bd);
  2322. output[11] = HIGHBD_WRAPLOW(step1[11] + step1[20], bd);
  2323. output[12] = HIGHBD_WRAPLOW(step1[12] + step1[19], bd);
  2324. output[13] = HIGHBD_WRAPLOW(step1[13] + step1[18], bd);
  2325. output[14] = HIGHBD_WRAPLOW(step1[14] + step1[17], bd);
  2326. output[15] = HIGHBD_WRAPLOW(step1[15] + step1[16], bd);
  2327. output[16] = HIGHBD_WRAPLOW(step1[15] - step1[16], bd);
  2328. output[17] = HIGHBD_WRAPLOW(step1[14] - step1[17], bd);
  2329. output[18] = HIGHBD_WRAPLOW(step1[13] - step1[18], bd);
  2330. output[19] = HIGHBD_WRAPLOW(step1[12] - step1[19], bd);
  2331. output[20] = HIGHBD_WRAPLOW(step1[11] - step1[20], bd);
  2332. output[21] = HIGHBD_WRAPLOW(step1[10] - step1[21], bd);
  2333. output[22] = HIGHBD_WRAPLOW(step1[9] - step1[22], bd);
  2334. output[23] = HIGHBD_WRAPLOW(step1[8] - step1[23], bd);
  2335. output[24] = HIGHBD_WRAPLOW(step1[7] - step1[24], bd);
  2336. output[25] = HIGHBD_WRAPLOW(step1[6] - step1[25], bd);
  2337. output[26] = HIGHBD_WRAPLOW(step1[5] - step1[26], bd);
  2338. output[27] = HIGHBD_WRAPLOW(step1[4] - step1[27], bd);
  2339. output[28] = HIGHBD_WRAPLOW(step1[3] - step1[28], bd);
  2340. output[29] = HIGHBD_WRAPLOW(step1[2] - step1[29], bd);
  2341. output[30] = HIGHBD_WRAPLOW(step1[1] - step1[30], bd);
  2342. output[31] = HIGHBD_WRAPLOW(step1[0] - step1[31], bd);
  2343. }
  2344. void vpx_highbd_idct32x32_1024_add_c(const tran_low_t *input, uint16_t *dest,
  2345. int stride, int bd) {
  2346. int i, j;
  2347. tran_low_t out[32 * 32];
  2348. tran_low_t *outptr = out;
  2349. tran_low_t temp_in[32], temp_out[32];
  2350. // Rows
  2351. for (i = 0; i < 32; ++i) {
  2352. tran_low_t zero_coeff = 0;
  2353. for (j = 0; j < 32; ++j) zero_coeff |= input[j];
  2354. if (zero_coeff)
  2355. highbd_idct32_c(input, outptr, bd);
  2356. else
  2357. memset(outptr, 0, sizeof(tran_low_t) * 32);
  2358. input += 32;
  2359. outptr += 32;
  2360. }
  2361. // Columns
  2362. for (i = 0; i < 32; ++i) {
  2363. for (j = 0; j < 32; ++j) temp_in[j] = out[j * 32 + i];
  2364. highbd_idct32_c(temp_in, temp_out, bd);
  2365. for (j = 0; j < 32; ++j) {
  2366. dest[j * stride + i] = highbd_clip_pixel_add(
  2367. dest[j * stride + i], ROUND_POWER_OF_TWO(temp_out[j], 6), bd);
  2368. }
  2369. }
  2370. }
  2371. void vpx_highbd_idct32x32_135_add_c(const tran_low_t *input, uint16_t *dest,
  2372. int stride, int bd) {
  2373. int i, j;
  2374. tran_low_t out[32 * 32] = { 0 };
  2375. tran_low_t *outptr = out;
  2376. tran_low_t temp_in[32], temp_out[32];
  2377. // Rows
  2378. // Only upper-left 16x16 has non-zero coeff
  2379. for (i = 0; i < 16; ++i) {
  2380. highbd_idct32_c(input, outptr, bd);
  2381. input += 32;
  2382. outptr += 32;
  2383. }
  2384. // Columns
  2385. for (i = 0; i < 32; ++i) {
  2386. uint16_t *destT = dest;
  2387. for (j = 0; j < 32; ++j) temp_in[j] = out[j * 32 + i];
  2388. highbd_idct32_c(temp_in, temp_out, bd);
  2389. for (j = 0; j < 32; ++j) {
  2390. destT[i] = highbd_clip_pixel_add(destT[i],
  2391. ROUND_POWER_OF_TWO(temp_out[j], 6), bd);
  2392. destT += stride;
  2393. }
  2394. }
  2395. }
  2396. void vpx_highbd_idct32x32_34_add_c(const tran_low_t *input, uint16_t *dest,
  2397. int stride, int bd) {
  2398. int i, j;
  2399. tran_low_t out[32 * 32] = { 0 };
  2400. tran_low_t *outptr = out;
  2401. tran_low_t temp_in[32], temp_out[32];
  2402. // Rows
  2403. // Only upper-left 8x8 has non-zero coeff
  2404. for (i = 0; i < 8; ++i) {
  2405. highbd_idct32_c(input, outptr, bd);
  2406. input += 32;
  2407. outptr += 32;
  2408. }
  2409. // Columns
  2410. for (i = 0; i < 32; ++i) {
  2411. for (j = 0; j < 32; ++j) temp_in[j] = out[j * 32 + i];
  2412. highbd_idct32_c(temp_in, temp_out, bd);
  2413. for (j = 0; j < 32; ++j) {
  2414. dest[j * stride + i] = highbd_clip_pixel_add(
  2415. dest[j * stride + i], ROUND_POWER_OF_TWO(temp_out[j], 6), bd);
  2416. }
  2417. }
  2418. }
  2419. void vpx_highbd_idct32x32_1_add_c(const tran_low_t *input, uint16_t *dest,
  2420. int stride, int bd) {
  2421. int i, j;
  2422. int a1;
  2423. tran_low_t out = HIGHBD_WRAPLOW(
  2424. dct_const_round_shift(input[0] * (tran_high_t)cospi_16_64), bd);
  2425. out =
  2426. HIGHBD_WRAPLOW(dct_const_round_shift(out * (tran_high_t)cospi_16_64), bd);
  2427. a1 = ROUND_POWER_OF_TWO(out, 6);
  2428. for (j = 0; j < 32; ++j) {
  2429. for (i = 0; i < 32; ++i) dest[i] = highbd_clip_pixel_add(dest[i], a1, bd);
  2430. dest += stride;
  2431. }
  2432. }
  2433. #endif // CONFIG_VP9_HIGHBITDEPTH