dct64_i386.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /*
  2. * dct64_i368.c
  3. *
  4. * Copyright (C) 1999-2010 The L.A.M.E. project
  5. *
  6. * Initially written by Michael Hipp, see also AUTHORS and README.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Library General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Library General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Library General Public
  19. * License along with this library; if not, write to the
  20. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. * Boston, MA 02111-1307, USA.
  22. *
  23. *
  24. * Discrete Cosine Tansform (DCT) for subband synthesis
  25. * optimized for machines with no auto-increment.
  26. * The performance is highly compiler dependend. Maybe
  27. * the dct64.c version for 'normal' processor may be faster
  28. * even for Intel processors.
  29. */
  30. /* $Id: dct64_i386.c,v 1.14 2010/03/22 14:30:19 robert Exp $ */
  31. #ifdef HAVE_CONFIG_H
  32. #include <config.h>
  33. #endif
  34. #include "dct64_i386.h"
  35. #include "tabinit.h"
  36. #ifdef WITH_DMALLOC
  37. #include <dmalloc.h>
  38. #endif
  39. static void
  40. dct64_1(real * out0, real * out1, real * b1, real * b2, real * samples)
  41. {
  42. {
  43. real *costab = pnts[0];
  44. b1[0x00] = samples[0x00] + samples[0x1F];
  45. b1[0x1F] = (samples[0x00] - samples[0x1F]) * costab[0x0];
  46. b1[0x01] = samples[0x01] + samples[0x1E];
  47. b1[0x1E] = (samples[0x01] - samples[0x1E]) * costab[0x1];
  48. b1[0x02] = samples[0x02] + samples[0x1D];
  49. b1[0x1D] = (samples[0x02] - samples[0x1D]) * costab[0x2];
  50. b1[0x03] = samples[0x03] + samples[0x1C];
  51. b1[0x1C] = (samples[0x03] - samples[0x1C]) * costab[0x3];
  52. b1[0x04] = samples[0x04] + samples[0x1B];
  53. b1[0x1B] = (samples[0x04] - samples[0x1B]) * costab[0x4];
  54. b1[0x05] = samples[0x05] + samples[0x1A];
  55. b1[0x1A] = (samples[0x05] - samples[0x1A]) * costab[0x5];
  56. b1[0x06] = samples[0x06] + samples[0x19];
  57. b1[0x19] = (samples[0x06] - samples[0x19]) * costab[0x6];
  58. b1[0x07] = samples[0x07] + samples[0x18];
  59. b1[0x18] = (samples[0x07] - samples[0x18]) * costab[0x7];
  60. b1[0x08] = samples[0x08] + samples[0x17];
  61. b1[0x17] = (samples[0x08] - samples[0x17]) * costab[0x8];
  62. b1[0x09] = samples[0x09] + samples[0x16];
  63. b1[0x16] = (samples[0x09] - samples[0x16]) * costab[0x9];
  64. b1[0x0A] = samples[0x0A] + samples[0x15];
  65. b1[0x15] = (samples[0x0A] - samples[0x15]) * costab[0xA];
  66. b1[0x0B] = samples[0x0B] + samples[0x14];
  67. b1[0x14] = (samples[0x0B] - samples[0x14]) * costab[0xB];
  68. b1[0x0C] = samples[0x0C] + samples[0x13];
  69. b1[0x13] = (samples[0x0C] - samples[0x13]) * costab[0xC];
  70. b1[0x0D] = samples[0x0D] + samples[0x12];
  71. b1[0x12] = (samples[0x0D] - samples[0x12]) * costab[0xD];
  72. b1[0x0E] = samples[0x0E] + samples[0x11];
  73. b1[0x11] = (samples[0x0E] - samples[0x11]) * costab[0xE];
  74. b1[0x0F] = samples[0x0F] + samples[0x10];
  75. b1[0x10] = (samples[0x0F] - samples[0x10]) * costab[0xF];
  76. }
  77. {
  78. real *costab = pnts[1];
  79. b2[0x00] = b1[0x00] + b1[0x0F];
  80. b2[0x0F] = (b1[0x00] - b1[0x0F]) * costab[0];
  81. b2[0x01] = b1[0x01] + b1[0x0E];
  82. b2[0x0E] = (b1[0x01] - b1[0x0E]) * costab[1];
  83. b2[0x02] = b1[0x02] + b1[0x0D];
  84. b2[0x0D] = (b1[0x02] - b1[0x0D]) * costab[2];
  85. b2[0x03] = b1[0x03] + b1[0x0C];
  86. b2[0x0C] = (b1[0x03] - b1[0x0C]) * costab[3];
  87. b2[0x04] = b1[0x04] + b1[0x0B];
  88. b2[0x0B] = (b1[0x04] - b1[0x0B]) * costab[4];
  89. b2[0x05] = b1[0x05] + b1[0x0A];
  90. b2[0x0A] = (b1[0x05] - b1[0x0A]) * costab[5];
  91. b2[0x06] = b1[0x06] + b1[0x09];
  92. b2[0x09] = (b1[0x06] - b1[0x09]) * costab[6];
  93. b2[0x07] = b1[0x07] + b1[0x08];
  94. b2[0x08] = (b1[0x07] - b1[0x08]) * costab[7];
  95. b2[0x10] = b1[0x10] + b1[0x1F];
  96. b2[0x1F] = (b1[0x1F] - b1[0x10]) * costab[0];
  97. b2[0x11] = b1[0x11] + b1[0x1E];
  98. b2[0x1E] = (b1[0x1E] - b1[0x11]) * costab[1];
  99. b2[0x12] = b1[0x12] + b1[0x1D];
  100. b2[0x1D] = (b1[0x1D] - b1[0x12]) * costab[2];
  101. b2[0x13] = b1[0x13] + b1[0x1C];
  102. b2[0x1C] = (b1[0x1C] - b1[0x13]) * costab[3];
  103. b2[0x14] = b1[0x14] + b1[0x1B];
  104. b2[0x1B] = (b1[0x1B] - b1[0x14]) * costab[4];
  105. b2[0x15] = b1[0x15] + b1[0x1A];
  106. b2[0x1A] = (b1[0x1A] - b1[0x15]) * costab[5];
  107. b2[0x16] = b1[0x16] + b1[0x19];
  108. b2[0x19] = (b1[0x19] - b1[0x16]) * costab[6];
  109. b2[0x17] = b1[0x17] + b1[0x18];
  110. b2[0x18] = (b1[0x18] - b1[0x17]) * costab[7];
  111. }
  112. {
  113. real *costab = pnts[2];
  114. b1[0x00] = b2[0x00] + b2[0x07];
  115. b1[0x07] = (b2[0x00] - b2[0x07]) * costab[0];
  116. b1[0x01] = b2[0x01] + b2[0x06];
  117. b1[0x06] = (b2[0x01] - b2[0x06]) * costab[1];
  118. b1[0x02] = b2[0x02] + b2[0x05];
  119. b1[0x05] = (b2[0x02] - b2[0x05]) * costab[2];
  120. b1[0x03] = b2[0x03] + b2[0x04];
  121. b1[0x04] = (b2[0x03] - b2[0x04]) * costab[3];
  122. b1[0x08] = b2[0x08] + b2[0x0F];
  123. b1[0x0F] = (b2[0x0F] - b2[0x08]) * costab[0];
  124. b1[0x09] = b2[0x09] + b2[0x0E];
  125. b1[0x0E] = (b2[0x0E] - b2[0x09]) * costab[1];
  126. b1[0x0A] = b2[0x0A] + b2[0x0D];
  127. b1[0x0D] = (b2[0x0D] - b2[0x0A]) * costab[2];
  128. b1[0x0B] = b2[0x0B] + b2[0x0C];
  129. b1[0x0C] = (b2[0x0C] - b2[0x0B]) * costab[3];
  130. b1[0x10] = b2[0x10] + b2[0x17];
  131. b1[0x17] = (b2[0x10] - b2[0x17]) * costab[0];
  132. b1[0x11] = b2[0x11] + b2[0x16];
  133. b1[0x16] = (b2[0x11] - b2[0x16]) * costab[1];
  134. b1[0x12] = b2[0x12] + b2[0x15];
  135. b1[0x15] = (b2[0x12] - b2[0x15]) * costab[2];
  136. b1[0x13] = b2[0x13] + b2[0x14];
  137. b1[0x14] = (b2[0x13] - b2[0x14]) * costab[3];
  138. b1[0x18] = b2[0x18] + b2[0x1F];
  139. b1[0x1F] = (b2[0x1F] - b2[0x18]) * costab[0];
  140. b1[0x19] = b2[0x19] + b2[0x1E];
  141. b1[0x1E] = (b2[0x1E] - b2[0x19]) * costab[1];
  142. b1[0x1A] = b2[0x1A] + b2[0x1D];
  143. b1[0x1D] = (b2[0x1D] - b2[0x1A]) * costab[2];
  144. b1[0x1B] = b2[0x1B] + b2[0x1C];
  145. b1[0x1C] = (b2[0x1C] - b2[0x1B]) * costab[3];
  146. }
  147. {
  148. real const cos0 = pnts[3][0];
  149. real const cos1 = pnts[3][1];
  150. b2[0x00] = b1[0x00] + b1[0x03];
  151. b2[0x03] = (b1[0x00] - b1[0x03]) * cos0;
  152. b2[0x01] = b1[0x01] + b1[0x02];
  153. b2[0x02] = (b1[0x01] - b1[0x02]) * cos1;
  154. b2[0x04] = b1[0x04] + b1[0x07];
  155. b2[0x07] = (b1[0x07] - b1[0x04]) * cos0;
  156. b2[0x05] = b1[0x05] + b1[0x06];
  157. b2[0x06] = (b1[0x06] - b1[0x05]) * cos1;
  158. b2[0x08] = b1[0x08] + b1[0x0B];
  159. b2[0x0B] = (b1[0x08] - b1[0x0B]) * cos0;
  160. b2[0x09] = b1[0x09] + b1[0x0A];
  161. b2[0x0A] = (b1[0x09] - b1[0x0A]) * cos1;
  162. b2[0x0C] = b1[0x0C] + b1[0x0F];
  163. b2[0x0F] = (b1[0x0F] - b1[0x0C]) * cos0;
  164. b2[0x0D] = b1[0x0D] + b1[0x0E];
  165. b2[0x0E] = (b1[0x0E] - b1[0x0D]) * cos1;
  166. b2[0x10] = b1[0x10] + b1[0x13];
  167. b2[0x13] = (b1[0x10] - b1[0x13]) * cos0;
  168. b2[0x11] = b1[0x11] + b1[0x12];
  169. b2[0x12] = (b1[0x11] - b1[0x12]) * cos1;
  170. b2[0x14] = b1[0x14] + b1[0x17];
  171. b2[0x17] = (b1[0x17] - b1[0x14]) * cos0;
  172. b2[0x15] = b1[0x15] + b1[0x16];
  173. b2[0x16] = (b1[0x16] - b1[0x15]) * cos1;
  174. b2[0x18] = b1[0x18] + b1[0x1B];
  175. b2[0x1B] = (b1[0x18] - b1[0x1B]) * cos0;
  176. b2[0x19] = b1[0x19] + b1[0x1A];
  177. b2[0x1A] = (b1[0x19] - b1[0x1A]) * cos1;
  178. b2[0x1C] = b1[0x1C] + b1[0x1F];
  179. b2[0x1F] = (b1[0x1F] - b1[0x1C]) * cos0;
  180. b2[0x1D] = b1[0x1D] + b1[0x1E];
  181. b2[0x1E] = (b1[0x1E] - b1[0x1D]) * cos1;
  182. }
  183. {
  184. real const cos0 = pnts[4][0];
  185. b1[0x00] = b2[0x00] + b2[0x01];
  186. b1[0x01] = (b2[0x00] - b2[0x01]) * cos0;
  187. b1[0x02] = b2[0x02] + b2[0x03];
  188. b1[0x03] = (b2[0x03] - b2[0x02]) * cos0;
  189. b1[0x02] += b1[0x03];
  190. b1[0x04] = b2[0x04] + b2[0x05];
  191. b1[0x05] = (b2[0x04] - b2[0x05]) * cos0;
  192. b1[0x06] = b2[0x06] + b2[0x07];
  193. b1[0x07] = (b2[0x07] - b2[0x06]) * cos0;
  194. b1[0x06] += b1[0x07];
  195. b1[0x04] += b1[0x06];
  196. b1[0x06] += b1[0x05];
  197. b1[0x05] += b1[0x07];
  198. b1[0x08] = b2[0x08] + b2[0x09];
  199. b1[0x09] = (b2[0x08] - b2[0x09]) * cos0;
  200. b1[0x0A] = b2[0x0A] + b2[0x0B];
  201. b1[0x0B] = (b2[0x0B] - b2[0x0A]) * cos0;
  202. b1[0x0A] += b1[0x0B];
  203. b1[0x0C] = b2[0x0C] + b2[0x0D];
  204. b1[0x0D] = (b2[0x0C] - b2[0x0D]) * cos0;
  205. b1[0x0E] = b2[0x0E] + b2[0x0F];
  206. b1[0x0F] = (b2[0x0F] - b2[0x0E]) * cos0;
  207. b1[0x0E] += b1[0x0F];
  208. b1[0x0C] += b1[0x0E];
  209. b1[0x0E] += b1[0x0D];
  210. b1[0x0D] += b1[0x0F];
  211. b1[0x10] = b2[0x10] + b2[0x11];
  212. b1[0x11] = (b2[0x10] - b2[0x11]) * cos0;
  213. b1[0x12] = b2[0x12] + b2[0x13];
  214. b1[0x13] = (b2[0x13] - b2[0x12]) * cos0;
  215. b1[0x12] += b1[0x13];
  216. b1[0x14] = b2[0x14] + b2[0x15];
  217. b1[0x15] = (b2[0x14] - b2[0x15]) * cos0;
  218. b1[0x16] = b2[0x16] + b2[0x17];
  219. b1[0x17] = (b2[0x17] - b2[0x16]) * cos0;
  220. b1[0x16] += b1[0x17];
  221. b1[0x14] += b1[0x16];
  222. b1[0x16] += b1[0x15];
  223. b1[0x15] += b1[0x17];
  224. b1[0x18] = b2[0x18] + b2[0x19];
  225. b1[0x19] = (b2[0x18] - b2[0x19]) * cos0;
  226. b1[0x1A] = b2[0x1A] + b2[0x1B];
  227. b1[0x1B] = (b2[0x1B] - b2[0x1A]) * cos0;
  228. b1[0x1A] += b1[0x1B];
  229. b1[0x1C] = b2[0x1C] + b2[0x1D];
  230. b1[0x1D] = (b2[0x1C] - b2[0x1D]) * cos0;
  231. b1[0x1E] = b2[0x1E] + b2[0x1F];
  232. b1[0x1F] = (b2[0x1F] - b2[0x1E]) * cos0;
  233. b1[0x1E] += b1[0x1F];
  234. b1[0x1C] += b1[0x1E];
  235. b1[0x1E] += b1[0x1D];
  236. b1[0x1D] += b1[0x1F];
  237. }
  238. out0[0x10 * 16] = b1[0x00];
  239. out0[0x10 * 12] = b1[0x04];
  240. out0[0x10 * 8] = b1[0x02];
  241. out0[0x10 * 4] = b1[0x06];
  242. out0[0x10 * 0] = b1[0x01];
  243. out1[0x10 * 0] = b1[0x01];
  244. out1[0x10 * 4] = b1[0x05];
  245. out1[0x10 * 8] = b1[0x03];
  246. out1[0x10 * 12] = b1[0x07];
  247. b1[0x08] += b1[0x0C];
  248. out0[0x10 * 14] = b1[0x08];
  249. b1[0x0C] += b1[0x0a];
  250. out0[0x10 * 10] = b1[0x0C];
  251. b1[0x0A] += b1[0x0E];
  252. out0[0x10 * 6] = b1[0x0A];
  253. b1[0x0E] += b1[0x09];
  254. out0[0x10 * 2] = b1[0x0E];
  255. b1[0x09] += b1[0x0D];
  256. out1[0x10 * 2] = b1[0x09];
  257. b1[0x0D] += b1[0x0B];
  258. out1[0x10 * 6] = b1[0x0D];
  259. b1[0x0B] += b1[0x0F];
  260. out1[0x10 * 10] = b1[0x0B];
  261. out1[0x10 * 14] = b1[0x0F];
  262. b1[0x18] += b1[0x1C];
  263. out0[0x10 * 15] = b1[0x10] + b1[0x18];
  264. out0[0x10 * 13] = b1[0x18] + b1[0x14];
  265. b1[0x1C] += b1[0x1a];
  266. out0[0x10 * 11] = b1[0x14] + b1[0x1C];
  267. out0[0x10 * 9] = b1[0x1C] + b1[0x12];
  268. b1[0x1A] += b1[0x1E];
  269. out0[0x10 * 7] = b1[0x12] + b1[0x1A];
  270. out0[0x10 * 5] = b1[0x1A] + b1[0x16];
  271. b1[0x1E] += b1[0x19];
  272. out0[0x10 * 3] = b1[0x16] + b1[0x1E];
  273. out0[0x10 * 1] = b1[0x1E] + b1[0x11];
  274. b1[0x19] += b1[0x1D];
  275. out1[0x10 * 1] = b1[0x11] + b1[0x19];
  276. out1[0x10 * 3] = b1[0x19] + b1[0x15];
  277. b1[0x1D] += b1[0x1B];
  278. out1[0x10 * 5] = b1[0x15] + b1[0x1D];
  279. out1[0x10 * 7] = b1[0x1D] + b1[0x13];
  280. b1[0x1B] += b1[0x1F];
  281. out1[0x10 * 9] = b1[0x13] + b1[0x1B];
  282. out1[0x10 * 11] = b1[0x1B] + b1[0x17];
  283. out1[0x10 * 13] = b1[0x17] + b1[0x1F];
  284. out1[0x10 * 15] = b1[0x1F];
  285. }
  286. /*
  287. * the call via dct64 is a trick to force GCC to use
  288. * (new) registers for the b1,b2 pointer to the bufs[xx] field
  289. */
  290. void
  291. dct64(real * a, real * b, real * c)
  292. {
  293. real bufs[0x40];
  294. dct64_1(a, b, bufs, bufs + 0x20, c);
  295. }