jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1195 lines
33KB

  1. /*
  2. Copyright (C) 2000 Paul Davis
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #define _ISOC9X_SOURCE 1
  16. #define _ISOC99_SOURCE 1
  17. #define __USE_ISOC9X 1
  18. #define __USE_ISOC99 1
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <math.h>
  22. #include <memory.h>
  23. #include <stdlib.h>
  24. #include <stdint.h>
  25. #include <limits.h>
  26. #ifdef __linux__
  27. #include <endian.h>
  28. #endif
  29. #include "memops.h"
  30. #if defined (__SSE2__) && !defined (__sun__)
  31. #include <emmintrin.h>
  32. #ifdef __SSE4_1__
  33. #include <smmintrin.h>
  34. #endif
  35. #endif
  36. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  37. #include <arm_neon.h>
  38. #endif
  39. /* Notes about these *_SCALING values.
  40. the MAX_<N>BIT values are floating point. when multiplied by
  41. a full-scale normalized floating point sample value (-1.0..+1.0)
  42. they should give the maxium value representable with an integer
  43. sample type of N bits. Note that this is asymmetric. Sample ranges
  44. for signed integer, 2's complement values are -(2^(N-1) to +(2^(N-1)-1)
  45. Complications
  46. -------------
  47. If we use +2^(N-1) for the scaling factors, we run into a problem:
  48. if we start with a normalized float value of -1.0, scaling
  49. to 24 bits would give -8388608 (-2^23), which is ideal.
  50. But with +1.0, we get +8388608, which is technically out of range.
  51. We never multiply a full range normalized value by this constant,
  52. but we could multiply it by a positive value that is close enough to +1.0
  53. to produce a value > +(2^(N-1)-1.
  54. There is no way around this paradox without wasting CPU cycles to determine
  55. which scaling factor to use (i.e. determine if its negative or not,
  56. use the right factor).
  57. So, for now (October 2008) we use 2^(N-1)-1 as the scaling factor.
  58. */
  59. #define SAMPLE_32BIT_SCALING 0x7FFFFFFF
  60. #define SAMPLE_24BIT_SCALING 8388607
  61. #define SAMPLE_16BIT_SCALING 32767
  62. /* these are just values to use if the floating point value was out of range
  63. advice from Fons Adriaensen: make the limits symmetrical
  64. */
  65. #define SAMPLE_24BIT_MAX 8388607
  66. #define SAMPLE_24BIT_MIN -8388607
  67. #define SAMPLE_16BIT_MAX 32767
  68. #define SAMPLE_16BIT_MIN -32767
  69. #define SAMPLE_16BIT_MAX_F 32767.0f
  70. #define SAMPLE_16BIT_MIN_F -32767.0f
  71. /* these mark the outer edges of the range considered "within" range
  72. for a floating point sample value. values outside (and on the boundaries)
  73. of this range will be clipped before conversion; values within this
  74. range will be scaled to appropriate values for the target sample
  75. type.
  76. */
  77. #define NORMALIZED_FLOAT_MIN -1.0f
  78. #define NORMALIZED_FLOAT_MAX 1.0f
  79. /* define this in case we end up on a platform that is missing
  80. the real lrintf functions
  81. */
  82. #define f_round(f) lrintf(f)
  83. #define float_16(s, d)\
  84. if ((s) <= NORMALIZED_FLOAT_MIN) {\
  85. (d) = SAMPLE_16BIT_MIN;\
  86. } else if ((s) >= NORMALIZED_FLOAT_MAX) {\
  87. (d) = SAMPLE_16BIT_MAX;\
  88. } else {\
  89. (d) = f_round ((s) * SAMPLE_16BIT_SCALING);\
  90. }
  91. /* call this when "s" has already been scaled (e.g. when dithering)
  92. */
  93. #define float_16_scaled(s, d)\
  94. if ((s) <= SAMPLE_16BIT_MIN_F) {\
  95. (d) = SAMPLE_16BIT_MIN_F;\
  96. } else if ((s) >= SAMPLE_16BIT_MAX_F) { \
  97. (d) = SAMPLE_16BIT_MAX;\
  98. } else {\
  99. (d) = f_round ((s));\
  100. }
  101. #define float_32(s, d, scale) \
  102. if ((s) <= NORMALIZED_FLOAT_MIN) {\
  103. (d) = -scale;\
  104. } else if ((s) >= NORMALIZED_FLOAT_MAX) {\
  105. (d) = scale;\
  106. } else {\
  107. (d) = f_round ((s) * scale);\
  108. }
  109. #define float_24(s, d) \
  110. if ((s) <= NORMALIZED_FLOAT_MIN) {\
  111. (d) = SAMPLE_24BIT_MIN;\
  112. } else if ((s) >= NORMALIZED_FLOAT_MAX) {\
  113. (d) = SAMPLE_24BIT_MAX;\
  114. } else {\
  115. (d) = f_round ((s) * SAMPLE_24BIT_SCALING);\
  116. }
  117. #if defined (__SSE2__) && !defined (__sun__)
  118. /* generates same as _mm_set_ps(1.f, 1.f, 1f., 1f) but faster */
  119. static inline __m128 gen_one(void)
  120. {
  121. volatile __m128i x = { 0 }; /* shut up, GCC */
  122. __m128i ones = _mm_cmpeq_epi32(x, x);
  123. return (__m128)_mm_slli_epi32 (_mm_srli_epi32(ones, 25), 23);
  124. }
  125. static inline __m128 clip(__m128 s, __m128 min, __m128 max)
  126. {
  127. return _mm_min_ps(max, _mm_max_ps(s, min));
  128. }
  129. static inline __m128i float_24_sse(__m128 s)
  130. {
  131. const __m128 upper_bound = gen_one(); /* NORMALIZED_FLOAT_MAX */
  132. const __m128 lower_bound = _mm_sub_ps(_mm_setzero_ps(), upper_bound);
  133. __m128 clipped = clip(s, lower_bound, upper_bound);
  134. __m128 scaled = _mm_mul_ps(clipped, _mm_set1_ps(SAMPLE_24BIT_SCALING));
  135. return _mm_cvtps_epi32(scaled);
  136. }
  137. #endif
  138. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  139. static inline float32x4_t clip(float32x4_t s, float32x4_t min, float32x4_t max)
  140. {
  141. return vminq_f32(max, vmaxq_f32(s, min));
  142. }
  143. static inline int32x4_t float_32_neon(float32x4_t s, const int32_t scaling)
  144. {
  145. const float32x4_t upper_bound = vdupq_n_f32(NORMALIZED_FLOAT_MAX);
  146. const float32x4_t lower_bound = vdupq_n_f32(NORMALIZED_FLOAT_MIN);
  147. float32x4_t clipped = clip(s, lower_bound, upper_bound);
  148. float32x4_t scaled = vmulq_f32(clipped, vdupq_n_f32(scaling));
  149. return vcvtq_s32_f32(scaled);
  150. }
  151. static inline int16x4_t float_16_neon(float32x4_t s)
  152. {
  153. const float32x4_t upper_bound = vdupq_n_f32(NORMALIZED_FLOAT_MAX);
  154. const float32x4_t lower_bound = vdupq_n_f32(NORMALIZED_FLOAT_MIN);
  155. float32x4_t clipped = clip(s, lower_bound, upper_bound);
  156. float32x4_t scaled = vmulq_f32(clipped, vdupq_n_f32(SAMPLE_16BIT_SCALING));
  157. return vmovn_s32(vcvtq_s32_f32(scaled));
  158. }
  159. #endif
  160. /* Linear Congruential noise generator. From the music-dsp list
  161. * less random than rand(), but good enough and 10x faster
  162. */
  163. static unsigned int seed = 22222;
  164. static inline unsigned int fast_rand() {
  165. seed = (seed * 196314165) + 907633515;
  166. return seed;
  167. }
  168. /* functions for native float sample data */
  169. void sample_move_floatLE_sSs (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip) {
  170. while (nsamples--) {
  171. *dst = *((float *) src);
  172. dst++;
  173. src += src_skip;
  174. }
  175. }
  176. void sample_move_dS_floatLE (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state) {
  177. while (nsamples--) {
  178. *((float *) dst) = *src;
  179. dst += dst_skip;
  180. src++;
  181. }
  182. }
  183. /* NOTES on function naming:
  184. foo_bar_d<TYPE>_s<TYPE>
  185. the "d<TYPE>" component defines the destination type for the operation
  186. the "s<TYPE>" component defines the source type for the operation
  187. TYPE can be one of:
  188. S - sample is a jack_default_audio_sample_t, currently (October 2008) a 32 bit floating point value
  189. Ss - like S but reverse endian from the host CPU
  190. 32 - sample is an signed 32 bit integer value
  191. 32s - like 32 but reverse endian from the host CPU
  192. 32u24 - sample is an signed 32 bit integer value, but data is in lower 24 bits only
  193. 32u24s - like 32u24 but reverse endian from the host CPU
  194. 24 - sample is an signed 24 bit integer value
  195. 24s - like 24 but reverse endian from the host CPU
  196. 16 - sample is an signed 16 bit integer value
  197. 16s - like 16 but reverse endian from the host CPU
  198. For obvious reasons, the reverse endian versions only show as source types.
  199. This covers all known sample formats at 16 bits or larger.
  200. */
  201. /* functions for native integer sample data */
  202. static inline void sample_move_d32scal_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state, const int32_t scaling)
  203. {
  204. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  205. unsigned long unrolled = nsamples / 4;
  206. nsamples = nsamples & 3;
  207. while (unrolled--) {
  208. float32x4_t samples = vld1q_f32(src);
  209. int32x4_t converted = float_32_neon(samples, scaling);
  210. converted = vreinterpretq_s32_u8(vrev32q_u8(vreinterpretq_u8_s32(converted)));
  211. switch(dst_skip) {
  212. case 4:
  213. vst1q_s32((int32_t*)dst, converted);
  214. break;
  215. default:
  216. vst1q_lane_s32((int32_t*)(dst), converted, 0);
  217. vst1q_lane_s32((int32_t*)(dst+dst_skip), converted, 1);
  218. vst1q_lane_s32((int32_t*)(dst+2*dst_skip), converted, 2);
  219. vst1q_lane_s32((int32_t*)(dst+3*dst_skip), converted, 3);
  220. break;
  221. }
  222. dst += 4*dst_skip;
  223. src+= 4;
  224. }
  225. #endif
  226. int32_t z;
  227. while (nsamples--) {
  228. float_32 (*src, z, scaling);
  229. #if __BYTE_ORDER == __LITTLE_ENDIAN
  230. dst[0]=(char)(z>>24);
  231. dst[1]=(char)(z>>16);
  232. dst[2]=(char)(z>>8);
  233. dst[3]=(char)(z);
  234. #elif __BYTE_ORDER == __BIG_ENDIAN
  235. dst[0]=(char)(z);
  236. dst[1]=(char)(z>>8);
  237. dst[2]=(char)(z>>16);
  238. dst[3]=(char)(z>>24);
  239. #endif
  240. dst += dst_skip;
  241. src++;
  242. }
  243. }
  244. void sample_move_d32u24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  245. {
  246. sample_move_d32scal_sSs (dst, src, nsamples, dst_skip, state, SAMPLE_24BIT_SCALING);
  247. }
  248. void sample_move_d32_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  249. {
  250. sample_move_d32scal_sSs (dst, src, nsamples, dst_skip, state, SAMPLE_32BIT_SCALING);
  251. }
  252. static inline void sample_move_d32scal_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state, const int32_t scaling)
  253. {
  254. #if defined (__SSE2__) && !defined (__sun__)
  255. __m128 int_max = _mm_set1_ps(scaling);
  256. __m128 int_min = _mm_sub_ps(_mm_setzero_ps(), int_max);
  257. __m128 factor = int_max;
  258. unsigned long unrolled = nsamples / 4;
  259. nsamples = nsamples & 3;
  260. while (unrolled--) {
  261. __m128 in = _mm_load_ps(src);
  262. __m128 scaled = _mm_mul_ps(in, factor);
  263. __m128 clipped = clip(scaled, int_min, int_max);
  264. __m128i y = _mm_cvttps_epi32(clipped);
  265. #ifdef __SSE4_1__
  266. *(int32_t*)dst = _mm_extract_epi32(y, 0);
  267. *(int32_t*)(dst+dst_skip) = _mm_extract_epi32(y, 1);
  268. *(int32_t*)(dst+2*dst_skip) = _mm_extract_epi32(y, 2);
  269. *(int32_t*)(dst+3*dst_skip) = _mm_extract_epi32(y, 3);
  270. #else
  271. __m128i shuffled1 = _mm_shuffle_epi32(y, _MM_SHUFFLE(0, 3, 2, 1));
  272. __m128i shuffled2 = _mm_shuffle_epi32(y, _MM_SHUFFLE(1, 0, 3, 2));
  273. __m128i shuffled3 = _mm_shuffle_epi32(y, _MM_SHUFFLE(2, 1, 0, 3));
  274. _mm_store_ss((float*)dst, (__m128)y);
  275. _mm_store_ss((float*)(dst+dst_skip), (__m128)shuffled1);
  276. _mm_store_ss((float*)(dst+2*dst_skip), (__m128)shuffled2);
  277. _mm_store_ss((float*)(dst+3*dst_skip), (__m128)shuffled3);
  278. #endif
  279. dst += 4*dst_skip;
  280. src+= 4;
  281. }
  282. while (nsamples--) {
  283. __m128 in = _mm_load_ss(src);
  284. __m128 scaled = _mm_mul_ss(in, factor);
  285. __m128 clipped = _mm_min_ss(int_max, _mm_max_ss(scaled, int_min));
  286. int y = _mm_cvttss_si32(clipped);
  287. *((int *) dst) = y;
  288. dst += dst_skip;
  289. src++;
  290. }
  291. #elif defined (__ARM_NEON__) || defined (__ARM_NEON)
  292. unsigned long unrolled = nsamples / 4;
  293. nsamples = nsamples & 3;
  294. while (unrolled--) {
  295. float32x4_t samples = vld1q_f32(src);
  296. int32x4_t converted = float_32_neon(samples, scaling);
  297. switch(dst_skip) {
  298. case 4:
  299. vst1q_s32((int32_t*)dst, converted);
  300. break;
  301. default:
  302. vst1q_lane_s32((int32_t*)(dst), converted, 0);
  303. vst1q_lane_s32((int32_t*)(dst+dst_skip), converted, 1);
  304. vst1q_lane_s32((int32_t*)(dst+2*dst_skip), converted, 2);
  305. vst1q_lane_s32((int32_t*)(dst+3*dst_skip), converted, 3);
  306. break;
  307. }
  308. dst += 4*dst_skip;
  309. src+= 4;
  310. }
  311. #endif
  312. #if !defined (__SSE2__)
  313. while (nsamples--) {
  314. float_32 (*src, *((int32_t*) dst), scaling);
  315. dst += dst_skip;
  316. src++;
  317. }
  318. #endif
  319. }
  320. void sample_move_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  321. {
  322. sample_move_d32scal_sS (dst, src, nsamples, dst_skip, state, SAMPLE_24BIT_SCALING);
  323. }
  324. void sample_move_d32_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  325. {
  326. sample_move_d32scal_sS (dst, src, nsamples, dst_skip, state, SAMPLE_32BIT_SCALING);
  327. }
  328. void sample_move_dS_s32u24s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  329. {
  330. const jack_default_audio_sample_t scaling = 1.0 / (SAMPLE_24BIT_SCALING << 8);
  331. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  332. float32x4_t factor = vdupq_n_f32(scaling);
  333. unsigned long unrolled = nsamples / 4;
  334. while (unrolled--) {
  335. int32x4_t src128;
  336. switch(src_skip)
  337. {
  338. case 4:
  339. src128 = vld1q_s32((int32_t*)src);
  340. break;
  341. case 8:
  342. src128 = vld2q_s32((int32_t*)src).val[0];
  343. break;
  344. default:
  345. src128 = vld1q_lane_s32((int32_t*)src, src128, 0);
  346. src128 = vld1q_lane_s32((int32_t*)(src+src_skip), src128, 1);
  347. src128 = vld1q_lane_s32((int32_t*)(src+2*src_skip), src128, 2);
  348. src128 = vld1q_lane_s32((int32_t*)(src+3*src_skip), src128, 3);
  349. break;
  350. }
  351. src128 = vreinterpretq_s32_u8(vrev32q_u8(vreinterpretq_u8_s32(src128)));
  352. /* sign extension - left shift will be reverted by scaling */
  353. int32x4_t shifted = vshlq_n_s32(src128, 8);
  354. float32x4_t as_float = vcvtq_f32_s32(shifted);
  355. float32x4_t divided = vmulq_f32(as_float, factor);
  356. vst1q_f32(dst, divided);
  357. src += 4*src_skip;
  358. dst += 4;
  359. }
  360. nsamples = nsamples & 3;
  361. #endif
  362. /* ALERT: signed sign-extension portability !!! */
  363. while (nsamples--) {
  364. int x;
  365. #if __BYTE_ORDER == __LITTLE_ENDIAN
  366. x = (unsigned char)(src[0]);
  367. x <<= 8;
  368. x |= (unsigned char)(src[1]);
  369. x <<= 8;
  370. x |= (unsigned char)(src[2]);
  371. x <<= 8;
  372. x |= (unsigned char)(src[3]);
  373. #elif __BYTE_ORDER == __BIG_ENDIAN
  374. x = (unsigned char)(src[3]);
  375. x <<= 8;
  376. x |= (unsigned char)(src[2]);
  377. x <<= 8;
  378. x |= (unsigned char)(src[1]);
  379. x <<= 8;
  380. x |= (unsigned char)(src[0]);
  381. #endif
  382. /* sign extension - left shift will be reverted by scaling */
  383. *dst = (x << 8) * scaling;
  384. dst++;
  385. src += src_skip;
  386. }
  387. }
  388. void sample_move_dS_s32u24 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  389. {
  390. const jack_default_audio_sample_t scaling = 1.0 / (SAMPLE_24BIT_SCALING << 8);
  391. #if defined (__SSE2__) && !defined (__sun__)
  392. unsigned long unrolled = nsamples / 4;
  393. __m128 factor = _mm_set1_ps(scaling);
  394. while (unrolled--)
  395. {
  396. int i1 = *((int *) src);
  397. src+= src_skip;
  398. int i2 = *((int *) src);
  399. src+= src_skip;
  400. int i3 = *((int *) src);
  401. src+= src_skip;
  402. int i4 = *((int *) src);
  403. src+= src_skip;
  404. __m128i src = _mm_set_epi32(i4, i3, i2, i1);
  405. /* sign extension - left shift will be reverted by scaling */
  406. __m128i shifted = _mm_slli_epi32(src, 8);
  407. __m128 as_float = _mm_cvtepi32_ps(shifted);
  408. __m128 divided = _mm_mul_ps(as_float, factor);
  409. _mm_storeu_ps(dst, divided);
  410. dst += 4;
  411. }
  412. nsamples = nsamples & 3;
  413. #elif defined (__ARM_NEON__) || defined (__ARM_NEON)
  414. unsigned long unrolled = nsamples / 4;
  415. float32x4_t factor = vdupq_n_f32(scaling);
  416. while (unrolled--) {
  417. int32x4_t src128;
  418. switch(src_skip) {
  419. case 4:
  420. src128 = vld1q_s32((int32_t*)src);
  421. break;
  422. case 8:
  423. src128 = vld2q_s32((int32_t*)src).val[0];
  424. break;
  425. default:
  426. src128 = vld1q_lane_s32((int32_t*)src, src128, 0);
  427. src128 = vld1q_lane_s32((int32_t*)(src+src_skip), src128, 1);
  428. src128 = vld1q_lane_s32((int32_t*)(src+2*src_skip), src128, 2);
  429. src128 = vld1q_lane_s32((int32_t*)(src+3*src_skip), src128, 3);
  430. break;
  431. }
  432. /* sign extension - left shift will be reverted by scaling */
  433. int32x4_t shifted = vshlq_n_s32(src128, 8);
  434. float32x4_t as_float = vcvtq_f32_s32(shifted);
  435. float32x4_t divided = vmulq_f32(as_float, factor);
  436. vst1q_f32(dst, divided);
  437. src += 4*src_skip;
  438. dst += 4;
  439. }
  440. nsamples = nsamples & 3;
  441. #endif
  442. /* ALERT: signed sign-extension portability !!! */
  443. while (nsamples--) {
  444. /* sign extension - left shift will be reverted by scaling */
  445. *dst = (*((int *) src) << 8) * scaling;
  446. dst++;
  447. src += src_skip;
  448. }
  449. }
  450. void sample_move_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  451. {
  452. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  453. unsigned long unrolled = nsamples / 4;
  454. while (unrolled--) {
  455. int i;
  456. int32_t z[4];
  457. float32x4_t samples = vld1q_f32(src);
  458. int32x4_t converted = float_32_neon(samples, SAMPLE_24BIT_SCALING);
  459. converted = vreinterpretq_s32_u8(vrev32q_u8(vreinterpretq_u8_s32(converted)));
  460. vst1q_s32(z, converted);
  461. for (i = 0; i != 4; ++i) {
  462. memcpy (dst, ((char*)(z+i))+1, 3);
  463. dst += dst_skip;
  464. }
  465. src += 4;
  466. }
  467. nsamples = nsamples & 3;
  468. #endif
  469. int32_t z;
  470. while (nsamples--) {
  471. float_24 (*src, z);
  472. #if __BYTE_ORDER == __LITTLE_ENDIAN
  473. dst[0]=(char)(z>>16);
  474. dst[1]=(char)(z>>8);
  475. dst[2]=(char)(z);
  476. #elif __BYTE_ORDER == __BIG_ENDIAN
  477. dst[0]=(char)(z);
  478. dst[1]=(char)(z>>8);
  479. dst[2]=(char)(z>>16);
  480. #endif
  481. dst += dst_skip;
  482. src++;
  483. }
  484. }
  485. void sample_move_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  486. {
  487. #if defined (__SSE2__) && !defined (__sun__)
  488. _MM_SET_ROUNDING_MODE(_MM_ROUND_NEAREST);
  489. while (nsamples >= 4) {
  490. int i;
  491. int32_t z[4];
  492. __m128 samples = _mm_loadu_ps(src);
  493. __m128i converted = float_24_sse(samples);
  494. #ifdef __SSE4_1__
  495. z[0] = _mm_extract_epi32(converted, 0);
  496. z[1] = _mm_extract_epi32(converted, 1);
  497. z[2] = _mm_extract_epi32(converted, 2);
  498. z[3] = _mm_extract_epi32(converted, 3);
  499. #else
  500. __m128i shuffled1 = _mm_shuffle_epi32(converted, _MM_SHUFFLE(0, 3, 2, 1));
  501. __m128i shuffled2 = _mm_shuffle_epi32(converted, _MM_SHUFFLE(1, 0, 3, 2));
  502. __m128i shuffled3 = _mm_shuffle_epi32(converted, _MM_SHUFFLE(2, 1, 0, 3));
  503. _mm_store_ss((float*)z, (__m128)converted);
  504. _mm_store_ss((float*)z+1, (__m128)shuffled1);
  505. _mm_store_ss((float*)z+2, (__m128)shuffled2);
  506. _mm_store_ss((float*)z+3, (__m128)shuffled3);
  507. #endif
  508. for (i = 0; i != 4; ++i) {
  509. memcpy (dst, z+i, 3);
  510. dst += dst_skip;
  511. }
  512. nsamples -= 4;
  513. src += 4;
  514. }
  515. #elif defined (__ARM_NEON__) || defined (__ARM_NEON)
  516. unsigned long unrolled = nsamples / 4;
  517. while (unrolled--) {
  518. int i;
  519. int32_t z[4];
  520. float32x4_t samples = vld1q_f32(src);
  521. int32x4_t converted = float_32_neon(samples, SAMPLE_24BIT_SCALING);
  522. vst1q_s32(z, converted);
  523. for (i = 0; i != 4; ++i) {
  524. memcpy (dst, z+i, 3);
  525. dst += dst_skip;
  526. }
  527. src += 4;
  528. }
  529. nsamples = nsamples & 3;
  530. #endif
  531. int32_t z;
  532. while (nsamples--) {
  533. float_24 (*src, z);
  534. #if __BYTE_ORDER == __LITTLE_ENDIAN
  535. memcpy (dst, &z, 3);
  536. #elif __BYTE_ORDER == __BIG_ENDIAN
  537. memcpy (dst, (char *)&z + 1, 3);
  538. #endif
  539. dst += dst_skip;
  540. src++;
  541. }
  542. }
  543. void sample_move_dS_s24s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  544. {
  545. const jack_default_audio_sample_t scaling = 1.0/SAMPLE_24BIT_SCALING;
  546. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  547. // we shift 8 to the right by dividing by 256.0 -> no sign extra handling
  548. const float32x4_t vscaling = vdupq_n_f32(scaling/256.0);
  549. int32_t x[4];
  550. memset(x, 0, sizeof(x));
  551. unsigned long unrolled = nsamples / 4;
  552. while (unrolled--) {
  553. #if __BYTE_ORDER == __BIG_ENDIAN /* ARM big endian?? */
  554. // right aligned / inverse sequence below -> *256
  555. memcpy(((char*)&x[0])+1, src, 3);
  556. memcpy(((char*)&x[1])+1, src+src_skip, 3);
  557. memcpy(((char*)&x[2])+1, src+2*src_skip, 3);
  558. memcpy(((char*)&x[3])+1, src+3*src_skip, 3);
  559. #else
  560. memcpy(&x[0], src, 3);
  561. memcpy(&x[1], src+src_skip, 3);
  562. memcpy(&x[2], src+2*src_skip, 3);
  563. memcpy(&x[3], src+3*src_skip, 3);
  564. #endif
  565. src += 4 * src_skip;
  566. int32x4_t source = vld1q_s32(x);
  567. source = vreinterpretq_s32_u8(vrev32q_u8(vreinterpretq_u8_s32(source)));
  568. float32x4_t converted = vcvtq_f32_s32(source);
  569. float32x4_t scaled = vmulq_f32(converted, vscaling);
  570. vst1q_f32(dst, scaled);
  571. dst += 4;
  572. }
  573. nsamples = nsamples & 3;
  574. #endif
  575. /* ALERT: signed sign-extension portability !!! */
  576. while (nsamples--) {
  577. int x;
  578. #if __BYTE_ORDER == __LITTLE_ENDIAN
  579. x = (unsigned char)(src[0]);
  580. x <<= 8;
  581. x |= (unsigned char)(src[1]);
  582. x <<= 8;
  583. x |= (unsigned char)(src[2]);
  584. /* correct sign bit and the rest of the top byte */
  585. if (src[0] & 0x80) {
  586. x |= 0xff << 24;
  587. }
  588. #elif __BYTE_ORDER == __BIG_ENDIAN
  589. x = (unsigned char)(src[2]);
  590. x <<= 8;
  591. x |= (unsigned char)(src[1]);
  592. x <<= 8;
  593. x |= (unsigned char)(src[0]);
  594. /* correct sign bit and the rest of the top byte */
  595. if (src[2] & 0x80) {
  596. x |= 0xff << 24;
  597. }
  598. #endif
  599. *dst = x * scaling;
  600. dst++;
  601. src += src_skip;
  602. }
  603. }
  604. void sample_move_dS_s24 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  605. {
  606. const jack_default_audio_sample_t scaling = 1.f/SAMPLE_24BIT_SCALING;
  607. #if defined (__SSE2__) && !defined (__sun__)
  608. const __m128 scaling_block = _mm_set_ps1(scaling);
  609. while (nsamples >= 4) {
  610. int x0, x1, x2, x3;
  611. memcpy((char*)&x0 + 1, src, 3);
  612. memcpy((char*)&x1 + 1, src+src_skip, 3);
  613. memcpy((char*)&x2 + 1, src+2*src_skip, 3);
  614. memcpy((char*)&x3 + 1, src+3*src_skip, 3);
  615. src += 4 * src_skip;
  616. const __m128i block_i = _mm_set_epi32(x3, x2, x1, x0);
  617. const __m128i shifted = _mm_srai_epi32(block_i, 8);
  618. const __m128 converted = _mm_cvtepi32_ps (shifted);
  619. const __m128 scaled = _mm_mul_ps(converted, scaling_block);
  620. _mm_storeu_ps(dst, scaled);
  621. dst += 4;
  622. nsamples -= 4;
  623. }
  624. #elif defined (__ARM_NEON__) || defined (__ARM_NEON)
  625. // we shift 8 to the right by dividing by 256.0 -> no sign extra handling
  626. const float32x4_t vscaling = vdupq_n_f32(scaling/256.0);
  627. int32_t x[4];
  628. memset(x, 0, sizeof(x));
  629. unsigned long unrolled = nsamples / 4;
  630. while (unrolled--) {
  631. #if __BYTE_ORDER == __BIG_ENDIAN /* ARM big endian?? */
  632. // left aligned -> *256
  633. memcpy(&x[0], src, 3);
  634. memcpy(&x[1], src+src_skip, 3);
  635. memcpy(&x[2], src+2*src_skip, 3);
  636. memcpy(&x[3], src+3*src_skip, 3);
  637. #else
  638. memcpy(((char*)&x[0])+1, src, 3);
  639. memcpy(((char*)&x[1])+1, src+src_skip, 3);
  640. memcpy(((char*)&x[2])+1, src+2*src_skip, 3);
  641. memcpy(((char*)&x[3])+1, src+3*src_skip, 3);
  642. #endif
  643. src += 4 * src_skip;
  644. int32x4_t source = vld1q_s32(x);
  645. float32x4_t converted = vcvtq_f32_s32(source);
  646. float32x4_t scaled = vmulq_f32(converted, vscaling);
  647. vst1q_f32(dst, scaled);
  648. dst += 4;
  649. }
  650. nsamples = nsamples & 3;
  651. #endif
  652. while (nsamples--) {
  653. int x;
  654. #if __BYTE_ORDER == __LITTLE_ENDIAN
  655. memcpy((char*)&x + 1, src, 3);
  656. #elif __BYTE_ORDER == __BIG_ENDIAN
  657. memcpy(&x, src, 3);
  658. #endif
  659. x >>= 8;
  660. *dst = x * scaling;
  661. dst++;
  662. src += src_skip;
  663. }
  664. }
  665. void sample_move_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  666. {
  667. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  668. unsigned long unrolled = nsamples / 4;
  669. nsamples = nsamples & 3;
  670. while (unrolled--) {
  671. float32x4_t samples = vld1q_f32(src);
  672. int16x4_t converted = float_16_neon(samples);
  673. converted = vreinterpret_s16_u8(vrev16_u8(vreinterpret_u8_s16(converted)));
  674. switch(dst_skip) {
  675. case 2:
  676. vst1_s16((int16_t*)dst, converted);
  677. break;
  678. default:
  679. vst1_lane_s16((int16_t*)(dst), converted, 0);
  680. vst1_lane_s16((int16_t*)(dst+dst_skip), converted, 1);
  681. vst1_lane_s16((int16_t*)(dst+2*dst_skip), converted, 2);
  682. vst1_lane_s16((int16_t*)(dst+3*dst_skip), converted, 3);
  683. break;
  684. }
  685. dst += 4*dst_skip;
  686. src+= 4;
  687. }
  688. #endif
  689. int16_t tmp;
  690. while (nsamples--) {
  691. // float_16 (*src, tmp);
  692. if (*src <= NORMALIZED_FLOAT_MIN) {
  693. tmp = SAMPLE_16BIT_MIN;
  694. } else if (*src >= NORMALIZED_FLOAT_MAX) {
  695. tmp = SAMPLE_16BIT_MAX;
  696. } else {
  697. tmp = (int16_t) f_round (*src * SAMPLE_16BIT_SCALING);
  698. }
  699. #if __BYTE_ORDER == __LITTLE_ENDIAN
  700. dst[0]=(char)(tmp>>8);
  701. dst[1]=(char)(tmp);
  702. #elif __BYTE_ORDER == __BIG_ENDIAN
  703. dst[0]=(char)(tmp);
  704. dst[1]=(char)(tmp>>8);
  705. #endif
  706. dst += dst_skip;
  707. src++;
  708. }
  709. }
  710. void sample_move_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  711. {
  712. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  713. unsigned long unrolled = nsamples / 4;
  714. nsamples = nsamples & 3;
  715. while (unrolled--) {
  716. float32x4_t samples = vld1q_f32(src);
  717. int16x4_t converted = float_16_neon(samples);
  718. switch(dst_skip) {
  719. case 2:
  720. vst1_s16((int16_t*)dst, converted);
  721. break;
  722. default:
  723. vst1_lane_s16((int16_t*)(dst), converted, 0);
  724. vst1_lane_s16((int16_t*)(dst+dst_skip), converted, 1);
  725. vst1_lane_s16((int16_t*)(dst+2*dst_skip), converted, 2);
  726. vst1_lane_s16((int16_t*)(dst+3*dst_skip), converted, 3);
  727. break;
  728. }
  729. dst += 4*dst_skip;
  730. src+= 4;
  731. }
  732. #endif
  733. while (nsamples--) {
  734. float_16 (*src, *((int16_t*) dst));
  735. dst += dst_skip;
  736. src++;
  737. }
  738. }
  739. void sample_move_dither_rect_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  740. {
  741. jack_default_audio_sample_t val;
  742. int16_t tmp;
  743. while (nsamples--) {
  744. val = (*src * SAMPLE_16BIT_SCALING) + fast_rand() / (float) UINT_MAX - 0.5f;
  745. float_16_scaled (val, tmp);
  746. #if __BYTE_ORDER == __LITTLE_ENDIAN
  747. dst[0]=(char)(tmp>>8);
  748. dst[1]=(char)(tmp);
  749. #elif __BYTE_ORDER == __BIG_ENDIAN
  750. dst[0]=(char)(tmp);
  751. dst[1]=(char)(tmp>>8);
  752. #endif
  753. dst += dst_skip;
  754. src++;
  755. }
  756. }
  757. void sample_move_dither_rect_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  758. {
  759. jack_default_audio_sample_t val;
  760. while (nsamples--) {
  761. val = (*src * SAMPLE_16BIT_SCALING) + fast_rand() / (float)UINT_MAX - 0.5f;
  762. float_16_scaled (val, *((int16_t*) dst));
  763. dst += dst_skip;
  764. src++;
  765. }
  766. }
  767. void sample_move_dither_tri_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  768. {
  769. jack_default_audio_sample_t val;
  770. int16_t tmp;
  771. while (nsamples--) {
  772. val = (*src * SAMPLE_16BIT_SCALING) + ((float)fast_rand() + (float)fast_rand()) / (float)UINT_MAX - 1.0f;
  773. float_16_scaled (val, tmp);
  774. #if __BYTE_ORDER == __LITTLE_ENDIAN
  775. dst[0]=(char)(tmp>>8);
  776. dst[1]=(char)(tmp);
  777. #elif __BYTE_ORDER == __BIG_ENDIAN
  778. dst[0]=(char)(tmp);
  779. dst[1]=(char)(tmp>>8);
  780. #endif
  781. dst += dst_skip;
  782. src++;
  783. }
  784. }
  785. void sample_move_dither_tri_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  786. {
  787. jack_default_audio_sample_t val;
  788. while (nsamples--) {
  789. val = (*src * SAMPLE_16BIT_SCALING) + ((float)fast_rand() + (float)fast_rand()) / (float)UINT_MAX - 1.0f;
  790. float_16_scaled (val, *((int16_t*) dst));
  791. dst += dst_skip;
  792. src++;
  793. }
  794. }
  795. void sample_move_dither_shaped_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  796. {
  797. jack_default_audio_sample_t x;
  798. jack_default_audio_sample_t xe; /* the innput sample - filtered error */
  799. jack_default_audio_sample_t xp; /* x' */
  800. float r;
  801. float rm1 = state->rm1;
  802. unsigned int idx = state->idx;
  803. int16_t tmp;
  804. while (nsamples--) {
  805. x = *src * SAMPLE_16BIT_SCALING;
  806. r = ((float)fast_rand() + (float)fast_rand()) / (float)UINT_MAX - 1.0f;
  807. /* Filter the error with Lipshitz's minimally audible FIR:
  808. [2.033 -2.165 1.959 -1.590 0.6149] */
  809. xe = x
  810. - state->e[idx] * 2.033f
  811. + state->e[(idx - 1) & DITHER_BUF_MASK] * 2.165f
  812. - state->e[(idx - 2) & DITHER_BUF_MASK] * 1.959f
  813. + state->e[(idx - 3) & DITHER_BUF_MASK] * 1.590f
  814. - state->e[(idx - 4) & DITHER_BUF_MASK] * 0.6149f;
  815. xp = xe + r - rm1;
  816. rm1 = r;
  817. float_16_scaled (xp, tmp);
  818. /* Intrinsic z^-1 delay */
  819. idx = (idx + 1) & DITHER_BUF_MASK;
  820. state->e[idx] = xp - xe;
  821. #if __BYTE_ORDER == __LITTLE_ENDIAN
  822. dst[0]=(char)(tmp>>8);
  823. dst[1]=(char)(tmp);
  824. #elif __BYTE_ORDER == __BIG_ENDIAN
  825. dst[0]=(char)(tmp);
  826. dst[1]=(char)(tmp>>8);
  827. #endif
  828. dst += dst_skip;
  829. src++;
  830. }
  831. state->rm1 = rm1;
  832. state->idx = idx;
  833. }
  834. void sample_move_dither_shaped_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  835. {
  836. jack_default_audio_sample_t x;
  837. jack_default_audio_sample_t xe; /* the innput sample - filtered error */
  838. jack_default_audio_sample_t xp; /* x' */
  839. float r;
  840. float rm1 = state->rm1;
  841. unsigned int idx = state->idx;
  842. while (nsamples--) {
  843. x = *src * SAMPLE_16BIT_SCALING;
  844. r = ((float)fast_rand() + (float)fast_rand()) / (float)UINT_MAX - 1.0f;
  845. /* Filter the error with Lipshitz's minimally audible FIR:
  846. [2.033 -2.165 1.959 -1.590 0.6149] */
  847. xe = x
  848. - state->e[idx] * 2.033f
  849. + state->e[(idx - 1) & DITHER_BUF_MASK] * 2.165f
  850. - state->e[(idx - 2) & DITHER_BUF_MASK] * 1.959f
  851. + state->e[(idx - 3) & DITHER_BUF_MASK] * 1.590f
  852. - state->e[(idx - 4) & DITHER_BUF_MASK] * 0.6149f;
  853. xp = xe + r - rm1;
  854. rm1 = r;
  855. float_16_scaled (xp, *((int16_t*) dst));
  856. /* Intrinsic z^-1 delay */
  857. idx = (idx + 1) & DITHER_BUF_MASK;
  858. state->e[idx] = *((int16_t*) dst) - xe;
  859. dst += dst_skip;
  860. src++;
  861. }
  862. state->rm1 = rm1;
  863. state->idx = idx;
  864. }
  865. void sample_move_dS_s16s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  866. {
  867. short z;
  868. const jack_default_audio_sample_t scaling = 1.0/SAMPLE_16BIT_SCALING;
  869. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  870. const float32x4_t vscaling = vdupq_n_f32(scaling);
  871. unsigned long unrolled = nsamples / 4;
  872. while (unrolled--) {
  873. int16x4_t source16x4;
  874. switch(src_skip) {
  875. case 2:
  876. source16x4 = vld1_s16((int16_t*)src);
  877. break;
  878. case 4:
  879. source16x4 = vld2_s16((int16_t*)src).val[0];
  880. break;
  881. default:
  882. source16x4 = vld1_lane_s16((int16_t*)src, source16x4, 0);
  883. source16x4 = vld1_lane_s16((int16_t*)(src+src_skip), source16x4, 1);
  884. source16x4 = vld1_lane_s16((int16_t*)(src+2*src_skip), source16x4, 2);
  885. source16x4 = vld1_lane_s16((int16_t*)(src+3*src_skip), source16x4, 3);
  886. break;
  887. }
  888. source16x4 = vreinterpret_s16_u8(vrev16_u8(vreinterpret_u8_s16(source16x4)));
  889. int32x4_t source32x4 = vmovl_s16(source16x4);
  890. src += 4 * src_skip;
  891. float32x4_t converted = vcvtq_f32_s32(source32x4);
  892. float32x4_t scaled = vmulq_f32(converted, vscaling);
  893. vst1q_f32(dst, scaled);
  894. dst += 4;
  895. }
  896. nsamples = nsamples & 3;
  897. #endif
  898. /* ALERT: signed sign-extension portability !!! */
  899. while (nsamples--) {
  900. #if __BYTE_ORDER == __LITTLE_ENDIAN
  901. z = (unsigned char)(src[0]);
  902. z <<= 8;
  903. z |= (unsigned char)(src[1]);
  904. #elif __BYTE_ORDER == __BIG_ENDIAN
  905. z = (unsigned char)(src[1]);
  906. z <<= 8;
  907. z |= (unsigned char)(src[0]);
  908. #endif
  909. *dst = z * scaling;
  910. dst++;
  911. src += src_skip;
  912. }
  913. }
  914. void sample_move_dS_s16 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  915. {
  916. /* ALERT: signed sign-extension portability !!! */
  917. const jack_default_audio_sample_t scaling = 1.0/SAMPLE_16BIT_SCALING;
  918. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  919. const float32x4_t vscaling = vdupq_n_f32(scaling);
  920. unsigned long unrolled = nsamples / 4;
  921. while (unrolled--) {
  922. int16x4_t source16x4;
  923. switch(src_skip) {
  924. case 2:
  925. source16x4 = vld1_s16((int16_t*)src);
  926. break;
  927. case 4:
  928. source16x4 = vld2_s16((int16_t*)src).val[0];
  929. break;
  930. default:
  931. source16x4 = vld1_lane_s16((int16_t*)src, source16x4, 0);
  932. source16x4 = vld1_lane_s16((int16_t*)(src+src_skip), source16x4, 1);
  933. source16x4 = vld1_lane_s16((int16_t*)(src+2*src_skip), source16x4, 2);
  934. source16x4 = vld1_lane_s16((int16_t*)(src+3*src_skip), source16x4, 3);
  935. break;
  936. }
  937. int32x4_t source32x4 = vmovl_s16(source16x4);
  938. src += 4 * src_skip;
  939. float32x4_t converted = vcvtq_f32_s32(source32x4);
  940. float32x4_t scaled = vmulq_f32(converted, vscaling);
  941. vst1q_f32(dst, scaled);
  942. dst += 4;
  943. }
  944. nsamples = nsamples & 3;
  945. #endif
  946. while (nsamples--) {
  947. *dst = (*((short *) src)) * scaling;
  948. dst++;
  949. src += src_skip;
  950. }
  951. }
  952. void memset_interleave (char *dst, char val, unsigned long bytes,
  953. unsigned long unit_bytes,
  954. unsigned long skip_bytes)
  955. {
  956. switch (unit_bytes) {
  957. case 1:
  958. while (bytes--) {
  959. *dst = val;
  960. dst += skip_bytes;
  961. }
  962. break;
  963. case 2:
  964. while (bytes) {
  965. *((short *) dst) = (short) val;
  966. dst += skip_bytes;
  967. bytes -= 2;
  968. }
  969. break;
  970. case 4:
  971. while (bytes) {
  972. *((int *) dst) = (int) val;
  973. dst += skip_bytes;
  974. bytes -= 4;
  975. }
  976. break;
  977. default:
  978. while (bytes) {
  979. memset(dst, val, unit_bytes);
  980. dst += skip_bytes;
  981. bytes -= unit_bytes;
  982. }
  983. break;
  984. }
  985. }
  986. /* COPY FUNCTIONS: used to move data from an input channel to an
  987. output channel. Note that we assume that the skip distance
  988. is the same for both channels. This is completely fine
  989. unless the input and output were on different audio interfaces that
  990. were interleaved differently. We don't try to handle that.
  991. */
  992. void
  993. memcpy_fake (char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar)
  994. {
  995. memcpy (dst, src, src_bytes);
  996. }
  997. void
  998. memcpy_interleave_d16_s16 (char *dst, char *src, unsigned long src_bytes,
  999. unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
  1000. {
  1001. while (src_bytes) {
  1002. *((short *) dst) = *((short *) src);
  1003. dst += dst_skip_bytes;
  1004. src += src_skip_bytes;
  1005. src_bytes -= 2;
  1006. }
  1007. }
  1008. void
  1009. memcpy_interleave_d24_s24 (char *dst, char *src, unsigned long src_bytes,
  1010. unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
  1011. {
  1012. while (src_bytes) {
  1013. memcpy(dst, src, 3);
  1014. dst += dst_skip_bytes;
  1015. src += src_skip_bytes;
  1016. src_bytes -= 3;
  1017. }
  1018. }
  1019. void
  1020. memcpy_interleave_d32_s32 (char *dst, char *src, unsigned long src_bytes,
  1021. unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
  1022. {
  1023. while (src_bytes) {
  1024. *((int *) dst) = *((int *) src);
  1025. dst += dst_skip_bytes;
  1026. src += src_skip_bytes;
  1027. src_bytes -= 4;
  1028. }
  1029. }