aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2009-06-05 11:40:04 -0400
committerTakashi Iwai <tiwai@suse.de>2009-06-05 11:45:17 -0400
commit3f7440a6b771169e1f11fa582e53a4259b682809 (patch)
tree4d91c07abf4269de4f681b821b594f5ad3d4f79a
parent3218911f839b6c85acbf872ad264ea69aa4d89ad (diff)
ALSA: Clean up 64bit division functions
Replace the house-made div64_32() with the standard div_u64*() functions. Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--include/sound/pcm.h74
-rw-r--r--sound/core/oss/pcm_oss.c5
-rw-r--r--sound/core/pcm_lib.c3
-rw-r--r--sound/pci/rme9652/hdsp.c7
-rw-r--r--sound/pci/rme9652/hdspm.c4
5 files changed, 9 insertions, 84 deletions
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index c17296891617..0caf71e16944 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -486,80 +486,6 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream);
486void snd_pcm_vma_notify_data(void *client, void *data); 486void snd_pcm_vma_notify_data(void *client, void *data);
487int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area); 487int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area);
488 488
489#if BITS_PER_LONG >= 64
490
491static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem)
492{
493 *rem = *n % div;
494 *n /= div;
495}
496
497#elif defined(i386)
498
499static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem)
500{
501 u_int32_t low, high;
502 low = *n & 0xffffffff;
503 high = *n >> 32;
504 if (high) {
505 u_int32_t high1 = high % div;
506 high /= div;
507 asm("divl %2":"=a" (low), "=d" (*rem):"rm" (div), "a" (low), "d" (high1));
508 *n = (u_int64_t)high << 32 | low;
509 } else {
510 *n = low / div;
511 *rem = low % div;
512 }
513}
514#else
515
516static inline void divl(u_int32_t high, u_int32_t low,
517 u_int32_t div,
518 u_int32_t *q, u_int32_t *r)
519{
520 u_int64_t n = (u_int64_t)high << 32 | low;
521 u_int64_t d = (u_int64_t)div << 31;
522 u_int32_t q1 = 0;
523 int c = 32;
524 while (n > 0xffffffffU) {
525 q1 <<= 1;
526 if (n >= d) {
527 n -= d;
528 q1 |= 1;
529 }
530 d >>= 1;
531 c--;
532 }
533 q1 <<= c;
534 if (n) {
535 low = n;
536 *q = q1 | (low / div);
537 *r = low % div;
538 } else {
539 *r = 0;
540 *q = q1;
541 }
542 return;
543}
544
545static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem)
546{
547 u_int32_t low, high;
548 low = *n & 0xffffffff;
549 high = *n >> 32;
550 if (high) {
551 u_int32_t high1 = high % div;
552 u_int32_t low1 = low;
553 high /= div;
554 divl(high1, low1, div, &low, rem);
555 *n = (u_int64_t)high << 32 | low;
556 } else {
557 *n = low / div;
558 *rem = low % div;
559 }
560}
561#endif
562
563/* 489/*
564 * PCM library 490 * PCM library
565 */ 491 */
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index dda000b9684c..dbe406b82591 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -31,6 +31,7 @@
31#include <linux/time.h> 31#include <linux/time.h>
32#include <linux/vmalloc.h> 32#include <linux/vmalloc.h>
33#include <linux/moduleparam.h> 33#include <linux/moduleparam.h>
34#include <linux/math64.h>
34#include <linux/string.h> 35#include <linux/string.h>
35#include <sound/core.h> 36#include <sound/core.h>
36#include <sound/minors.h> 37#include <sound/minors.h>
@@ -617,9 +618,7 @@ static long snd_pcm_oss_bytes(struct snd_pcm_substream *substream, long frames)
617#else 618#else
618 { 619 {
619 u64 bsize = (u64)runtime->oss.buffer_bytes * (u64)bytes; 620 u64 bsize = (u64)runtime->oss.buffer_bytes * (u64)bytes;
620 u32 rem; 621 return div_u64(bsize, buffer_size);
621 div64_32(&bsize, buffer_size, &rem);
622 return (long)bsize;
623 } 622 }
624#endif 623#endif
625} 624}
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index d659995ac3ac..a7482874c451 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -22,6 +22,7 @@
22 22
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/time.h> 24#include <linux/time.h>
25#include <linux/math64.h>
25#include <sound/core.h> 26#include <sound/core.h>
26#include <sound/control.h> 27#include <sound/control.h>
27#include <sound/info.h> 28#include <sound/info.h>
@@ -452,7 +453,7 @@ static inline unsigned int muldiv32(unsigned int a, unsigned int b,
452 *r = 0; 453 *r = 0;
453 return UINT_MAX; 454 return UINT_MAX;
454 } 455 }
455 div64_32(&n, c, r); 456 n = div_u64_rem(n, c, r);
456 if (n >= UINT_MAX) { 457 if (n >= UINT_MAX) {
457 *r = 0; 458 *r = 0;
458 return UINT_MAX; 459 return UINT_MAX;
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 314e73531bd1..bcfdbb5ebc40 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -28,6 +28,7 @@
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/firmware.h> 29#include <linux/firmware.h>
30#include <linux/moduleparam.h> 30#include <linux/moduleparam.h>
31#include <linux/math64.h>
31 32
32#include <sound/core.h> 33#include <sound/core.h>
33#include <sound/control.h> 34#include <sound/control.h>
@@ -1047,7 +1048,6 @@ static int hdsp_set_interrupt_interval(struct hdsp *s, unsigned int frames)
1047static void hdsp_set_dds_value(struct hdsp *hdsp, int rate) 1048static void hdsp_set_dds_value(struct hdsp *hdsp, int rate)
1048{ 1049{
1049 u64 n; 1050 u64 n;
1050 u32 r;
1051 1051
1052 if (rate >= 112000) 1052 if (rate >= 112000)
1053 rate /= 4; 1053 rate /= 4;
@@ -1055,7 +1055,7 @@ static void hdsp_set_dds_value(struct hdsp *hdsp, int rate)
1055 rate /= 2; 1055 rate /= 2;
1056 1056
1057 n = DDS_NUMERATOR; 1057 n = DDS_NUMERATOR;
1058 div64_32(&n, rate, &r); 1058 n = div_u64(n, rate);
1059 /* n should be less than 2^32 for being written to FREQ register */ 1059 /* n should be less than 2^32 for being written to FREQ register */
1060 snd_BUG_ON(n >> 32); 1060 snd_BUG_ON(n >> 32);
1061 /* HDSP_freqReg and HDSP_resetPointer are the same, so keep the DDS 1061 /* HDSP_freqReg and HDSP_resetPointer are the same, so keep the DDS
@@ -3097,7 +3097,6 @@ static int snd_hdsp_get_adat_sync_check(struct snd_kcontrol *kcontrol, struct sn
3097static int hdsp_dds_offset(struct hdsp *hdsp) 3097static int hdsp_dds_offset(struct hdsp *hdsp)
3098{ 3098{
3099 u64 n; 3099 u64 n;
3100 u32 r;
3101 unsigned int dds_value = hdsp->dds_value; 3100 unsigned int dds_value = hdsp->dds_value;
3102 int system_sample_rate = hdsp->system_sample_rate; 3101 int system_sample_rate = hdsp->system_sample_rate;
3103 3102
@@ -3109,7 +3108,7 @@ static int hdsp_dds_offset(struct hdsp *hdsp)
3109 * dds_value = n / rate 3108 * dds_value = n / rate
3110 * rate = n / dds_value 3109 * rate = n / dds_value
3111 */ 3110 */
3112 div64_32(&n, dds_value, &r); 3111 n = div_u64(n, dds_value);
3113 if (system_sample_rate >= 112000) 3112 if (system_sample_rate >= 112000)
3114 n *= 4; 3113 n *= 4;
3115 else if (system_sample_rate >= 56000) 3114 else if (system_sample_rate >= 56000)
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index bac2dc0c5d85..0dce331a2a3b 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -29,6 +29,7 @@
29#include <linux/moduleparam.h> 29#include <linux/moduleparam.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/pci.h> 31#include <linux/pci.h>
32#include <linux/math64.h>
32#include <asm/io.h> 33#include <asm/io.h>
33 34
34#include <sound/core.h> 35#include <sound/core.h>
@@ -831,7 +832,6 @@ static int hdspm_set_interrupt_interval(struct hdspm * s, unsigned int frames)
831static void hdspm_set_dds_value(struct hdspm *hdspm, int rate) 832static void hdspm_set_dds_value(struct hdspm *hdspm, int rate)
832{ 833{
833 u64 n; 834 u64 n;
834 u32 r;
835 835
836 if (rate >= 112000) 836 if (rate >= 112000)
837 rate /= 4; 837 rate /= 4;
@@ -844,7 +844,7 @@ static void hdspm_set_dds_value(struct hdspm *hdspm, int rate)
844 */ 844 */
845 /* n = 104857600000000ULL; */ /* = 2^20 * 10^8 */ 845 /* n = 104857600000000ULL; */ /* = 2^20 * 10^8 */
846 n = 110100480000000ULL; /* Value checked for AES32 and MADI */ 846 n = 110100480000000ULL; /* Value checked for AES32 and MADI */
847 div64_32(&n, rate, &r); 847 n = div_u64(n, rate);
848 /* n should be less than 2^32 for being written to FREQ register */ 848 /* n should be less than 2^32 for being written to FREQ register */
849 snd_BUG_ON(n >> 32); 849 snd_BUG_ON(n >> 32);
850 hdspm_write(hdspm, HDSPM_freqReg, (u32)n); 850 hdspm_write(hdspm, HDSPM_freqReg, (u32)n);