1# Copyright (c) 2021-2024 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# Test if compilation succeeds when two different .rodata sections are emitted by llvm 15# 16# Some functions after optimizations will produce .rodata.cst16 sections 17# And some .rodata.cst8 18# 19# This test is two tests combined together. 20# * access-nsieve benchmark 21# * const-f64-03.pa 22.function u1 main0(){ 23 movi v0, 3 24 movi v1, 2000000 25 movi v2, 1854053 26 call test, v0, v1, v2, v0 27 return 28} 29 30.function u1 test(i32 a0, i32 a1, i32 a2){ 31 call.short sieve, a0, a1 32 jne a2, exit_failure 33 ldai 0 34 return 35exit_failure: 36 ldai 1 37 return 38} 39 40.function i32 sieve(i32 a0, i32 a1){ 41 movi v2, 0 #sum 42 movi v3, 1 #loop_counter 43 ldai 1 44loop: 45 jgt a0, loop_exit 46 ldai 1 47 shl2 v3 48 mul2 a1 49 addi 1 50 sta v4 #m+1 51 newarr v5, v4, u1[] #flags 52 inci v4, -1 53 call.short nsieve, v4, v5 54 add2 v2 55 sta v2 56 inci v3, 1 57 lda v3 58 jmp loop 59loop_exit: 60 lda v2 61 return 62} 63 64.function i32 nsieve(i32 a0, u1[] a1){ 65 call.short init, a1, a1 66 movi v2, 0 #count 67 movi v3, 2 #loop_counter 68 ldai 2 69loop: 70 jgt a0, loop_exit 71 ldarr.8 a1 72 jnez if 73endif: 74 inci v3, 1 75 lda v3 76 jmp loop 77loop_exit: 78 lda v2 79 return 80if: 81 lda v3 82 add2 v3 83 sta v4 #loop2_counter 84loop2: 85 jgt a0, loop2_exit 86 ldai 0 87 starr.8 a1, v4 88 lda v4 89 add2 v3 90 sta v4 91 jmp loop2 92loop2_exit: 93 inci v2, 1 94 lda v2 95 jmp endif 96} 97 98.function void init(u1[] a0){ 99 lenarr a0 100 sta v0 #sizeof(a0) 101 movi v1, 2 #loop_counter 102 ldai 2 103loop: 104 jeq v0, loop_exit 105 ldai 1 106 starr.8 a0, v1 107 inci v1, 1 108 lda v1 109 jmp loop 110loop_exit: 111 lda.obj a0 112 return.void 113} 114 115 116.function f64 getPi() { 117 fldai.64 3.1415926 118 return.64 119} 120 121.function f64 getOtherNumber() { 122 fldai.64 2.0405926 123 return.64 124} 125 126.function f64 getPiAndOtherNumberDifference() { 127 fldai.64 1.101 128 return.64 129} 130 131.function i32 main() { 132 call.short getOtherNumber 133 sta.64 v0 134 call.short getPi 135 fsub2.64 v0 136 sta.64 v0 137 call.short getPiAndOtherNumberDifference 138 fcmpl.64 v0 139 140 return 141} 142