mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-19 11:23:46 +00:00
Compile-time evaluation of `int' operations previously required that the target have the same number of bits per int as the host compiler. In other cases, the user would have to pass `--cross-compiling' to avoid the compiler silently producing a different result at compile time to what would be produced at run time. This change makes the compiler aware of the target's `int' width when evaluating operations at compile-time. Passing `--cross-compiling' is no longer required to avoid the problems that this change addresses, but it MAY still be required for other reasons. As of now, the one problem it would avoid is generating incorrect trie string switches containing non-ASCII strings when targeting a high-level C grade from a compiler built in Java or C# grades (not really supported, but something we can fix anyway). I have not removed any references to the `--cross-compiling' option in the documentation. compiler/libs.m: compiler/int_emu.m: Add new module to emulate `int' operations for the target bits-per-int. The predicates will only succeed if the result would be well-defined (including no overflow), and the result fits in the host's `int' type (no truncation). compiler/const_prop.m: Evaluate `int' operations at compile time using `int_emu' predicates. Delete now unnecessary checks for cross_compiling=no. Delete comment about checking for overflow, now done. compiler/simplify_goal_call.m: Use the target's value of bits-per-int in relevant simplifications. Delete check for cross_compiling=no. compiler/handle_options.m: Don't imply `--cross-compiling' when targeting java, csharp and erlang grades. This was a temporary workaround in case the Mercury compiler itself uses 64-bit ints. tests/hard_coded/Mercury.options: tests/hard_coded/Mmakefile: tests/hard_coded/constant_prop_int.exp: tests/hard_coded/constant_prop_int.exp2: tests/hard_coded/constant_prop_int.m: Add test case. compiler/notes/compiler_design.html: Document new module.
410 lines
12 KiB
Plaintext
410 lines
12 KiB
Plaintext
plus(1, 0) = 1
|
|
plus(1, 1) = 2
|
|
plus(1, -1) = 0
|
|
plus(1, 31) = 32
|
|
plus(1, -31) = -30
|
|
plus(1, 2147483647) = -2147483648
|
|
plus(1, -2147483648) = -2147483647
|
|
plus(-1, 0) = -1
|
|
plus(-1, 1) = 0
|
|
plus(-1, -1) = -2
|
|
plus(-1, 31) = 30
|
|
plus(-1, -31) = -32
|
|
plus(-1, 2147483647) = 2147483646
|
|
plus(-1, -2147483648) = 2147483647
|
|
plus(31, 0) = 31
|
|
plus(31, 1) = 32
|
|
plus(31, -1) = 30
|
|
plus(31, 31) = 62
|
|
plus(31, -31) = 0
|
|
plus(31, 2147483647) = -2147483618
|
|
plus(31, -2147483648) = -2147483617
|
|
plus(-31, 0) = -31
|
|
plus(-31, 1) = -30
|
|
plus(-31, -1) = -32
|
|
plus(-31, 31) = 0
|
|
plus(-31, -31) = -62
|
|
plus(-31, 2147483647) = 2147483616
|
|
plus(-31, -2147483648) = 2147483617
|
|
plus(2147483647, 0) = 2147483647
|
|
plus(2147483647, 1) = -2147483648
|
|
plus(2147483647, -1) = 2147483646
|
|
plus(2147483647, 31) = -2147483618
|
|
plus(2147483647, -31) = 2147483616
|
|
plus(2147483647, 2147483647) = -2
|
|
plus(2147483647, -2147483648) = -1
|
|
plus(-2147483648, 0) = -2147483648
|
|
plus(-2147483648, 1) = -2147483647
|
|
plus(-2147483648, -1) = 2147483647
|
|
plus(-2147483648, 31) = -2147483617
|
|
plus(-2147483648, -31) = 2147483617
|
|
plus(-2147483648, 2147483647) = -1
|
|
plus(-2147483648, -2147483648) = 0
|
|
|
|
minus(1, 0) = 1
|
|
minus(1, 1) = 0
|
|
minus(1, -1) = 2
|
|
minus(1, 31) = -30
|
|
minus(1, -31) = 32
|
|
minus(1, 2147483647) = -2147483646
|
|
minus(1, -2147483648) = -2147483647
|
|
minus(-1, 0) = -1
|
|
minus(-1, 1) = -2
|
|
minus(-1, -1) = 0
|
|
minus(-1, 31) = -32
|
|
minus(-1, -31) = 30
|
|
minus(-1, 2147483647) = -2147483648
|
|
minus(-1, -2147483648) = 2147483647
|
|
minus(31, 0) = 31
|
|
minus(31, 1) = 30
|
|
minus(31, -1) = 32
|
|
minus(31, 31) = 0
|
|
minus(31, -31) = 62
|
|
minus(31, 2147483647) = -2147483616
|
|
minus(31, -2147483648) = -2147483617
|
|
minus(-31, 0) = -31
|
|
minus(-31, 1) = -32
|
|
minus(-31, -1) = -30
|
|
minus(-31, 31) = -62
|
|
minus(-31, -31) = 0
|
|
minus(-31, 2147483647) = 2147483618
|
|
minus(-31, -2147483648) = 2147483617
|
|
minus(2147483647, 0) = 2147483647
|
|
minus(2147483647, 1) = 2147483646
|
|
minus(2147483647, -1) = -2147483648
|
|
minus(2147483647, 31) = 2147483616
|
|
minus(2147483647, -31) = -2147483618
|
|
minus(2147483647, 2147483647) = 0
|
|
minus(2147483647, -2147483648) = -1
|
|
minus(-2147483648, 0) = -2147483648
|
|
minus(-2147483648, 1) = 2147483647
|
|
minus(-2147483648, -1) = -2147483647
|
|
minus(-2147483648, 31) = 2147483617
|
|
minus(-2147483648, -31) = -2147483617
|
|
minus(-2147483648, 2147483647) = 1
|
|
minus(-2147483648, -2147483648) = 0
|
|
|
|
times(1, 0) = 0
|
|
times(1, 1) = 1
|
|
times(1, -1) = -1
|
|
times(1, 31) = 31
|
|
times(1, -31) = -31
|
|
times(1, 2147483647) = 2147483647
|
|
times(1, -2147483648) = -2147483648
|
|
times(-1, 0) = 0
|
|
times(-1, 1) = -1
|
|
times(-1, -1) = 1
|
|
times(-1, 31) = -31
|
|
times(-1, -31) = 31
|
|
times(-1, 2147483647) = -2147483647
|
|
times(-1, -2147483648) = -2147483648
|
|
times(31, 0) = 0
|
|
times(31, 1) = 31
|
|
times(31, -1) = -31
|
|
times(31, 31) = 961
|
|
times(31, -31) = -961
|
|
times(31, 2147483647) = 2147483617
|
|
times(31, -2147483648) = -2147483648
|
|
times(-31, 0) = 0
|
|
times(-31, 1) = -31
|
|
times(-31, -1) = 31
|
|
times(-31, 31) = -961
|
|
times(-31, -31) = 961
|
|
times(-31, 2147483647) = -2147483617
|
|
times(-31, -2147483648) = -2147483648
|
|
times(2147483647, 0) = 0
|
|
times(2147483647, 1) = 2147483647
|
|
times(2147483647, -1) = -2147483647
|
|
times(2147483647, 31) = 2147483617
|
|
times(2147483647, -31) = -2147483617
|
|
times(2147483647, 2147483647) = 1
|
|
times(2147483647, -2147483648) = -2147483648
|
|
times(-2147483648, 0) = 0
|
|
times(-2147483648, 1) = -2147483648
|
|
times(-2147483648, -1) = -2147483648
|
|
times(-2147483648, 31) = -2147483648
|
|
times(-2147483648, -31) = -2147483648
|
|
times(-2147483648, 2147483647) = -2147483648
|
|
times(-2147483648, -2147483648) = 0
|
|
|
|
quotient(1, 1) = 1
|
|
quotient(1, -1) = -1
|
|
quotient(1, 31) = 0
|
|
quotient(1, -31) = 0
|
|
quotient(1, 2147483647) = 0
|
|
quotient(1, -2147483648) = 0
|
|
quotient(-1, 1) = -1
|
|
quotient(-1, -1) = 1
|
|
quotient(-1, 31) = 0
|
|
quotient(-1, -31) = 0
|
|
quotient(-1, 2147483647) = 0
|
|
quotient(-1, -2147483648) = 0
|
|
quotient(31, 1) = 31
|
|
quotient(31, -1) = -31
|
|
quotient(31, 31) = 1
|
|
quotient(31, -31) = -1
|
|
quotient(31, 2147483647) = 0
|
|
quotient(31, -2147483648) = 0
|
|
quotient(-31, 1) = -31
|
|
quotient(-31, -1) = 31
|
|
quotient(-31, 31) = -1
|
|
quotient(-31, -31) = 1
|
|
quotient(-31, 2147483647) = 0
|
|
quotient(-31, -2147483648) = 0
|
|
quotient(2147483647, 1) = 2147483647
|
|
quotient(2147483647, -1) = -2147483647
|
|
quotient(2147483647, 31) = 69273666
|
|
quotient(2147483647, -31) = -69273666
|
|
quotient(2147483647, 2147483647) = 1
|
|
quotient(2147483647, -2147483648) = 0
|
|
quotient(-2147483648, 1) = -2147483648
|
|
quotient(-2147483648, 31) = -69273666
|
|
quotient(-2147483648, -31) = 69273666
|
|
quotient(-2147483648, 2147483647) = -1
|
|
quotient(-2147483648, -2147483648) = 1
|
|
|
|
unchecked_quotient(1, 1) = 1
|
|
unchecked_quotient(1, -1) = -1
|
|
unchecked_quotient(1, 31) = 0
|
|
unchecked_quotient(1, -31) = 0
|
|
unchecked_quotient(1, 2147483647) = 0
|
|
unchecked_quotient(1, -2147483648) = 0
|
|
unchecked_quotient(-1, 1) = -1
|
|
unchecked_quotient(-1, -1) = 1
|
|
unchecked_quotient(-1, 31) = 0
|
|
unchecked_quotient(-1, -31) = 0
|
|
unchecked_quotient(-1, 2147483647) = 0
|
|
unchecked_quotient(-1, -2147483648) = 0
|
|
unchecked_quotient(31, 1) = 31
|
|
unchecked_quotient(31, -1) = -31
|
|
unchecked_quotient(31, 31) = 1
|
|
unchecked_quotient(31, -31) = -1
|
|
unchecked_quotient(31, 2147483647) = 0
|
|
unchecked_quotient(31, -2147483648) = 0
|
|
unchecked_quotient(-31, 1) = -31
|
|
unchecked_quotient(-31, -1) = 31
|
|
unchecked_quotient(-31, 31) = -1
|
|
unchecked_quotient(-31, -31) = 1
|
|
unchecked_quotient(-31, 2147483647) = 0
|
|
unchecked_quotient(-31, -2147483648) = 0
|
|
unchecked_quotient(2147483647, 1) = 2147483647
|
|
unchecked_quotient(2147483647, -1) = -2147483647
|
|
unchecked_quotient(2147483647, 31) = 69273666
|
|
unchecked_quotient(2147483647, -31) = -69273666
|
|
unchecked_quotient(2147483647, 2147483647) = 1
|
|
unchecked_quotient(2147483647, -2147483648) = 0
|
|
unchecked_quotient(-2147483648, 1) = -2147483648
|
|
unchecked_quotient(-2147483648, 31) = -69273666
|
|
unchecked_quotient(-2147483648, -31) = 69273666
|
|
unchecked_quotient(-2147483648, 2147483647) = -1
|
|
unchecked_quotient(-2147483648, -2147483648) = 1
|
|
|
|
mod(1, 1) = 0
|
|
mod(1, -1) = 0
|
|
mod(1, 31) = 1
|
|
mod(1, -31) = -30
|
|
mod(1, 2147483647) = 1
|
|
mod(1, -2147483648) = -2147483647
|
|
mod(-1, 1) = 0
|
|
mod(-1, -1) = 0
|
|
mod(-1, 31) = 30
|
|
mod(-1, -31) = -1
|
|
mod(-1, 2147483647) = 2147483646
|
|
mod(-1, -2147483648) = -1
|
|
mod(31, 1) = 0
|
|
mod(31, -1) = 0
|
|
mod(31, 31) = 0
|
|
mod(31, -31) = 0
|
|
mod(31, 2147483647) = 31
|
|
mod(31, -2147483648) = -2147483617
|
|
mod(-31, 1) = 0
|
|
mod(-31, -1) = 0
|
|
mod(-31, 31) = 0
|
|
mod(-31, -31) = 0
|
|
mod(-31, 2147483647) = 2147483616
|
|
mod(-31, -2147483648) = -31
|
|
mod(2147483647, 1) = 0
|
|
mod(2147483647, -1) = 0
|
|
mod(2147483647, 31) = 1
|
|
mod(2147483647, -31) = -30
|
|
mod(2147483647, 2147483647) = 0
|
|
mod(2147483647, -2147483648) = -1
|
|
mod(-2147483648, 1) = 0
|
|
mod(-2147483648, 31) = 29
|
|
mod(-2147483648, -31) = -2
|
|
mod(-2147483648, 2147483647) = 2147483646
|
|
mod(-2147483648, -2147483648) = 0
|
|
|
|
rem(1, 1) = 0
|
|
rem(1, -1) = 0
|
|
rem(1, 31) = 1
|
|
rem(1, -31) = 1
|
|
rem(1, 2147483647) = 1
|
|
rem(1, -2147483648) = 1
|
|
rem(-1, 1) = 0
|
|
rem(-1, -1) = 0
|
|
rem(-1, 31) = -1
|
|
rem(-1, -31) = -1
|
|
rem(-1, 2147483647) = -1
|
|
rem(-1, -2147483648) = -1
|
|
rem(31, 1) = 0
|
|
rem(31, -1) = 0
|
|
rem(31, 31) = 0
|
|
rem(31, -31) = 0
|
|
rem(31, 2147483647) = 31
|
|
rem(31, -2147483648) = 31
|
|
rem(-31, 1) = 0
|
|
rem(-31, -1) = 0
|
|
rem(-31, 31) = 0
|
|
rem(-31, -31) = 0
|
|
rem(-31, 2147483647) = -31
|
|
rem(-31, -2147483648) = -31
|
|
rem(2147483647, 1) = 0
|
|
rem(2147483647, -1) = 0
|
|
rem(2147483647, 31) = 1
|
|
rem(2147483647, -31) = 1
|
|
rem(2147483647, 2147483647) = 0
|
|
rem(2147483647, -2147483648) = 2147483647
|
|
rem(-2147483648, 1) = 0
|
|
rem(-2147483648, 31) = -2
|
|
rem(-2147483648, -31) = -2
|
|
rem(-2147483648, 2147483647) = -1
|
|
rem(-2147483648, -2147483648) = 0
|
|
|
|
unchecked_rem(1, 1) = 0
|
|
unchecked_rem(1, -1) = 0
|
|
unchecked_rem(1, 31) = 1
|
|
unchecked_rem(1, -31) = 1
|
|
unchecked_rem(1, 2147483647) = 1
|
|
unchecked_rem(1, -2147483648) = 1
|
|
unchecked_rem(-1, 1) = 0
|
|
unchecked_rem(-1, -1) = 0
|
|
unchecked_rem(-1, 31) = -1
|
|
unchecked_rem(-1, -31) = -1
|
|
unchecked_rem(-1, 2147483647) = -1
|
|
unchecked_rem(-1, -2147483648) = -1
|
|
unchecked_rem(31, 1) = 0
|
|
unchecked_rem(31, -1) = 0
|
|
unchecked_rem(31, 31) = 0
|
|
unchecked_rem(31, -31) = 0
|
|
unchecked_rem(31, 2147483647) = 31
|
|
unchecked_rem(31, -2147483648) = 31
|
|
unchecked_rem(-31, 1) = 0
|
|
unchecked_rem(-31, -1) = 0
|
|
unchecked_rem(-31, 31) = 0
|
|
unchecked_rem(-31, -31) = 0
|
|
unchecked_rem(-31, 2147483647) = -31
|
|
unchecked_rem(-31, -2147483648) = -31
|
|
unchecked_rem(2147483647, 1) = 0
|
|
unchecked_rem(2147483647, -1) = 0
|
|
unchecked_rem(2147483647, 31) = 1
|
|
unchecked_rem(2147483647, -31) = 1
|
|
unchecked_rem(2147483647, 2147483647) = 0
|
|
unchecked_rem(2147483647, -2147483648) = 2147483647
|
|
unchecked_rem(-2147483648, 1) = 0
|
|
unchecked_rem(-2147483648, 31) = -2
|
|
unchecked_rem(-2147483648, -31) = -2
|
|
unchecked_rem(-2147483648, 2147483647) = -1
|
|
unchecked_rem(-2147483648, -2147483648) = 0
|
|
|
|
left_shift(1, 0) = 1
|
|
left_shift(1, 1) = 2
|
|
left_shift(1, -1) = 0
|
|
left_shift(1, 31) = -2147483648
|
|
left_shift(1, -31) = 0
|
|
left_shift(-1, 0) = -1
|
|
left_shift(-1, 1) = -2
|
|
left_shift(-1, -1) = -1
|
|
left_shift(-1, 31) = -2147483648
|
|
left_shift(-1, -31) = -1
|
|
left_shift(31, 0) = 31
|
|
left_shift(31, 1) = 62
|
|
left_shift(31, -1) = 15
|
|
left_shift(31, 31) = -2147483648
|
|
left_shift(31, -31) = 0
|
|
left_shift(-31, 0) = -31
|
|
left_shift(-31, 1) = -62
|
|
left_shift(-31, -1) = -16
|
|
left_shift(-31, 31) = -2147483648
|
|
left_shift(-31, -31) = -1
|
|
left_shift(2147483647, 0) = 2147483647
|
|
left_shift(2147483647, 1) = -2
|
|
left_shift(2147483647, -1) = 1073741823
|
|
left_shift(2147483647, 31) = -2147483648
|
|
left_shift(2147483647, -31) = 0
|
|
left_shift(-2147483648, 0) = -2147483648
|
|
left_shift(-2147483648, 1) = 0
|
|
left_shift(-2147483648, -1) = -1073741824
|
|
left_shift(-2147483648, 31) = 0
|
|
left_shift(-2147483648, -31) = -1
|
|
|
|
unchecked_left_shift(1, 0) = 1
|
|
unchecked_left_shift(1, 1) = 2
|
|
unchecked_left_shift(1, 31) = -2147483648
|
|
unchecked_left_shift(-1, 0) = -1
|
|
unchecked_left_shift(-1, 1) = -2
|
|
unchecked_left_shift(-1, 31) = -2147483648
|
|
unchecked_left_shift(31, 0) = 31
|
|
unchecked_left_shift(31, 1) = 62
|
|
unchecked_left_shift(31, 31) = -2147483648
|
|
unchecked_left_shift(-31, 0) = -31
|
|
unchecked_left_shift(-31, 1) = -62
|
|
unchecked_left_shift(-31, 31) = -2147483648
|
|
unchecked_left_shift(2147483647, 0) = 2147483647
|
|
unchecked_left_shift(2147483647, 1) = -2
|
|
unchecked_left_shift(2147483647, 31) = -2147483648
|
|
unchecked_left_shift(-2147483648, 0) = -2147483648
|
|
unchecked_left_shift(-2147483648, 1) = 0
|
|
unchecked_left_shift(-2147483648, 31) = 0
|
|
|
|
right_shift(1, 0) = 1
|
|
right_shift(1, 1) = 0
|
|
right_shift(1, -1) = 2
|
|
right_shift(1, 31) = 0
|
|
right_shift(1, -31) = -2147483648
|
|
right_shift(-1, 0) = -1
|
|
right_shift(-1, 1) = -1
|
|
right_shift(-1, -1) = -2
|
|
right_shift(-1, 31) = -1
|
|
right_shift(-1, -31) = -2147483648
|
|
right_shift(31, 0) = 31
|
|
right_shift(31, 1) = 15
|
|
right_shift(31, -1) = 62
|
|
right_shift(31, 31) = 0
|
|
right_shift(31, -31) = -2147483648
|
|
right_shift(-31, 0) = -31
|
|
right_shift(-31, 1) = -16
|
|
right_shift(-31, -1) = -62
|
|
right_shift(-31, 31) = -1
|
|
right_shift(-31, -31) = -2147483648
|
|
right_shift(2147483647, 0) = 2147483647
|
|
right_shift(2147483647, 1) = 1073741823
|
|
right_shift(2147483647, -1) = -2
|
|
right_shift(2147483647, 31) = 0
|
|
right_shift(2147483647, -31) = -2147483648
|
|
right_shift(-2147483648, 0) = -2147483648
|
|
right_shift(-2147483648, 1) = -1073741824
|
|
right_shift(-2147483648, -1) = 0
|
|
right_shift(-2147483648, 31) = -1
|
|
right_shift(-2147483648, -31) = 0
|
|
|
|
unchecked_right_shift(1, 0) = 1
|
|
unchecked_right_shift(1, 1) = 0
|
|
unchecked_right_shift(1, 31) = 0
|
|
unchecked_right_shift(-1, 0) = -1
|
|
unchecked_right_shift(-1, 1) = -1
|
|
unchecked_right_shift(-1, 31) = -1
|
|
unchecked_right_shift(31, 0) = 31
|
|
unchecked_right_shift(31, 1) = 15
|
|
unchecked_right_shift(31, 31) = 0
|
|
unchecked_right_shift(-31, 0) = -31
|
|
unchecked_right_shift(-31, 1) = -16
|
|
unchecked_right_shift(-31, 31) = -1
|
|
unchecked_right_shift(2147483647, 0) = 2147483647
|
|
unchecked_right_shift(2147483647, 1) = 1073741823
|
|
unchecked_right_shift(2147483647, 31) = 0
|
|
unchecked_right_shift(-2147483648, 0) = -2147483648
|
|
unchecked_right_shift(-2147483648, 1) = -1073741824
|
|
unchecked_right_shift(-2147483648, 31) = -1
|
|
|