1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24 #pragma once
25
26 static const char *
fpd_shift_prefix_32(int shift)27 fpd_shift_prefix_32(int shift)
28 {
29 switch (shift) {
30 case 32:
31 return "";
32 case 0:
33 return " ";
34 case -32:
35 return " 0.";
36 case -64:
37 return " 0.00000000 ";
38 default:
39 return "???";
40 }
41 }
42
43 static const char *
fpd_shift_prefix_64(int shift)44 fpd_shift_prefix_64(int shift)
45 {
46 switch (shift) {
47 case 32:
48 return "";
49 case 0:
50 return " ";
51 case -32:
52 return " ";
53 case -64:
54 return " 0.";
55 default:
56 return "???";
57 }
58 }
59
60 static const char *
fpd_shift_suffix(int shift)61 fpd_shift_suffix(int shift)
62 {
63 switch (shift) {
64 case 32:
65 return " 00000000 ";
66 case 0:
67 return " ";
68 case -32:
69 return " ";
70 case -64:
71 return "";
72 default:
73 return "???";
74 }
75 }
76
77 static void
debug_mul_u32_u32(uint32_t a,uint32_t b,int a_shift,int b_shift,uint64_t ret)78 debug_mul_u32_u32(uint32_t a, uint32_t b, int a_shift, int b_shift, uint64_t ret)
79 {
80 #if DEBUG_FIXED_POINT
81 TRACEF(" %s%08x%s * %s%08x%s = %s%08x%s%08x%s\n",
82 fpd_shift_prefix_32(a_shift), a, fpd_shift_suffix(a_shift),
83 fpd_shift_prefix_32(b_shift), b, fpd_shift_suffix(b_shift),
84 fpd_shift_prefix_64(a_shift + b_shift),
85 (uint32_t)(ret >> 32),
86 (a_shift + b_shift == -32) ? "." : " ",
87 (uint32_t)ret,
88 fpd_shift_suffix(a_shift + b_shift));
89 #endif
90 }
91
92 static void
debug_u64_mul_u32_fp32_64(uint32_t a,struct fp_32_64 b,uint64_t res_0,uint32_t res_l32_32,uint64_t ret)93 debug_u64_mul_u32_fp32_64(uint32_t a, struct fp_32_64 b, uint64_t res_0, uint32_t res_l32_32, uint64_t ret)
94 {
95 #if DEBUG_FIXED_POINT
96 TRACEF(" %08x * %08x.%08x %08x"
97 " = %08x %08x.%08x\n",
98 a, b.l0, b.l32, b.l64,
99 (uint32_t)(res_0 >> 32), (uint32_t)res_0, res_l32_32);
100 TRACEF(" "
101 " "
102 "~= %08x %08x\n",
103 (uint32_t)(ret >> 32), (uint32_t)ret);
104 #endif
105 }
106
107 static void
debug_u32_mul_u64_fp32_64(uint64_t a,struct fp_32_64 b,uint64_t res_l32,uint32_t ret)108 debug_u32_mul_u64_fp32_64(uint64_t a, struct fp_32_64 b, uint64_t res_l32, uint32_t ret)
109 {
110 #if DEBUG_FIXED_POINT
111 TRACEF("%08x %08x * %08x.%08x %08x"
112 " = %08x.%08x\n",
113 (uint32_t)(a >> 32), (uint32_t)a, b.l0, b.l32, b.l64,
114 (uint32_t)(res_l32 >> 32), (uint32_t)res_l32);
115 TRACEF(" "
116 " "
117 "~= %08x\n",
118 ret);
119 #endif
120 }
121
122 static void
debug_u64_mul_u64_fp32_64(uint64_t a,struct fp_32_64 b,uint64_t res_0,uint32_t res_l32_32,uint64_t ret)123 debug_u64_mul_u64_fp32_64(uint64_t a, struct fp_32_64 b, uint64_t res_0, uint32_t res_l32_32, uint64_t ret)
124 {
125 #if DEBUG_FIXED_POINT
126 TRACEF("%08x %08x * %08x.%08x %08x"
127 " = %08x %08x.%08x\n",
128 (uint32_t)(a >> 32), (uint32_t)a, b.l0, b.l32, b.l64,
129 (uint32_t)(res_0 >> 32), (uint32_t)res_0, res_l32_32);
130 TRACEF(" "
131 " "
132 "~= %08x %08x\n",
133 (uint32_t)(ret >> 32), (uint32_t)ret);
134 #endif
135 }
136
137