1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2009 Tomer Shalev
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
25 inline static short muls16_asr10(short a
, short b
)
42 inline static long muls32_asr26(long a
, long b
)
46 /* Signed 32bit * 32bit -> 64bit multiplication.
47 Notation: xxab * xxcd, where each letter represents 16 bits.
48 xx is the 64 bit sign extension. */
49 "swap.w %[a],%[t1] \n" /* t1 = ba */
50 "mulu %[t1],%[b] \n" /* a * d */
51 "swap.w %[b],%[t3] \n" /* t3 = dc */
52 "sts macl,%[t2] \n" /* t2 = a * d */
53 "mulu %[t1],%[t3] \n" /* a * c */
54 "sts macl,%[r] \n" /* hi = a * c */
55 "mulu %[a],%[t3] \n" /* b * c */
57 "sts macl,%[t3] \n" /* t3 = b * c */
58 "addc %[t2],%[t3] \n" /* t3 += t2, carry -> t2 */
60 "mulu %[a],%[b] \n" /* b * d */
61 "mov %[t3],%[t1] \n" /* t1t3 = t2t3 << 16 */
62 "xtrct %[t2],%[t1] \n"
64 "sts macl,%[t2] \n" /* lo = b * d */
65 "clrt \n" /* hi.lo += t1t3 */
68 "cmp/pz %[a] \n" /* ab >= 0 ? */
70 "sub %[b],%[r] \n" /* no: hi -= cd (sign extension of ab is -1) */
72 "cmp/pz %[b] \n" /* cd >= 0 ? */
74 "sub %[a],%[r] \n" /* no: hi -= ab (sign extension of cd is -1) */
76 /* Shift right by 26 and return low 32 bits */
77 "shll2 %[r] \n" /* hi <<= 6 */
80 "shlr16 %[t2] \n" /* (unsigned)lo >>= 26 */
83 "or %[t2],%[r] \n" /* combine result */