mirror of
https://github.com/cc65/cc65.git
synced 2024-06-24 18:28:53 +00:00
Merge pull request #2252 from colinleroy/optimize-multiply-by-zero
Optimize multiplication by zero
This commit is contained in:
commit
d7d1d89698
|
@ -2726,7 +2726,12 @@ void g_mul (unsigned flags, unsigned long val)
|
||||||
if (flags & CF_FORCECHAR) {
|
if (flags & CF_FORCECHAR) {
|
||||||
/* Handle some special cases */
|
/* Handle some special cases */
|
||||||
switch (val) {
|
switch (val) {
|
||||||
|
case 0:
|
||||||
|
AddCodeLine ("lda #$00");
|
||||||
|
return;
|
||||||
|
case 1:
|
||||||
|
/* Nothing to do */
|
||||||
|
return;
|
||||||
case 3:
|
case 3:
|
||||||
AddCodeLine ("sta tmp1");
|
AddCodeLine ("sta tmp1");
|
||||||
AddCodeLine ("asl a");
|
AddCodeLine ("asl a");
|
||||||
|
@ -2764,6 +2769,13 @@ void g_mul (unsigned flags, unsigned long val)
|
||||||
|
|
||||||
case CF_INT:
|
case CF_INT:
|
||||||
switch (val) {
|
switch (val) {
|
||||||
|
case 0:
|
||||||
|
AddCodeLine ("lda #$00");
|
||||||
|
AddCodeLine ("tax");
|
||||||
|
return;
|
||||||
|
case 1:
|
||||||
|
/* Nothing to do */
|
||||||
|
return;
|
||||||
case 3:
|
case 3:
|
||||||
AddCodeLine ("jsr mulax3");
|
AddCodeLine ("jsr mulax3");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -55,6 +55,7 @@ void m3(unsigned char uc)
|
||||||
/* testing literal multiply with same source and destination */
|
/* testing literal multiply with same source and destination */
|
||||||
vuc = uc;
|
vuc = uc;
|
||||||
uc2 = 0;
|
uc2 = 0;
|
||||||
|
uc1 = vuc; uc1 = uc1*0; if( uc1 != 0 ) failures++;
|
||||||
uc1 = vuc; uc1 = uc1*1; if( uc1 != (uc2+=TESTLIT) ) failures++;
|
uc1 = vuc; uc1 = uc1*1; if( uc1 != (uc2+=TESTLIT) ) failures++;
|
||||||
uc1 = vuc; uc1 = uc1*2; if( uc1 != (uc2+=TESTLIT) ) failures++;
|
uc1 = vuc; uc1 = uc1*2; if( uc1 != (uc2+=TESTLIT) ) failures++;
|
||||||
uc1 = vuc; uc1 = uc1*3; if( uc1 != (uc2+=TESTLIT) ) failures++;
|
uc1 = vuc; uc1 = uc1*3; if( uc1 != (uc2+=TESTLIT) ) failures++;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user