# 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: 'fneg'
    isa:
      title: Floating-point unary
      description: >
        Perform specified floating-point operation on accumulator
      exceptions:
        - x_none

    commands:
      - file-name: 'op_none'
        isa:
          instructions:
            - sig: fneg
              acc: inout:f32
              prefix: f32
              format: [pref_op_none]
        code-template: |
          #
              fldai %s
              fneg
              fmovi v0, %s
              fcmpg v0
        description: Check fneg with various values.
        tags: ['tsan', 'irtoc_ignore']
        cases:
          - values:
              - '0.0'
              - '0.0'
          - values:
              - '-1.0'
              - '1.0'
          - values:
              - '1.0'
              - '-1.0'
          - values:
              - '3.1415926'
              - '-3.1415926'
          - values:
              - '-4.9e-30'
              - '+4.9e-30'
          - values:
              - '1.7976931e30'
              - '-1.7976931e30'
          - values:
              - '+4.9e-30'
              - '-4.9e-30'
          - values:
              - '-1.7976931e38'
              - '+1.7976931e38'

      - file-name: 'nan'
        isa:
          instructions:
            - sig: fneg
              acc: inout:f32
              prefix: f32
              format: [pref_op_none]
        tags: ['irtoc_ignore']
        check-type: check-acc-nan-f32
        code-template: |
          #
              fldai %s
              fneg
        description: Check fneg with NaN.
        cases:
          - values:
              # NaN
              - '0x7fc00000'
          - values:
              # NaN
              - '0xFFFFFFFF'

      - file-name: 'bin_val'
        isa:
          instructions:
            - sig: fneg
              acc: inout:f32
              prefix: f32
              format: [pref_op_none]
        tags: ['irtoc_ignore']
        code-template: |
          #
              fldai %s
              fneg
              fmovi v0, %s
              fcmpg v0
        description: Check fneg with various values (HEX literals).
        cases:
          - values:
              # -max
              - '0xff7fffff'
              # +max
              - '0x7f7fffff'
          - values:
              # +max
              - '0x7f7fffff'
              # -max
              - '0xff7fffff'
          - values:
              # -Inf
              - '0xff800000'
              # +Inf
              - '0x7f800000'
          - values:
              # +Inf
              - '0x7f800000'
              # -Inf
              - '0xff800000'
          - values:
              # +min
              - '0x00000001'
              # -min
              - '0x80000001'
          - values:
              # -min
              - '0x80000001'
              # +min
              - '0x00000001'
          - values:
              # -0.0d
              - '0x80000000'
              - '0'
          - values:
              - '0'
              # -0.0d
              - '0x80000000'

      - file-name: 'acc_type'
        isa:
          verification:
            - acc_type
        runner-options: ['verifier-failure', 'verifier-config']
        bugid: ['964']
        tags: ['verifier']
        header-template: []
        code-template: |
          .record T {}
          .record panda.String <external>
          .record panda.Object <external>
          #
          .function i32 main() {
              %s
              fneg
        check-type: exit-positive
        description: Check `fneg` with incorrect accumulator type.
        cases:
          - values:
              - ldai 1
          - values:
              - ldai.64 1
          - values:
              - fldai.64 0
          - values:
              - lda.type T
          - values:
              - lda.type T[]
          - values:
              - lda.type panda.Object
          - values:
              - lda.type panda.String
          - values:
              - lda.str "x"
          - values:
              - |
                #
                    newobj v0, T
                    lda.obj v0
          - values:
              - lda.null
          - values:
              - |
                #
                    movi v0, 10
                    newarr v0, v0, i32[]
                    lda.obj v0

      - file-name: uninitialized_regs
        bugid: ['2787']
        tags: ['verifier']
        isa:
          instructions:
            - sig: fneg
              acc: inout:f32
              prefix: f32
              format: [pref_op_none]
        description: Check fneg with uninitialized accumulator.
        runner-options: ['verifier-failure', 'verifier-config']
        header-template: []
        code-template: |
          #
          .function i32 main() {
              # acc is undefined
              fneg
        check-type: exit-positive