# 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. --- definitions: [] tests: - file-name: modi isa: title: Two address integer division or modulo with immediate on accumulator description: > Perform two address integer division or modulo on accumulator and immediate and store result into accumulator. Immediate is sign extended to operand size. exceptions: - x_arith commands: - file-name: op_imm_8_zero isa: instructions: - sig: modi imm:i32 acc: inout:i32 format: [op_imm_8] code-template: | # ldai 0 modi %s movi v0, 0 jne v0, set_failure ldai 0 return set_failure: ldai 1 return check-type: none description: Check `modi` with zero and various values. cases: - values: ["1"] - values: ["-1"] - values: ["0xF"] - values: ["-0xF"] - values: ["0x7F"] - values: ["-0x7F"] - values: ["0x80"] - values: ["-0x80"] - values: ["0xFF"] - values: ["-0xFF"] - file-name: op_imm_8_pone isa: instructions: - sig: modi imm:i32 acc: inout:i32 format: [op_imm_8] code-template: | # ldai 1 modi %s movi v0, %s jne v0, set_failure ldai 0 return set_failure: ldai 1 return check-type: none description: Check `modi` with +1 and various values. cases: - values: ["1", "0x0"] - values: ["-1", "0x0"] - values: ["0xF", "0x1"] - values: ["-0xF", "0x1"] - values: ["0x7F", "0x1"] - values: ["-0x7F", "0x1"] - values: ["0x80", "0x1"] - values: ["-0x80", "0x1"] - values: ["0xFF", "0x0"] - values: ["-0xFF", "0x0"] - file-name: op_imm_8_none isa: instructions: - sig: modi imm:i32 acc: inout:i32 format: [op_imm_8] code-template: | # ldai -1 modi %s movi v0, %s jne v0, set_failure ldai 0 return set_failure: ldai 1 return check-type: none description: Check `modi` with -1 and various values. cases: - values: ["1", "0x0"] - values: ["-1", "0x0"] - values: ["0xF", "0xFFFFFFFF"] - values: ["-0xF", "0xFFFFFFFF"] - values: ["0x7F", "0xFFFFFFFF"] - values: ["-0x7F", "0xFFFFFFFF"] - values: ["0x80", "0xFFFFFFFF"] - values: ["-0x80", "0xFFFFFFFF"] - values: ["0xFF", "0x0"] - values: ["-0xFF", "0x0"] - file-name: op_imm_8_pmax isa: instructions: - sig: modi imm:i32 acc: inout:i32 format: [op_imm_8] code-template: | # ldai 0x7FFFFFFF modi %s movi v0, %s jne v0, set_failure ldai 0 return set_failure: ldai 1 return check-type: none description: Check `modi` with +max and various values. cases: - values: ["1", "0x0"] - values: ["-1", "0x0"] - values: ["0xF", "0x7"] - values: ["-0xF", "0x7"] - values: ["0x7F", "0x7"] - values: ["-0x7F", "0x7"] - values: ["0x80", "0x7F"] - values: ["-0x80", "0x7F"] - values: ["0xFF", "0x0"] - values: ["-0xFF", "0x0"] - file-name: op_imm_8_nmax isa: instructions: - sig: modi imm:i32 acc: inout:i32 format: [op_imm_8] code-template: | # ldai -0x80000000 modi %s movi v0, %s jne v0, set_failure ldai 0 return set_failure: ldai 1 return check-type: none description: Check `modi` with -max and various values. cases: - values: ["1", "0x0"] - values: ["-1", "0x0"] - values: ["0xF", "0xFFFFFFF8"] - values: ["-0xF", "0xFFFFFFF8"] - values: ["0x7F", "0xFFFFFFF8"] - values: ["-0x7F", "0xFFFFFFF8"] - values: ["0x80", "0x0"] - values: ["-0x80", "0x0"] - values: ["0xFF", "0x0"] - values: ["-0xFF", "0x0"] - file-name: op_imm_8_exception isa: instructions: - sig: modi imm:i32 acc: inout:i32 format: [op_imm_8] tags: ['irtoc_ignore'] header-template: [ArithmeticException, main] code-template: | # ldai %s begin: modi %s end: ldai 1 # Should not reach this line return catch_AE: ldai 0 # Expected panda.ArithmeticException return catch_all: ldai 1 # Unexpected exception, test failed return .catch panda.ArithmeticException, begin, end, catch_AE .catchall begin, end, catch_all check-type: none description: Check `modi` throws ArithmeticException when divides by zero. cases: - values: ["0", "0"] - values: ["1", "0"] - values: ["-1", "0"] - values: ["0x7FFFFFFF", "0"] - values: ["0x80000000", "0"] - values: ["-0x7FFFFFFF", "0"] - values: ["-0x80000000", "0"] - values: ["0xFFFFFFFF", "0"] - values: ["-0xFFFFFFFF", "0"] - file-name: vals isa: instructions: - sig: modi imm:i32 acc: inout:i32 format: [op_imm_8] code-template: | # ldai %s modi %s movi v0, %s jne v0, set_failure ldai 0 return set_failure: ldai 1 return check-type: none description: Check `modi` with various values. tags: ['tsan'] cases: - values: ["0xB7B95C3B", "0x46", "0xFFFFFFBD"] - values: ["0x916AF28B", "0x6C", "0xFFFFFFCB"] - values: ["0x3DF18885", "0x1F", "0xD"] - values: ["0x23C4316E", "0xCC", "0x1E"] - values: ["0x217C7378", "0x51", "0x3B"] - values: ["0x95022A5B", "0xE5", "0xFFFFFFF2"] - values: ["0x5C9E8AED", "0x04", "0x1"] - values: ["0xBED70106", "0xE7", "0xFFFFFFFC"] - values: ["0x4DE91F53", "0x03", "0x1"] - values: ["0x6D79C474", "0x67", "0x4A"] - values: ["0x80000000", "-1", "0"] - values: ["-2147483648", "-1", "0"] - file-name: type isa: verification: - acc_type tags: ['verifier'] runner-options: ['verifier-failure', 'verifier-config'] header-template: [] code-template: | # .record panda.Object .function i32 main() { %s modi 0 check-type: exit-positive description: Check 'modi' with incorrect accumulator type. cases: - values: [ldai.64 0] - values: [fldai 0] bugid: ['7315'] - values: [fldai.64 0] - values: [lda.null] - values: [lda.type panda.Object] - values: ['lda.type i32[]'] - values: [lda.str ""] - values: - | # newobj v0, panda.Object lda.obj v0 - values: - | # movi v0, 10 newarr v0, v0, i32[] lda.obj v0 - file-name: uninitialized_acc isa: instructions: - sig: modi imm:i32 acc: inout:i32 format: [op_imm_8] description: Check 'modi' with uninitialized accumulator. tags: ['verifier'] runner-options: ['verifier-failure', 'verifier-config'] code-template: | modi 1 check-type: exit-positive