github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/integration_test/spectest/v1/testdata/select.wast (about)

     1  (module
     2  
     3    (memory 1)
     4  
     5    (func $dummy)
     6  
     7    (func (export "select_i32") (param $lhs i32) (param $rhs i32) (param $cond i32) (result i32)
     8     (select (local.get $lhs) (local.get $rhs) (local.get $cond)))
     9  
    10    (func (export "select_i64") (param $lhs i64) (param $rhs i64) (param $cond i32) (result i64)
    11     (select (local.get $lhs) (local.get $rhs) (local.get $cond)))
    12  
    13    (func (export "select_f32") (param $lhs f32) (param $rhs f32) (param $cond i32) (result f32)
    14     (select (local.get $lhs) (local.get $rhs) (local.get $cond)))
    15  
    16    (func (export "select_f64") (param $lhs f64) (param $rhs f64) (param $cond i32) (result f64)
    17     (select (local.get $lhs) (local.get $rhs) (local.get $cond)))
    18  
    19    ;; Check that both sides of the select are evaluated
    20    (func (export "select_trap_l") (param $cond i32) (result i32)
    21      (select (unreachable) (i32.const 0) (local.get $cond))
    22    )
    23    (func (export "select_trap_r") (param $cond i32) (result i32)
    24      (select (i32.const 0) (unreachable) (local.get $cond))
    25    )
    26  
    27    (func (export "select_unreached")
    28      (unreachable) (select)
    29      (unreachable) (i32.const 0) (select)
    30      (unreachable) (i32.const 0) (i32.const 0) (select)
    31      (unreachable) (f32.const 0) (i32.const 0) (select)
    32      (unreachable)
    33    )
    34  
    35    ;; As the argument of control constructs and instructions
    36  
    37    (func (export "as-select-first") (param i32) (result i32)
    38      (select (select (i32.const 0) (i32.const 1) (local.get 0)) (i32.const 2) (i32.const 3))
    39    )
    40    (func (export "as-select-mid") (param i32) (result i32)
    41      (select (i32.const 2) (select (i32.const 0) (i32.const 1) (local.get 0)) (i32.const 3))
    42    )
    43    (func (export "as-select-last") (param i32) (result i32)
    44      (select (i32.const 2) (i32.const 3) (select (i32.const 0) (i32.const 1) (local.get 0)))
    45    )
    46  
    47    (func (export "as-loop-first") (param i32) (result i32)
    48      (loop (result i32) (select (i32.const 2) (i32.const 3) (local.get 0)) (call $dummy) (call $dummy))
    49    )
    50    (func (export "as-loop-mid") (param i32) (result i32)
    51      (loop (result i32) (call $dummy) (select (i32.const 2) (i32.const 3) (local.get 0)) (call $dummy))
    52    )
    53    (func (export "as-loop-last") (param i32) (result i32)
    54      (loop (result i32) (call $dummy) (call $dummy) (select (i32.const 2) (i32.const 3) (local.get 0)))
    55    )
    56  
    57    (func (export "as-if-condition") (param i32)
    58      (select (i32.const 2) (i32.const 3) (local.get 0)) (if (then (call $dummy)))
    59    )
    60    (func (export "as-if-then") (param i32) (result i32)
    61      (if (result i32) (i32.const 1) (then (select (i32.const 2) (i32.const 3) (local.get 0))) (else (i32.const 4)))
    62    )
    63    (func (export "as-if-else") (param i32) (result i32)
    64      (if (result i32) (i32.const 0) (then (i32.const 2)) (else (select (i32.const 2) (i32.const 3) (local.get 0))))
    65    )
    66  
    67    (func (export "as-br_if-first") (param i32) (result i32)
    68      (block (result i32) (br_if 0 (select (i32.const 2) (i32.const 3) (local.get 0)) (i32.const 4)))
    69    )
    70    (func (export "as-br_if-last") (param i32) (result i32)
    71      (block (result i32) (br_if 0 (i32.const 2) (select (i32.const 2) (i32.const 3) (local.get 0))))
    72    )
    73  
    74    (func (export "as-br_table-first") (param i32) (result i32)
    75      (block (result i32) (select (i32.const 2) (i32.const 3) (local.get 0)) (i32.const 2) (br_table 0 0))
    76    )
    77    (func (export "as-br_table-last") (param i32) (result i32)
    78      (block (result i32) (i32.const 2) (select (i32.const 2) (i32.const 3) (local.get 0)) (br_table 0 0))
    79    )
    80  
    81    (func $func (param i32 i32) (result i32) (local.get 0))
    82    (type $check (func (param i32 i32) (result i32)))
    83    (table funcref (elem $func))
    84    (func (export "as-call_indirect-first") (param i32) (result i32)
    85      (block (result i32)
    86        (call_indirect (type $check)
    87          (select (i32.const 2) (i32.const 3) (local.get 0)) (i32.const 1) (i32.const 0)
    88        )
    89      )
    90    )
    91    (func (export "as-call_indirect-mid") (param i32) (result i32)
    92      (block (result i32)
    93        (call_indirect (type $check)
    94          (i32.const 1) (select (i32.const 2) (i32.const 3) (local.get 0)) (i32.const 0)
    95        )
    96      )
    97    )
    98    (func (export "as-call_indirect-last") (param i32) (result i32)
    99      (block (result i32)
   100        (call_indirect (type $check)
   101          (i32.const 1) (i32.const 4) (select (i32.const 2) (i32.const 3) (local.get 0))
   102        )
   103      )
   104    )
   105  
   106    (func (export "as-store-first") (param i32)
   107      (select (i32.const 0) (i32.const 4) (local.get 0)) (i32.const 1) (i32.store)
   108    )
   109    (func (export "as-store-last") (param i32)
   110      (i32.const 8) (select (i32.const 1) (i32.const 2) (local.get 0)) (i32.store)
   111    )
   112  
   113    (func (export "as-memory.grow-value") (param i32) (result i32)
   114      (memory.grow (select (i32.const 1) (i32.const 2) (local.get 0)))
   115    )
   116  
   117    (func $f (param i32) (result i32) (local.get 0))
   118  
   119    (func (export "as-call-value") (param i32) (result i32)
   120      (call $f (select (i32.const 1) (i32.const 2) (local.get 0)))
   121    )
   122    (func (export "as-return-value") (param i32) (result i32)
   123      (select (i32.const 1) (i32.const 2) (local.get 0)) (return)
   124    )
   125    (func (export "as-drop-operand") (param i32)
   126      (drop (select (i32.const 1) (i32.const 2) (local.get 0)))
   127    )
   128    (func (export "as-br-value") (param i32) (result i32)
   129      (block (result i32) (br 0 (select (i32.const 1) (i32.const 2) (local.get 0))))
   130    )
   131    (func (export "as-local.set-value") (param i32) (result i32)
   132      (local i32) (local.set 0 (select (i32.const 1) (i32.const 2) (local.get 0))) (local.get 0)
   133    )
   134    (func (export "as-local.tee-value") (param i32) (result i32)
   135      (local.tee 0 (select (i32.const 1) (i32.const 2) (local.get 0)))
   136    )
   137    (global $a (mut i32) (i32.const 10))
   138    (func (export "as-global.set-value") (param i32) (result i32)
   139      (global.set $a (select (i32.const 1) (i32.const 2) (local.get 0)))
   140      (global.get $a)
   141    )
   142    (func (export "as-load-operand") (param i32) (result i32)
   143      (i32.load (select (i32.const 0) (i32.const 4) (local.get 0)))
   144    )
   145  
   146    (func (export "as-unary-operand") (param i32) (result i32)
   147      (i32.eqz (select (i32.const 0) (i32.const 1) (local.get 0)))
   148    )
   149    (func (export "as-binary-operand") (param i32) (result i32)
   150      (i32.mul
   151        (select (i32.const 1) (i32.const 2) (local.get 0))
   152        (select (i32.const 1) (i32.const 2) (local.get 0))
   153      )
   154    )
   155    (func (export "as-test-operand") (param i32) (result i32)
   156      (block (result i32)
   157        (i32.eqz (select (i32.const 0) (i32.const 1) (local.get 0)))
   158      )
   159    )
   160  
   161    (func (export "as-compare-left") (param i32) (result i32)
   162      (block (result i32)
   163        (i32.le_s (select (i32.const 1) (i32.const 2) (local.get 0)) (i32.const 1))
   164      )
   165    )
   166    (func (export "as-compare-right") (param i32) (result i32)
   167      (block (result i32)
   168        (i32.ne (i32.const 1) (select (i32.const 0) (i32.const 1) (local.get 0)))
   169      )
   170    )
   171  
   172    (func (export "as-convert-operand") (param i32) (result i32)
   173      (block (result i32)
   174        (i32.wrap_i64 (select (i64.const 1) (i64.const 0) (local.get 0)))
   175      )
   176    )
   177  
   178  )
   179  
   180  (assert_return (invoke "select_i32" (i32.const 1) (i32.const 2) (i32.const 1)) (i32.const 1))
   181  (assert_return (invoke "select_i64" (i64.const 2) (i64.const 1) (i32.const 1)) (i64.const 2))
   182  (assert_return (invoke "select_f32" (f32.const 1) (f32.const 2) (i32.const 1)) (f32.const 1))
   183  (assert_return (invoke "select_f64" (f64.const 1) (f64.const 2) (i32.const 1)) (f64.const 1))
   184  
   185  (assert_return (invoke "select_i32" (i32.const 1) (i32.const 2) (i32.const 0)) (i32.const 2))
   186  (assert_return (invoke "select_i32" (i32.const 2) (i32.const 1) (i32.const 0)) (i32.const 1))
   187  (assert_return (invoke "select_i64" (i64.const 2) (i64.const 1) (i32.const -1)) (i64.const 2))
   188  (assert_return (invoke "select_i64" (i64.const 2) (i64.const 1) (i32.const 0xf0f0f0f0)) (i64.const 2))
   189  
   190  (assert_return (invoke "select_f32" (f32.const nan) (f32.const 1) (i32.const 1)) (f32.const nan))
   191  (assert_return (invoke "select_f32" (f32.const nan:0x20304) (f32.const 1) (i32.const 1)) (f32.const nan:0x20304))
   192  (assert_return (invoke "select_f32" (f32.const nan) (f32.const 1) (i32.const 0)) (f32.const 1))
   193  (assert_return (invoke "select_f32" (f32.const nan:0x20304) (f32.const 1) (i32.const 0)) (f32.const 1))
   194  (assert_return (invoke "select_f32" (f32.const 2) (f32.const nan) (i32.const 1)) (f32.const 2))
   195  (assert_return (invoke "select_f32" (f32.const 2) (f32.const nan:0x20304) (i32.const 1)) (f32.const 2))
   196  (assert_return (invoke "select_f32" (f32.const 2) (f32.const nan) (i32.const 0)) (f32.const nan))
   197  (assert_return (invoke "select_f32" (f32.const 2) (f32.const nan:0x20304) (i32.const 0)) (f32.const nan:0x20304))
   198  
   199  (assert_return (invoke "select_f64" (f64.const nan) (f64.const 1) (i32.const 1)) (f64.const nan))
   200  (assert_return (invoke "select_f64" (f64.const nan:0x20304) (f64.const 1) (i32.const 1)) (f64.const nan:0x20304))
   201  (assert_return (invoke "select_f64" (f64.const nan) (f64.const 1) (i32.const 0)) (f64.const 1))
   202  (assert_return (invoke "select_f64" (f64.const nan:0x20304) (f64.const 1) (i32.const 0)) (f64.const 1))
   203  (assert_return (invoke "select_f64" (f64.const 2) (f64.const nan) (i32.const 1)) (f64.const 2))
   204  (assert_return (invoke "select_f64" (f64.const 2) (f64.const nan:0x20304) (i32.const 1)) (f64.const 2))
   205  (assert_return (invoke "select_f64" (f64.const 2) (f64.const nan) (i32.const 0)) (f64.const nan))
   206  (assert_return (invoke "select_f64" (f64.const 2) (f64.const nan:0x20304) (i32.const 0)) (f64.const nan:0x20304))
   207  
   208  (assert_trap (invoke "select_trap_l" (i32.const 1)) "unreachable")
   209  (assert_trap (invoke "select_trap_l" (i32.const 0)) "unreachable")
   210  (assert_trap (invoke "select_trap_r" (i32.const 1)) "unreachable")
   211  (assert_trap (invoke "select_trap_r" (i32.const 0)) "unreachable")
   212  
   213  (assert_return (invoke "as-select-first" (i32.const 0)) (i32.const 1))
   214  (assert_return (invoke "as-select-first" (i32.const 1)) (i32.const 0))
   215  (assert_return (invoke "as-select-mid" (i32.const 0)) (i32.const 2))
   216  (assert_return (invoke "as-select-mid" (i32.const 1)) (i32.const 2))
   217  (assert_return (invoke "as-select-last" (i32.const 0)) (i32.const 2))
   218  (assert_return (invoke "as-select-last" (i32.const 1)) (i32.const 3))
   219  
   220  (assert_return (invoke "as-loop-first" (i32.const 0)) (i32.const 3))
   221  (assert_return (invoke "as-loop-first" (i32.const 1)) (i32.const 2))
   222  (assert_return (invoke "as-loop-mid" (i32.const 0)) (i32.const 3))
   223  (assert_return (invoke "as-loop-mid" (i32.const 1)) (i32.const 2))
   224  (assert_return (invoke "as-loop-last" (i32.const 0)) (i32.const 3))
   225  (assert_return (invoke "as-loop-last" (i32.const 1)) (i32.const 2))
   226  
   227  (assert_return (invoke "as-if-condition" (i32.const 0)))
   228  (assert_return (invoke "as-if-condition" (i32.const 1)))
   229  (assert_return (invoke "as-if-then" (i32.const 0)) (i32.const 3))
   230  (assert_return (invoke "as-if-then" (i32.const 1)) (i32.const 2))
   231  (assert_return (invoke "as-if-else" (i32.const 0)) (i32.const 3))
   232  (assert_return (invoke "as-if-else" (i32.const 1)) (i32.const 2))
   233  
   234  (assert_return (invoke "as-br_if-first" (i32.const 0)) (i32.const 3))
   235  (assert_return (invoke "as-br_if-first" (i32.const 1)) (i32.const 2))
   236  (assert_return (invoke "as-br_if-last" (i32.const 0)) (i32.const 2))
   237  (assert_return (invoke "as-br_if-last" (i32.const 1)) (i32.const 2))
   238  
   239  (assert_return (invoke "as-br_table-first" (i32.const 0)) (i32.const 3))
   240  (assert_return (invoke "as-br_table-first" (i32.const 1)) (i32.const 2))
   241  (assert_return (invoke "as-br_table-last" (i32.const 0)) (i32.const 2))
   242  (assert_return (invoke "as-br_table-last" (i32.const 1)) (i32.const 2))
   243  
   244  (assert_return (invoke "as-call_indirect-first" (i32.const 0)) (i32.const 3))
   245  (assert_return (invoke "as-call_indirect-first" (i32.const 1)) (i32.const 2))
   246  (assert_return (invoke "as-call_indirect-mid" (i32.const 0)) (i32.const 1))
   247  (assert_return (invoke "as-call_indirect-mid" (i32.const 1)) (i32.const 1))
   248  (assert_trap (invoke "as-call_indirect-last" (i32.const 0)) "undefined element")
   249  (assert_trap (invoke "as-call_indirect-last" (i32.const 1)) "undefined element")
   250  
   251  (assert_return (invoke "as-store-first" (i32.const 0)))
   252  (assert_return (invoke "as-store-first" (i32.const 1)))
   253  (assert_return (invoke "as-store-last" (i32.const 0)))
   254  (assert_return (invoke "as-store-last" (i32.const 1)))
   255  
   256  (assert_return (invoke "as-memory.grow-value" (i32.const 0)) (i32.const 1))
   257  (assert_return (invoke "as-memory.grow-value" (i32.const 1)) (i32.const 3))
   258  
   259  (assert_return (invoke "as-call-value" (i32.const 0)) (i32.const 2))
   260  (assert_return (invoke "as-call-value" (i32.const 1)) (i32.const 1))
   261  (assert_return (invoke "as-return-value" (i32.const 0)) (i32.const 2))
   262  (assert_return (invoke "as-return-value" (i32.const 1)) (i32.const 1))
   263  (assert_return (invoke "as-drop-operand" (i32.const 0)))
   264  (assert_return (invoke "as-drop-operand" (i32.const 1)))
   265  (assert_return (invoke "as-br-value" (i32.const 0)) (i32.const 2))
   266  (assert_return (invoke "as-br-value" (i32.const 1)) (i32.const 1))
   267  (assert_return (invoke "as-local.set-value" (i32.const 0)) (i32.const 2))
   268  (assert_return (invoke "as-local.set-value" (i32.const 1)) (i32.const 1))
   269  (assert_return (invoke "as-local.tee-value" (i32.const 0)) (i32.const 2))
   270  (assert_return (invoke "as-local.tee-value" (i32.const 1)) (i32.const 1))
   271  (assert_return (invoke "as-global.set-value" (i32.const 0)) (i32.const 2))
   272  (assert_return (invoke "as-global.set-value" (i32.const 1)) (i32.const 1))
   273  (assert_return (invoke "as-load-operand" (i32.const 0)) (i32.const 1))
   274  (assert_return (invoke "as-load-operand" (i32.const 1)) (i32.const 1))
   275  
   276  (assert_return (invoke "as-unary-operand" (i32.const 0)) (i32.const 0))
   277  (assert_return (invoke "as-unary-operand" (i32.const 1)) (i32.const 1))
   278  (assert_return (invoke "as-binary-operand" (i32.const 0)) (i32.const 4))
   279  (assert_return (invoke "as-binary-operand" (i32.const 1)) (i32.const 1))
   280  (assert_return (invoke "as-test-operand" (i32.const 0)) (i32.const 0))
   281  (assert_return (invoke "as-test-operand" (i32.const 1)) (i32.const 1))
   282  (assert_return (invoke "as-compare-left" (i32.const 0)) (i32.const 0))
   283  (assert_return (invoke "as-compare-left" (i32.const 1)) (i32.const 1))
   284  (assert_return (invoke "as-compare-right" (i32.const 0)) (i32.const 0))
   285  (assert_return (invoke "as-compare-right" (i32.const 1)) (i32.const 1))
   286  (assert_return (invoke "as-convert-operand" (i32.const 0)) (i32.const 0))
   287  (assert_return (invoke "as-convert-operand" (i32.const 1)) (i32.const 1))
   288  
   289  (assert_invalid
   290    (module (func $arity-0 (select (nop) (nop) (i32.const 1))))
   291    "type mismatch"
   292  )
   293  
   294  ;; The first two operands should have the same type as each other
   295  
   296  (assert_invalid
   297    (module (func $type-num-vs-num (select (i32.const 1) (i64.const 1) (i32.const 1))))
   298    "type mismatch"
   299  )
   300  (assert_invalid
   301    (module (func $type-num-vs-num (select (i32.const 1) (f32.const 1.0) (i32.const 1))))
   302    "type mismatch"
   303  )
   304  (assert_invalid
   305    (module (func $type-num-vs-num (select (i32.const 1) (f64.const 1.0) (i32.const 1))))
   306    "type mismatch"
   307  )
   308  
   309  
   310  (assert_invalid
   311    (module
   312      (func $type-1st-operand-empty
   313        (select) (drop)
   314      )
   315    )
   316    "type mismatch"
   317  )
   318  (assert_invalid
   319    (module
   320      (func $type-2nd-operand-empty
   321        (i32.const 0) (select) (drop)
   322      )
   323    )
   324    "type mismatch"
   325  )
   326  (assert_invalid
   327    (module
   328      (func $type-3rd-operand-empty
   329        (i32.const 0) (i32.const 0) (select) (drop)
   330      )
   331    )
   332    "type mismatch"
   333  )
   334  (assert_invalid
   335    (module
   336      (func $type-1st-operand-empty-in-block
   337        (i32.const 0) (i32.const 0) (i32.const 0)
   338        (block (select) (drop))
   339      )
   340    )
   341    "type mismatch"
   342  )
   343  (assert_invalid
   344    (module
   345      (func $type-2nd-operand-empty-in-block
   346        (i32.const 0) (i32.const 0)
   347        (block (i32.const 0) (select) (drop))
   348      )
   349    )
   350    "type mismatch"
   351  )
   352  (assert_invalid
   353    (module
   354      (func $type-3rd-operand-empty-in-block
   355        (i32.const 0)
   356        (block (i32.const 0) (i32.const 0) (select) (drop))
   357      )
   358    )
   359    "type mismatch"
   360  )
   361  (assert_invalid
   362    (module
   363      (func $type-1st-operand-empty-in-loop
   364        (i32.const 0) (i32.const 0) (i32.const 0)
   365        (loop (select) (drop))
   366      )
   367    )
   368    "type mismatch"
   369  )
   370  (assert_invalid
   371    (module
   372      (func $type-2nd-operand-empty-in-loop
   373        (i32.const 0) (i32.const 0)
   374        (loop (i32.const 0) (select) (drop))
   375      )
   376    )
   377    "type mismatch"
   378  )
   379  (assert_invalid
   380    (module
   381      (func $type-3rd-operand-empty-in-loop
   382        (i32.const 0)
   383        (loop (i32.const 0) (i32.const 0) (select) (drop))
   384      )
   385    )
   386    "type mismatch"
   387  )
   388  (assert_invalid
   389    (module
   390      (func $type-1st-operand-empty-in-then
   391        (i32.const 0) (i32.const 0) (i32.const 0)
   392        (if (then (select) (drop)))
   393      )
   394    )
   395    "type mismatch"
   396  )
   397  (assert_invalid
   398    (module
   399      (func $type-2nd-operand-empty-in-then
   400        (i32.const 0) (i32.const 0)
   401        (if (then (i32.const 0) (select) (drop)))
   402      )
   403    )
   404    "type mismatch"
   405  )
   406  (assert_invalid
   407    (module
   408      (func $type-3rd-operand-empty-in-then
   409        (i32.const 0)
   410        (if (then (i32.const 0) (i32.const 0) (select) (drop)))
   411      )
   412    )
   413    "type mismatch"
   414  )