Menu

#531 Algebraic optimization on masked xor

open
nobody
None
5
2017-07-16
2017-07-16
No

Let C be an integer constant. Then

(a & C) ^ (b & C) == (a ^ b) & C.

The latter requires one operation less (and has lower register pressure). SDCC should optimize the former into the latter.

I noticed this in a real world example of a checksum calculation routine, in the line

x16 = (unsigned char)((data & 1) ^ ((unsigned char)crc & 1));

Philipp

Related

Patches: #392
Wiki: SDCC 4.3.0 Release
Wiki: SDCC 4.4.0 Release
Wiki: SDCC 4.5.0 Release

Discussion


Log in to post a comment.