Mozzi
version v2.0
sound synthesis library for Arduino
mult32x16.h
1
2
/*
3
Norbert Pozar 2009
4
http://mekonik.wordpress.com/2009/03/18/arduino-avr-gcc-multiplication/
5
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
7
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
8
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
9
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
10
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11
*/
12
13
// multiplies a signed long X unsigned int
14
// stores the high 4 uint8_ts of the result
15
// rounds the number up if the MSB of the 2 low uint8_ts is set
16
// 47 cycles
17
#
define
MultiSU32X16toH32Round
(
longRes
,
longIn1
,
intIn2
)
asm
18
volatile
(
\
19
"clr r26 \n\t"\
20
\
21
\
22
"mul %A1, %A2 \n\t"\
23
"mov r27, r1 \n\t"\
24
\
25
"mul %B1, %B2 \n\t"\
26
"movw %A0, r0 \n\t"\
27
\
28
"mulsu %D1, %B2 \n\t"\
29
"movw %C0, r0 \n\t"\
30
\
31
"mulsu %D1, %A2 \n\t"\
32
"sbc %D0, r26 \n\t"\
33
"add %B0, r0 \n\t"\
34
"adc %C0, r1 \n\t"\
35
"adc %D0, r26 \n\t"\
36
\
37
\
38
"mul %B1, %A2 \n\t"\
39
"add r27, r0 \n\t"\
40
"adc %A0, r1 \n\t"\
41
"adc %B0, r26 \n\t"\
42
"adc %C0, r26 \n\t"\
43
"adc %D0, r26 \n\t"\
44
\
45
"mul %A1, %B2 \n\t"\
46
"add r27, r0 \n\t"\
47
"adc %A0, r1 \n\t"\
48
"adc %B0, r26 \n\t"\
49
"adc %C0, r26 \n\t"\
50
"adc %D0, r26 \n\t"\
51
\
52
"mul %C1, %A2 \n\t"\
53
"adc %A0, r0 \n\t"\
54
"adc %B0, r1 \n\t"\
55
"adc %C0, r26 \n\t"\
56
"adc %D0, r26 \n\t"\
57
\
58
"mul %C1, %B2 \n\t"\
59
"adc %B0, r0 \n\t"\
60
"adc %C0, r1 \n\t"\
61
"adc %D0, r26 \n\t"\
62
\
63
\
64
"lsl r27 \n\t"\
65
"adc %A0, r26 \n\t"\
66
"adc %B0, r26 \n\t"\
67
"adc %C0, r26 \n\t"\
68
"adc %D0, r26 \n\t"\
69
\
70
\
71
"clr r1 \n\t"
\
72
:
\
73
"=&r"
(
longRes
)
\
74
:
\
75
"a"
(
longIn1
)
,
\
76
"a"
(
intIn2
)
\
77
:
\
78
"r26"
,
"r27"
\
79
)
Generated automatically using Doxygen. If info on this page is outdated, incomplete, or wrong, please open an issue at https://github.com/sensorium/Mozzi/issues