1# Copyright (c) 2021-2022 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14.function u1 main(){ 15 movi v0, 2500000 16 fmovi.64 v1, 1036257.0468539958 17 call.short test, v0, v1 18 return 19} 20 21.function u1 test(i32 a0, f64 a1){ 22 movi v3, 12 23 newarr v0, v3, f64[] #Angles 24 call.short init, v0, v0 25 call.short cordic, a0, v0 26 sta.64 v2 #total 27 fsub2.64 a1 28 sta.64 v1 29 fldai.64 1e-13 30 fcmpl.64 v1 31 jltz exit_failure 32 ldai 0 33 return 34exit_failure: 35 ldai 1 36 return 37} 38 39.function f64 cordic(i32 a0, f64[] a1){ 40 fmovi.64 v1, 0.0 #total 41 movi v2, 0 #loop_counter 42 fmovi.64 v3, 28.027 #TARGET_ANGLE 43loop: 44 lda v2 45 jeq a0, loop_exit 46 call.short cordicsincos, v3, a1 47 fadd2.64 v1 48 sta.64 v1 49 inci v2, 1 50 jmp loop 51loop_exit: 52 lda.64 v1 53 return.64 54} 55 56.function f64 cordicsincos(f64 a0, f64[] a1){ 57 fmovi.64 v1, 0.0 #x 58 fmovi.64 v2, 0.0 #y 59 fmovi.64 v3, 0.0 #targetAngle 60 fmovi.64 v4, 0.0 #currAngle 61 movi.64 v5, 0 #step 62 fmovi.64 v6, 0.6072529350 #AG_CONST 63 movi v12, 12 64 call.short FIXED, v6, v1 #x 65 sta.64 v1 66 call.short FIXED, a0, a0 67 sta.64 v3 68 movi v8, 0 #step 69loop: 70 lda v8 71 jeq v12, loop_exit 72 lda.64 v3 73 fcmpl.64 v4 74 jgtz if 75 lda.64 v2 76 f64toi32 77 shr2 v8 78 i32tof64 79 fadd2.64 v1 80 sta.64 v10 #newX 81 lda.64 v1 82 f64toi32 83 shr2 v8 84 i32tof64 85 fneg.64 86 fadd2.64 v2 87 sta.64 v2 88 mov.64 v1, v10 89 lda.64 v8 90 fldarr.64 a1 91 fneg.64 92 fadd2.64 v4 93 sta.64 v4 94 inci v8, 1 95 jmp loop 96loop_exit: 97 call.short FLOAT, v1, v1 98 sta.64 v12 99 call.short FLOAT, v2, v1 100 sta.64 v13 101 fmul2.64 v12 102 return.64 103if: 104 lda.64 v2 105 f64toi32 106 shr2 v8 107 i32tof64 108 fneg.64 109 fadd2.64 v1 110 sta.64 v10 #newX 111 lda.64 v1 112 f64toi32 113 shr2 v8 114 i32tof64 115 fadd2.64 v2 116 sta.64 v2 117 mov.64 v1, v10 118 lda v8 119 fldarr.64 a1 120 fadd2.64 v4 121 sta.64 v4 122 inci v8, 1 123 lda v8 124 jmp loop 125} 126 127.function f64 FLOAT(f64 a0){ 128 fmovi.64 v1, 65536.0 129 lda.64 a0 130 fdiv2.64 v1 131 return.64 132} 133 134.function f64 FIXED(f64 a0){ 135 fldai.64 65536.0 136 fmul2.64 a0 137 return.64 138} 139 140.function void init(f64[] a0){ 141 movi.64 v2, 0 142 fmovi.64 v1, 45.0 143 call.short FIXED, v1, v1 144 fstarr.64 a0, v2 145 inci v2, 1 146 fmovi.64 v1, 26.565 147 call.short FIXED, v1, v1 148 fstarr.64 a0, v2 149 inci v2, 1 150 fmovi.64 v1, 14.0362 151 call.short FIXED, v1, v1 152 fstarr.64 a0, v2 153 inci v2, 1 154 fmovi.64 v1, 7.12502 155 call.short FIXED, v1, v1 156 fstarr.64 a0, v2 157 inci v2, 1 158 fmovi.64 v1, 3.57633 159 call.short FIXED, v1, v1 160 fstarr.64 a0, v2 161 inci v2, 1 162 fmovi.64 v1, 1.78991 163 call.short FIXED, v1, v1 164 fstarr.64 a0, v2 165 inci v2, 1 166 fmovi.64 v1, 0.895174 167 call.short FIXED, v1, v1 168 fstarr.64 a0, v2 169 inci v2, 1 170 fmovi.64 v1, 0.447614 171 call.short FIXED, v1, v1 172 fstarr.64 a0, v2 173 inci v2, 1 174 fmovi.64 v1, 0.223811 175 call.short FIXED, v1, v1 176 fstarr.64 a0, v2 177 inci v2, 1 178 fmovi.64 v1, 0.111906 179 call.short FIXED, v1, v1 180 fstarr.64 a0, v2 181 inci v2, 1 182 fmovi.64 v1, 0.055953 183 call.short FIXED, v1, v1 184 fstarr.64 a0, v2 185 inci v2, 1 186 fmovi.64 v1, 0.027977 187 call.short FIXED, v1, v1 188 fstarr.64 a0, v2 189 return.void 190} 191