# 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: fldai
    isa:
      title: Load accumulator from immediate
      description: >
        Load immediate into accumulator. For short formats immediate is sign extended to operand size.
      exceptions:
        - x_none
      verification:
        - none
    commands:
      - file-name: pos
        isa:
          instructions:
            - sig: fldai imm:f32
              acc: out:f32
              prefix: f32
              format: [pref_op_imm_32]
        check-type: no-check
        code-template: |
          #   test - check binary representation of FP literals - positive
              fldai %s
              fmovi v0, %s
              fcmpg v0
        description: Check fldai with various positive values (float and HEX literal).
        tags: ['tsan', 'irtoc_ignore']
        cases:
          - values:
              - '0.0'
              - '0x0'
          - values:
              - '0.1'
              - '0x3dcccccd'
          - values:
              - '1.0'
              - '0x3f800000'
          - values:
              - '12345678.90987654'
              - '0x4b3c614f'
          - values:
              - '3.141592653589793'
              - '0x40490fdb'
          - values:
              - '3.1415e3'
              - '0x45445800'
          - values:
              - '1.7976931e308'
              - '0x7f800000'
          - values:
              - '4.9e-324'
              - '0x0'
          - values:
              - '0x12345678'
              - '5.6904566e-28'
          - values:
              - '9223372036854775807'
              - '0x5f000000'
          - values:
              - '0.55'
              - '0x3f0ccccd'

      - file-name: neg
        isa:
          instructions:
            - sig: fldai imm:f32
              acc: out:f32
              prefix: f32
              format: [pref_op_imm_32]
        check-type: no-check
        tags: ['irtoc_ignore']
        code-template: |
          #   test - check binary representation of FP literals - negative
              fldai %s
              fmovi v0, %s
              fcmpg v0
        description: Check fldai with various negative values (float and HEX literal).
        cases:
          - values:
              - '-0'
              - '0x80000000'
          - values:
              - '-1'
              - '0xbf800000'
          - values:
              - '-0.0'
              - '0x80000000'
          - values:
              - '-0.1'
              - '0xbdcccccd'
          - values:
              - '-1.0'
              - '0xbf800000'
          - values:
              - '-12345678.90987654'
              - '0xcb3c614f'
          - values:
              - '-3.141592653589793'
              - '0xc0490fdb'
          - values:
              - '-1.4012985e-45'
              - '0x80000001'
          - values:
              - '-3.4028235e+38'
              - '0xff7fffff'
          - values:
              - '-0.55'
              - '0xbf0ccccd'

      - file-name: err
        isa:
          instructions:
            - sig: fldai imm:f32
              acc: out:f32
              prefix: f32
              format: [pref_op_imm_32]
        code-template: |
          #
              fldai %s
        check-type: none
        runner-options: [compile-failure]
        description: Check fldai with incorrect literal.
        cases:
          - values:
              - '1e'
          - values:
              - 'e1'
            ignore: true
            bugid: ['932']
          - values:
              - '-1e'
          - values:
              - '-e1'
            ignore: true
            bugid: ['932']
          - values:
              - '1e1e1'
          - values:
              - '-1e1e1'

      - file-name: range
        isa:
          instructions:
            - sig: fldai imm:f32
              acc: out:f32
              prefix: f32
              format: [pref_op_imm_32]
        check-type: no-check
        tags: ['irtoc_ignore']
        code-template: |
          #   test - check binary representation of FP literals - positive
              fldai %s
              fmovi v0, %s
              fcmpg v0
        description: Check fldai with out-of-range positive/negative values.
        cases:
          - values:
              - '+1.4e-45'
              - '0x00000001'
          - values:
              - '+1.4e-46'
              - '0x00000000'
          - values:
              - '-1.4e-45'
              - '0x80000001'
          - values:
              - '-1.4e-46'
              - '0x80000000'
          - values:
              - '3.4028235e38'
              - '0x7f7fffff'
            bugid: ['966', '965']
          - values:
              - '3.4028235e39'
              - '0x7f800000'
            bugid: ['966', '965']
          - values:
              - '-3.4028235e38'
              - '0xff7fffff'
            bugid: ['966', '965']
          - values:
              - '-3.4028235e39'
              - '0xff800000'
            bugid: ['966', '965']