2018-04-25 21:21:25 +02:00
|
|
|
# Stint
|
2018-04-25 17:50:53 +02: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 22:29:08 +02:00
|
|
|
import ./datatypes, ./as_words
|
2018-04-25 17:50:53 +02:00
|
|
|
|
2018-05-06 22:29:08 +02:00
|
|
|
func `not`*(x: IntImpl): IntImpl {.inline.}=
|
2018-04-25 17:50:53 +02:00
|
|
|
## Bitwise complement of unsigned integer x
|
2018-09-06 12:35:12 +03:00
|
|
|
{.push experimental: "forLoopMacros".}
|
2018-06-18 12:54:25 +02:00
|
|
|
for wr, wx in asWords(result, x):
|
|
|
|
wr = not wx
|
2018-09-06 12:35:12 +03:00
|
|
|
{.pop.}
|
2018-04-25 17:50:53 +02:00
|
|
|
|
2018-05-06 22:29:08 +02:00
|
|
|
func `or`*(x, y: IntImpl): IntImpl {.inline.}=
|
2018-04-25 17:50:53 +02:00
|
|
|
## `Bitwise or` of numbers x and y
|
2018-09-06 12:35:12 +03:00
|
|
|
{.push experimental: "forLoopMacros".}
|
2018-06-18 12:54:25 +02:00
|
|
|
for wr, wx, wy in asWords(result, x, y):
|
|
|
|
wr = wx or wy
|
2018-09-06 12:35:12 +03:00
|
|
|
{.pop.}
|
2018-04-25 17:50:53 +02:00
|
|
|
|
2018-05-06 22:29:08 +02:00
|
|
|
func `and`*(x, y: IntImpl): IntImpl {.inline.}=
|
2018-04-25 17:50:53 +02:00
|
|
|
## `Bitwise and` of numbers x and y
|
2018-09-06 12:35:12 +03:00
|
|
|
{.push experimental: "forLoopMacros".}
|
2018-06-18 12:54:25 +02:00
|
|
|
for wr, wx, wy in asWords(result, x, y):
|
|
|
|
wr = wx and wy
|
2018-09-06 12:35:12 +03:00
|
|
|
{.pop.}
|
2018-04-25 17:50:53 +02:00
|
|
|
|
2018-05-06 22:29:08 +02:00
|
|
|
func `xor`*(x, y: IntImpl): IntImpl {.inline.}=
|
2018-04-25 17:50:53 +02:00
|
|
|
## `Bitwise xor` of numbers x and y
|
2018-09-06 12:35:12 +03:00
|
|
|
{.push experimental: "forLoopMacros".}
|
2018-06-18 12:54:25 +02:00
|
|
|
for wr, wx, wy in asWords(result, x, y):
|
|
|
|
wr = wx xor wy
|
2018-09-06 12:35:12 +03:00
|
|
|
{.pop.}
|