1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-02 04:41:35 +00:00
Commit Graph

191 Commits

Author SHA1 Message Date
Colin Leroy-Mira
7d7cf2d1e0 Implement aslax7/shlax7/asrax7/shrax7 2024-01-29 07:59:11 +01:00
Colin Leroy-Mira
2a2cc6cad6 Fix bug introduced in #2260
bne should have applied to A, not X, but adding a cmp #$00 before
makes the change less optimized than the existing.
2023-12-09 16:43:23 +01:00
Colin Leroy-Mira
d8a3938f2b Optimize a bit static long assignation 2023-12-01 14:20:00 +01:00
Bob Andrews
86b09f56a6
Merge pull request #2260 from colinleroy/optimize-substraction
Optimize integer decrements by 1
2023-11-28 14:40:51 +01:00
Colin Leroy-Mira
3066b1f9b4 Optimize unsigned int and long > 255 2023-11-17 22:49:03 +01:00
Colin Leroy-Mira
9242508abf Optimize substraction of 1 2023-11-13 10:31:48 +01:00
Colin Leroy-Mira
cff611711b Optimize multiplication by zero 2023-11-06 11:04:00 +01:00
mrdudz
05c2530243 it should have been I64x, not I64u 2022-11-28 06:25:45 +01:00
mrdudz
b166dc4261 hopefully thats it 2022-11-18 18:19:31 +01:00
mrdudz
bbe8c62e9d coffee 2022-11-18 18:13:15 +01:00
mrdudz
a6feeac5ed or msvc I64u ? 2022-11-18 18:10:07 +01:00
mrdudz
ca94cfcbac that perhaps? 2022-11-18 18:03:40 +01:00
mrdudz
4c6fddd300 i want a cookie each time i do this 2022-11-18 17:58:12 +01:00
mrdudz
feb839e7f0 narrisch werd i! 2022-11-18 17:55:22 +01:00
mrdudz
8a9029d393 hnnngg 2022-11-18 17:50:32 +01:00
mrdudz
c6ecee0748 Babydino sagt: nochmal! 2022-11-18 17:45:21 +01:00
mrdudz
5fb20dec91 commit message 2022-11-18 17:41:22 +01:00
mrdudz
5638e0916a spül es noch einmal, Sam 2022-11-18 17:39:35 +01:00
acqn
3bcfa735cb clearer comments on and usage of code generator flags with type conversions in the primary register. 2022-11-13 14:57:48 +08:00
mrdudz
e5777f7ccf add ATTR_UNUSED on the flags variable 2022-11-05 20:38:07 +01:00
mrdudz
d371046ae4 Despite not technically needed, it seems to be desirable to remove all trailing whitespace from inline assembly 2022-08-28 03:43:02 +02:00
mrdudz
a6b807b1d8 more verbose comment 2022-07-14 22:39:29 +02:00
acqn
970607cde5 Optimized g_testbitfield() and g_extractbitfield() with enhanced support for long bit-fields. 2021-12-05 12:21:01 +08:00
nyanpasu64
9cb81f1410 Replace #include "inttypes.h" with <inttypes.h> 2022-03-06 14:48:51 -08:00
nyanpasu64
3466abc60c Fix format strings to properly format uintptr_t 2022-03-06 14:48:03 -08:00
nyanpasu64
f36b9b544d Fix segfault on 64-bit LLP64 Windows builds
There are many occurrences of unsigned long in codegen.h's function
arguments. Changing g_getimmed and g_defdata makes `make` succeed
without segfaulting. I don't know if it makes cc65 behave correctly in
all cases, or if there are more unsigned long that need to be changed.
2022-03-06 14:47:51 -08:00
Jeff Tranter
2bf8be5b3b Fix some commonly made spelling errors in comments. 2022-02-21 15:44:31 -05:00
acqn
004c60de39 Optional flags for the codegen to skip restoring the expression results into the primary registers. 2021-06-09 08:03:12 +02:00
acqn
b02838439c Changed g_addaddr_local() codegen to reduce code size. 2021-03-16 22:29:20 +01:00
acqn
047d0f479b Comments format fix. 2021-03-03 10:07:24 +01:00
Jesse Rosenstock
e0c12c90cd g_asr, g_asl: Use ROL/ROR for char shifts by >= 6
Instead of `val` right (left) shifts, we can also do `9 - val` left (right)
rotates and a mask.  This saves 3 bytes and 8 cycles for `val == 7` and
1 byte and 4 cycles for `val == 6`.
2020-12-27 14:22:40 -05:00
Jesse Rosenstock
dfd047ce6a g_typeadjust: Use CF_CHAR for char args
If lhs and rhs are either both signed char or both unsigned char,
return flags for that type instead of (unsigned) int.  The flags
are used only for codegen.  Currently, this does nothing, since
codegen treats chars as ints unless CF_FORCECHAR is set, but it
allows more efficient char x char -> int codegen to be added in
the future.
2020-12-24 14:40:39 -05:00
Greg King
2915464667 Fixed cc65's generation of char-type bit-shift code.
Fixed CHAR-to-INT type conversions in the right-shift code generator.  Also fixed some printf-style format specifiers.
2020-11-15 15:22:23 -05:00
Zsolt Branyiczky
b33b053307 add c64dtv support 2020-11-15 16:35:55 +01:00
Jesse Rosenstock
5db74b4b19 Use u16 codegen for u8 x u8 ops
In g_typeadjust, before we apply the integral promotions, we check if
both types are unsigned char.  If so, we promote to unsigned int, rather
than int, which would be chosen by the standard rules.  This is only a
performance optimization and does not affect correctness, as the flags
returned by g_typeadjust are only used for code generation, and not to
determine types of other expressions containing this one.  All unsigned
char bit-patterns are valid as both int and unsigned int and represent
the same value, so either signed or unsigned int operations can be used.
This special case part is not duplicated by ArithmeticConvert.

Partial fix for #1308.
2020-11-09 21:19:22 +01:00
acqn
e58c84acf7 Support for optionally specifying address size for segments with:
#pragma ***-name([push,] "name"[, "addrsize"])
where "addrsize" is any addressing size supported in ca65.
2020-10-11 23:05:20 +02:00
Greg King
81ac28ff71 Used TAY/TYA instead of PHA/PLA when extracting a bit-field.
Without optimization, it saves a few CPU cycles.  With optimization, it saves more cycles and a few bytes.
2020-09-22 12:47:09 -04:00
Greg King
bf4b195016 Added some comments that explain where the g_branch() code generator can and can't be used. 2020-09-18 15:50:26 -04:00
acqn
6b64b43395 Made local static data use a separated label pool from the code label pool. 2020-08-31 09:12:03 +02:00
acqn
9398e1cd33 Use a dedicated label pool for literals. 2020-08-31 09:12:03 +02:00
acqn
63256fd15d Changed negation of signed long stored in unsigned long to unsigned subtraction. 2020-08-21 23:16:17 +02:00
acqn
f59c2a08d9 Added support for changing multiplications with certain negative multipliers into bit-shifts. Only enable certain kinds of signed mul replacements with shift according to the code size factor settings. 2020-08-21 23:16:17 +02:00
acqn
ea7336591c Removed special-casing code for scaling up. Now it uses the normal multiplying code. 2020-08-21 23:16:17 +02:00
Greg King
36dd82f0e6 Added g_branch() to cc65's code generator.
It uses BRA if the platform's CPU has BRA.  Else, it generates a JMP.

(Used it in the bitfield sign-extending code.)
2020-08-18 19:11:18 -04:00
Jesse Rosenstock
ff535b8e1a Treat signed int bit-fields as signed
Prior to this PR, `int`, `signed int`, and `unsigned int`
bitfields are all treated as `unsigned int`.

With this PR, `signed int` will be treated as `signed int`,
and the others remain unsigned.

Since `Type` does not distinguish between `int` and `signed int`,
add an extra `int* SignenessSpecified` param to `ParseTypeSpec`
so we can tell these apart for bit-fields and treat plain `int : N`
as `unsigned int : N` since it is more efficient to zero-extend
than sign-extend.

Fixes #1095
2020-08-18 12:23:20 +02:00
Jesse Rosenstock
55cebc7b9e Move bit-field adjustment to codegen.c
Extract functions g_testbitfield and g_extractbitfield from LoadExpr.

This helps prepare for #1192, since g_extractbitfield will get much
longer and call AddCodeLine.
2020-08-18 10:55:31 +02:00
Jesse Rosenstock
c4698dfd07 Use C89 semantics for integer conversions
Previously, the following rules were used for binary operators:
* If one of the values is a long, the result is long.
* If one of the values is unsigned, the result is also unsigned.
* Otherwise the result is an int.

C89 specifies the "usual arithmetic conversions" as:
* The integral promotions are performed on both operands.
* Then the following rules are applied:
  * If either operand has type unsigned long int, the other operand is
    converted to unsigned long int.
  * Otherwise, if one operand has type long int and the other has type
    unsigned int, if a long int can represent all values of an unsigned int,
    the operand of type unsigned int is converted to long int; if a long int
    cannot represent all the values of an unsigned int, both operands are
    converted to unsigned long int.
  * Otherwise, if either operand has type long int, the other operand is
    converted to long int.
  * Otherwise, if either operand has type unsigned int, the other operand is
    converted to unsigned int.
  * Otherwise, both operands have type int.
https://port70.net/~nsz/c/c89/c89-draft.html#3.2.1.5

As one example, these rules give a different result for an operator
with one long operand and one unsigned int operand.  Previously,
the result type was unsigned long.  With C89 semantics, it is just long,
since long can represent all unsigned ints.

Integral promotions convert types shorter than int to int (or unsigned int).
Both char and unsigned char are promoted to int since int can represent
all unsigned chars.
https://port70.net/~nsz/c/c89/c89-draft.html#3.2.1.1

Rename promoteint to ArithmeticConvert, since this is more accurate.

Fixes #170
2020-08-15 19:14:31 +02:00
acqn
2ab7272673 Improved warning on comparison of unsigned type < 0. 2020-08-02 23:51:11 +02:00
acqn
d23b577331 More compiler flags on address types to match the location types of expressions. 2020-07-18 12:54:29 +02:00
acqn
2108489523 Fix for Issue #1075 and #1077. 2020-07-18 12:54:29 +02:00