Commit 3f7440a6b771169e1f11fa582e53a4259b682809
1 parent
3218911f83
Exists in
master
and in
7 other branches
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>
Showing 5 changed files with 9 additions and 84 deletions Side-by-side Diff
include/sound/pcm.h
... | ... | @@ -486,80 +486,6 @@ |
486 | 486 | void snd_pcm_vma_notify_data(void *client, void *data); |
487 | 487 | int 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 | - | |
491 | -static 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 | - | |
499 | -static 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 | - | |
516 | -static 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 | - | |
545 | -static 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 | 490 | * PCM library |
565 | 491 | */ |
sound/core/oss/pcm_oss.c
... | ... | @@ -31,6 +31,7 @@ |
31 | 31 | #include <linux/time.h> |
32 | 32 | #include <linux/vmalloc.h> |
33 | 33 | #include <linux/moduleparam.h> |
34 | +#include <linux/math64.h> | |
34 | 35 | #include <linux/string.h> |
35 | 36 | #include <sound/core.h> |
36 | 37 | #include <sound/minors.h> |
... | ... | @@ -617,9 +618,7 @@ |
617 | 618 | #else |
618 | 619 | { |
619 | 620 | u64 bsize = (u64)runtime->oss.buffer_bytes * (u64)bytes; |
620 | - u32 rem; | |
621 | - div64_32(&bsize, buffer_size, &rem); | |
622 | - return (long)bsize; | |
621 | + return div_u64(bsize, buffer_size); | |
623 | 622 | } |
624 | 623 | #endif |
625 | 624 | } |
sound/core/pcm_lib.c
... | ... | @@ -22,6 +22,7 @@ |
22 | 22 | |
23 | 23 | #include <linux/slab.h> |
24 | 24 | #include <linux/time.h> |
25 | +#include <linux/math64.h> | |
25 | 26 | #include <sound/core.h> |
26 | 27 | #include <sound/control.h> |
27 | 28 | #include <sound/info.h> |
... | ... | @@ -452,7 +453,7 @@ |
452 | 453 | *r = 0; |
453 | 454 | return UINT_MAX; |
454 | 455 | } |
455 | - div64_32(&n, c, r); | |
456 | + n = div_u64_rem(n, c, r); | |
456 | 457 | if (n >= UINT_MAX) { |
457 | 458 | *r = 0; |
458 | 459 | return UINT_MAX; |
sound/pci/rme9652/hdsp.c
... | ... | @@ -28,6 +28,7 @@ |
28 | 28 | #include <linux/pci.h> |
29 | 29 | #include <linux/firmware.h> |
30 | 30 | #include <linux/moduleparam.h> |
31 | +#include <linux/math64.h> | |
31 | 32 | |
32 | 33 | #include <sound/core.h> |
33 | 34 | #include <sound/control.h> |
... | ... | @@ -1047,7 +1048,6 @@ |
1047 | 1048 | static void hdsp_set_dds_value(struct hdsp *hdsp, int rate) |
1048 | 1049 | { |
1049 | 1050 | u64 n; |
1050 | - u32 r; | |
1051 | 1051 | |
1052 | 1052 | if (rate >= 112000) |
1053 | 1053 | rate /= 4; |
... | ... | @@ -1055,7 +1055,7 @@ |
1055 | 1055 | rate /= 2; |
1056 | 1056 | |
1057 | 1057 | n = DDS_NUMERATOR; |
1058 | - div64_32(&n, rate, &r); | |
1058 | + n = div_u64(n, rate); | |
1059 | 1059 | /* n should be less than 2^32 for being written to FREQ register */ |
1060 | 1060 | snd_BUG_ON(n >> 32); |
1061 | 1061 | /* HDSP_freqReg and HDSP_resetPointer are the same, so keep the DDS |
... | ... | @@ -3097,7 +3097,6 @@ |
3097 | 3097 | static int hdsp_dds_offset(struct hdsp *hdsp) |
3098 | 3098 | { |
3099 | 3099 | u64 n; |
3100 | - u32 r; | |
3101 | 3100 | unsigned int dds_value = hdsp->dds_value; |
3102 | 3101 | int system_sample_rate = hdsp->system_sample_rate; |
3103 | 3102 | |
... | ... | @@ -3109,7 +3108,7 @@ |
3109 | 3108 | * dds_value = n / rate |
3110 | 3109 | * rate = n / dds_value |
3111 | 3110 | */ |
3112 | - div64_32(&n, dds_value, &r); | |
3111 | + n = div_u64(n, dds_value); | |
3113 | 3112 | if (system_sample_rate >= 112000) |
3114 | 3113 | n *= 4; |
3115 | 3114 | else if (system_sample_rate >= 56000) |
sound/pci/rme9652/hdspm.c
... | ... | @@ -29,6 +29,7 @@ |
29 | 29 | #include <linux/moduleparam.h> |
30 | 30 | #include <linux/slab.h> |
31 | 31 | #include <linux/pci.h> |
32 | +#include <linux/math64.h> | |
32 | 33 | #include <asm/io.h> |
33 | 34 | |
34 | 35 | #include <sound/core.h> |
... | ... | @@ -831,7 +832,6 @@ |
831 | 832 | static void hdspm_set_dds_value(struct hdspm *hdspm, int rate) |
832 | 833 | { |
833 | 834 | u64 n; |
834 | - u32 r; | |
835 | 835 | |
836 | 836 | if (rate >= 112000) |
837 | 837 | rate /= 4; |
... | ... | @@ -844,7 +844,7 @@ |
844 | 844 | */ |
845 | 845 | /* n = 104857600000000ULL; */ /* = 2^20 * 10^8 */ |
846 | 846 | n = 110100480000000ULL; /* Value checked for AES32 and MADI */ |
847 | - div64_32(&n, rate, &r); | |
847 | + n = div_u64(n, rate); | |
848 | 848 | /* n should be less than 2^32 for being written to FREQ register */ |
849 | 849 | snd_BUG_ON(n >> 32); |
850 | 850 | hdspm_write(hdspm, HDSPM_freqReg, (u32)n); |