rgbds icon indicating copy to clipboard operation
rgbds copied to clipboard

Operations that always have the same value can be assembly-time constant

Open Rangi42 opened this issue 3 years ago • 5 comments

  • Foo * 0 is always 0
  • Foo & 0 is always 0
  • Foo - Foo is always 0
  • Foo ^ Foo is always 0

These could be constant even when Foo is floating and unaligned.

Rangi42 avatar Feb 05 '22 18:02 Rangi42

  • Foo + ~Foo and Foo | ~Foo are always -1
  • Foo + -Foo is always 0
  • Foo * 1 is always Foo; Foo * -1 is always -Foo (helps reducing into the other cases)

...and so on

aaaaaa123456789 avatar Feb 05 '22 18:02 aaaaaa123456789

Reducing those will prove very difficult, however. (And time-consuming if the comparison strategy is to compare the RPN buffers.)

ISSOtm avatar Feb 05 '22 19:02 ISSOtm

I see what you mean, assuming Foo can be literally any expression, not just a symbol. In that case only expr * 0 and expr & 0 would be feasible.

Rangi42 avatar Feb 05 '22 19:02 Rangi42

And besides, I have considered those a long time ago, but I think they are too fringe to be worth special-casing. #965 made sense to be able to poll for alignment, but I can't see use cases for these.

ISSOtm avatar Feb 05 '22 19:02 ISSOtm

And besides, I have considered those a long time ago, but I think they are too fringe to be worth special-casing. #965 made sense to be able to poll for alignment, but I can't see use cases for these.

The best use case I can think of is !cond * val0 + !!cond * val1 as a cheap inline conditional. (Yes, I know, true conditional expressions are coming someday, but someday is far away.)

aaaaaa123456789 avatar Feb 05 '22 20:02 aaaaaa123456789

Base the implementation for expr * 0 and expr & 0 on #976.

Rangi42 avatar Aug 27 '22 19:08 Rangi42

Closing as not worth the complexity.

Rangi42 avatar Aug 28 '22 18:08 Rangi42