2018-04-25 19:21:58 +00:00
|
|
|
# Stint
|
2018-04-25 17:51:14 +00:00
|
|
|
# Copyright 2018 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
#
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
|
|
#
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
2018-05-06 20:29:08 +00:00
|
|
|
|
2018-10-25 10:58:40 +00:00
|
|
|
import ./datatypes, ./int_bitwise_ops, ./initialization, ./uint_highlow
|
2018-04-25 17:51:14 +00:00
|
|
|
|
2018-10-25 10:58:40 +00:00
|
|
|
# XXX There's some Araq reason why this isn't part of the std lib..
|
|
|
|
func high(_: typedesc[SomeUnsignedInt]): SomeUnsignedInt =
|
|
|
|
not SomeUnsignedInt(0'u8)
|
|
|
|
|
|
|
|
func high*[T, T2](_: typedesc[IntImpl[T, T2]]): IntImpl[T, T2] {.inline.}=
|
2018-05-17 07:45:42 +00:00
|
|
|
# The highest signed int has representation
|
2018-04-30 11:38:55 +00:00
|
|
|
# 0b0111_1111_1111_1111 ....
|
|
|
|
# so we only have to unset the most significant bit.
|
2018-10-25 10:58:40 +00:00
|
|
|
result.hi = high(type result.hi)
|
|
|
|
result.lo = high(type result.lo)
|
2018-04-25 17:51:14 +00:00
|
|
|
|
2018-10-25 10:58:40 +00:00
|
|
|
func low*[T, T2](_: typedesc[IntImpl[T, T2]]): IntImpl[T, T2] {.inline.}=
|
2018-04-25 17:51:14 +00:00
|
|
|
# The lowest signed int has representation
|
2018-04-30 11:38:55 +00:00
|
|
|
# 0b1000_0000_0000_0000 ....
|
|
|
|
# so we only have to set the most significant bit.
|
2018-10-25 10:58:40 +00:00
|
|
|
not high(IntImpl[T, T2])
|