logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0004-Use-switch-statements-instead-of-labels-as-values.patch (72970B)


  1. From 33cc8c8e77a2282c11601a8a1e14fb2e856af0dc Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Fri, 31 May 2019 17:47:08 -0700
  4. Subject: [PATCH] Use switch statements instead of labels as values
  5. ---
  6. src/pcm/pcm_adpcm.c | 20 +-
  7. src/pcm/pcm_alaw.c | 20 +-
  8. src/pcm/pcm_iec958.c | 22 +-
  9. src/pcm/pcm_lfloat.c | 42 +-
  10. src/pcm/pcm_linear.c | 22 +-
  11. src/pcm/pcm_mulaw.c | 20 +-
  12. src/pcm/pcm_rate_linear.c | 42 +-
  13. src/pcm/pcm_route.c | 163 +++----
  14. src/pcm/plugin_ops.h | 937 ++++++++++++++------------------------
  15. 9 files changed, 412 insertions(+), 876 deletions(-)
  16. diff --git a/src/pcm/pcm_adpcm.c b/src/pcm/pcm_adpcm.c
  17. index fd9b9e8e..d4546cd0 100644
  18. --- a/src/pcm/pcm_adpcm.c
  19. +++ b/src/pcm/pcm_adpcm.c
  20. @@ -220,10 +220,6 @@ void snd_pcm_adpcm_decode(const snd_pcm_channel_area_t *dst_areas,
  21. unsigned int putidx,
  22. snd_pcm_adpcm_state_t *states)
  23. {
  24. -#define PUT16_LABELS
  25. -#include "plugin_ops.h"
  26. -#undef PUT16_LABELS
  27. - void *put = put16_labels[putidx];
  28. unsigned int channel;
  29. for (channel = 0; channel < channels; ++channel, ++states) {
  30. const char *src;
  31. @@ -249,11 +245,7 @@ void snd_pcm_adpcm_decode(const snd_pcm_channel_area_t *dst_areas,
  32. else
  33. v = (*src >> 4) & 0x0f;
  34. sample = adpcm_decoder(v, states);
  35. - goto *put;
  36. -#define PUT16_END after
  37. -#include "plugin_ops.h"
  38. -#undef PUT16_END
  39. - after:
  40. + put16(dst, sample, putidx);
  41. src += src_step;
  42. srcbit += srcbit_step;
  43. if (srcbit == 8) {
  44. @@ -273,10 +265,6 @@ void snd_pcm_adpcm_encode(const snd_pcm_channel_area_t *dst_areas,
  45. unsigned int getidx,
  46. snd_pcm_adpcm_state_t *states)
  47. {
  48. -#define GET16_LABELS
  49. -#include "plugin_ops.h"
  50. -#undef GET16_LABELS
  51. - void *get = get16_labels[getidx];
  52. unsigned int channel;
  53. int16_t sample = 0;
  54. for (channel = 0; channel < channels; ++channel, ++states) {
  55. @@ -297,11 +285,7 @@ void snd_pcm_adpcm_encode(const snd_pcm_channel_area_t *dst_areas,
  56. frames1 = frames;
  57. while (frames1-- > 0) {
  58. int v;
  59. - goto *get;
  60. -#define GET16_END after
  61. -#include "plugin_ops.h"
  62. -#undef GET16_END
  63. - after:
  64. + sample = get16(src, getidx);
  65. v = adpcm_encoder(sample, states);
  66. if (dstbit)
  67. *dst = (*dst & 0xf0) | v;
  68. diff --git a/src/pcm/pcm_alaw.c b/src/pcm/pcm_alaw.c
  69. index 0a889183..f24e6351 100644
  70. --- a/src/pcm/pcm_alaw.c
  71. +++ b/src/pcm/pcm_alaw.c
  72. @@ -148,10 +148,6 @@ void snd_pcm_alaw_decode(const snd_pcm_channel_area_t *dst_areas,
  73. unsigned int channels, snd_pcm_uframes_t frames,
  74. unsigned int putidx)
  75. {
  76. -#define PUT16_LABELS
  77. -#include "plugin_ops.h"
  78. -#undef PUT16_LABELS
  79. - void *put = put16_labels[putidx];
  80. unsigned int channel;
  81. for (channel = 0; channel < channels; ++channel) {
  82. const unsigned char *src;
  83. @@ -167,11 +163,7 @@ void snd_pcm_alaw_decode(const snd_pcm_channel_area_t *dst_areas,
  84. frames1 = frames;
  85. while (frames1-- > 0) {
  86. int16_t sample = alaw_to_s16(*src);
  87. - goto *put;
  88. -#define PUT16_END after
  89. -#include "plugin_ops.h"
  90. -#undef PUT16_END
  91. - after:
  92. + put16(dst, sample, putidx);
  93. src += src_step;
  94. dst += dst_step;
  95. }
  96. @@ -185,10 +177,6 @@ void snd_pcm_alaw_encode(const snd_pcm_channel_area_t *dst_areas,
  97. unsigned int channels, snd_pcm_uframes_t frames,
  98. unsigned int getidx)
  99. {
  100. -#define GET16_LABELS
  101. -#include "plugin_ops.h"
  102. -#undef GET16_LABELS
  103. - void *get = get16_labels[getidx];
  104. unsigned int channel;
  105. int16_t sample = 0;
  106. for (channel = 0; channel < channels; ++channel) {
  107. @@ -204,11 +192,7 @@ void snd_pcm_alaw_encode(const snd_pcm_channel_area_t *dst_areas,
  108. dst_step = snd_pcm_channel_area_step(dst_area);
  109. frames1 = frames;
  110. while (frames1-- > 0) {
  111. - goto *get;
  112. -#define GET16_END after
  113. -#include "plugin_ops.h"
  114. -#undef GET16_END
  115. - after:
  116. + sample = get16(src, getidx);
  117. *dst = s16_to_alaw(sample);
  118. src += src_step;
  119. dst += dst_step;
  120. diff --git a/src/pcm/pcm_iec958.c b/src/pcm/pcm_iec958.c
  121. index 1afe7393..8f1cd9e9 100644
  122. --- a/src/pcm/pcm_iec958.c
  123. +++ b/src/pcm/pcm_iec958.c
  124. @@ -149,11 +149,8 @@ static void snd_pcm_iec958_decode(snd_pcm_iec958_t *iec,
  125. snd_pcm_uframes_t src_offset,
  126. unsigned int channels, snd_pcm_uframes_t frames)
  127. {
  128. -#define PUT32_LABELS
  129. -#include "plugin_ops.h"
  130. -#undef PUT32_LABELS
  131. - void *put = put32_labels[iec->getput_idx];
  132. unsigned int channel;
  133. + unsigned int idx = iec->getput_idx;
  134. for (channel = 0; channel < channels; ++channel) {
  135. const uint32_t *src;
  136. char *dst;
  137. @@ -168,11 +165,7 @@ static void snd_pcm_iec958_decode(snd_pcm_iec958_t *iec,
  138. frames1 = frames;
  139. while (frames1-- > 0) {
  140. int32_t sample = iec958_to_s32(iec, *src);
  141. - goto *put;
  142. -#define PUT32_END after
  143. -#include "plugin_ops.h"
  144. -#undef PUT32_END
  145. - after:
  146. + put32(dst, sample, idx);
  147. src += src_step;
  148. dst += dst_step;
  149. }
  150. @@ -186,10 +179,6 @@ static void snd_pcm_iec958_encode(snd_pcm_iec958_t *iec,
  151. snd_pcm_uframes_t src_offset,
  152. unsigned int channels, snd_pcm_uframes_t frames)
  153. {
  154. -#define GET32_LABELS
  155. -#include "plugin_ops.h"
  156. -#undef GET32_LABELS
  157. - void *get = get32_labels[iec->getput_idx];
  158. unsigned int channel;
  159. int32_t sample = 0;
  160. int counter = iec->counter;
  161. @@ -197,6 +186,7 @@ static void snd_pcm_iec958_encode(snd_pcm_iec958_t *iec,
  162. (iec->status[0] & IEC958_AES0_NONAUDIO) &&
  163. (channels == 8);
  164. int counter_step = single_stream ? ((channels + 1) >> 1) : 1;
  165. + unsigned int idx = iec->getput_idx;
  166. for (channel = 0; channel < channels; ++channel) {
  167. const char *src;
  168. uint32_t *dst;
  169. @@ -216,11 +206,7 @@ static void snd_pcm_iec958_encode(snd_pcm_iec958_t *iec,
  170. iec->counter = counter;
  171. while (frames1-- > 0) {
  172. - goto *get;
  173. -#define GET32_END after
  174. -#include "plugin_ops.h"
  175. -#undef GET32_END
  176. - after:
  177. + sample = get32(src, idx);
  178. sample = iec958_subframe(iec, sample, channel);
  179. // fprintf(stderr, "%d:%08x\n", frames1, sample);
  180. *dst = sample;
  181. diff --git a/src/pcm/pcm_lfloat.c b/src/pcm/pcm_lfloat.c
  182. index 7785e4b9..c2e07a57 100644
  183. --- a/src/pcm/pcm_lfloat.c
  184. +++ b/src/pcm/pcm_lfloat.c
  185. @@ -97,13 +97,6 @@ void snd_pcm_lfloat_convert_integer_float(const snd_pcm_channel_area_t *dst_area
  186. unsigned int channels, snd_pcm_uframes_t frames,
  187. unsigned int get32idx, unsigned int put32floatidx)
  188. {
  189. -#define GET32_LABELS
  190. -#define PUT32F_LABELS
  191. -#include "plugin_ops.h"
  192. -#undef PUT32F_LABELS
  193. -#undef GET32_LABELS
  194. - void *get32 = get32_labels[get32idx];
  195. - void *put32float = put32float_labels[put32floatidx];
  196. unsigned int channel;
  197. for (channel = 0; channel < channels; ++channel) {
  198. const char *src;
  199. @@ -111,8 +104,6 @@ void snd_pcm_lfloat_convert_integer_float(const snd_pcm_channel_area_t *dst_area
  200. int src_step, dst_step;
  201. snd_pcm_uframes_t frames1;
  202. int32_t sample = 0;
  203. - snd_tmp_float_t tmp_float;
  204. - snd_tmp_double_t tmp_double;
  205. const snd_pcm_channel_area_t *src_area = &src_areas[channel];
  206. const snd_pcm_channel_area_t *dst_area = &dst_areas[channel];
  207. src = snd_pcm_channel_area_addr(src_area, src_offset);
  208. @@ -121,16 +112,8 @@ void snd_pcm_lfloat_convert_integer_float(const snd_pcm_channel_area_t *dst_area
  209. dst_step = snd_pcm_channel_area_step(dst_area);
  210. frames1 = frames;
  211. while (frames1-- > 0) {
  212. - goto *get32;
  213. -#define GET32_END sample_loaded
  214. -#include "plugin_ops.h"
  215. -#undef GET32_END
  216. - sample_loaded:
  217. - goto *put32float;
  218. -#define PUT32F_END sample_put
  219. -#include "plugin_ops.h"
  220. -#undef PUT32F_END
  221. - sample_put:
  222. + sample = get32(src, get32idx);
  223. + put32float(dst, sample, put32floatidx);
  224. src += src_step;
  225. dst += dst_step;
  226. }
  227. @@ -142,13 +125,6 @@ void snd_pcm_lfloat_convert_float_integer(const snd_pcm_channel_area_t *dst_area
  228. unsigned int channels, snd_pcm_uframes_t frames,
  229. unsigned int put32idx, unsigned int get32floatidx)
  230. {
  231. -#define PUT32_LABELS
  232. -#define GET32F_LABELS
  233. -#include "plugin_ops.h"
  234. -#undef GET32F_LABELS
  235. -#undef PUT32_LABELS
  236. - void *put32 = put32_labels[put32idx];
  237. - void *get32float = get32float_labels[get32floatidx];
  238. unsigned int channel;
  239. for (channel = 0; channel < channels; ++channel) {
  240. const char *src;
  241. @@ -156,8 +132,6 @@ void snd_pcm_lfloat_convert_float_integer(const snd_pcm_channel_area_t *dst_area
  242. int src_step, dst_step;
  243. snd_pcm_uframes_t frames1;
  244. int32_t sample = 0;
  245. - snd_tmp_float_t tmp_float;
  246. - snd_tmp_double_t tmp_double;
  247. const snd_pcm_channel_area_t *src_area = &src_areas[channel];
  248. const snd_pcm_channel_area_t *dst_area = &dst_areas[channel];
  249. src = snd_pcm_channel_area_addr(src_area, src_offset);
  250. @@ -166,16 +140,8 @@ void snd_pcm_lfloat_convert_float_integer(const snd_pcm_channel_area_t *dst_area
  251. dst_step = snd_pcm_channel_area_step(dst_area);
  252. frames1 = frames;
  253. while (frames1-- > 0) {
  254. - goto *get32float;
  255. -#define GET32F_END sample_loaded
  256. -#include "plugin_ops.h"
  257. -#undef GET32F_END
  258. - sample_loaded:
  259. - goto *put32;
  260. -#define PUT32_END sample_put
  261. -#include "plugin_ops.h"
  262. -#undef PUT32_END
  263. - sample_put:
  264. + sample = get32float(src, get32floatidx);
  265. + put32(dst, sample, put32idx);
  266. src += src_step;
  267. dst += dst_step;
  268. }
  269. diff --git a/src/pcm/pcm_linear.c b/src/pcm/pcm_linear.c
  270. index c95d1b95..bc8c7aa8 100644
  271. --- a/src/pcm/pcm_linear.c
  272. +++ b/src/pcm/pcm_linear.c
  273. @@ -148,10 +148,6 @@ void snd_pcm_linear_convert(const snd_pcm_channel_area_t *dst_areas, snd_pcm_ufr
  274. unsigned int channels, snd_pcm_uframes_t frames,
  275. unsigned int convidx)
  276. {
  277. -#define CONV_LABELS
  278. -#include "plugin_ops.h"
  279. -#undef CONV_LABELS
  280. - void *conv = conv_labels[convidx];
  281. unsigned int channel;
  282. for (channel = 0; channel < channels; ++channel) {
  283. const char *src;
  284. @@ -166,11 +162,7 @@ void snd_pcm_linear_convert(const snd_pcm_channel_area_t *dst_areas, snd_pcm_ufr
  285. dst_step = snd_pcm_channel_area_step(dst_area);
  286. frames1 = frames;
  287. while (frames1-- > 0) {
  288. - goto *conv;
  289. -#define CONV_END after
  290. -#include "plugin_ops.h"
  291. -#undef CONV_END
  292. - after:
  293. + conv(dst, src, convidx);
  294. src += src_step;
  295. dst += dst_step;
  296. }
  297. @@ -182,11 +174,6 @@ void snd_pcm_linear_getput(const snd_pcm_channel_area_t *dst_areas, snd_pcm_ufra
  298. unsigned int channels, snd_pcm_uframes_t frames,
  299. unsigned int get_idx, unsigned int put_idx)
  300. {
  301. -#define CONV24_LABELS
  302. -#include "plugin_ops.h"
  303. -#undef CONV24_LABELS
  304. - void *get = get32_labels[get_idx];
  305. - void *put = put32_labels[put_idx];
  306. unsigned int channel;
  307. uint32_t sample = 0;
  308. for (channel = 0; channel < channels; ++channel) {
  309. @@ -202,11 +189,8 @@ void snd_pcm_linear_getput(const snd_pcm_channel_area_t *dst_areas, snd_pcm_ufra
  310. dst_step = snd_pcm_channel_area_step(dst_area);
  311. frames1 = frames;
  312. while (frames1-- > 0) {
  313. - goto *get;
  314. -#define CONV24_END after
  315. -#include "plugin_ops.h"
  316. -#undef CONV24_END
  317. - after:
  318. + sample = get32(src, get_idx);
  319. + put32(dst, sample, put_idx);
  320. src += src_step;
  321. dst += dst_step;
  322. }
  323. diff --git a/src/pcm/pcm_mulaw.c b/src/pcm/pcm_mulaw.c
  324. index 587fa54e..97dae154 100644
  325. --- a/src/pcm/pcm_mulaw.c
  326. +++ b/src/pcm/pcm_mulaw.c
  327. @@ -164,10 +164,6 @@ void snd_pcm_mulaw_decode(const snd_pcm_channel_area_t *dst_areas,
  328. unsigned int channels, snd_pcm_uframes_t frames,
  329. unsigned int putidx)
  330. {
  331. -#define PUT16_LABELS
  332. -#include "plugin_ops.h"
  333. -#undef PUT16_LABELS
  334. - void *put = put16_labels[putidx];
  335. unsigned int channel;
  336. for (channel = 0; channel < channels; ++channel) {
  337. const unsigned char *src;
  338. @@ -183,11 +179,7 @@ void snd_pcm_mulaw_decode(const snd_pcm_channel_area_t *dst_areas,
  339. frames1 = frames;
  340. while (frames1-- > 0) {
  341. int16_t sample = ulaw_to_s16(*src);
  342. - goto *put;
  343. -#define PUT16_END after
  344. -#include "plugin_ops.h"
  345. -#undef PUT16_END
  346. - after:
  347. + put16(dst, sample, putidx);
  348. src += src_step;
  349. dst += dst_step;
  350. }
  351. @@ -201,10 +193,6 @@ void snd_pcm_mulaw_encode(const snd_pcm_channel_area_t *dst_areas,
  352. unsigned int channels, snd_pcm_uframes_t frames,
  353. unsigned int getidx)
  354. {
  355. -#define GET16_LABELS
  356. -#include "plugin_ops.h"
  357. -#undef GET16_LABELS
  358. - void *get = get16_labels[getidx];
  359. unsigned int channel;
  360. int16_t sample = 0;
  361. for (channel = 0; channel < channels; ++channel) {
  362. @@ -220,11 +208,7 @@ void snd_pcm_mulaw_encode(const snd_pcm_channel_area_t *dst_areas,
  363. dst_step = snd_pcm_channel_area_step(dst_area);
  364. frames1 = frames;
  365. while (frames1-- > 0) {
  366. - goto *get;
  367. -#define GET16_END after
  368. -#include "plugin_ops.h"
  369. -#undef GET16_END
  370. - after:
  371. + sample = get16(src, getidx);
  372. *dst = s16_to_ulaw(sample);
  373. src += src_step;
  374. dst += dst_step;
  375. diff --git a/src/pcm/pcm_rate_linear.c b/src/pcm/pcm_rate_linear.c
  376. index 35a4d8ea..366fdad7 100644
  377. --- a/src/pcm/pcm_rate_linear.c
  378. +++ b/src/pcm/pcm_rate_linear.c
  379. @@ -70,19 +70,13 @@ static void linear_expand(struct rate_linear *rate,
  380. const snd_pcm_channel_area_t *src_areas,
  381. snd_pcm_uframes_t src_offset, unsigned int src_frames)
  382. {
  383. -#define GET16_LABELS
  384. -#define PUT16_LABELS
  385. -#include "plugin_ops.h"
  386. -#undef GET16_LABELS
  387. -#undef PUT16_LABELS
  388. - void *get = get16_labels[rate->get_idx];
  389. - void *put = put16_labels[rate->put_idx];
  390. unsigned int get_threshold = rate->pitch;
  391. unsigned int channel;
  392. unsigned int src_frames1;
  393. unsigned int dst_frames1;
  394. int16_t sample = 0;
  395. unsigned int pos;
  396. + unsigned int get_idx = rate->get_idx, put_idx = rate->get_idx;
  397. for (channel = 0; channel < rate->channels; ++channel) {
  398. const snd_pcm_channel_area_t *src_area = &src_areas[channel];
  399. @@ -106,22 +100,14 @@ static void linear_expand(struct rate_linear *rate,
  400. pos -= get_threshold;
  401. old_sample = new_sample;
  402. if (src_frames1 < src_frames) {
  403. - goto *get;
  404. -#define GET16_END after_get
  405. -#include "plugin_ops.h"
  406. -#undef GET16_END
  407. - after_get:
  408. + sample = get16(src, get_idx);
  409. new_sample = sample;
  410. }
  411. }
  412. new_weight = (pos << (16 - rate->pitch_shift)) / (get_threshold >> rate->pitch_shift);
  413. old_weight = 0x10000 - new_weight;
  414. sample = (old_sample * old_weight + new_sample * new_weight) >> 16;
  415. - goto *put;
  416. -#define PUT16_END after_put
  417. -#include "plugin_ops.h"
  418. -#undef PUT16_END
  419. - after_put:
  420. + put16(dst, sample, put_idx);
  421. dst += dst_step;
  422. dst_frames1++;
  423. pos += LINEAR_DIV;
  424. @@ -192,19 +178,13 @@ static void linear_shrink(struct rate_linear *rate,
  425. const snd_pcm_channel_area_t *src_areas,
  426. snd_pcm_uframes_t src_offset, unsigned int src_frames)
  427. {
  428. -#define GET16_LABELS
  429. -#define PUT16_LABELS
  430. -#include "plugin_ops.h"
  431. -#undef GET16_LABELS
  432. -#undef PUT16_LABELS
  433. - void *get = get16_labels[rate->get_idx];
  434. - void *put = put16_labels[rate->put_idx];
  435. unsigned int get_increment = rate->pitch;
  436. unsigned int channel;
  437. unsigned int src_frames1;
  438. unsigned int dst_frames1;
  439. int16_t sample = 0;
  440. unsigned int pos;
  441. + unsigned int get_idx = rate->get_idx, put_idx = rate->get_idx;
  442. for (channel = 0; channel < rate->channels; ++channel) {
  443. const snd_pcm_channel_area_t *src_area = &src_areas[channel];
  444. @@ -223,13 +203,7 @@ static void linear_shrink(struct rate_linear *rate,
  445. src_frames1 = 0;
  446. dst_frames1 = 0;
  447. while (src_frames1 < src_frames) {
  448. -
  449. - goto *get;
  450. -#define GET16_END after_get
  451. -#include "plugin_ops.h"
  452. -#undef GET16_END
  453. - after_get:
  454. - new_sample = sample;
  455. + new_sample = get16(src, get_idx);
  456. src += src_step;
  457. src_frames1++;
  458. pos += get_increment;
  459. @@ -238,11 +212,7 @@ static void linear_shrink(struct rate_linear *rate,
  460. old_weight = (pos << (32 - LINEAR_DIV_SHIFT)) / (get_increment >> (LINEAR_DIV_SHIFT - 16));
  461. new_weight = 0x10000 - old_weight;
  462. sample = (old_sample * old_weight + new_sample * new_weight) >> 16;
  463. - goto *put;
  464. -#define PUT16_END after_put
  465. -#include "plugin_ops.h"
  466. -#undef PUT16_END
  467. - after_put:
  468. + put16(dst, sample, put_idx);
  469. dst += dst_step;
  470. dst_frames1++;
  471. if (CHECK_SANITY(dst_frames1 > dst_frames)) {
  472. diff --git a/src/pcm/pcm_route.c b/src/pcm/pcm_route.c
  473. index 737c8fa4..f9ba16a1 100644
  474. --- a/src/pcm/pcm_route.c
  475. +++ b/src/pcm/pcm_route.c
  476. @@ -131,10 +131,6 @@ static void snd_pcm_route_convert1_one(const snd_pcm_channel_area_t *dst_area,
  477. const snd_pcm_route_ttable_dst_t* ttable,
  478. const snd_pcm_route_params_t *params)
  479. {
  480. -#define CONV_LABELS
  481. -#include "plugin_ops.h"
  482. -#undef CONV_LABELS
  483. - void *conv;
  484. const snd_pcm_channel_area_t *src_area = 0;
  485. unsigned int srcidx;
  486. const char *src;
  487. @@ -156,17 +152,12 @@ static void snd_pcm_route_convert1_one(const snd_pcm_channel_area_t *dst_area,
  488. return;
  489. }
  490. - conv = conv_labels[params->conv_idx];
  491. src = snd_pcm_channel_area_addr(src_area, src_offset);
  492. dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
  493. src_step = snd_pcm_channel_area_step(src_area);
  494. dst_step = snd_pcm_channel_area_step(dst_area);
  495. while (frames-- > 0) {
  496. - goto *conv;
  497. -#define CONV_END after
  498. -#include "plugin_ops.h"
  499. -#undef CONV_END
  500. - after:
  501. + conv(dst, src, params->conv_idx);
  502. src += src_step;
  503. dst += dst_step;
  504. }
  505. @@ -181,16 +172,13 @@ static void snd_pcm_route_convert1_one_getput(const snd_pcm_channel_area_t *dst_
  506. const snd_pcm_route_ttable_dst_t* ttable,
  507. const snd_pcm_route_params_t *params)
  508. {
  509. -#define CONV24_LABELS
  510. -#include "plugin_ops.h"
  511. -#undef CONV24_LABELS
  512. - void *get, *put;
  513. const snd_pcm_channel_area_t *src_area = 0;
  514. unsigned int srcidx;
  515. const char *src;
  516. char *dst;
  517. int src_step, dst_step;
  518. uint32_t sample = 0;
  519. + unsigned int get_idx = params->get_idx, put_idx = params->put_idx;
  520. for (srcidx = 0; srcidx < ttable->nsrcs && srcidx < src_channels; ++srcidx) {
  521. unsigned int channel = ttable->srcs[srcidx].channel;
  522. if (channel >= src_channels)
  523. @@ -207,18 +195,13 @@ static void snd_pcm_route_convert1_one_getput(const snd_pcm_channel_area_t *dst_
  524. return;
  525. }
  526. - get = get32_labels[params->get_idx];
  527. - put = put32_labels[params->put_idx];
  528. src = snd_pcm_channel_area_addr(src_area, src_offset);
  529. dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
  530. src_step = snd_pcm_channel_area_step(src_area);
  531. dst_step = snd_pcm_channel_area_step(dst_area);
  532. while (frames-- > 0) {
  533. - goto *get;
  534. -#define CONV24_END after
  535. -#include "plugin_ops.h"
  536. -#undef CONV24_END
  537. - after:
  538. + sample = get32(src, get_idx);
  539. + put32(dst, sample, put_idx);
  540. src += src_step;
  541. dst += dst_step;
  542. }
  543. @@ -233,34 +216,6 @@ static void snd_pcm_route_convert1_many(const snd_pcm_channel_area_t *dst_area,
  544. const snd_pcm_route_ttable_dst_t* ttable,
  545. const snd_pcm_route_params_t *params)
  546. {
  547. -#define GET32_LABELS
  548. -#define PUT32_LABELS
  549. -#include "plugin_ops.h"
  550. -#undef GET32_LABELS
  551. -#undef PUT32_LABELS
  552. - static void *const zero_labels[2] = {
  553. - &&zero_int64,
  554. -#if SND_PCM_PLUGIN_ROUTE_FLOAT
  555. - &&zero_float
  556. -#endif
  557. - };
  558. - /* sum_type att */
  559. - static void *const add_labels[2 * 2] = {
  560. - &&add_int64_noatt, &&add_int64_att,
  561. -#if SND_PCM_PLUGIN_ROUTE_FLOAT
  562. - &&add_float_noatt, &&add_float_att
  563. -#endif
  564. - };
  565. - /* sum_type att */
  566. - static void *const norm_labels[2 * 2] = {
  567. - &&norm_int64_noatt,
  568. - &&norm_int64_att,
  569. -#if SND_PCM_PLUGIN_ROUTE_FLOAT
  570. - &&norm_float,
  571. - &&norm_float,
  572. -#endif
  573. - };
  574. - void *zero, *get32, *add, *norm, *put32;
  575. int nsrcs = ttable->nsrcs;
  576. char *dst;
  577. int dst_step;
  578. @@ -269,6 +224,7 @@ static void snd_pcm_route_convert1_many(const snd_pcm_channel_area_t *dst_area,
  579. snd_pcm_route_ttable_src_t src_tt[nsrcs];
  580. int32_t sample = 0;
  581. int srcidx, srcidx1 = 0;
  582. + unsigned get_idx = params->get_idx, put_idx = params->put_idx;
  583. for (srcidx = 0; srcidx < nsrcs && (unsigned)srcidx < src_channels; ++srcidx) {
  584. const snd_pcm_channel_area_t *src_area;
  585. unsigned int channel = ttable->srcs[srcidx].channel;
  586. @@ -301,11 +257,6 @@ static void snd_pcm_route_convert1_many(const snd_pcm_channel_area_t *dst_area,
  587. return;
  588. }
  589. - zero = zero_labels[params->sum_idx];
  590. - get32 = get32_labels[params->get_idx];
  591. - add = add_labels[params->sum_idx * 2 + ttable->att];
  592. - norm = norm_labels[params->sum_idx * 2 + ttable->att];
  593. - put32 = put32_labels[params->put_idx];
  594. dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
  595. dst_step = snd_pcm_channel_area_step(dst_area);
  596. @@ -314,83 +265,71 @@ static void snd_pcm_route_convert1_many(const snd_pcm_channel_area_t *dst_area,
  597. sum_t sum;
  598. /* Zero sum */
  599. - goto *zero;
  600. - zero_int64:
  601. - sum.as_sint64 = 0;
  602. - goto zero_end;
  603. + switch (params->sum_idx) {
  604. + case 0: sum.as_sint64 = 0; break;
  605. #if SND_PCM_PLUGIN_ROUTE_FLOAT
  606. - zero_float:
  607. - sum.as_float = 0.0;
  608. - goto zero_end;
  609. + case 1: sum.as_float = 0.0; break;
  610. #endif
  611. - zero_end:
  612. + }
  613. for (srcidx = 0; srcidx < nsrcs; ++srcidx) {
  614. const char *src = srcs[srcidx];
  615. /* Get sample */
  616. - goto *get32;
  617. -#define GET32_END after_get
  618. -#include "plugin_ops.h"
  619. -#undef GET32_END
  620. - after_get:
  621. + sample = get32(src, get_idx);
  622. /* Sum */
  623. - goto *add;
  624. - add_int64_att:
  625. - sum.as_sint64 += (int64_t) sample * ttp->as_int;
  626. - goto after_sum;
  627. - add_int64_noatt:
  628. - if (ttp->as_int)
  629. - sum.as_sint64 += sample;
  630. - goto after_sum;
  631. + switch (params->sum_idx * 2 + ttable->att) {
  632. + case 0:
  633. + if (ttp->as_int)
  634. + sum.as_sint64 += sample;
  635. + break;
  636. + case 1:
  637. + sum.as_sint64 += (int64_t) sample * ttp->as_int;
  638. + break;
  639. #if SND_PCM_PLUGIN_ROUTE_FLOAT
  640. - add_float_att:
  641. - sum.as_float += sample * ttp->as_float;
  642. - goto after_sum;
  643. - add_float_noatt:
  644. - if (ttp->as_int)
  645. - sum.as_float += sample;
  646. - goto after_sum;
  647. + case 2:
  648. + if (ttp->as_int)
  649. + sum.as_float += sample;
  650. + break;
  651. + case 3:
  652. + sum.as_float += sample * ttp->as_float;
  653. + break;
  654. #endif
  655. - after_sum:
  656. + }
  657. srcs[srcidx] += src_steps[srcidx];
  658. ttp++;
  659. }
  660. /* Normalization */
  661. - goto *norm;
  662. - norm_int64_att:
  663. - div(sum.as_sint64);
  664. - /* fallthru */
  665. - norm_int64_noatt:
  666. - if (sum.as_sint64 > (int64_t)0x7fffffff)
  667. - sample = 0x7fffffff; /* maximum positive value */
  668. - else if (sum.as_sint64 < -(int64_t)0x80000000)
  669. - sample = 0x80000000; /* maximum negative value */
  670. - else
  671. - sample = sum.as_sint64;
  672. - goto after_norm;
  673. -
  674. + switch (params->sum_idx * 2 + ttable->att) {
  675. + case 1:
  676. + div(sum.as_sint64);
  677. + /* fallthru */
  678. + case 0:
  679. + if (sum.as_sint64 > (int64_t)0x7fffffff)
  680. + sample = 0x7fffffff; /* maximum positive value */
  681. + else if (sum.as_sint64 < -(int64_t)0x80000000)
  682. + sample = 0x80000000; /* maximum negative value */
  683. + else
  684. + sample = sum.as_sint64;
  685. + break;
  686. #if SND_PCM_PLUGIN_ROUTE_FLOAT
  687. - norm_float:
  688. - sum.as_float = rint(sum.as_float);
  689. - if (sum.as_float > (int64_t)0x7fffffff)
  690. - sample = 0x7fffffff; /* maximum positive value */
  691. - else if (sum.as_float < -(int64_t)0x80000000)
  692. - sample = 0x80000000; /* maximum negative value */
  693. - else
  694. - sample = sum.as_float;
  695. - goto after_norm;
  696. + case 2:
  697. + case 3:
  698. + sum.as_float = rint(sum.as_float);
  699. + if (sum.as_float > (int64_t)0x7fffffff)
  700. + sample = 0x7fffffff; /* maximum positive value */
  701. + else if (sum.as_float < -(int64_t)0x80000000)
  702. + sample = 0x80000000; /* maximum negative value */
  703. + else
  704. + sample = sum.as_float;
  705. + break;
  706. #endif
  707. - after_norm:
  708. + }
  709. /* Put sample */
  710. - goto *put32;
  711. -#define PUT32_END after_put32
  712. -#include "plugin_ops.h"
  713. -#undef PUT32_END
  714. - after_put32:
  715. -
  716. + put32(dst, sample, put_idx);
  717. +
  718. dst += dst_step;
  719. }
  720. }
  721. diff --git a/src/pcm/plugin_ops.h b/src/pcm/plugin_ops.h
  722. index 6392073c..5c89a24f 100644
  723. --- a/src/pcm/plugin_ops.h
  724. +++ b/src/pcm/plugin_ops.h
  725. @@ -19,6 +19,11 @@
  726. *
  727. */
  728. +#include <assert.h>
  729. +#include <math.h>
  730. +#include <stdint.h>
  731. +#include <byteswap.h>
  732. +
  733. #ifndef SX_INLINES
  734. #define SX_INLINES
  735. static inline uint32_t sx20(uint32_t x)
  736. @@ -92,626 +97,360 @@ static inline uint32_t sx24s(uint32_t x)
  737. #define _put_triple_s(ptr,val) _put_triple_le(ptr,val)
  738. #endif
  739. -#ifdef CONV_LABELS
  740. -/* src_wid src_endswap sign_toggle dst_wid dst_endswap */
  741. -static void *const conv_labels[4 * 2 * 2 * 4 * 2] = {
  742. - &&conv_xxx1_xxx1, /* 8h -> 8h */
  743. - &&conv_xxx1_xxx1, /* 8h -> 8s */
  744. - &&conv_xxx1_xx10, /* 8h -> 16h */
  745. - &&conv_xxx1_xx01, /* 8h -> 16s */
  746. - &&conv_xxx1_x100, /* 8h -> 24h */
  747. - &&conv_xxx1_001x, /* 8h -> 24s */
  748. - &&conv_xxx1_1000, /* 8h -> 32h */
  749. - &&conv_xxx1_0001, /* 8h -> 32s */
  750. - &&conv_xxx1_xxx9, /* 8h ^> 8h */
  751. - &&conv_xxx1_xxx9, /* 8h ^> 8s */
  752. - &&conv_xxx1_xx90, /* 8h ^> 16h */
  753. - &&conv_xxx1_xx09, /* 8h ^> 16s */
  754. - &&conv_xxx1_x900, /* 8h ^> 24h */
  755. - &&conv_xxx1_009x, /* 8h ^> 24s */
  756. - &&conv_xxx1_9000, /* 8h ^> 32h */
  757. - &&conv_xxx1_0009, /* 8h ^> 32s */
  758. - &&conv_xxx1_xxx1, /* 8s -> 8h */
  759. - &&conv_xxx1_xxx1, /* 8s -> 8s */
  760. - &&conv_xxx1_xx10, /* 8s -> 16h */
  761. - &&conv_xxx1_xx01, /* 8s -> 16s */
  762. - &&conv_xxx1_x100, /* 8s -> 24h */
  763. - &&conv_xxx1_001x, /* 8s -> 24s */
  764. - &&conv_xxx1_1000, /* 8s -> 32h */
  765. - &&conv_xxx1_0001, /* 8s -> 32s */
  766. - &&conv_xxx1_xxx9, /* 8s ^> 8h */
  767. - &&conv_xxx1_xxx9, /* 8s ^> 8s */
  768. - &&conv_xxx1_xx90, /* 8s ^> 16h */
  769. - &&conv_xxx1_xx09, /* 8s ^> 16s */
  770. - &&conv_xxx1_x900, /* 8s ^> 24h */
  771. - &&conv_xxx1_009x, /* 8s ^> 24s */
  772. - &&conv_xxx1_9000, /* 8s ^> 32h */
  773. - &&conv_xxx1_0009, /* 8s ^> 32s */
  774. - &&conv_xx12_xxx1, /* 16h -> 8h */
  775. - &&conv_xx12_xxx1, /* 16h -> 8s */
  776. - &&conv_xx12_xx12, /* 16h -> 16h */
  777. - &&conv_xx12_xx21, /* 16h -> 16s */
  778. - &&conv_xx12_x120, /* 16h -> 24h */
  779. - &&conv_xx12_021x, /* 16h -> 24s */
  780. - &&conv_xx12_1200, /* 16h -> 32h */
  781. - &&conv_xx12_0021, /* 16h -> 32s */
  782. - &&conv_xx12_xxx9, /* 16h ^> 8h */
  783. - &&conv_xx12_xxx9, /* 16h ^> 8s */
  784. - &&conv_xx12_xx92, /* 16h ^> 16h */
  785. - &&conv_xx12_xx29, /* 16h ^> 16s */
  786. - &&conv_xx12_x920, /* 16h ^> 24h */
  787. - &&conv_xx12_029x, /* 16h ^> 24s */
  788. - &&conv_xx12_9200, /* 16h ^> 32h */
  789. - &&conv_xx12_0029, /* 16h ^> 32s */
  790. - &&conv_xx12_xxx2, /* 16s -> 8h */
  791. - &&conv_xx12_xxx2, /* 16s -> 8s */
  792. - &&conv_xx12_xx21, /* 16s -> 16h */
  793. - &&conv_xx12_xx12, /* 16s -> 16s */
  794. - &&conv_xx12_x210, /* 16s -> 24h */
  795. - &&conv_xx12_012x, /* 16s -> 24s */
  796. - &&conv_xx12_2100, /* 16s -> 32h */
  797. - &&conv_xx12_0012, /* 16s -> 32s */
  798. - &&conv_xx12_xxxA, /* 16s ^> 8h */
  799. - &&conv_xx12_xxxA, /* 16s ^> 8s */
  800. - &&conv_xx12_xxA1, /* 16s ^> 16h */
  801. - &&conv_xx12_xx1A, /* 16s ^> 16s */
  802. - &&conv_xx12_xA10, /* 16s ^> 24h */
  803. - &&conv_xx12_01Ax, /* 16s ^> 24s */
  804. - &&conv_xx12_A100, /* 16s ^> 32h */
  805. - &&conv_xx12_001A, /* 16s ^> 32s */
  806. - &&conv_x123_xxx1, /* 24h -> 8h */
  807. - &&conv_x123_xxx1, /* 24h -> 8s */
  808. - &&conv_x123_xx12, /* 24h -> 16h */
  809. - &&conv_x123_xx21, /* 24h -> 16s */
  810. - &&conv_x123_x123, /* 24h -> 24h */
  811. - &&conv_x123_321x, /* 24h -> 24s */
  812. - &&conv_x123_1230, /* 24h -> 32h */
  813. - &&conv_x123_0321, /* 24h -> 32s */
  814. - &&conv_x123_xxx9, /* 24h ^> 8h */
  815. - &&conv_x123_xxx9, /* 24h ^> 8s */
  816. - &&conv_x123_xx92, /* 24h ^> 16h */
  817. - &&conv_x123_xx29, /* 24h ^> 16s */
  818. - &&conv_x123_x923, /* 24h ^> 24h */
  819. - &&conv_x123_329x, /* 24h ^> 24s */
  820. - &&conv_x123_9230, /* 24h ^> 32h */
  821. - &&conv_x123_0329, /* 24h ^> 32s */
  822. - &&conv_123x_xxx3, /* 24s -> 8h */
  823. - &&conv_123x_xxx3, /* 24s -> 8s */
  824. - &&conv_123x_xx32, /* 24s -> 16h */
  825. - &&conv_123x_xx23, /* 24s -> 16s */
  826. - &&conv_123x_x321, /* 24s -> 24h */
  827. - &&conv_123x_123x, /* 24s -> 24s */
  828. - &&conv_123x_3210, /* 24s -> 32h */
  829. - &&conv_123x_0123, /* 24s -> 32s */
  830. - &&conv_123x_xxxB, /* 24s ^> 8h */
  831. - &&conv_123x_xxxB, /* 24s ^> 8s */
  832. - &&conv_123x_xxB2, /* 24s ^> 16h */
  833. - &&conv_123x_xx2B, /* 24s ^> 16s */
  834. - &&conv_123x_xB21, /* 24s ^> 24h */
  835. - &&conv_123x_12Bx, /* 24s ^> 24s */
  836. - &&conv_123x_B210, /* 24s ^> 32h */
  837. - &&conv_123x_012B, /* 24s ^> 32s */
  838. - &&conv_1234_xxx1, /* 32h -> 8h */
  839. - &&conv_1234_xxx1, /* 32h -> 8s */
  840. - &&conv_1234_xx12, /* 32h -> 16h */
  841. - &&conv_1234_xx21, /* 32h -> 16s */
  842. - &&conv_1234_x123, /* 32h -> 24h */
  843. - &&conv_1234_321x, /* 32h -> 24s */
  844. - &&conv_1234_1234, /* 32h -> 32h */
  845. - &&conv_1234_4321, /* 32h -> 32s */
  846. - &&conv_1234_xxx9, /* 32h ^> 8h */
  847. - &&conv_1234_xxx9, /* 32h ^> 8s */
  848. - &&conv_1234_xx92, /* 32h ^> 16h */
  849. - &&conv_1234_xx29, /* 32h ^> 16s */
  850. - &&conv_1234_x923, /* 32h ^> 24h */
  851. - &&conv_1234_329x, /* 32h ^> 24s */
  852. - &&conv_1234_9234, /* 32h ^> 32h */
  853. - &&conv_1234_4329, /* 32h ^> 32s */
  854. - &&conv_1234_xxx4, /* 32s -> 8h */
  855. - &&conv_1234_xxx4, /* 32s -> 8s */
  856. - &&conv_1234_xx43, /* 32s -> 16h */
  857. - &&conv_1234_xx34, /* 32s -> 16s */
  858. - &&conv_1234_x432, /* 32s -> 24h */
  859. - &&conv_1234_234x, /* 32s -> 24s */
  860. - &&conv_1234_4321, /* 32s -> 32h */
  861. - &&conv_1234_1234, /* 32s -> 32s */
  862. - &&conv_1234_xxxC, /* 32s ^> 8h */
  863. - &&conv_1234_xxxC, /* 32s ^> 8s */
  864. - &&conv_1234_xxC3, /* 32s ^> 16h */
  865. - &&conv_1234_xx3C, /* 32s ^> 16s */
  866. - &&conv_1234_xC32, /* 32s ^> 24h */
  867. - &&conv_1234_23Cx, /* 32s ^> 24s */
  868. - &&conv_1234_C321, /* 32s ^> 32h */
  869. - &&conv_1234_123C, /* 32s ^> 32s */
  870. -};
  871. -#endif
  872. -
  873. -#ifdef CONV_END
  874. -while(0) {
  875. -conv_xxx1_xxx1: as_u8(dst) = as_u8c(src); goto CONV_END;
  876. -conv_xxx1_xx10: as_u16(dst) = (uint16_t)as_u8c(src) << 8; goto CONV_END;
  877. -conv_xxx1_xx01: as_u16(dst) = (uint16_t)as_u8c(src); goto CONV_END;
  878. -conv_xxx1_x100: as_u32(dst) = sx24((uint32_t)as_u8c(src) << 16); goto CONV_END;
  879. -conv_xxx1_001x: as_u32(dst) = sx24s((uint32_t)as_u8c(src) << 8); goto CONV_END;
  880. -conv_xxx1_1000: as_u32(dst) = (uint32_t)as_u8c(src) << 24; goto CONV_END;
  881. -conv_xxx1_0001: as_u32(dst) = (uint32_t)as_u8c(src); goto CONV_END;
  882. -conv_xxx1_xxx9: as_u8(dst) = as_u8c(src) ^ 0x80; goto CONV_END;
  883. -conv_xxx1_xx90: as_u16(dst) = (uint16_t)(as_u8c(src) ^ 0x80) << 8; goto CONV_END;
  884. -conv_xxx1_xx09: as_u16(dst) = (uint16_t)(as_u8c(src) ^ 0x80); goto CONV_END;
  885. -conv_xxx1_x900: as_u32(dst) = sx24((uint32_t)(as_u8c(src) ^ 0x80) << 16); goto CONV_END;
  886. -conv_xxx1_009x: as_u32(dst) = sx24s((uint32_t)(as_u8c(src) ^ 0x80) << 8); goto CONV_END;
  887. -conv_xxx1_9000: as_u32(dst) = (uint32_t)(as_u8c(src) ^ 0x80) << 24; goto CONV_END;
  888. -conv_xxx1_0009: as_u32(dst) = (uint32_t)(as_u8c(src) ^ 0x80); goto CONV_END;
  889. -conv_xx12_xxx1: as_u8(dst) = as_u16c(src) >> 8; goto CONV_END;
  890. -conv_xx12_xx12: as_u16(dst) = as_u16c(src); goto CONV_END;
  891. -conv_xx12_xx21: as_u16(dst) = bswap_16(as_u16c(src)); goto CONV_END;
  892. -conv_xx12_x120: as_u32(dst) = sx24((uint32_t)as_u16c(src) << 8); goto CONV_END;
  893. -conv_xx12_021x: as_u32(dst) = sx24s((uint32_t)bswap_16(as_u16c(src)) << 8); goto CONV_END;
  894. -conv_xx12_1200: as_u32(dst) = (uint32_t)as_u16c(src) << 16; goto CONV_END;
  895. -conv_xx12_0021: as_u32(dst) = (uint32_t)bswap_16(as_u16c(src)); goto CONV_END;
  896. -conv_xx12_xxx9: as_u8(dst) = (as_u16c(src) >> 8) ^ 0x80; goto CONV_END;
  897. -conv_xx12_xx92: as_u16(dst) = as_u16c(src) ^ 0x8000; goto CONV_END;
  898. -conv_xx12_xx29: as_u16(dst) = bswap_16(as_u16c(src)) ^ 0x80; goto CONV_END;
  899. -conv_xx12_x920: as_u32(dst) = sx24((uint32_t)(as_u16c(src) ^ 0x8000) << 8); goto CONV_END;
  900. -conv_xx12_029x: as_u32(dst) = sx24s((uint32_t)(bswap_16(as_u16c(src)) ^ 0x80) << 8); goto CONV_END;
  901. -conv_xx12_9200: as_u32(dst) = (uint32_t)(as_u16c(src) ^ 0x8000) << 16; goto CONV_END;
  902. -conv_xx12_0029: as_u32(dst) = (uint32_t)(bswap_16(as_u16c(src)) ^ 0x80); goto CONV_END;
  903. -conv_xx12_xxx2: as_u8(dst) = as_u16c(src) & 0xff; goto CONV_END;
  904. -conv_xx12_x210: as_u32(dst) = sx24((uint32_t)bswap_16(as_u16c(src)) << 8); goto CONV_END;
  905. -conv_xx12_012x: as_u32(dst) = sx24s((uint32_t)as_u16c(src) << 8); goto CONV_END;
  906. -conv_xx12_2100: as_u32(dst) = (uint32_t)bswap_16(as_u16c(src)) << 16; goto CONV_END;
  907. -conv_xx12_0012: as_u32(dst) = (uint32_t)as_u16c(src); goto CONV_END;
  908. -conv_xx12_xxxA: as_u8(dst) = (as_u16c(src) ^ 0x80) & 0xff; goto CONV_END;
  909. -conv_xx12_xxA1: as_u16(dst) = bswap_16(as_u16c(src) ^ 0x80); goto CONV_END;
  910. -conv_xx12_xx1A: as_u16(dst) = as_u16c(src) ^ 0x80; goto CONV_END;
  911. -conv_xx12_xA10: as_u32(dst) = sx24((uint32_t)bswap_16(as_u16c(src) ^ 0x80) << 8); goto CONV_END;
  912. -conv_xx12_01Ax: as_u32(dst) = sx24s((uint32_t)(as_u16c(src) ^ 0x80) << 8); goto CONV_END;
  913. -conv_xx12_A100: as_u32(dst) = (uint32_t)bswap_16(as_u16c(src) ^ 0x80) << 16; goto CONV_END;
  914. -conv_xx12_001A: as_u32(dst) = (uint32_t)(as_u16c(src) ^ 0x80); goto CONV_END;
  915. -conv_x123_xxx1: as_u8(dst) = as_u32c(src) >> 16; goto CONV_END;
  916. -conv_x123_xx12: as_u16(dst) = as_u32c(src) >> 8; goto CONV_END;
  917. -conv_x123_xx21: as_u16(dst) = bswap_16(as_u32c(src) >> 8); goto CONV_END;
  918. -conv_x123_x123: as_u32(dst) = sx24(as_u32c(src)); goto CONV_END;
  919. -conv_x123_321x: as_u32(dst) = sx24s(bswap_32(as_u32c(src))); goto CONV_END;
  920. -conv_x123_1230: as_u32(dst) = as_u32c(src) << 8; goto CONV_END;
  921. -conv_x123_0321: as_u32(dst) = bswap_32(as_u32c(src)) >> 8; goto CONV_END;
  922. -conv_x123_xxx9: as_u8(dst) = (as_u32c(src) >> 16) ^ 0x80; goto CONV_END;
  923. -conv_x123_xx92: as_u16(dst) = (as_u32c(src) >> 8) ^ 0x8000; goto CONV_END;
  924. -conv_x123_xx29: as_u16(dst) = bswap_16(as_u32c(src) >> 8) ^ 0x80; goto CONV_END;
  925. -conv_x123_x923: as_u32(dst) = sx24(as_u32c(src) ^ 0x800000); goto CONV_END;
  926. -conv_x123_329x: as_u32(dst) = sx24s(bswap_32(as_u32c(src)) ^ 0x8000); goto CONV_END;
  927. -conv_x123_9230: as_u32(dst) = (as_u32c(src) ^ 0x800000) << 8; goto CONV_END;
  928. -conv_x123_0329: as_u32(dst) = (bswap_32(as_u32c(src)) >> 8) ^ 0x80; goto CONV_END;
  929. -conv_123x_xxx3: as_u8(dst) = (as_u32c(src) >> 8) & 0xff; goto CONV_END;
  930. -conv_123x_xx32: as_u16(dst) = bswap_16(as_u32c(src) >> 8); goto CONV_END;
  931. -conv_123x_xx23: as_u16(dst) = (as_u32c(src) >> 8) & 0xffff; goto CONV_END;
  932. -conv_123x_x321: as_u32(dst) = sx24(bswap_32(as_u32c(src))); goto CONV_END;
  933. -conv_123x_123x: as_u32(dst) = sx24s(as_u32c(src)); goto CONV_END;
  934. -conv_123x_3210: as_u32(dst) = bswap_32(as_u32c(src)) << 8; goto CONV_END;
  935. -conv_123x_0123: as_u32(dst) = as_u32c(src) >> 8; goto CONV_END;
  936. -conv_123x_xxxB: as_u8(dst) = ((as_u32c(src) >> 8) & 0xff) ^ 0x80; goto CONV_END;
  937. -conv_123x_xxB2: as_u16(dst) = bswap_16((as_u32c(src) >> 8) ^ 0x80); goto CONV_END;
  938. -conv_123x_xx2B: as_u16(dst) = ((as_u32c(src) >> 8) & 0xffff) ^ 0x80; goto CONV_END;
  939. -conv_123x_xB21: as_u32(dst) = sx24(bswap_32(as_u32c(src)) ^ 0x800000); goto CONV_END;
  940. -conv_123x_12Bx: as_u32(dst) = sx24s(as_u32c(src) ^ 0x8000); goto CONV_END;
  941. -conv_123x_B210: as_u32(dst) = bswap_32(as_u32c(src) ^ 0x8000) << 8; goto CONV_END;
  942. -conv_123x_012B: as_u32(dst) = (as_u32c(src) >> 8) ^ 0x80; goto CONV_END;
  943. -conv_1234_xxx1: as_u8(dst) = as_u32c(src) >> 24; goto CONV_END;
  944. -conv_1234_xx12: as_u16(dst) = as_u32c(src) >> 16; goto CONV_END;
  945. -conv_1234_xx21: as_u16(dst) = bswap_16(as_u32c(src) >> 16); goto CONV_END;
  946. -conv_1234_x123: as_u32(dst) = sx24(as_u32c(src) >> 8); goto CONV_END;
  947. -conv_1234_321x: as_u32(dst) = sx24s(bswap_32(as_u32c(src)) << 8); goto CONV_END;
  948. -conv_1234_1234: as_u32(dst) = as_u32c(src); goto CONV_END;
  949. -conv_1234_4321: as_u32(dst) = bswap_32(as_u32c(src)); goto CONV_END;
  950. -conv_1234_xxx9: as_u8(dst) = (as_u32c(src) >> 24) ^ 0x80; goto CONV_END;
  951. -conv_1234_xx92: as_u16(dst) = (as_u32c(src) >> 16) ^ 0x8000; goto CONV_END;
  952. -conv_1234_xx29: as_u16(dst) = bswap_16(as_u32c(src) >> 16) ^ 0x80; goto CONV_END;
  953. -conv_1234_x923: as_u32(dst) = sx24((as_u32c(src) >> 8) ^ 0x800000); goto CONV_END;
  954. -conv_1234_329x: as_u32(dst) = sx24s((bswap_32(as_u32c(src)) ^ 0x80) << 8); goto CONV_END;
  955. -conv_1234_9234: as_u32(dst) = as_u32c(src) ^ 0x80000000; goto CONV_END;
  956. -conv_1234_4329: as_u32(dst) = bswap_32(as_u32c(src)) ^ 0x80; goto CONV_END;
  957. -conv_1234_xxx4: as_u8(dst) = as_u32c(src) & 0xff; goto CONV_END;
  958. -conv_1234_xx43: as_u16(dst) = bswap_16(as_u32c(src)); goto CONV_END;
  959. -conv_1234_xx34: as_u16(dst) = as_u32c(src) & 0xffff; goto CONV_END;
  960. -conv_1234_x432: as_u32(dst) = sx24(bswap_32(as_u32c(src)) >> 8); goto CONV_END;
  961. -conv_1234_234x: as_u32(dst) = sx24s(as_u32c(src) << 8); goto CONV_END;
  962. -conv_1234_xxxC: as_u8(dst) = (as_u32c(src) & 0xff) ^ 0x80; goto CONV_END;
  963. -conv_1234_xxC3: as_u16(dst) = bswap_16(as_u32c(src) ^ 0x80); goto CONV_END;
  964. -conv_1234_xx3C: as_u16(dst) = (as_u32c(src) & 0xffff) ^ 0x80; goto CONV_END;
  965. -conv_1234_xC32: as_u32(dst) = sx24((bswap_32(as_u32c(src)) >> 8) ^ 0x800000); goto CONV_END;
  966. -conv_1234_23Cx: as_u32(dst) = sx24s((as_u32c(src) ^ 0x80) << 8); goto CONV_END;
  967. -conv_1234_C321: as_u32(dst) = bswap_32(as_u32c(src) ^ 0x80); goto CONV_END;
  968. -conv_1234_123C: as_u32(dst) = as_u32c(src) ^ 0x80; goto CONV_END;
  969. +static inline void conv(char *dst, const char *src, unsigned int idx) {
  970. + switch (idx) {
  971. + case 0: /* 8h -> 8h */
  972. + case 1: /* 8h -> 8s */
  973. + case 16: /* 8s -> 8h */
  974. + case 17: /* 8s -> 8s */ as_u8(dst) = as_u8c(src); break;
  975. + case 2: /* 8h -> 16h */
  976. + case 18: /* 8s -> 16h */ as_u16(dst) = (uint16_t)as_u8c(src) << 8; break;
  977. + case 3: /* 8h -> 16s */
  978. + case 19: /* 8s -> 16s */ as_u16(dst) = (uint16_t)as_u8c(src); break;
  979. + case 4: /* 8h -> 24h */
  980. + case 20: /* 8s -> 24h */ as_u32(dst) = sx24((uint32_t)as_u8c(src) << 16); break;
  981. + case 5: /* 8h -> 24s */
  982. + case 21: /* 8s -> 24s */ as_u32(dst) = sx24s((uint32_t)as_u8c(src) << 8); break;
  983. + case 6: /* 8h -> 32h */
  984. + case 22: /* 8s -> 32h */ as_u32(dst) = (uint32_t)as_u8c(src) << 24; break;
  985. + case 7: /* 8h -> 32s */
  986. + case 23: /* 8s -> 32s */ as_u32(dst) = (uint32_t)as_u8c(src); break;
  987. + case 8: /* 8h ^> 8h */
  988. + case 9: /* 8h ^> 8s */
  989. + case 24: /* 8s ^> 8h */
  990. + case 25: /* 8s ^> 8s */ as_u8(dst) = as_u8c(src) ^ 0x80; break;
  991. + case 10: /* 8h ^> 16h */
  992. + case 26: /* 8s ^> 16h */ as_u16(dst) = (uint16_t)(as_u8c(src) ^ 0x80) << 8; break;
  993. + case 11: /* 8h ^> 16s */
  994. + case 27: /* 8s ^> 16s */ as_u16(dst) = (uint16_t)(as_u8c(src) ^ 0x80); break;
  995. + case 12: /* 8h ^> 24h */
  996. + case 28: /* 8s ^> 24h */ as_u32(dst) = sx24((uint32_t)(as_u8c(src) ^ 0x80) << 16); break;
  997. + case 13: /* 8h ^> 24s */
  998. + case 29: /* 8s ^> 24s */ as_u32(dst) = sx24s((uint32_t)(as_u8c(src) ^ 0x80) << 8); break;
  999. + case 14: /* 8h ^> 32h */
  1000. + case 30: /* 8s ^> 32h */ as_u32(dst) = (uint32_t)(as_u8c(src) ^ 0x80) << 24; break;
  1001. + case 15: /* 8h ^> 32s */
  1002. + case 31: /* 8s ^> 32s */ as_u32(dst) = (uint32_t)(as_u8c(src) ^ 0x80); break;
  1003. + case 32: /* 16h -> 8h */
  1004. + case 33: /* 16h -> 8s */ as_u8(dst) = as_u16c(src) >> 8; break;
  1005. + case 34: /* 16h -> 16h */ as_u16(dst) = as_u16c(src); break;
  1006. + case 35: /* 16h -> 16s */ as_u16(dst) = bswap_16(as_u16c(src)); break;
  1007. + case 36: /* 16h -> 24h */ as_u32(dst) = sx24((uint32_t)as_u16c(src) << 8); break;
  1008. + case 37: /* 16h -> 24s */ as_u32(dst) = sx24s((uint32_t)bswap_16(as_u16c(src)) << 8); break;
  1009. + case 38: /* 16h -> 32h */ as_u32(dst) = (uint32_t)as_u16c(src) << 16; break;
  1010. + case 39: /* 16h -> 32s */ as_u32(dst) = (uint32_t)bswap_16(as_u16c(src)); break;
  1011. + case 40: /* 16h ^> 8h */
  1012. + case 41: /* 16h ^> 8s */ as_u8(dst) = (as_u16c(src) >> 8) ^ 0x80; break;
  1013. + case 42: /* 16h ^> 16h */
  1014. + case 51: /* 16s -> 16s */ as_u16(dst) = as_u16c(src) ^ 0x8000; break;
  1015. + case 43: /* 16h ^> 16s */
  1016. + case 50: /* 16s -> 16h */ as_u16(dst) = bswap_16(as_u16c(src)) ^ 0x80; break;
  1017. + case 44: /* 16h ^> 24h */ as_u32(dst) = sx24((uint32_t)(as_u16c(src) ^ 0x8000) << 8); break;
  1018. + case 45: /* 16h ^> 24s */ as_u32(dst) = sx24s((uint32_t)(bswap_16(as_u16c(src)) ^ 0x80) << 8); break;
  1019. + case 46: /* 16h ^> 32h */ as_u32(dst) = (uint32_t)(as_u16c(src) ^ 0x8000) << 16; break;
  1020. + case 47: /* 16h ^> 32s */ as_u32(dst) = (uint32_t)(bswap_16(as_u16c(src)) ^ 0x80); break;
  1021. + case 48: /* 16s -> 8h */
  1022. + case 49: /* 16s -> 8s */ as_u8(dst) = as_u16c(src) & 0xff; break;
  1023. + case 52: /* 16s -> 24h */ as_u32(dst) = sx24((uint32_t)bswap_16(as_u16c(src)) << 8); break;
  1024. + case 53: /* 16s -> 24s */ as_u32(dst) = sx24s((uint32_t)as_u16c(src) << 8); break;
  1025. + case 54: /* 16s -> 32h */ as_u32(dst) = (uint32_t)bswap_16(as_u16c(src)) << 16; break;
  1026. + case 55: /* 16s -> 32s */ as_u32(dst) = (uint32_t)as_u16c(src); break;
  1027. + case 56: /* 16s ^> 8h */
  1028. + case 57: /* 16s ^> 8s */ as_u8(dst) = (as_u16c(src) ^ 0x80) & 0xff; break;
  1029. + case 58: /* 16s ^> 16h */ as_u16(dst) = bswap_16(as_u16c(src) ^ 0x80); break;
  1030. + case 59: /* 16s ^> 16s */ as_u16(dst) = as_u16c(src) ^ 0x80; break;
  1031. + case 60: /* 16s ^> 24h */ as_u32(dst) = sx24((uint32_t)bswap_16(as_u16c(src) ^ 0x80) << 8); break;
  1032. + case 61: /* 16s ^> 24s */ as_u32(dst) = sx24s((uint32_t)(as_u16c(src) ^ 0x80) << 8); break;
  1033. + case 62: /* 16s ^> 32h */ as_u32(dst) = (uint32_t)bswap_16(as_u16c(src) ^ 0x80) << 16; break;
  1034. + case 63: /* 16s ^> 32s */ as_u32(dst) = (uint32_t)(as_u16c(src) ^ 0x80); break;
  1035. + case 64: /* 24h -> 8h */
  1036. + case 65: /* 24h -> 8s */ as_u8(dst) = as_u32c(src) >> 16; break;
  1037. + case 66: /* 24h -> 16h */ as_u16(dst) = as_u32c(src) >> 8; break;
  1038. + case 67: /* 24h -> 16s */ as_u16(dst) = bswap_16(as_u32c(src) >> 8); break;
  1039. + case 68: /* 24h -> 24h */ as_u32(dst) = sx24(as_u32c(src)); break;
  1040. + case 69: /* 24h -> 24s */ as_u32(dst) = sx24s(bswap_32(as_u32c(src))); break;
  1041. + case 70: /* 24h -> 32h */ as_u32(dst) = as_u32c(src) << 8; break;
  1042. + case 71: /* 24h -> 32s */ as_u32(dst) = bswap_32(as_u32c(src)) >> 8; break;
  1043. + case 72: /* 24h ^> 8h */
  1044. + case 73: /* 24h ^> 8s */ as_u8(dst) = (as_u32c(src) >> 16) ^ 0x80; break;
  1045. + case 74: /* 24h ^> 16h */ as_u16(dst) = (as_u32c(src) >> 8) ^ 0x8000; break;
  1046. + case 75: /* 24h ^> 16s */ as_u16(dst) = bswap_16(as_u32c(src) >> 8) ^ 0x80; break;
  1047. + case 76: /* 24h ^> 24h */ as_u32(dst) = sx24(as_u32c(src) ^ 0x800000); break;
  1048. + case 77: /* 24h ^> 24s */ as_u32(dst) = sx24s(bswap_32(as_u32c(src)) ^ 0x8000); break;
  1049. + case 78: /* 24h ^> 32h */ as_u32(dst) = (as_u32c(src) ^ 0x800000) << 8; break;
  1050. + case 79: /* 24h ^> 32s */ as_u32(dst) = (bswap_32(as_u32c(src)) >> 8) ^ 0x80; break;
  1051. + case 80: /* 24s -> 8h */
  1052. + case 81: /* 24s -> 8s */ as_u8(dst) = (as_u32c(src) >> 8) & 0xff; break;
  1053. + case 82: /* 24s -> 16h */ as_u16(dst) = bswap_16(as_u32c(src) >> 8); break;
  1054. + case 83: /* 24s -> 16s */ as_u16(dst) = (as_u32c(src) >> 8) & 0xffff; break;
  1055. + case 84: /* 24s -> 24h */ as_u32(dst) = sx24(bswap_32(as_u32c(src))); break;
  1056. + case 85: /* 24s -> 24s */ as_u32(dst) = sx24s(as_u32c(src)); break;
  1057. + case 86: /* 24s -> 32h */ as_u32(dst) = bswap_32(as_u32c(src)) << 8; break;
  1058. + case 87: /* 24s -> 32s */ as_u32(dst) = as_u32c(src) >> 8; break;
  1059. + case 88: /* 24s ^> 8h */
  1060. + case 89: /* 24s ^> 8s */ as_u8(dst) = ((as_u32c(src) >> 8) & 0xff) ^ 0x80; break;
  1061. + case 90: /* 24s ^> 16h */ as_u16(dst) = bswap_16((as_u32c(src) >> 8) ^ 0x80); break;
  1062. + case 91: /* 24s ^> 16s */ as_u16(dst) = ((as_u32c(src) >> 8) & 0xffff) ^ 0x80; break;
  1063. + case 92: /* 24s ^> 24h */ as_u32(dst) = sx24(bswap_32(as_u32c(src)) ^ 0x800000); break;
  1064. + case 93: /* 24s ^> 24s */ as_u32(dst) = sx24s(as_u32c(src) ^ 0x8000); break;
  1065. + case 94: /* 24s ^> 32h */ as_u32(dst) = bswap_32(as_u32c(src) ^ 0x8000) << 8; break;
  1066. + case 95: /* 24s ^> 32s */ as_u32(dst) = (as_u32c(src) >> 8) ^ 0x80; break;
  1067. + case 96: /* 32h -> 8h */
  1068. + case 97: /* 32h -> 8s */ as_u8(dst) = as_u32c(src) >> 24; break;
  1069. + case 98: /* 32h -> 16h */ as_u16(dst) = as_u32c(src) >> 16; break;
  1070. + case 99: /* 32h -> 16s */ as_u16(dst) = bswap_16(as_u32c(src) >> 16); break;
  1071. + case 100: /* 32h -> 24h */ as_u32(dst) = sx24(as_u32c(src) >> 8); break;
  1072. + case 101: /* 32h -> 24s */ as_u32(dst) = sx24s(bswap_32(as_u32c(src)) << 8); break;
  1073. + case 102: /* 32h -> 32h */
  1074. + case 119: /* 32s -> 32s */ as_u32(dst) = as_u32c(src); break;
  1075. + case 103: /* 32h -> 32s */
  1076. + case 118: /* 32s -> 32h */ as_u32(dst) = bswap_32(as_u32c(src)); break;
  1077. + case 104: /* 32h ^> 8h */
  1078. + case 105: /* 32h ^> 8s */ as_u8(dst) = (as_u32c(src) >> 24) ^ 0x80; break;
  1079. + case 106: /* 32h ^> 16h */ as_u16(dst) = (as_u32c(src) >> 16) ^ 0x8000; break;
  1080. + case 107: /* 32h ^> 16s */ as_u16(dst) = bswap_16(as_u32c(src) >> 16) ^ 0x80; break;
  1081. + case 108: /* 32h ^> 24h */ as_u32(dst) = sx24((as_u32c(src) >> 8) ^ 0x800000); break;
  1082. + case 109: /* 32h ^> 24s */ as_u32(dst) = sx24s((bswap_32(as_u32c(src)) ^ 0x80) << 8); break;
  1083. + case 110: /* 32h ^> 32h */ as_u32(dst) = as_u32c(src) ^ 0x80000000; break;
  1084. + case 111: /* 32h ^> 32s */ as_u32(dst) = bswap_32(as_u32c(src)) ^ 0x80; break;
  1085. + case 112: /* 32s -> 8h */
  1086. + case 113: /* 32s -> 8s */ as_u8(dst) = as_u32c(src) & 0xff; break;
  1087. + case 114: /* 32s -> 16h */ as_u16(dst) = bswap_16(as_u32c(src)); break;
  1088. + case 115: /* 32s -> 16s */ as_u16(dst) = as_u32c(src) & 0xffff; break;
  1089. + case 116: /* 32s -> 24h */ as_u32(dst) = sx24(bswap_32(as_u32c(src)) >> 8); break;
  1090. + case 117: /* 32s -> 24s */ as_u32(dst) = sx24s(as_u32c(src) << 8); break;
  1091. + case 120: /* 32s ^> 8h */
  1092. + case 121: /* 32s ^> 8s */ as_u8(dst) = (as_u32c(src) & 0xff) ^ 0x80; break;
  1093. + case 122: /* 32s ^> 16h */ as_u16(dst) = bswap_16(as_u32c(src) ^ 0x80); break;
  1094. + case 123: /* 32s ^> 16s */ as_u16(dst) = (as_u32c(src) & 0xffff) ^ 0x80; break;
  1095. + case 124: /* 32s ^> 24h */ as_u32(dst) = sx24((bswap_32(as_u32c(src)) >> 8) ^ 0x800000); break;
  1096. + case 125: /* 32s ^> 24s */ as_u32(dst) = sx24s((as_u32c(src) ^ 0x80) << 8); break;
  1097. + case 126: /* 32s ^> 32h */ as_u32(dst) = bswap_32(as_u32c(src) ^ 0x80); break;
  1098. + case 127: /* 32s ^> 32s */ as_u32(dst) = as_u32c(src) ^ 0x80; break;
  1099. + default: assert(0);
  1100. + }
  1101. }
  1102. -#endif
  1103. -#ifdef GET16_LABELS
  1104. -/* src_wid src_endswap sign_toggle */
  1105. -static void *const get16_labels[5 * 2 * 2 + 4 * 3] = {
  1106. - &&get16_1_10, /* 8h -> 16h */
  1107. - &&get16_1_90, /* 8h ^> 16h */
  1108. - &&get16_1_10, /* 8s -> 16h */
  1109. - &&get16_1_90, /* 8s ^> 16h */
  1110. - &&get16_12_12, /* 16h -> 16h */
  1111. - &&get16_12_92, /* 16h ^> 16h */
  1112. - &&get16_12_21, /* 16s -> 16h */
  1113. - &&get16_12_A1, /* 16s ^> 16h */
  1114. +static inline uint16_t get16(const char *src, unsigned int idx) {
  1115. + switch(idx) {
  1116. + case 0: /* 8h -> 16h */
  1117. + case 2: /* 8s -> 16h */ return (uint16_t)as_u8c(src) << 8;
  1118. + case 1: /* 8h ^> 16h */
  1119. + case 3: /* 8s ^> 16h */ return (uint16_t)(as_u8c(src) ^ 0x80) << 8;
  1120. + case 4: /* 16h -> 16h */ return as_u16c(src);
  1121. + case 5: /* 16h ^> 16h */ return as_u16c(src) ^ 0x8000;
  1122. + case 6: /* 16s -> 16h */ return bswap_16(as_u16c(src));
  1123. + case 7: /* 16s ^> 16h */ return bswap_16(as_u16c(src) ^ 0x80);
  1124. /* 4 byte formats */
  1125. - &&get16_0123_12, /* 24h -> 16h */
  1126. - &&get16_0123_92, /* 24h ^> 16h */
  1127. - &&get16_1230_32, /* 24s -> 16h */
  1128. - &&get16_1230_B2, /* 24s ^> 16h */
  1129. - &&get16_1234_12, /* 32h -> 16h */
  1130. - &&get16_1234_92, /* 32h ^> 16h */
  1131. - &&get16_1234_43, /* 32s -> 16h */
  1132. - &&get16_1234_C3, /* 32s ^> 16h */
  1133. - &&get16_0123_12_20, /* 20h -> 16h */
  1134. - &&get16_0123_92_20, /* 20h ^> 16h */
  1135. - &&get16_1230_32_20, /* 20s -> 16h */
  1136. - &&get16_1230_B2_20, /* 20s ^> 16h */
  1137. + case 8: /* 24h -> 16h */ return as_u32c(src) >> 8;
  1138. + case 9: /* 24h ^> 16h */ return (as_u32c(src) >> 8) ^ 0x8000;
  1139. + case 10: /* 24s -> 16h */ return bswap_16(as_u32c(src) >> 8);
  1140. + case 11: /* 24s ^> 16h */ return bswap_16((as_u32c(src) >> 8) ^ 0x80);
  1141. + case 12: /* 32h -> 16h */ return as_u32c(src) >> 16;
  1142. + case 13: /* 32h ^> 16h */ return (as_u32c(src) >> 16) ^ 0x8000;
  1143. + case 14: /* 32s -> 16h */ return bswap_16(as_u32c(src));
  1144. + case 15: /* 32s ^> 16h */ return bswap_16(as_u32c(src) ^ 0x80);
  1145. + case 16: /* 20h -> 16h */ return as_u32c(src) >> 4;
  1146. + case 17: /* 20h ^> 16h */ return (as_u32c(src) >> 4) ^ 0x8000;
  1147. + case 18: /* 20s -> 16h */ return bswap_32(as_u32c(src)) >> 4;
  1148. + case 19: /* 20s ^> 16h */ return (bswap_32(as_u32c(src)) >> 4) ^ 0x8000;
  1149. /* 3bytes format */
  1150. - &&get16_123_12, /* 24h -> 16h */
  1151. - &&get16_123_92, /* 24h ^> 16h */
  1152. - &&get16_123_32, /* 24s -> 16h */
  1153. - &&get16_123_B2, /* 24s ^> 16h */
  1154. - &&get16_123_12_20, /* 20h -> 16h */
  1155. - &&get16_123_92_20, /* 20h ^> 16h */
  1156. - &&get16_123_32_20, /* 20s -> 16h */
  1157. - &&get16_123_B2_20, /* 20s ^> 16h */
  1158. - &&get16_123_12_18, /* 18h -> 16h */
  1159. - &&get16_123_92_18, /* 18h ^> 16h */
  1160. - &&get16_123_32_18, /* 18s -> 16h */
  1161. - &&get16_123_B2_18, /* 18s ^> 16h */
  1162. -};
  1163. -#endif
  1164. -
  1165. -#ifdef GET16_END
  1166. -while(0) {
  1167. -get16_1_10: sample = (uint16_t)as_u8c(src) << 8; goto GET16_END;
  1168. -get16_1_90: sample = (uint16_t)(as_u8c(src) ^ 0x80) << 8; goto GET16_END;
  1169. -get16_12_12: sample = as_u16c(src); goto GET16_END;
  1170. -get16_12_92: sample = as_u16c(src) ^ 0x8000; goto GET16_END;
  1171. -get16_12_21: sample = bswap_16(as_u16c(src)); goto GET16_END;
  1172. -get16_12_A1: sample = bswap_16(as_u16c(src) ^ 0x80); goto GET16_END;
  1173. -get16_0123_12: sample = as_u32c(src) >> 8; goto GET16_END;
  1174. -get16_0123_92: sample = (as_u32c(src) >> 8) ^ 0x8000; goto GET16_END;
  1175. -get16_1230_32: sample = bswap_16(as_u32c(src) >> 8); goto GET16_END;
  1176. -get16_1230_B2: sample = bswap_16((as_u32c(src) >> 8) ^ 0x80); goto GET16_END;
  1177. -get16_1234_12: sample = as_u32c(src) >> 16; goto GET16_END;
  1178. -get16_1234_92: sample = (as_u32c(src) >> 16) ^ 0x8000; goto GET16_END;
  1179. -get16_1234_43: sample = bswap_16(as_u32c(src)); goto GET16_END;
  1180. -get16_1234_C3: sample = bswap_16(as_u32c(src) ^ 0x80); goto GET16_END;
  1181. -get16_0123_12_20: sample = as_u32c(src) >> 4; goto GET16_END;
  1182. -get16_0123_92_20: sample = (as_u32c(src) >> 4) ^ 0x8000; goto GET16_END;
  1183. -get16_1230_32_20: sample = bswap_32(as_u32c(src)) >> 4; goto GET16_END;
  1184. -get16_1230_B2_20: sample = (bswap_32(as_u32c(src)) >> 4) ^ 0x8000; goto GET16_END;
  1185. -get16_123_12: sample = _get_triple(src) >> 8; goto GET16_END;
  1186. -get16_123_92: sample = (_get_triple(src) >> 8) ^ 0x8000; goto GET16_END;
  1187. -get16_123_32: sample = _get_triple_s(src) >> 8; goto GET16_END;
  1188. -get16_123_B2: sample = (_get_triple_s(src) >> 8) ^ 0x8000; goto GET16_END;
  1189. -get16_123_12_20: sample = _get_triple(src) >> 4; goto GET16_END;
  1190. -get16_123_92_20: sample = (_get_triple(src) >> 4) ^ 0x8000; goto GET16_END;
  1191. -get16_123_32_20: sample = _get_triple_s(src) >> 4; goto GET16_END;
  1192. -get16_123_B2_20: sample = (_get_triple_s(src) >> 4) ^ 0x8000; goto GET16_END;
  1193. -get16_123_12_18: sample = _get_triple(src) >> 2; goto GET16_END;
  1194. -get16_123_92_18: sample = (_get_triple(src) >> 2) ^ 0x8000; goto GET16_END;
  1195. -get16_123_32_18: sample = _get_triple_s(src) >> 2; goto GET16_END;
  1196. -get16_123_B2_18: sample = (_get_triple_s(src) >> 2) ^ 0x8000; goto GET16_END;
  1197. + case 20: /* 24h -> 16h */ return _get_triple(src) >> 8;
  1198. + case 21: /* 24h ^> 16h */ return (_get_triple(src) >> 8) ^ 0x8000;
  1199. + case 22: /* 24s -> 16h */ return _get_triple_s(src) >> 8;
  1200. + case 23: /* 24s ^> 16h */ return (_get_triple_s(src) >> 8) ^ 0x8000;
  1201. + case 24: /* 20h -> 16h */ return _get_triple(src) >> 4;
  1202. + case 25: /* 20h ^> 16h */ return (_get_triple(src) >> 4) ^ 0x8000;
  1203. + case 26: /* 20s -> 16h */ return _get_triple_s(src) >> 4;
  1204. + case 27: /* 20s ^> 16h */ return (_get_triple_s(src) >> 4) ^ 0x8000;
  1205. + case 28: /* 18h -> 16h */ return _get_triple(src) >> 2;
  1206. + case 29: /* 18h ^> 16h */ return (_get_triple(src) >> 2) ^ 0x8000;
  1207. + case 30: /* 18s -> 16h */ return _get_triple_s(src) >> 2;
  1208. + case 31: /* 18s ^> 16h */ return (_get_triple_s(src) >> 2) ^ 0x8000;
  1209. + default: assert(0);
  1210. + }
  1211. }
  1212. -#endif
  1213. -#ifdef PUT16_LABELS
  1214. -/* dst_wid dst_endswap sign_toggle */
  1215. -static void *const put16_labels[5 * 2 * 2 + 4 * 3] = {
  1216. - &&put16_12_1, /* 16h -> 8h */
  1217. - &&put16_12_9, /* 16h ^> 8h */
  1218. - &&put16_12_1, /* 16h -> 8s */
  1219. - &&put16_12_9, /* 16h ^> 8s */
  1220. - &&put16_12_12, /* 16h -> 16h */
  1221. - &&put16_12_92, /* 16h ^> 16h */
  1222. - &&put16_12_21, /* 16h -> 16s */
  1223. - &&put16_12_29, /* 16h ^> 16s */
  1224. +static inline void put16(char *dst, int16_t sample, unsigned int idx)
  1225. +{
  1226. + switch (idx) {
  1227. + case 0: /* 16h -> 8h */
  1228. + case 2: /* 16h -> 8s */ as_u8(dst) = sample >> 8; break;
  1229. + case 1: /* 16h ^> 8h */
  1230. + case 3: /* 16h ^> 8s */ as_u8(dst) = (sample >> 8) ^ 0x80; break;
  1231. + case 4: /* 16h -> 16h */ as_u16(dst) = sample; break;
  1232. + case 5: /* 16h ^> 16h */ as_u16(dst) = sample ^ 0x8000; break;
  1233. + case 6: /* 16h -> 16s */ as_u16(dst) = bswap_16(sample); break;
  1234. + case 7: /* 16h ^> 16s */ as_u16(dst) = bswap_16(sample) ^ 0x80; break;
  1235. /* 4 byte formats */
  1236. - &&put16_12_0120, /* 16h -> 24h */
  1237. - &&put16_12_0920, /* 16h ^> 24h */
  1238. - &&put16_12_0210, /* 16h -> 24s */
  1239. - &&put16_12_0290, /* 16h ^> 24s */
  1240. - &&put16_12_1200, /* 16h -> 32h */
  1241. - &&put16_12_9200, /* 16h ^> 32h */
  1242. - &&put16_12_0021, /* 16h -> 32s */
  1243. - &&put16_12_0029, /* 16h ^> 32s */
  1244. - &&put16_12_0120_20, /* 16h -> 20h */
  1245. - &&put16_12_0920_20, /* 16h ^> 20h */
  1246. - &&put16_12_0210_20, /* 16h -> 20s */
  1247. - &&put16_12_0290_20, /* 16h ^> 20s */
  1248. + case 8: /* 16h -> 24h */ as_u32(dst) = sx24((uint32_t)sample << 8); break;
  1249. + case 9: /* 16h ^> 24h */ as_u32(dst) = sx24((uint32_t)(sample ^ 0x8000) << 8); break;
  1250. + case 10: /* 16h -> 24s */ as_u32(dst) = sx24s((uint32_t)bswap_16(sample) << 8); break;
  1251. + case 11: /* 16h ^> 24s */ as_u32(dst) = sx24s((uint32_t)(bswap_16(sample) ^ 0x80) << 8); break;
  1252. + case 12: /* 16h -> 32h */ as_u32(dst) = (uint32_t)sample << 16; break;
  1253. + case 13: /* 16h ^> 32h */ as_u32(dst) = (uint32_t)(sample ^ 0x8000) << 16; break;
  1254. + case 14: /* 16h -> 32s */ as_u32(dst) = (uint32_t)bswap_16(sample); break;
  1255. + case 15: /* 16h ^> 32s */ as_u32(dst) = (uint32_t)bswap_16(sample) ^ 0x80; break;
  1256. + case 16: /* 16h -> 20h */ as_u32(dst) = sx20((uint32_t)sample << 4); break;
  1257. + case 17: /* 16h ^> 20h */ as_u32(dst) = sx20((uint32_t)(sample ^ 0x8000) << 4); break;
  1258. + case 18: /* 16h -> 20s */ as_u32(dst) = bswap_32(sx20((uint32_t)sample << 4)); break;
  1259. + case 19: /* 16h ^> 20s */ as_u32(dst) = bswap_32(sx20((uint32_t)(sample ^ 0x8000) << 4)); break;
  1260. /* 3bytes format */
  1261. - &&put16_12_120, /* 16h -> 24h */
  1262. - &&put16_12_920, /* 16h ^> 24h */
  1263. - &&put16_12_021, /* 16h -> 24s */
  1264. - &&put16_12_029, /* 16h ^> 24s */
  1265. - &&put16_12_120_20, /* 16h -> 20h */
  1266. - &&put16_12_920_20, /* 16h ^> 20h */
  1267. - &&put16_12_021_20, /* 16h -> 20s */
  1268. - &&put16_12_029_20, /* 16h ^> 20s */
  1269. - &&put16_12_120_18, /* 16h -> 18h */
  1270. - &&put16_12_920_18, /* 16h ^> 18h */
  1271. - &&put16_12_021_18, /* 16h -> 18s */
  1272. - &&put16_12_029_18, /* 16h ^> 18s */
  1273. -};
  1274. -#endif
  1275. -
  1276. -#ifdef PUT16_END
  1277. -while (0) {
  1278. -put16_12_1: as_u8(dst) = sample >> 8; goto PUT16_END;
  1279. -put16_12_9: as_u8(dst) = (sample >> 8) ^ 0x80; goto PUT16_END;
  1280. -put16_12_12: as_u16(dst) = sample; goto PUT16_END;
  1281. -put16_12_92: as_u16(dst) = sample ^ 0x8000; goto PUT16_END;
  1282. -put16_12_21: as_u16(dst) = bswap_16(sample); goto PUT16_END;
  1283. -put16_12_29: as_u16(dst) = bswap_16(sample) ^ 0x80; goto PUT16_END;
  1284. -put16_12_0120: as_u32(dst) = sx24((uint32_t)sample << 8); goto PUT16_END;
  1285. -put16_12_0920: as_u32(dst) = sx24((uint32_t)(sample ^ 0x8000) << 8); goto PUT16_END;
  1286. -put16_12_0210: as_u32(dst) = sx24s((uint32_t)bswap_16(sample) << 8); goto PUT16_END;
  1287. -put16_12_0290: as_u32(dst) = sx24s((uint32_t)(bswap_16(sample) ^ 0x80) << 8); goto PUT16_END;
  1288. -put16_12_1200: as_u32(dst) = (uint32_t)sample << 16; goto PUT16_END;
  1289. -put16_12_9200: as_u32(dst) = (uint32_t)(sample ^ 0x8000) << 16; goto PUT16_END;
  1290. -put16_12_0021: as_u32(dst) = (uint32_t)bswap_16(sample); goto PUT16_END;
  1291. -put16_12_0029: as_u32(dst) = (uint32_t)bswap_16(sample) ^ 0x80; goto PUT16_END;
  1292. -put16_12_0120_20: as_u32(dst) = sx20((uint32_t)sample << 4); goto PUT16_END;
  1293. -put16_12_0920_20: as_u32(dst) = sx20((uint32_t)(sample ^ 0x8000) << 4); goto PUT16_END;
  1294. -put16_12_0210_20: as_u32(dst) = bswap_32(sx20((uint32_t)sample << 4)); goto PUT16_END;
  1295. -put16_12_0290_20: as_u32(dst) = bswap_32(sx20((uint32_t)(sample ^ 0x8000) << 4)); goto PUT16_END;
  1296. -put16_12_120: _put_triple(dst, (uint32_t)sample << 8); goto PUT16_END;
  1297. -put16_12_920: _put_triple(dst, (uint32_t)(sample ^ 0x8000) << 8); goto PUT16_END;
  1298. -put16_12_021: _put_triple_s(dst, (uint32_t)sample << 8); goto PUT16_END;
  1299. -put16_12_029: _put_triple_s(dst, (uint32_t)(sample ^ 0x8000) << 8); goto PUT16_END;
  1300. -put16_12_120_20: _put_triple(dst, (uint32_t)sample << 4); goto PUT16_END;
  1301. -put16_12_920_20: _put_triple(dst, (uint32_t)(sample ^ 0x8000) << 4); goto PUT16_END;
  1302. -put16_12_021_20: _put_triple_s(dst, (uint32_t)sample << 4); goto PUT16_END;
  1303. -put16_12_029_20: _put_triple_s(dst, (uint32_t)(sample ^ 0x8000) << 4); goto PUT16_END;
  1304. -put16_12_120_18: _put_triple(dst, (uint32_t)sample << 2); goto PUT16_END;
  1305. -put16_12_920_18: _put_triple(dst, (uint32_t)(sample ^ 0x8000) << 2); goto PUT16_END;
  1306. -put16_12_021_18: _put_triple_s(dst, (uint32_t)sample << 2); goto PUT16_END;
  1307. -put16_12_029_18: _put_triple_s(dst, (uint32_t)(sample ^ 0x8000) << 2); goto PUT16_END;
  1308. + case 20: /* 16h -> 24h */ _put_triple(dst, (uint32_t)sample << 8); break;
  1309. + case 21: /* 16h ^> 24h */ _put_triple(dst, (uint32_t)(sample ^ 0x8000) << 8); break;
  1310. + case 22: /* 16h -> 24s */ _put_triple_s(dst, (uint32_t)sample << 8); break;
  1311. + case 23: /* 16h ^> 24s */ _put_triple_s(dst, (uint32_t)(sample ^ 0x8000) << 8); break;
  1312. + case 24: /* 16h -> 20h */ _put_triple(dst, (uint32_t)sample << 4); break;
  1313. + case 25: /* 16h ^> 20h */ _put_triple(dst, (uint32_t)(sample ^ 0x8000) << 4); break;
  1314. + case 26: /* 16h -> 20s */ _put_triple_s(dst, (uint32_t)sample << 4); break;
  1315. + case 27: /* 16h ^> 20s */ _put_triple_s(dst, (uint32_t)(sample ^ 0x8000) << 4); break;
  1316. + case 28: /* 16h -> 18h */ _put_triple(dst, (uint32_t)sample << 2); break;
  1317. + case 29: /* 16h ^> 18h */ _put_triple(dst, (uint32_t)(sample ^ 0x8000) << 2); break;
  1318. + case 30: /* 16h -> 18s */ _put_triple_s(dst, (uint32_t)sample << 2); break;
  1319. + case 31: /* 16h ^> 18s */ _put_triple_s(dst, (uint32_t)(sample ^ 0x8000) << 2); break;
  1320. + default: assert(0);
  1321. + }
  1322. }
  1323. -#endif
  1324. -
  1325. -#ifdef CONV24_LABELS
  1326. -#define GET32_LABELS
  1327. -#define PUT32_LABELS
  1328. -#endif
  1329. -#ifdef GET32_LABELS
  1330. -/* src_wid src_endswap sign_toggle */
  1331. -static void *const get32_labels[5 * 2 * 2 + 4 * 3] = {
  1332. - &&get32_1_1000, /* 8h -> 32h */
  1333. - &&get32_1_9000, /* 8h ^> 32h */
  1334. - &&get32_1_1000, /* 8s -> 32h */
  1335. - &&get32_1_9000, /* 8s ^> 32h */
  1336. - &&get32_12_1200, /* 16h -> 32h */
  1337. - &&get32_12_9200, /* 16h ^> 32h */
  1338. - &&get32_12_2100, /* 16s -> 32h */
  1339. - &&get32_12_A100, /* 16s ^> 32h */
  1340. +static inline int32_t get32(const char *src, unsigned int idx)
  1341. +{
  1342. + switch (idx) {
  1343. + case 0: /* 8h -> 32h */
  1344. + case 2: /* 8s -> 32h */ return (uint32_t)as_u8c(src) << 24;
  1345. + case 1: /* 8h ^> 32h */
  1346. + case 3: /* 8s ^> 32h */ return (uint32_t)(as_u8c(src) ^ 0x80) << 24;
  1347. + case 4: /* 16h -> 32h */ return (uint32_t)as_u16c(src) << 16;
  1348. + case 5: /* 16h ^> 32h */ return (uint32_t)(as_u16c(src) ^ 0x8000) << 16;
  1349. + case 6: /* 16s -> 32h */ return (uint32_t)bswap_16(as_u16c(src)) << 16;
  1350. + case 7: /* 16s ^> 32h */ return (uint32_t)bswap_16(as_u16c(src) ^ 0x80) << 16;
  1351. /* 4 byte formats */
  1352. - &&get32_0123_1230, /* 24h -> 32h */
  1353. - &&get32_0123_9230, /* 24h ^> 32h */
  1354. - &&get32_1230_3210, /* 24s -> 32h */
  1355. - &&get32_1230_B210, /* 24s ^> 32h */
  1356. - &&get32_1234_1234, /* 32h -> 32h */
  1357. - &&get32_1234_9234, /* 32h ^> 32h */
  1358. - &&get32_1234_4321, /* 32s -> 32h */
  1359. - &&get32_1234_C321, /* 32s ^> 32h */
  1360. - &&get32_0123_1230_20, /* 20h -> 32h */
  1361. - &&get32_0123_9230_20, /* 20h ^> 32h */
  1362. - &&get32_1230_3210_20, /* 20s -> 32h */
  1363. - &&get32_1230_B210_20, /* 20s ^> 32h */
  1364. + case 8: /* 24h -> 32h */ return as_u32c(src) << 8;
  1365. + case 9: /* 24h ^> 32h */ return (as_u32c(src) << 8) ^ 0x80000000;
  1366. + case 10: /* 24s -> 32h */ return bswap_32(as_u32c(src) >> 8);
  1367. + case 11: /* 24s ^> 32h */ return bswap_32((as_u32c(src) >> 8) ^ 0x80);
  1368. + case 12: /* 32h -> 32h */ return as_u32c(src);
  1369. + case 13: /* 32h ^> 32h */ return as_u32c(src) ^ 0x80000000;
  1370. + case 14: /* 32s -> 32h */ return bswap_32(as_u32c(src));
  1371. + case 15: /* 32s ^> 32h */ return bswap_32(as_u32c(src) ^ 0x80);
  1372. + case 16: /* 20h -> 32h */ return as_u32c(src) << 12;
  1373. + case 17: /* 20h ^> 32h */ return (as_u32c(src) << 12) ^ 0x80000000;
  1374. + case 18: /* 20s -> 32h */ return bswap_32(as_u32c(src)) << 12;
  1375. + case 19: /* 20s ^> 32h */ return (bswap_32(as_u32c(src)) << 12) ^ 0x80000000;
  1376. /* 3bytes format */
  1377. - &&get32_123_1230, /* 24h -> 32h */
  1378. - &&get32_123_9230, /* 24h ^> 32h */
  1379. - &&get32_123_3210, /* 24s -> 32h */
  1380. - &&get32_123_B210, /* 24s ^> 32h */
  1381. - &&get32_123_1230_20, /* 20h -> 32h */
  1382. - &&get32_123_9230_20, /* 20h ^> 32h */
  1383. - &&get32_123_3210_20, /* 20s -> 32h */
  1384. - &&get32_123_B210_20, /* 20s ^> 32h */
  1385. - &&get32_123_1230_18, /* 18h -> 32h */
  1386. - &&get32_123_9230_18, /* 18h ^> 32h */
  1387. - &&get32_123_3210_18, /* 18s -> 32h */
  1388. - &&get32_123_B210_18, /* 18s ^> 32h */
  1389. -};
  1390. -#endif
  1391. -
  1392. -#ifdef CONV24_END
  1393. -#define GET32_END __conv24_get
  1394. -#endif
  1395. -
  1396. -#ifdef GET32_END
  1397. -while (0) {
  1398. -get32_1_1000: sample = (uint32_t)as_u8c(src) << 24; goto GET32_END;
  1399. -get32_1_9000: sample = (uint32_t)(as_u8c(src) ^ 0x80) << 24; goto GET32_END;
  1400. -get32_12_1200: sample = (uint32_t)as_u16c(src) << 16; goto GET32_END;
  1401. -get32_12_9200: sample = (uint32_t)(as_u16c(src) ^ 0x8000) << 16; goto GET32_END;
  1402. -get32_12_2100: sample = (uint32_t)bswap_16(as_u16c(src)) << 16; goto GET32_END;
  1403. -get32_12_A100: sample = (uint32_t)bswap_16(as_u16c(src) ^ 0x80) << 16; goto GET32_END;
  1404. -get32_0123_1230: sample = as_u32c(src) << 8; goto GET32_END;
  1405. -get32_0123_9230: sample = (as_u32c(src) << 8) ^ 0x80000000; goto GET32_END;
  1406. -get32_1230_3210: sample = bswap_32(as_u32c(src) >> 8); goto GET32_END;
  1407. -get32_1230_B210: sample = bswap_32((as_u32c(src) >> 8) ^ 0x80); goto GET32_END;
  1408. -get32_1234_1234: sample = as_u32c(src); goto GET32_END;
  1409. -get32_1234_9234: sample = as_u32c(src) ^ 0x80000000; goto GET32_END;
  1410. -get32_1234_4321: sample = bswap_32(as_u32c(src)); goto GET32_END;
  1411. -get32_1234_C321: sample = bswap_32(as_u32c(src) ^ 0x80); goto GET32_END;
  1412. -get32_0123_1230_20: sample = as_u32c(src) << 12; goto GET32_END;
  1413. -get32_0123_9230_20: sample = (as_u32c(src) << 12) ^ 0x80000000; goto GET32_END;
  1414. -get32_1230_3210_20: sample = bswap_32(as_u32c(src)) << 12; goto GET32_END;
  1415. -get32_1230_B210_20: sample = (bswap_32(as_u32c(src)) << 12) ^ 0x80000000; goto GET32_END;
  1416. -get32_123_1230: sample = _get_triple(src) << 8; goto GET32_END;
  1417. -get32_123_9230: sample = (_get_triple(src) << 8) ^ 0x80000000; goto GET32_END;
  1418. -get32_123_3210: sample = _get_triple_s(src) << 8; goto GET32_END;
  1419. -get32_123_B210: sample = (_get_triple_s(src) << 8) ^ 0x80000000; goto GET32_END;
  1420. -get32_123_1230_20: sample = _get_triple(src) << 12; goto GET32_END;
  1421. -get32_123_9230_20: sample = (_get_triple(src) << 12) ^ 0x80000000; goto GET32_END;
  1422. -get32_123_3210_20: sample = _get_triple_s(src) << 12; goto GET32_END;
  1423. -get32_123_B210_20: sample = (_get_triple_s(src) << 12) ^ 0x80000000; goto GET32_END;
  1424. -get32_123_1230_18: sample = _get_triple(src) << 14; goto GET32_END;
  1425. -get32_123_9230_18: sample = (_get_triple(src) << 14) ^ 0x80000000; goto GET32_END;
  1426. -get32_123_3210_18: sample = _get_triple_s(src) << 14; goto GET32_END;
  1427. -get32_123_B210_18: sample = (_get_triple_s(src) << 14) ^ 0x80000000; goto GET32_END;
  1428. + case 20: /* 24h -> 32h */ return _get_triple(src) << 8;
  1429. + case 21: /* 24h ^> 32h */ return (_get_triple(src) << 8) ^ 0x80000000;
  1430. + case 22: /* 24s -> 32h */ return _get_triple_s(src) << 8;
  1431. + case 23: /* 24s ^> 32h */ return (_get_triple_s(src) << 8) ^ 0x80000000;
  1432. + case 24: /* 20h -> 32h */ return _get_triple(src) << 12;
  1433. + case 25: /* 20h ^> 32h */ return (_get_triple(src) << 12) ^ 0x80000000;
  1434. + case 26: /* 20s -> 32h */ return _get_triple_s(src) << 12;
  1435. + case 27: /* 20s ^> 32h */ return (_get_triple_s(src) << 12) ^ 0x80000000;
  1436. + case 28: /* 18h -> 32h */ return _get_triple(src) << 14;
  1437. + case 29: /* 18h ^> 32h */ return (_get_triple(src) << 14) ^ 0x80000000;
  1438. + case 30: /* 18s -> 32h */ return _get_triple_s(src) << 14;
  1439. + case 31: /* 18s ^> 32h */ return (_get_triple_s(src) << 14) ^ 0x80000000;
  1440. + default: assert(0);
  1441. + }
  1442. }
  1443. -#endif
  1444. -#ifdef CONV24_END
  1445. -__conv24_get: goto *put;
  1446. -#define PUT32_END CONV24_END
  1447. -#endif
  1448. -
  1449. -#ifdef PUT32_LABELS
  1450. -/* dst_wid dst_endswap sign_toggle */
  1451. -static void *const put32_labels[5 * 2 * 2 + 4 * 3] = {
  1452. - &&put32_1234_1, /* 32h -> 8h */
  1453. - &&put32_1234_9, /* 32h ^> 8h */
  1454. - &&put32_1234_1, /* 32h -> 8s */
  1455. - &&put32_1234_9, /* 32h ^> 8s */
  1456. - &&put32_1234_12, /* 32h -> 16h */
  1457. - &&put32_1234_92, /* 32h ^> 16h */
  1458. - &&put32_1234_21, /* 32h -> 16s */
  1459. - &&put32_1234_29, /* 32h ^> 16s */
  1460. +static inline void put32(char *dst, int32_t sample, unsigned int idx)
  1461. +{
  1462. + switch (idx) {
  1463. + case 0: /* 32h -> 8h */
  1464. + case 2: /* 32h -> 8s */ as_u8(dst) = sample >> 24; break;
  1465. + case 1: /* 32h ^> 8h */
  1466. + case 3: /* 32h ^> 8s */ as_u8(dst) = (sample >> 24) ^ 0x80; break;
  1467. + case 4: /* 32h -> 16h */ as_u16(dst) = sample >> 16; break;
  1468. + case 5: /* 32h ^> 16h */ as_u16(dst) = (sample >> 16) ^ 0x8000; break;
  1469. + case 6: /* 32h -> 16s */ as_u16(dst) = bswap_16(sample >> 16); break;
  1470. + case 7: /* 32h ^> 16s */ as_u16(dst) = bswap_16(sample >> 16) ^ 0x80; break;
  1471. /* 4 byte formats */
  1472. - &&put32_1234_0123, /* 32h -> 24h */
  1473. - &&put32_1234_0923, /* 32h ^> 24h */
  1474. - &&put32_1234_3210, /* 32h -> 24s */
  1475. - &&put32_1234_3290, /* 32h ^> 24s */
  1476. - &&put32_1234_1234, /* 32h -> 32h */
  1477. - &&put32_1234_9234, /* 32h ^> 32h */
  1478. - &&put32_1234_4321, /* 32h -> 32s */
  1479. - &&put32_1234_4329, /* 32h ^> 32s */
  1480. - &&put32_1234_0123_20, /* 32h -> 20h */
  1481. - &&put32_1234_0923_20, /* 32h ^> 20h */
  1482. - &&put32_1234_3210_20, /* 32h -> 20s */
  1483. - &&put32_1234_3290_20, /* 32h ^> 20s */
  1484. + case 8: /* 32h -> 24h */ as_u32(dst) = sx24(sample >> 8); break;
  1485. + case 9: /* 32h ^> 24h */ as_u32(dst) = sx24((sample >> 8) ^ 0x800000); break;
  1486. + case 10: /* 32h -> 24s */ as_u32(dst) = sx24s(bswap_32(sample) << 8); break;
  1487. + case 11: /* 32h ^> 24s */ as_u32(dst) = sx24s((bswap_32(sample) ^ 0x80) << 8); break;
  1488. + case 12: /* 32h -> 32h */ as_u32(dst) = sample; break;
  1489. + case 13: /* 32h ^> 32h */ as_u32(dst) = sample ^ 0x80000000; break;
  1490. + case 14: /* 32h -> 32s */ as_u32(dst) = bswap_32(sample); break;
  1491. + case 15: /* 32h ^> 32s */ as_u32(dst) = bswap_32(sample) ^ 0x80; break;
  1492. + case 16: /* 32h -> 20h */ as_u32(dst) = sx20(sample >> 12); break;
  1493. + case 17: /* 32h ^> 20h */ as_u32(dst) = sx20((sample ^ 0x80000000) >> 12); break;
  1494. + case 18: /* 32h -> 20s */ as_u32(dst) = bswap_32(sx20(sample >> 12)); break;
  1495. + case 19: /* 32h ^> 20s */ as_u32(dst) = bswap_32(sx20((sample ^ 0x80000000) >> 12)); break;
  1496. /* 3bytes format */
  1497. - &&put32_1234_123, /* 32h -> 24h */
  1498. - &&put32_1234_923, /* 32h ^> 24h */
  1499. - &&put32_1234_321, /* 32h -> 24s */
  1500. - &&put32_1234_329, /* 32h ^> 24s */
  1501. - &&put32_1234_123_20, /* 32h -> 20h */
  1502. - &&put32_1234_923_20, /* 32h ^> 20h */
  1503. - &&put32_1234_321_20, /* 32h -> 20s */
  1504. - &&put32_1234_329_20, /* 32h ^> 20s */
  1505. - &&put32_1234_123_18, /* 32h -> 18h */
  1506. - &&put32_1234_923_18, /* 32h ^> 18h */
  1507. - &&put32_1234_321_18, /* 32h -> 18s */
  1508. - &&put32_1234_329_18, /* 32h ^> 18s */
  1509. -};
  1510. -#endif
  1511. -
  1512. -#ifdef CONV24_LABELS
  1513. -#undef GET32_LABELS
  1514. -#undef PUT32_LABELS
  1515. -#endif
  1516. -
  1517. -#ifdef PUT32_END
  1518. -while (0) {
  1519. -put32_1234_1: as_u8(dst) = sample >> 24; goto PUT32_END;
  1520. -put32_1234_9: as_u8(dst) = (sample >> 24) ^ 0x80; goto PUT32_END;
  1521. -put32_1234_12: as_u16(dst) = sample >> 16; goto PUT32_END;
  1522. -put32_1234_92: as_u16(dst) = (sample >> 16) ^ 0x8000; goto PUT32_END;
  1523. -put32_1234_21: as_u16(dst) = bswap_16(sample >> 16); goto PUT32_END;
  1524. -put32_1234_29: as_u16(dst) = bswap_16(sample >> 16) ^ 0x80; goto PUT32_END;
  1525. -put32_1234_0123: as_u32(dst) = sx24(sample >> 8); goto PUT32_END;
  1526. -put32_1234_0923: as_u32(dst) = sx24((sample >> 8) ^ 0x800000); goto PUT32_END;
  1527. -put32_1234_3210: as_u32(dst) = sx24s(bswap_32(sample) << 8); goto PUT32_END;
  1528. -put32_1234_3290: as_u32(dst) = sx24s((bswap_32(sample) ^ 0x80) << 8); goto PUT32_END;
  1529. -put32_1234_1234: as_u32(dst) = sample; goto PUT32_END;
  1530. -put32_1234_9234: as_u32(dst) = sample ^ 0x80000000; goto PUT32_END;
  1531. -put32_1234_4321: as_u32(dst) = bswap_32(sample); goto PUT32_END;
  1532. -put32_1234_4329: as_u32(dst) = bswap_32(sample) ^ 0x80; goto PUT32_END;
  1533. -put32_1234_0123_20: as_u32(dst) = sx20(sample >> 12); goto PUT32_END;
  1534. -put32_1234_0923_20: as_u32(dst) = sx20((sample ^ 0x80000000) >> 12); goto PUT32_END;
  1535. -put32_1234_3210_20: as_u32(dst) = bswap_32(sx20(sample >> 12)); goto PUT32_END;
  1536. -put32_1234_3290_20: as_u32(dst) = bswap_32(sx20((sample ^ 0x80000000) >> 12)); goto PUT32_END;
  1537. -put32_1234_123: _put_triple(dst, sample >> 8); goto PUT32_END;
  1538. -put32_1234_923: _put_triple(dst, (sample ^ 0x80000000) >> 8); goto PUT32_END;
  1539. -put32_1234_321: _put_triple_s(dst, sample >> 8); goto PUT32_END;
  1540. -put32_1234_329: _put_triple_s(dst, (sample ^ 0x80000000) >> 8); goto PUT32_END;
  1541. -put32_1234_123_20: _put_triple(dst, sample >> 12); goto PUT32_END;
  1542. -put32_1234_923_20: _put_triple(dst, (sample ^ 0x80000000) >> 12); goto PUT32_END;
  1543. -put32_1234_321_20: _put_triple_s(dst, sample >> 12); goto PUT32_END;
  1544. -put32_1234_329_20: _put_triple_s(dst, (sample ^ 0x80000000) >> 12); goto PUT32_END;
  1545. -put32_1234_123_18: _put_triple(dst, sample >> 14); goto PUT32_END;
  1546. -put32_1234_923_18: _put_triple(dst, (sample ^ 0x80000000) >> 14); goto PUT32_END;
  1547. -put32_1234_321_18: _put_triple_s(dst, sample >> 14); goto PUT32_END;
  1548. -put32_1234_329_18: _put_triple_s(dst, (sample ^ 0x80000000) >> 14); goto PUT32_END;
  1549. + case 20: /* 32h -> 24h */ _put_triple(dst, sample >> 8); break;
  1550. + case 21: /* 32h ^> 24h */ _put_triple(dst, (sample ^ 0x80000000) >> 8); break;
  1551. + case 22: /* 32h -> 24s */ _put_triple_s(dst, sample >> 8); break;
  1552. + case 23: /* 32h ^> 24s */ _put_triple_s(dst, (sample ^ 0x80000000) >> 8); break;
  1553. + case 24: /* 32h -> 20h */ _put_triple(dst, sample >> 12); break;
  1554. + case 25: /* 32h ^> 20h */ _put_triple(dst, (sample ^ 0x80000000) >> 12); break;
  1555. + case 26: /* 32h -> 20s */ _put_triple_s(dst, sample >> 12); break;
  1556. + case 27: /* 32h ^> 20s */ _put_triple_s(dst, (sample ^ 0x80000000) >> 12); break;
  1557. + case 28: /* 32h -> 18h */ _put_triple(dst, sample >> 14); break;
  1558. + case 29: /* 32h ^> 18h */ _put_triple(dst, (sample ^ 0x80000000) >> 14); break;
  1559. + case 30: /* 32h -> 18s */ _put_triple_s(dst, sample >> 14); break;
  1560. + case 31: /* 32h ^> 18s */ _put_triple_s(dst, (sample ^ 0x80000000) >> 14); break;
  1561. + default: assert(0);
  1562. + }
  1563. }
  1564. -#endif
  1565. -
  1566. -#ifdef CONV24_END
  1567. -#undef GET32_END
  1568. -#undef PUT32_END
  1569. -#endif
  1570. -#ifdef PUT32F_LABELS
  1571. -/* type (0 = float, 1 = float64), endswap */
  1572. -static void *const put32float_labels[2 * 2] = {
  1573. - &&put32f_1234_1234F, /* 32h -> (float)h */
  1574. - &&put32f_1234_4321F, /* 32h -> (float)s */
  1575. - &&put32f_1234_1234D, /* 32h -> (float64)h */
  1576. - &&put32f_1234_4321D, /* 32h -> (float64)s */
  1577. -};
  1578. -#endif
  1579. +static inline void put32float(char *dst, int32_t sample, unsigned int idx)
  1580. +{
  1581. + snd_tmp_float_t tmp_float;
  1582. + snd_tmp_double_t tmp_double;
  1583. -#ifdef PUT32F_END
  1584. -put32f_1234_1234F: as_float(dst) = (float_t)((int32_t)sample) / (float_t)0x80000000UL; goto PUT32F_END;
  1585. -put32f_1234_4321F: tmp_float.f = (float_t)((int32_t)sample) / (float_t)0x80000000UL;
  1586. - as_u32(dst) = bswap_32(tmp_float.i); goto PUT32F_END;
  1587. -put32f_1234_1234D: as_double(dst) = (double_t)((int32_t)sample) / (double_t)0x80000000UL; goto PUT32F_END;
  1588. -put32f_1234_4321D: tmp_double.d = (double_t)((int32_t)sample) / (double_t)0x80000000UL;
  1589. - as_u64(dst) = bswap_64(tmp_double.l); goto PUT32F_END;
  1590. -#endif
  1591. + switch (idx) {
  1592. + case 0: /* 32h -> (float)h */
  1593. + as_float(dst) = (float_t)((int32_t)sample) / (float_t)0x80000000UL; break;
  1594. + case 1: /* 32h -> (float)s */
  1595. + tmp_float.f = (float_t)((int32_t)sample) / (float_t)0x80000000UL;
  1596. + as_u32(dst) = bswap_32(tmp_float.i); break;
  1597. + case 2: /* 32h -> (float64)h */
  1598. + as_double(dst) = (double_t)((int32_t)sample) / (double_t)0x80000000UL; break;
  1599. + case 3: /* 32h -> (float64)s */
  1600. + tmp_double.d = (double_t)((int32_t)sample) / (double_t)0x80000000UL;
  1601. + as_u64(dst) = bswap_64(tmp_double.l); break;
  1602. + default: assert(0);
  1603. + }
  1604. +}
  1605. -#ifdef GET32F_LABELS
  1606. -/* type (0 = float, 1 = float64), endswap */
  1607. -static void *const get32float_labels[2 * 2] = {
  1608. - &&get32f_1234F_1234, /* (float)h -> 32h */
  1609. - &&get32f_4321F_1234, /* (float)s -> 32h */
  1610. - &&get32f_1234D_1234, /* (float64)h -> 32h */
  1611. - &&get32f_4321D_1234, /* (float64)s -> 32h */
  1612. -};
  1613. -#endif
  1614. +static inline int32_t get32float(const char *src, unsigned int idx)
  1615. +{
  1616. + snd_tmp_float_t tmp_float;
  1617. + snd_tmp_double_t tmp_double;
  1618. -#ifdef GET32F_END
  1619. -get32f_1234F_1234: tmp_float.f = as_floatc(src);
  1620. - if (tmp_float.f >= 1.0)
  1621. - sample = 0x7fffffff;
  1622. - else if (tmp_float.f <= -1.0)
  1623. - sample = 0x80000000;
  1624. - else
  1625. - sample = (int32_t)(tmp_float.f * (float_t)0x80000000UL);
  1626. - goto GET32F_END;
  1627. -get32f_4321F_1234: tmp_float.i = bswap_32(as_u32c(src));
  1628. - if (tmp_float.f >= 1.0)
  1629. - sample = 0x7fffffff;
  1630. - else if (tmp_float.f <= -1.0)
  1631. - sample = 0x80000000;
  1632. - else
  1633. - sample = (int32_t)(tmp_float.f * (float_t)0x80000000UL);
  1634. - goto GET32F_END;
  1635. -get32f_1234D_1234: tmp_double.d = as_doublec(src);
  1636. - if (tmp_double.d >= 1.0)
  1637. - sample = 0x7fffffff;
  1638. - else if (tmp_double.d <= -1.0)
  1639. - sample = 0x80000000;
  1640. - else
  1641. - sample = (int32_t)(tmp_double.d * (double_t)0x80000000UL);
  1642. - goto GET32F_END;
  1643. -get32f_4321D_1234: tmp_double.l = bswap_64(as_u64c(src));
  1644. - if (tmp_double.d >= 1.0)
  1645. - sample = 0x7fffffff;
  1646. - else if (tmp_double.d <= -1.0)
  1647. - sample = 0x80000000;
  1648. - else
  1649. - sample = (int32_t)(tmp_double.d * (double_t)0x80000000UL);
  1650. - goto GET32F_END;
  1651. -#endif
  1652. + switch (idx) {
  1653. + case 0: /* (float)h -> 32h */
  1654. + tmp_float.f = as_floatc(src);
  1655. + if (tmp_float.f >= 1.0)
  1656. + return 0x7fffffff;
  1657. + if (tmp_float.f <= -1.0)
  1658. + return 0x80000000;
  1659. + return (int32_t)(tmp_float.f * (float_t)0x80000000UL);
  1660. + case 1: /* (float)s -> 32h */
  1661. + tmp_float.i = bswap_32(as_u32c(src));
  1662. + if (tmp_float.f >= 1.0)
  1663. + return 0x7fffffff;
  1664. + if (tmp_float.f <= -1.0)
  1665. + return 0x80000000;
  1666. + return (int32_t)(tmp_float.f * (float_t)0x80000000UL);
  1667. + case 2: /* (float64)h -> 32h */
  1668. + tmp_double.d = as_doublec(src);
  1669. + if (tmp_double.d >= 1.0)
  1670. + return 0x7fffffff;
  1671. + if (tmp_double.d <= -1.0)
  1672. + return 0x80000000;
  1673. + return (int32_t)(tmp_double.d * (double_t)0x80000000UL);
  1674. + case 3: /* (float64)s -> 32h */
  1675. + tmp_double.l = bswap_64(as_u64c(src));
  1676. + if (tmp_double.d >= 1.0)
  1677. + return 0x7fffffff;
  1678. + if (tmp_double.d <= -1.0)
  1679. + return 0x80000000;
  1680. + return (int32_t)(tmp_double.d * (double_t)0x80000000UL);
  1681. + default: assert(0);
  1682. + }
  1683. +}
  1684. #undef as_u8
  1685. #undef as_u16
  1686. --
  1687. 2.44.0