summaryrefslogtreecommitdiff
path: root/apps/plugins/fractals/cpu_sh7043.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/fractals/cpu_sh7043.h')
-rw-r--r--apps/plugins/fractals/cpu_sh7043.h71
1 files changed, 69 insertions, 2 deletions
diff --git a/apps/plugins/fractals/cpu_sh7043.h b/apps/plugins/fractals/cpu_sh7043.h
index 4805092377..0d773432a8 100644
--- a/apps/plugins/fractals/cpu_sh7043.h
+++ b/apps/plugins/fractals/cpu_sh7043.h
@@ -22,8 +22,75 @@
22#ifndef _CPU_SH7043_H 22#ifndef _CPU_SH7043_H
23#define _CPU_SH7043_H 23#define _CPU_SH7043_H
24 24
25inline short muls16_asr10(short a, short b); 25inline static short muls16_asr10(short a, short b)
26{
27 short r;
28 asm (
29 "muls %[a],%[b] \n"
30 "sts macl,%[r] \n"
31 "shlr8 %[r] \n"
32 "shlr2 %[r] \n"
33 : /* outputs */
34 [r]"=r"(r)
35 : /* inputs */
36 [a]"r"(a),
37 [b]"r"(b)
38 );
39 return r;
40}
26 41
27inline long muls32_asr26(long a, long b); 42inline static long muls32_asr26(long a, long b)
43{
44 long r, t1, t2, t3;
45 asm (
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 */
56 "clrt \n"
57 "sts macl,%[t3] \n" /* t3 = b * c */
58 "addc %[t2],%[t3] \n" /* t3 += t2, carry -> t2 */
59 "movt %[t2] \n"
60 "mulu %[a],%[b] \n" /* b * d */
61 "mov %[t3],%[t1] \n" /* t1t3 = t2t3 << 16 */
62 "xtrct %[t2],%[t1] \n"
63 "shll16 %[t3] \n"
64 "sts macl,%[t2] \n" /* lo = b * d */
65 "clrt \n" /* hi.lo += t1t3 */
66 "addc %[t3],%[t2] \n"
67 "addc %[t1],%[r] \n"
68 "cmp/pz %[a] \n" /* ab >= 0 ? */
69 "bt 1f \n"
70 "sub %[b],%[r] \n" /* no: hi -= cd (sign extension of ab is -1) */
71 "1: \n"
72 "cmp/pz %[b] \n" /* cd >= 0 ? */
73 "bt 2f \n"
74 "sub %[a],%[r] \n" /* no: hi -= ab (sign extension of cd is -1) */
75 "2: \n"
76 /* Shift right by 26 and return low 32 bits */
77 "shll2 %[r] \n" /* hi <<= 6 */
78 "shll2 %[r] \n"
79 "shll2 %[r] \n"
80 "shlr16 %[t2] \n" /* (unsigned)lo >>= 26 */
81 "shlr8 %[t2] \n"
82 "shlr2 %[t2] \n"
83 "or %[t2],%[r] \n" /* combine result */
84 : /* outputs */
85 [r] "=&r"(r),
86 [t1]"=&r"(t1),
87 [t2]"=&r"(t2),
88 [t3]"=&r"(t3)
89 : /* inputs */
90 [a] "r" (a),
91 [b] "r" (b)
92 );
93 return r;
94}
28 95
29#endif 96#endif