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

     1  (module
     2    (memory 1)
     3  
     4    ;; Stores an i16 value in little-endian-format
     5    (func $i16_store_little (param $address i32) (param $value i32)
     6      (i32.store8 (local.get $address) (local.get $value))
     7      (i32.store8 (i32.add (local.get $address) (i32.const 1)) (i32.shr_u (local.get $value) (i32.const 8)))
     8    )
     9  
    10    ;; Stores an i32 value in little-endian format
    11    (func $i32_store_little (param $address i32) (param $value i32)
    12      (call $i16_store_little (local.get $address) (local.get $value))
    13      (call $i16_store_little (i32.add (local.get $address) (i32.const 2)) (i32.shr_u (local.get $value) (i32.const 16)))
    14    )
    15  
    16    ;; Stores an i64 value in little-endian format
    17    (func $i64_store_little (param $address i32) (param $value i64)
    18      (call $i32_store_little (local.get $address) (i32.wrap_i64 (local.get $value)))
    19      (call $i32_store_little (i32.add (local.get $address) (i32.const 4)) (i32.wrap_i64 (i64.shr_u (local.get $value) (i64.const 32))))
    20    )
    21  
    22    ;; Loads an i16 value in little-endian format
    23    (func $i16_load_little (param $address i32) (result i32)
    24      (i32.or
    25        (i32.load8_u (local.get $address))
    26        (i32.shl (i32.load8_u (i32.add (local.get $address) (i32.const 1))) (i32.const 8))
    27      )
    28    )
    29  
    30    ;; Loads an i32 value in little-endian format
    31    (func $i32_load_little (param $address i32) (result i32)
    32      (i32.or
    33        (call $i16_load_little (local.get $address))
    34        (i32.shl (call $i16_load_little (i32.add (local.get $address) (i32.const 2))) (i32.const 16))
    35      )
    36    )
    37  
    38    ;; Loads an i64 value in little-endian format
    39    (func $i64_load_little (param $address i32) (result i64)
    40      (i64.or
    41        (i64.extend_i32_u (call $i32_load_little (local.get $address)))
    42        (i64.shl (i64.extend_i32_u (call $i32_load_little (i32.add (local.get $address) (i32.const 4)))) (i64.const 32))
    43      )
    44    )
    45  
    46    (func (export "i32_load16_s") (param $value i32) (result i32)
    47      (call $i16_store_little (i32.const 0) (local.get $value))
    48      (i32.load16_s (i32.const 0))
    49    )
    50  
    51    (func (export "i32_load16_u") (param $value i32) (result i32)
    52      (call $i16_store_little (i32.const 0) (local.get $value))
    53      (i32.load16_u (i32.const 0))
    54    )
    55  
    56    (func (export "i32_load") (param $value i32) (result i32)
    57      (call $i32_store_little (i32.const 0) (local.get $value))
    58      (i32.load (i32.const 0))
    59    )
    60  
    61    (func (export "i64_load16_s") (param $value i64) (result i64)
    62      (call $i16_store_little (i32.const 0) (i32.wrap_i64 (local.get $value)))
    63      (i64.load16_s (i32.const 0))
    64    )
    65  
    66    (func (export "i64_load16_u") (param $value i64) (result i64)
    67      (call $i16_store_little (i32.const 0) (i32.wrap_i64 (local.get $value)))
    68      (i64.load16_u (i32.const 0))
    69    )
    70  
    71    (func (export "i64_load32_s") (param $value i64) (result i64)
    72      (call $i32_store_little (i32.const 0) (i32.wrap_i64 (local.get $value)))
    73      (i64.load32_s (i32.const 0))
    74    )
    75  
    76    (func (export "i64_load32_u") (param $value i64) (result i64)
    77      (call $i32_store_little (i32.const 0) (i32.wrap_i64 (local.get $value)))
    78      (i64.load32_u (i32.const 0))
    79    )
    80  
    81    (func (export "i64_load") (param $value i64) (result i64)
    82      (call $i64_store_little (i32.const 0) (local.get $value))
    83      (i64.load (i32.const 0))
    84    )
    85  
    86    (func (export "f32_load") (param $value f32) (result f32)
    87      (call $i32_store_little (i32.const 0) (i32.reinterpret_f32 (local.get $value)))
    88      (f32.load (i32.const 0))
    89    )
    90  
    91    (func (export "f64_load") (param $value f64) (result f64)
    92      (call $i64_store_little (i32.const 0) (i64.reinterpret_f64 (local.get $value)))
    93      (f64.load (i32.const 0))
    94    )
    95  
    96  
    97    (func (export "i32_store16") (param $value i32) (result i32)
    98      (i32.store16 (i32.const 0) (local.get $value))
    99      (call $i16_load_little (i32.const 0))
   100    )
   101  
   102    (func (export "i32_store") (param $value i32) (result i32)
   103      (i32.store (i32.const 0) (local.get $value))
   104      (call $i32_load_little (i32.const 0))
   105    )
   106  
   107    (func (export "i64_store16") (param $value i64) (result i64)
   108      (i64.store16 (i32.const 0) (local.get $value))
   109      (i64.extend_i32_u (call $i16_load_little (i32.const 0)))
   110    )
   111  
   112    (func (export "i64_store32") (param $value i64) (result i64)
   113      (i64.store32 (i32.const 0) (local.get $value))
   114      (i64.extend_i32_u (call $i32_load_little (i32.const 0)))
   115    )
   116  
   117    (func (export "i64_store") (param $value i64) (result i64)
   118      (i64.store (i32.const 0) (local.get $value))
   119      (call $i64_load_little (i32.const 0))
   120    )
   121  
   122    (func (export "f32_store") (param $value f32) (result f32)
   123      (f32.store (i32.const 0) (local.get $value))
   124      (f32.reinterpret_i32 (call $i32_load_little (i32.const 0)))
   125    )
   126  
   127    (func (export "f64_store") (param $value f64) (result f64)
   128      (f64.store (i32.const 0) (local.get $value))
   129      (f64.reinterpret_i64 (call $i64_load_little (i32.const 0)))
   130    )
   131  )
   132  
   133  (assert_return (invoke "i32_load16_s" (i32.const -1)) (i32.const -1))
   134  (assert_return (invoke "i32_load16_s" (i32.const -4242)) (i32.const -4242))
   135  (assert_return (invoke "i32_load16_s" (i32.const 42)) (i32.const 42))
   136  (assert_return (invoke "i32_load16_s" (i32.const 0x3210)) (i32.const 0x3210))
   137  
   138  (assert_return (invoke "i32_load16_u" (i32.const -1)) (i32.const 0xFFFF))
   139  (assert_return (invoke "i32_load16_u" (i32.const -4242)) (i32.const 61294))
   140  (assert_return (invoke "i32_load16_u" (i32.const 42)) (i32.const 42))
   141  (assert_return (invoke "i32_load16_u" (i32.const 0xCAFE)) (i32.const 0xCAFE))
   142  
   143  (assert_return (invoke "i32_load" (i32.const -1)) (i32.const -1))
   144  (assert_return (invoke "i32_load" (i32.const -42424242)) (i32.const -42424242))
   145  (assert_return (invoke "i32_load" (i32.const 42424242)) (i32.const 42424242))
   146  (assert_return (invoke "i32_load" (i32.const 0xABAD1DEA)) (i32.const 0xABAD1DEA))
   147  
   148  (assert_return (invoke "i64_load16_s" (i64.const -1)) (i64.const -1))
   149  (assert_return (invoke "i64_load16_s" (i64.const -4242)) (i64.const -4242))
   150  (assert_return (invoke "i64_load16_s" (i64.const 42)) (i64.const 42))
   151  (assert_return (invoke "i64_load16_s" (i64.const 0x3210)) (i64.const 0x3210))
   152  
   153  (assert_return (invoke "i64_load16_u" (i64.const -1)) (i64.const 0xFFFF))
   154  (assert_return (invoke "i64_load16_u" (i64.const -4242)) (i64.const 61294))
   155  (assert_return (invoke "i64_load16_u" (i64.const 42)) (i64.const 42))
   156  (assert_return (invoke "i64_load16_u" (i64.const 0xCAFE)) (i64.const 0xCAFE))
   157  
   158  (assert_return (invoke "i64_load32_s" (i64.const -1)) (i64.const -1))
   159  (assert_return (invoke "i64_load32_s" (i64.const -42424242)) (i64.const -42424242))
   160  (assert_return (invoke "i64_load32_s" (i64.const 42424242)) (i64.const 42424242))
   161  (assert_return (invoke "i64_load32_s" (i64.const 0x12345678)) (i64.const 0x12345678))
   162  
   163  (assert_return (invoke "i64_load32_u" (i64.const -1)) (i64.const 0xFFFFFFFF))
   164  (assert_return (invoke "i64_load32_u" (i64.const -42424242)) (i64.const 4252543054))
   165  (assert_return (invoke "i64_load32_u" (i64.const 42424242)) (i64.const 42424242))
   166  (assert_return (invoke "i64_load32_u" (i64.const 0xABAD1DEA)) (i64.const 0xABAD1DEA))
   167  
   168  (assert_return (invoke "i64_load" (i64.const -1)) (i64.const -1))
   169  (assert_return (invoke "i64_load" (i64.const -42424242)) (i64.const -42424242))
   170  (assert_return (invoke "i64_load" (i64.const 0xABAD1DEA)) (i64.const 0xABAD1DEA))
   171  (assert_return (invoke "i64_load" (i64.const 0xABADCAFEDEAD1DEA)) (i64.const 0xABADCAFEDEAD1DEA))
   172  
   173  (assert_return (invoke "f32_load" (f32.const -1)) (f32.const -1))
   174  (assert_return (invoke "f32_load" (f32.const 1234e-5)) (f32.const 1234e-5))
   175  (assert_return (invoke "f32_load" (f32.const 4242.4242)) (f32.const 4242.4242))
   176  (assert_return (invoke "f32_load" (f32.const 0x1.fffffep+127)) (f32.const 0x1.fffffep+127))
   177  
   178  (assert_return (invoke "f64_load" (f64.const -1)) (f64.const -1))
   179  (assert_return (invoke "f64_load" (f64.const 123456789e-5)) (f64.const 123456789e-5))
   180  (assert_return (invoke "f64_load" (f64.const 424242.424242)) (f64.const 424242.424242))
   181  (assert_return (invoke "f64_load" (f64.const 0x1.fffffffffffffp+1023)) (f64.const 0x1.fffffffffffffp+1023))
   182  
   183  
   184  (assert_return (invoke "i32_store16" (i32.const -1)) (i32.const 0xFFFF))
   185  (assert_return (invoke "i32_store16" (i32.const -4242)) (i32.const 61294))
   186  (assert_return (invoke "i32_store16" (i32.const 42)) (i32.const 42))
   187  (assert_return (invoke "i32_store16" (i32.const 0xCAFE)) (i32.const 0xCAFE))
   188  
   189  (assert_return (invoke "i32_store" (i32.const -1)) (i32.const -1))
   190  (assert_return (invoke "i32_store" (i32.const -4242)) (i32.const -4242))
   191  (assert_return (invoke "i32_store" (i32.const 42424242)) (i32.const 42424242))
   192  (assert_return (invoke "i32_store" (i32.const 0xDEADCAFE)) (i32.const 0xDEADCAFE))
   193  
   194  (assert_return (invoke "i64_store16" (i64.const -1)) (i64.const 0xFFFF))
   195  (assert_return (invoke "i64_store16" (i64.const -4242)) (i64.const 61294))
   196  (assert_return (invoke "i64_store16" (i64.const 42)) (i64.const 42))
   197  (assert_return (invoke "i64_store16" (i64.const 0xCAFE)) (i64.const 0xCAFE))
   198  
   199  (assert_return (invoke "i64_store32" (i64.const -1)) (i64.const 0xFFFFFFFF))
   200  (assert_return (invoke "i64_store32" (i64.const -4242)) (i64.const 4294963054))
   201  (assert_return (invoke "i64_store32" (i64.const 42424242)) (i64.const 42424242))
   202  (assert_return (invoke "i64_store32" (i64.const 0xDEADCAFE)) (i64.const 0xDEADCAFE))
   203  
   204  (assert_return (invoke "i64_store" (i64.const -1)) (i64.const -1))
   205  (assert_return (invoke "i64_store" (i64.const -42424242)) (i64.const -42424242))
   206  (assert_return (invoke "i64_store" (i64.const 0xABAD1DEA)) (i64.const 0xABAD1DEA))
   207  (assert_return (invoke "i64_store" (i64.const 0xABADCAFEDEAD1DEA)) (i64.const 0xABADCAFEDEAD1DEA))
   208  
   209  (assert_return (invoke "f32_store" (f32.const -1)) (f32.const -1))
   210  (assert_return (invoke "f32_store" (f32.const 1234e-5)) (f32.const 1234e-5))
   211  (assert_return (invoke "f32_store" (f32.const 4242.4242)) (f32.const 4242.4242))
   212  (assert_return (invoke "f32_store" (f32.const 0x1.fffffep+127)) (f32.const 0x1.fffffep+127))
   213  
   214  (assert_return (invoke "f64_store" (f64.const -1)) (f64.const -1))
   215  (assert_return (invoke "f64_store" (f64.const 123456789e-5)) (f64.const 123456789e-5))
   216  (assert_return (invoke "f64_store" (f64.const 424242.424242)) (f64.const 424242.424242))
   217  (assert_return (invoke "f64_store" (f64.const 0x1.fffffffffffffp+1023)) (f64.const 0x1.fffffffffffffp+1023))