@@ -2262,6 +2262,88 @@ class WasmFoundationTests: XCTestCase {
2262
2262
return ( 0 ..< 4 ) . map { function. wasmSimdExtractLane ( kind: WasmSimdExtractLane . Kind. I32x4, result, $0) }
2263
2263
}
2264
2264
} , " (0|-1),7,0,0 " ) , // note: we use -1 to denote UINT32_MAX as it is pain to make .wasmi32 represented as unsigned integer
2265
+ // Test float add
2266
+ ( { wasmModule in
2267
+ let returnType = ( 0 ..< 4 ) . map { _ in ILType . wasmf32}
2268
+ wasmModule. addWasmFunction ( with: [ ] => returnType) { function, label, args in
2269
+ let varA = function. constSimd128 ( value: floatToByteArray ( [ 0.0 , 1.5 , 2.6 , 3.7 ] ) )
2270
+ let varB = function. constSimd128 ( value: floatToByteArray ( [ 4.8 , 5.9 , 7.0 , 8.1 ] ) )
2271
+ let result = function. wasmSimd128FloatBinOp ( varA, varB, WasmSimd128Shape . f32x4, WasmSimd128FloatBinOpKind . add)
2272
+ return ( 0 ..< 4 ) . map { function. wasmSimdExtractLane ( kind: WasmSimdExtractLane . Kind. F32x4, result, $0) }
2273
+ }
2274
+ } , " 4.8[0-9]*,7.4[0-9]*,9.6[0-9]*,11.8[0-9]* " ) , // for floating point math need to allow trailing digits
2275
+ // Test float sub
2276
+ ( { wasmModule in
2277
+ let returnType = ( 0 ..< 4 ) . map { _ in ILType . wasmf32}
2278
+ wasmModule. addWasmFunction ( with: [ ] => returnType) { function, label, args in
2279
+ let varA = function. constSimd128 ( value: floatToByteArray ( [ 4.8 , 1.5 , 7.0 , 8.1 ] ) )
2280
+ let varB = function. constSimd128 ( value: floatToByteArray ( [ 0.0 , 5.9 , 2.6 , 3.7 ] ) )
2281
+ let result = function. wasmSimd128FloatBinOp ( varA, varB, WasmSimd128Shape . f32x4, WasmSimd128FloatBinOpKind . sub)
2282
+ return ( 0 ..< 4 ) . map { function. wasmSimdExtractLane ( kind: WasmSimdExtractLane . Kind. F32x4, result, $0) }
2283
+ }
2284
+ } , " 4.8[0-9]*,-4.4[0-9]*,4.4[0-9]*,4.4[0-9]* " ) , // for floating point math need to allow trailing digits
2285
+ // Test float mul
2286
+ ( { wasmModule in
2287
+ let returnType = ( 0 ..< 4 ) . map { _ in ILType . wasmf32}
2288
+ wasmModule. addWasmFunction ( with: [ ] => returnType) { function, label, args in
2289
+ let varA = function. constSimd128 ( value: floatToByteArray ( [ 4.8 , 1.5 , 7.0 , 8.1 ] ) )
2290
+ let varB = function. constSimd128 ( value: floatToByteArray ( [ 0.0 , 5.9 , 2.6 , 3.7 ] ) )
2291
+ let result = function. wasmSimd128FloatBinOp ( varA, varB, WasmSimd128Shape . f32x4, WasmSimd128FloatBinOpKind . mul)
2292
+ return ( 0 ..< 4 ) . map { function. wasmSimdExtractLane ( kind: WasmSimdExtractLane . Kind. F32x4, result, $0) }
2293
+ }
2294
+ } , " 0,8.85[0-9]*,(18.1[0-9]*|18.2[0-9]*),29.97[0-9]* " ) , // for floating point math need to allow trailing digits and take into account rounding issues
2295
+ // Test float div
2296
+ ( { wasmModule in
2297
+ let returnType = ( 0 ..< 4 ) . map { _ in ILType . wasmf32}
2298
+ wasmModule. addWasmFunction ( with: [ ] => returnType) { function, label, args in
2299
+ let varA = function. constSimd128 ( value: floatToByteArray ( [ 0.0 , 1.5 , 7.0 , 8.1 ] ) )
2300
+ let varB = function. constSimd128 ( value: floatToByteArray ( [ 4.8 , 5.9 , 2.6 , 3.7 ] ) )
2301
+ let result = function. wasmSimd128FloatBinOp ( varA, varB, WasmSimd128Shape . f32x4, WasmSimd128FloatBinOpKind . div)
2302
+ return ( 0 ..< 4 ) . map { function. wasmSimdExtractLane ( kind: WasmSimdExtractLane . Kind. F32x4, result, $0) }
2303
+ }
2304
+ } , " 0,0.2542[0-9]*,2.6923[0-9]*,2.1891[0-9]* " ) , // for floating point math need to allow trailing digits and take into account rounding issues
2305
+ // Test float min
2306
+ ( { wasmModule in
2307
+ let returnType = ( 0 ..< 4 ) . map { _ in ILType . wasmf32}
2308
+ wasmModule. addWasmFunction ( with: [ ] => returnType) { function, label, args in
2309
+ let varA = function. constSimd128 ( value: floatToByteArray ( [ 0.0 , 5.9 , 7.0 , 0.0 / 0.0 ] ) )
2310
+ let varB = function. constSimd128 ( value: floatToByteArray ( [ 4.8 , 1.5 , 0.0 / 0.0 , 3.7 ] ) )
2311
+ let result = function. wasmSimd128FloatBinOp ( varA, varB, WasmSimd128Shape . f32x4, WasmSimd128FloatBinOpKind . min)
2312
+ return ( 0 ..< 4 ) . map { function. wasmSimdExtractLane ( kind: WasmSimdExtractLane . Kind. F32x4, result, $0) }
2313
+ }
2314
+ } , " 0,1.5[0-9]*,NaN,NaN " ) , // for floating point math need to allow trailing digits and take into account rounding issues
2315
+ // Test float max
2316
+ ( { wasmModule in
2317
+ let returnType = ( 0 ..< 4 ) . map { _ in ILType . wasmf32}
2318
+ wasmModule. addWasmFunction ( with: [ ] => returnType) { function, label, args in
2319
+ let varA = function. constSimd128 ( value: floatToByteArray ( [ 0.0 , 5.9 , 7.0 , 0.0 / 0.0 ] ) )
2320
+ let varB = function. constSimd128 ( value: floatToByteArray ( [ 4.8 , 1.5 , 0.0 / 0.0 , 3.7 ] ) )
2321
+ let result = function. wasmSimd128FloatBinOp ( varA, varB, WasmSimd128Shape . f32x4, WasmSimd128FloatBinOpKind . max)
2322
+ return ( 0 ..< 4 ) . map { function. wasmSimdExtractLane ( kind: WasmSimdExtractLane . Kind. F32x4, result, $0) }
2323
+ }
2324
+ } , " 4.8[0-9]*,5.9[0-9]*,NaN,NaN " ) , // for floating point math need to allow trailing digits and take into account rounding issues
2325
+ // Test float pmin
2326
+ ( { wasmModule in
2327
+ let returnType = ( 0 ..< 4 ) . map { _ in ILType . wasmf32}
2328
+ wasmModule. addWasmFunction ( with: [ ] => returnType) { function, label, args in
2329
+ let varA = function. constSimd128 ( value: floatToByteArray ( [ 0.0 , 5.9 , 7.0 , 0.0 / 0.0 ] ) )
2330
+ let varB = function. constSimd128 ( value: floatToByteArray ( [ 4.8 , 1.5 , 0.0 / 0.0 , 3.7 ] ) )
2331
+ let result = function. wasmSimd128FloatBinOp ( varA, varB, WasmSimd128Shape . f32x4, WasmSimd128FloatBinOpKind . pmin)
2332
+ return ( 0 ..< 4 ) . map { function. wasmSimdExtractLane ( kind: WasmSimdExtractLane . Kind. F32x4, result, $0) }
2333
+ }
2334
+ } , " 0,1.5[0-9]*,7,NaN " ) , // for floating point math need to allow trailing digits and take into account rounding issues
2335
+ // Test float pmax
2336
+ ( { wasmModule in
2337
+ let returnType = ( 0 ..< 4 ) . map { _ in ILType . wasmf32}
2338
+ wasmModule. addWasmFunction ( with: [ ] => returnType) { function, label, args in
2339
+ let varA = function. constSimd128 ( value: floatToByteArray ( [ 0.0 , 5.9 , 7.0 , 0.0 / 0.0 ] ) )
2340
+ let varB = function. constSimd128 ( value: floatToByteArray ( [ 4.8 , 1.5 , 0.0 / 0.0 , 3.7 ] ) )
2341
+ let result = function. wasmSimd128FloatBinOp ( varA, varB, WasmSimd128Shape . f32x4, WasmSimd128FloatBinOpKind . pmax)
2342
+ return ( 0 ..< 4 ) . map { function. wasmSimdExtractLane ( kind: WasmSimdExtractLane . Kind. F32x4, result, $0) }
2343
+ }
2344
+ } , " 4.8[0-9]*,5.9[0-9]*,7,NaN " ) , // for floating point math need to allow trailing digits and take into account rounding issues
2345
+
2346
+
2265
2347
]
2266
2348
2267
2349
let module = b. buildWasmModule { wasmModule in
0 commit comments