-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add small integer caching for Unsigned and Size integer types * Apply usage of cached valueOf integer accessor in nativelib * Adjust UnsigedEqualityTest to be aware of small integer caching * Add intrinisc unsignedOf method, ensuring the NIR generation emits box literal, instead of ordinar method call * Seperate Scala 2/3 unsigned package. Optimize Scala 3 by implementing toU conversions as inline defs * Use Size.valueOf to implement toSize conversions. Use inlined extension for Scala3 * Move UnsafeRich* to common scalanative.unsiged package for cross-compilation gurantees
- Loading branch information
1 parent
0290c97
commit f88d789
Showing
26 changed files
with
461 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
nativelib/src/main/scala-3/scala/scalanative/unsigned/extensions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package scala.scalanative.unsigned | ||
|
||
import scala.scalanative.runtime.Intrinsics._ | ||
|
||
/** Scala Native unsigned extensions to the standard Byte. */ | ||
extension (inline value: Byte) { | ||
inline def toUByte: UByte = unsignedOf(value) | ||
inline def toUShort: UShort = unsignedOf(value.toShort) | ||
inline def toUInt: UInt = unsignedOf(byteToUInt(value)) | ||
inline def toULong: ULong = unsignedOf(byteToULong(value)) | ||
} | ||
|
||
/** Scala Native unsigned extensions to the standard Short. */ | ||
extension (inline value: Short) { | ||
inline def toUByte: UByte = unsignedOf(value.toByte) | ||
inline def toUShort: UShort = unsignedOf(value) | ||
inline def toUInt: UInt = unsignedOf(shortToUInt(value)) | ||
inline def toULong: ULong = unsignedOf(shortToULong(value)) | ||
} | ||
|
||
/** Scala Native unsigned extensions to the standard Int. */ | ||
extension (inline value: Int) { | ||
inline def toUByte: UByte = unsignedOf(value.toByte) | ||
inline def toUShort: UShort = unsignedOf(value.toShort) | ||
inline def toUInt: UInt = unsignedOf(value) | ||
inline def toULong: ULong = unsignedOf(intToULong(value)) | ||
inline def toUSize: USize = unsignedOf(castIntToRawSizeUnsigned(value)) | ||
} | ||
|
||
/** Scala Native unsigned extensions to the standard Long. */ | ||
extension (inline value: Long) { | ||
inline def toUByte: UByte = unsignedOf(value.toByte) | ||
inline def toUShort: UShort = unsignedOf(value.toShort) | ||
inline def toUInt: UInt = unsignedOf(value.toInt) | ||
inline def toULong: ULong = unsignedOf(value) | ||
inline def toUSize: USize = unsignedOf(castLongToRawSize(value)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.