@@ -2070,11 +2070,8 @@ function builtin_store(ctx: BuiltinContext): ExpressionRef {
2070
2070
inType . size < type . size // int to larger int (clear garbage bits)
2071
2071
)
2072
2072
) {
2073
- arg1 = compiler . convertExpression ( arg1 ,
2074
- inType , type ,
2075
- false , false , // still clears garbage bits when not wrapping
2076
- operands [ 1 ]
2077
- ) ;
2073
+ // either conversion or memory operation clears garbage bits
2074
+ arg1 = compiler . convertExpression ( arg1 , inType , type , false , operands [ 1 ] ) ;
2078
2075
inType = type ;
2079
2076
}
2080
2077
var immOffset = 0 ;
@@ -2102,81 +2099,44 @@ builtins.set(BuiltinNames.store, builtin_store);
2102
2099
function builtin_add ( ctx : BuiltinContext ) : ExpressionRef {
2103
2100
var compiler = ctx . compiler ;
2104
2101
var module = compiler . module ;
2105
- if ( checkTypeOptional ( ctx , true ) | checkArgsRequired ( ctx , 2 ) )
2102
+ if ( checkTypeOptional ( ctx , true ) | checkArgsRequired ( ctx , 2 ) ) {
2106
2103
return module . unreachable ( ) ;
2104
+ }
2107
2105
var operands = ctx . operands ;
2108
2106
var typeArguments = ctx . typeArguments ;
2109
2107
var left = operands [ 0 ] ;
2110
2108
var arg0 = typeArguments
2111
2109
? compiler . compileExpression (
2112
2110
left ,
2113
2111
typeArguments [ 0 ] ,
2114
- Constraints . CONV_IMPLICIT | Constraints . MUST_WRAP
2112
+ Constraints . CONV_IMPLICIT
2115
2113
)
2116
- : compiler . compileExpression ( operands [ 0 ] , Type . auto , Constraints . MUST_WRAP ) ;
2114
+ : compiler . compileExpression ( operands [ 0 ] , Type . auto ) ;
2117
2115
var type = compiler . currentType ;
2118
2116
if ( type . isValue ) {
2119
2117
let arg1 : ExpressionRef ;
2120
2118
if ( ! typeArguments && left . isNumericLiteral ) {
2121
2119
// prefer right type
2122
2120
arg1 = compiler . compileExpression (
2123
2121
operands [ 1 ] ,
2124
- type ,
2125
- Constraints . MUST_WRAP
2122
+ type
2126
2123
) ;
2127
2124
if ( compiler . currentType != type ) {
2128
2125
arg0 = compiler . compileExpression (
2129
2126
left ,
2130
2127
( type = compiler . currentType ) ,
2131
- Constraints . CONV_IMPLICIT | Constraints . MUST_WRAP
2128
+ Constraints . CONV_IMPLICIT
2132
2129
) ;
2133
2130
}
2134
2131
} else {
2135
2132
arg1 = compiler . compileExpression (
2136
2133
operands [ 1 ] ,
2137
2134
type ,
2138
- Constraints . CONV_IMPLICIT | Constraints . MUST_WRAP
2135
+ Constraints . CONV_IMPLICIT
2139
2136
) ;
2140
2137
}
2141
- let op : BinaryOp = - 1 ;
2142
- switch ( type . kind ) {
2143
- case TypeKind . I8 :
2144
- case TypeKind . I16 :
2145
- case TypeKind . U8 :
2146
- case TypeKind . U16 :
2147
- case TypeKind . BOOL : {
2148
- return compiler . ensureSmallIntegerWrap (
2149
- module . binary ( BinaryOp . AddI32 , arg0 , arg1 ) ,
2150
- type
2151
- ) ;
2152
- }
2153
- case TypeKind . I32 :
2154
- case TypeKind . U32 :
2155
- {
2156
- op = BinaryOp . AddI32 ;
2157
- break ;
2158
- }
2159
- case TypeKind . I64 :
2160
- case TypeKind . U64 : {
2161
- op = BinaryOp . AddI64 ;
2162
- break ;
2163
- }
2164
- case TypeKind . ISIZE :
2165
- case TypeKind . USIZE : {
2166
- op = compiler . options . isWasm64 ? BinaryOp . AddI64 : BinaryOp . AddI32 ;
2167
- break ;
2168
- }
2169
- case TypeKind . F32 : {
2170
- op = BinaryOp . AddF32 ;
2171
- break ;
2172
- }
2173
- case TypeKind . F64 : {
2174
- op = BinaryOp . AddF64 ;
2175
- break ;
2176
- }
2177
- }
2178
- if ( op != - 1 ) {
2179
- return module . binary ( op , arg0 , arg1 ) ;
2138
+ if ( type . isNumericValue ) {
2139
+ return compiler . makeAdd ( arg0 , arg1 , type ) ;
2180
2140
}
2181
2141
}
2182
2142
compiler . error (
@@ -2193,81 +2153,44 @@ builtins.set(BuiltinNames.add, builtin_add);
2193
2153
function builtin_sub ( ctx : BuiltinContext ) : ExpressionRef {
2194
2154
var compiler = ctx . compiler ;
2195
2155
var module = compiler . module ;
2196
- if ( checkTypeOptional ( ctx , true ) | checkArgsRequired ( ctx , 2 ) )
2156
+ if ( checkTypeOptional ( ctx , true ) | checkArgsRequired ( ctx , 2 ) ) {
2197
2157
return module . unreachable ( ) ;
2158
+ }
2198
2159
var operands = ctx . operands ;
2199
2160
var typeArguments = ctx . typeArguments ;
2200
2161
var left = operands [ 0 ] ;
2201
2162
var arg0 = typeArguments
2202
2163
? compiler . compileExpression (
2203
2164
left ,
2204
2165
typeArguments [ 0 ] ,
2205
- Constraints . CONV_IMPLICIT | Constraints . MUST_WRAP
2166
+ Constraints . CONV_IMPLICIT
2206
2167
)
2207
- : compiler . compileExpression ( operands [ 0 ] , Type . auto , Constraints . MUST_WRAP ) ;
2168
+ : compiler . compileExpression ( operands [ 0 ] , Type . auto ) ;
2208
2169
var type = compiler . currentType ;
2209
2170
if ( type . isValue ) {
2210
2171
let arg1 : ExpressionRef ;
2211
2172
if ( ! typeArguments && left . isNumericLiteral ) {
2212
2173
// prefer right type
2213
2174
arg1 = compiler . compileExpression (
2214
2175
operands [ 1 ] ,
2215
- type ,
2216
- Constraints . MUST_WRAP
2176
+ type
2217
2177
) ;
2218
2178
if ( compiler . currentType != type ) {
2219
2179
arg0 = compiler . compileExpression (
2220
2180
left ,
2221
2181
( type = compiler . currentType ) ,
2222
- Constraints . CONV_IMPLICIT | Constraints . MUST_WRAP
2182
+ Constraints . CONV_IMPLICIT
2223
2183
) ;
2224
2184
}
2225
2185
} else {
2226
2186
arg1 = compiler . compileExpression (
2227
2187
operands [ 1 ] ,
2228
2188
type ,
2229
- Constraints . CONV_IMPLICIT | Constraints . MUST_WRAP
2189
+ Constraints . CONV_IMPLICIT
2230
2190
) ;
2231
2191
}
2232
- let op : BinaryOp = - 1 ;
2233
- switch ( type . kind ) {
2234
- case TypeKind . I8 :
2235
- case TypeKind . I16 :
2236
- case TypeKind . U8 :
2237
- case TypeKind . U16 :
2238
- case TypeKind . BOOL : {
2239
- return compiler . ensureSmallIntegerWrap (
2240
- module . binary ( BinaryOp . SubI32 , arg0 , arg1 ) ,
2241
- type
2242
- ) ;
2243
- }
2244
- case TypeKind . I32 :
2245
- case TypeKind . U32 :
2246
- {
2247
- op = BinaryOp . SubI32 ;
2248
- break ;
2249
- }
2250
- case TypeKind . I64 :
2251
- case TypeKind . U64 : {
2252
- op = BinaryOp . SubI64 ;
2253
- break ;
2254
- }
2255
- case TypeKind . ISIZE :
2256
- case TypeKind . USIZE : {
2257
- op = compiler . options . isWasm64 ? BinaryOp . SubI64 : BinaryOp . SubI32 ;
2258
- break ;
2259
- }
2260
- case TypeKind . F32 : {
2261
- op = BinaryOp . SubF32 ;
2262
- break ;
2263
- }
2264
- case TypeKind . F64 : {
2265
- op = BinaryOp . SubF64 ;
2266
- break ;
2267
- }
2268
- }
2269
- if ( op != - 1 ) {
2270
- return module . binary ( op , arg0 , arg1 ) ;
2192
+ if ( type . isNumericValue ) {
2193
+ return compiler . makeSub ( arg0 , arg1 , type ) ;
2271
2194
}
2272
2195
}
2273
2196
compiler . error (
@@ -2284,81 +2207,44 @@ builtins.set(BuiltinNames.sub, builtin_sub);
2284
2207
function builtin_mul ( ctx : BuiltinContext ) : ExpressionRef {
2285
2208
var compiler = ctx . compiler ;
2286
2209
var module = compiler . module ;
2287
- if ( checkTypeOptional ( ctx , true ) | checkArgsRequired ( ctx , 2 ) )
2210
+ if ( checkTypeOptional ( ctx , true ) | checkArgsRequired ( ctx , 2 ) ) {
2288
2211
return module . unreachable ( ) ;
2212
+ }
2289
2213
var operands = ctx . operands ;
2290
2214
var typeArguments = ctx . typeArguments ;
2291
2215
var left = operands [ 0 ] ;
2292
2216
var arg0 = typeArguments
2293
2217
? compiler . compileExpression (
2294
2218
left ,
2295
2219
typeArguments [ 0 ] ,
2296
- Constraints . CONV_IMPLICIT | Constraints . MUST_WRAP
2220
+ Constraints . CONV_IMPLICIT
2297
2221
)
2298
- : compiler . compileExpression ( operands [ 0 ] , Type . auto , Constraints . MUST_WRAP ) ;
2222
+ : compiler . compileExpression ( operands [ 0 ] , Type . auto ) ;
2299
2223
var type = compiler . currentType ;
2300
2224
if ( type . isValue ) {
2301
2225
let arg1 : ExpressionRef ;
2302
2226
if ( ! typeArguments && left . isNumericLiteral ) {
2303
2227
// prefer right type
2304
2228
arg1 = compiler . compileExpression (
2305
2229
operands [ 1 ] ,
2306
- type ,
2307
- Constraints . MUST_WRAP
2230
+ type
2308
2231
) ;
2309
2232
if ( compiler . currentType != type ) {
2310
2233
arg0 = compiler . compileExpression (
2311
2234
left ,
2312
2235
( type = compiler . currentType ) ,
2313
- Constraints . CONV_IMPLICIT | Constraints . MUST_WRAP
2236
+ Constraints . CONV_IMPLICIT
2314
2237
) ;
2315
2238
}
2316
2239
} else {
2317
2240
arg1 = compiler . compileExpression (
2318
2241
operands [ 1 ] ,
2319
2242
type ,
2320
- Constraints . CONV_IMPLICIT | Constraints . MUST_WRAP
2243
+ Constraints . CONV_IMPLICIT
2321
2244
) ;
2322
2245
}
2323
- let op : BinaryOp = - 1 ;
2324
- switch ( type . kind ) {
2325
- case TypeKind . I8 :
2326
- case TypeKind . I16 :
2327
- case TypeKind . U8 :
2328
- case TypeKind . U16 :
2329
- case TypeKind . BOOL : {
2330
- return compiler . ensureSmallIntegerWrap (
2331
- module . binary ( BinaryOp . MulI32 , arg0 , arg1 ) ,
2332
- type
2333
- ) ;
2334
- }
2335
- case TypeKind . I32 :
2336
- case TypeKind . U32 :
2337
- {
2338
- op = BinaryOp . MulI32 ;
2339
- break ;
2340
- }
2341
- case TypeKind . I64 :
2342
- case TypeKind . U64 : {
2343
- op = BinaryOp . MulI64 ;
2344
- break ;
2345
- }
2346
- case TypeKind . ISIZE :
2347
- case TypeKind . USIZE : {
2348
- op = compiler . options . isWasm64 ? BinaryOp . MulI64 : BinaryOp . MulI32 ;
2349
- break ;
2350
- }
2351
- case TypeKind . F32 : {
2352
- op = BinaryOp . MulF32 ;
2353
- break ;
2354
- }
2355
- case TypeKind . F64 : {
2356
- op = BinaryOp . MulF64 ;
2357
- break ;
2358
- }
2359
- }
2360
- if ( op != - 1 ) {
2361
- return module . binary ( op , arg0 , arg1 ) ;
2246
+ if ( type . isNumericValue ) {
2247
+ return compiler . makeMul ( arg0 , arg1 , type ) ;
2362
2248
}
2363
2249
}
2364
2250
compiler . error (
@@ -2458,11 +2344,8 @@ function builtin_atomic_store(ctx: BuiltinContext): ExpressionRef {
2458
2344
inType . size < type . size // int to larger int (clear garbage bits)
2459
2345
)
2460
2346
) {
2461
- arg1 = compiler . convertExpression ( arg1 ,
2462
- inType , type ,
2463
- false , false , // still clears garbage bits when not wrapping
2464
- operands [ 1 ]
2465
- ) ;
2347
+ // either conversion or memory operation clears garbage bits
2348
+ arg1 = compiler . convertExpression ( arg1 , inType , type , false , operands [ 1 ] ) ;
2466
2349
inType = type ;
2467
2350
}
2468
2351
var immOffset = operands . length == 3 ? evaluateImmediateOffset ( operands [ 2 ] , compiler ) : 0 ; // reports
@@ -2519,11 +2402,8 @@ function builtin_atomic_binary(ctx: BuiltinContext, op: AtomicRMWOp, opName: str
2519
2402
inType . size < type . size // int to larger int (clear garbage bits)
2520
2403
)
2521
2404
) {
2522
- arg1 = compiler . convertExpression ( arg1 ,
2523
- inType , type ,
2524
- false , false , // still clears garbage bits when not wrapping
2525
- operands [ 1 ]
2526
- ) ;
2405
+ // either conversion or memory operation clears garbage bits
2406
+ arg1 = compiler . convertExpression ( arg1 , inType , type , false , operands [ 1 ] ) ;
2527
2407
inType = type ;
2528
2408
}
2529
2409
var immOffset = operands . length == 3 ? evaluateImmediateOffset ( operands [ 2 ] , compiler ) : 0 ; // reports
@@ -2619,16 +2499,9 @@ function builtin_atomic_cmpxchg(ctx: BuiltinContext): ExpressionRef {
2619
2499
inType . size < type . size // int to larger int (clear garbage bits)
2620
2500
)
2621
2501
) {
2622
- arg1 = compiler . convertExpression ( arg1 ,
2623
- inType , type ,
2624
- false , false , // still clears garbage bits when not wrapping
2625
- operands [ 1 ]
2626
- ) ;
2627
- arg2 = compiler . convertExpression ( arg2 ,
2628
- inType , type ,
2629
- false , false , // still clears garbage bits when not wrapping
2630
- operands [ 2 ]
2631
- ) ;
2502
+ // either conversion or memory operation clears garbage bits
2503
+ arg1 = compiler . convertExpression ( arg1 , inType , type , false , operands [ 1 ] ) ;
2504
+ arg2 = compiler . convertExpression ( arg2 , inType , type , false , operands [ 2 ] ) ;
2632
2505
inType = type ;
2633
2506
}
2634
2507
var immOffset = operands . length == 4 ? evaluateImmediateOffset ( operands [ 3 ] , compiler ) : 0 ; // reports
0 commit comments