|
1 |
| -//public module core; |
| 1 | +public module core; |
2 | 2 |
|
3 | 3 | // Slang `core` library
|
4 | 4 |
|
@@ -2367,49 +2367,6 @@ __generic<T> __extension vector<T, 4>
|
2367 | 2367 |
|
2368 | 2368 | ${{{{
|
2369 | 2369 |
|
2370 |
| -// The above extensions are generic in the *type* of the vector, |
2371 |
| -// but explicit in the *size*. We will now declare an extension |
2372 |
| -// for each builtin type that is generic in the size. |
2373 |
| -// |
2374 |
| -for (int tt = 0; tt < kBaseTypeCount; ++tt) |
2375 |
| -{ |
2376 |
| - if(kBaseTypes[tt].tag == BaseType::Void) continue; |
2377 |
| - |
2378 |
| - sb << "__generic<let N : int> __extension vector<" |
2379 |
| - << kBaseTypes[tt].name << ",N>\n{\n"; |
2380 |
| - |
2381 |
| - for (int ff = 0; ff < kBaseTypeCount; ++ff) |
2382 |
| - { |
2383 |
| - if(kBaseTypes[ff].tag == BaseType::Void) continue; |
2384 |
| - |
2385 |
| - |
2386 |
| - if( tt != ff ) |
2387 |
| - { |
2388 |
| - auto cost = getBaseTypeConversionCost( |
2389 |
| - kBaseTypes[tt], |
2390 |
| - kBaseTypes[ff]); |
2391 |
| - auto op = getBaseTypeConversionOp( |
2392 |
| - kBaseTypes[tt], |
2393 |
| - kBaseTypes[ff]); |
2394 |
| - |
2395 |
| - // Implicit conversion from a vector of the same |
2396 |
| - // size, but different element type. |
2397 |
| - sb << " __implicit_conversion(" << cost << ")\n"; |
2398 |
| - sb << " __intrinsic_op(" << int(op) << ")\n"; |
2399 |
| - sb << " __init(vector<" << kBaseTypes[ff].name << ",N> value);\n"; |
2400 |
| - |
2401 |
| - // Constructor to make a vector from a scalar of another type. |
2402 |
| - if (cost != kConversionCost_Impossible) |
2403 |
| - { |
2404 |
| - cost += kConversionCost_ScalarToVector; |
2405 |
| - sb << " __implicit_conversion(" << cost << ")\n"; |
2406 |
| - sb << " [__unsafeForceInlineEarly]\n"; |
2407 |
| - sb << " __init(" << kBaseTypes[ff].name << " value) { this = vector<" << kBaseTypes[tt].name << ",N>( " << kBaseTypes[tt].name << "(value)); }\n"; |
2408 |
| - } |
2409 |
| - } |
2410 |
| - } |
2411 |
| - sb << "}\n"; |
2412 |
| -} |
2413 | 2370 |
|
2414 | 2371 | for( int R = 1; R <= 4; ++R )
|
2415 | 2372 | for( int C = 1; C <= 4; ++C )
|
@@ -2464,38 +2421,36 @@ for( int C = 1; C <= 4; ++C )
|
2464 | 2421 | sb << "}\n";
|
2465 | 2422 | }
|
2466 | 2423 |
|
2467 |
| -for (int tt = 0; tt < kBaseTypeCount; ++tt) |
2468 |
| -{ |
2469 |
| - if(kBaseTypes[tt].tag == BaseType::Void) continue; |
2470 |
| - auto toType = kBaseTypes[tt].name; |
2471 | 2424 | }}}}
|
2472 | 2425 |
|
2473 |
| -__generic<let R : int, let C : int, let L : int> extension matrix<$(toType),R,C,L> |
| 2426 | +//@hidden: |
| 2427 | +__intrinsic_op($(kIROp_BuiltinCast)) |
| 2428 | +internal T __builtin_cast<T, U>(U u); |
| 2429 | + |
| 2430 | +// If T is implicitly convertible to U, then vector<T,N> is implicitly convertible to vector<U,N>. |
| 2431 | +__generic<ToType, let N : int> extension vector<ToType,N> |
2474 | 2432 | {
|
2475 |
| -${{{{ |
2476 |
| - for (int ff = 0; ff < kBaseTypeCount; ++ff) |
2477 |
| - { |
2478 |
| - if(kBaseTypes[ff].tag == BaseType::Void) continue; |
2479 |
| - if( tt == ff ) continue; |
| 2433 | + __implicit_conversion(constraint) |
| 2434 | + __intrinsic_op(BuiltinCast) |
| 2435 | + __init<FromType>(vector<FromType,N> value) where ToType(FromType) implicit; |
2480 | 2436 |
|
2481 |
| - auto cost = getBaseTypeConversionCost( |
2482 |
| - kBaseTypes[tt], |
2483 |
| - kBaseTypes[ff]); |
2484 |
| - auto fromType = kBaseTypes[ff].name; |
2485 |
| - auto op = getBaseTypeConversionOp( |
2486 |
| - kBaseTypes[tt], |
2487 |
| - kBaseTypes[ff]); |
2488 |
| -}}}} |
2489 |
| - __implicit_conversion($(cost)) |
2490 |
| - __intrinsic_op($(op)) |
2491 |
| - __init(matrix<$(fromType),R,C,L> value); |
2492 |
| -${{{{ |
| 2437 | + __implicit_conversion(constraint+) |
| 2438 | + [__unsafeForceInlineEarly] |
| 2439 | + [__readNone] |
| 2440 | + [TreatAsDifferentiable] |
| 2441 | + __init<FromType>(FromType value) where ToType(FromType) implicit |
| 2442 | + { |
| 2443 | + this = __builtin_cast<vector<ToType,N>>(vector<FromType,N>(value)); |
2493 | 2444 | }
|
2494 |
| -}}}} |
2495 | 2445 | }
|
2496 |
| -${{{{ |
| 2446 | + |
| 2447 | +// If T is implicitly convertible to U, then matrix<T,R,C,L> is implicitly convertible to matrix<U,R,C,L>. |
| 2448 | +__generic<ToType, let R : int, let C : int, let L : int> extension matrix<ToType,R,C,L> |
| 2449 | +{ |
| 2450 | + __implicit_conversion(constraint) |
| 2451 | + __intrinsic_op(BuiltinCast) |
| 2452 | + __init<FromType>(matrix<FromType,R,C,L> value) where ToType(FromType) implicit; |
2497 | 2453 | }
|
2498 |
| -}}}} |
2499 | 2454 |
|
2500 | 2455 | //@ hidden:
|
2501 | 2456 | __generic<T, U>
|
|
0 commit comments