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, 20000 16 movi v1, 2560 17 movi v2, 204800000 18 call test, v0, v1, v2, v0 19 return 20} 21 22.function i32 test(i32 a0, i32 a1, i32 a2){ 23 movi v3, 0 #sum 24 movi v4, 0 #loop counter 25 ldai 0 26loop: 27 movi v5, 0 #loop2 counter 28 jeq a0, loop_exit 29 lda v5 30loop2: 31 jeq a1, loop2_exit 32 call.short fast3bitlookup, v5, v5 33 add2 v3 34 sta v3 35 inci v5, 1 36 lda v5 37 jmp loop2 38loop2_exit: 39 inci v4, 1 40 lda v4 41 jmp loop 42loop_exit: 43 lda v3 44 jne a2, assert_err 45 ldai 0 46 return 47assert_err: 48 ldai 1 49 return 50} 51 52.function i32 fast3bitlookup(i32 a0){ 53 movi v1, 0 #c 54 movi v2, 0xE994 #bi3b 55 lda a0 56 shli 1 57 andi 14 58 sta v3 59 shr v2, v3 60 andi 3 61 sta v1 62 lda a0 63 shri 2 64 andi 14 65 sta v3 66 shr v2, v3 67 andi 3 68 add2 v1 69 sta v1 70 lda a0 71 shri 5 72 andi 6 73 sta v3 74 shr v2, v3 75 andi 3 76 add2 v1 77 sta v1 78 lda v1 79 return 80} 81