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# The following comment until the empty line must be a valid YAML document 15# containing exact copies of ISA specification assertions relevant to this test. 16#--- 17# - title: Load from array 18# description: > 19# Load an element from array using accumulator as an index and puts it into accumulator. 20# instructions: 21# - sig: fldarr.32 vs 22# format: [op_vs_8] 23# type: obj 24# dtype: f32 25# etype: f32 26# properties: [acc_read, acc_write, float] 27# - title: Store to array 28# description: > 29# Store accumulator content into array slot pointed by index. 30# instructions: 31# - sig: fstarr.32 vs1, vs2 32# format: [op_vs1_4_vs2_4] 33# type: f32 34# dtype: none 35# etype: f32 36# properties: [acc_read, float] 37 38#assert that operations with array of f32 works fine 39#i32 i; 40#for(i=0; i<7; i++) array[i]=(float)i; 41#for(i=6; i>=0; i--) assert_eq((float)i, array[i]); 42 43.function i32 main(){ 44 movi v0, 7 45 newarr v1, v0, f32[] 46 movi v2, 0 47 ldai 0 48loop: 49 jeq v0, loop_exit 50 i32tof32 51 fstarr.32 v1, v2 52 inci v2, 1 53 lda v2 54 jmp loop 55loop_exit: 56 subi 1 57 sta v2 58loop2: 59 jltz loop2_exit 60 lda v2 61 i32tof32 62 sta v3 63 lda v2 64 fldarr.32 v1 65 fsub2 v3 66 sta v3 67 call.short abs, v3, v3 68 sta v3 69 fldai 1e-6 70 fcmpl v3 71 jlez exit_failure 72 inci v2, -1 73 lda v2 74 jmp loop2 75loop2_exit: 76 ldai 0 77 return 78exit_failure: 79 ldai 1 80 return 81} 82 83.function f32 abs(f32 a0){ 84 fldai 0.0 85 fcmpl a0 86 jlez label 87 lda a0 88 fneg 89 return 90label: 91 lda a0 92 return 93} 94 95