# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. .function u1 main(){ movi v0, 20000 movi v1, 2560 movi v2, 204800000 call test, v0, v1, v2, v0 return } .function i32 test(i32 a0, i32 a1, i32 a2){ movi v3, 0 #sum movi v4, 0 #loop counter ldai 0 loop: movi v5, 0 #loop2 counter jeq a0, loop_exit lda v5 loop2: jeq a1, loop2_exit call.short fast3bitlookup, v5, v5 add2 v3 sta v3 inci v5, 1 lda v5 jmp loop2 loop2_exit: inci v4, 1 lda v4 jmp loop loop_exit: lda v3 jne a2, assert_err ldai 0 return assert_err: ldai 1 return } .function i32 fast3bitlookup(i32 a0){ movi v1, 0 #c movi v2, 0xE994 #bi3b lda a0 shli 1 andi 14 sta v3 shr v2, v3 andi 3 sta v1 lda a0 shri 2 andi 14 sta v3 shr v2, v3 andi 3 add2 v1 sta v1 lda a0 shri 5 andi 6 sta v3 shr v2, v3 andi 3 add2 v1 sta v1 lda v1 return }