Commit Graph

171 Commits

Author SHA1 Message Date
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
acqn 85e73e91f8 Only enable signed div replacements with shift according to the code size factor settings.
Also with better comments.
2020-07-09 10:00:50 +02:00
acqn 09bcff0862 Added support for changing divisions by negative power-of-2 denominators into bit shifts,
and fixed #169 including the case of -2147483648 which is negative but appears positive.
2020-07-09 10:00:50 +02:00
acqn 30835e3d9d More optimized codegen for the correct cases of the Issue #169 fix. 2020-07-09 10:00:50 +02:00
acqn e98fe04cc2 Almost fixed Issue #169. The only denominator not working right now is -2147483648. 2020-07-09 10:00:50 +02:00
acqn f9204e5b6f Fixed g_addlocal codegen with long types. 2020-06-01 22:37:40 +02:00
Christian Groessler 58484449b4 remove TABs 2019-02-05 23:27:52 +01:00
Oliver Schmidt 88d1d20cd0
Minor style adjustment. 2018-10-02 18:53:01 +02:00
laubzega 2ac2ffcd43 Adjust SP on gotos between blocks with local variables. 2018-10-02 18:49:53 +02:00
Greg King c67e90dd19 Changed the type of a compiler variable that holds either integers or pointers.
The change allows cc65 to be compiled on 64-bit Windows, without getting warnings.  That OS is actually 32 bits with 64-bit pointers.  Its pointers are "long long" instead of "long".  The change uses type-names that are configured for the actual pointer width.
2018-01-09 05:34:16 -05:00
Piotr Fusik c0812670c1 Fix coding style. 2017-06-30 07:35:21 +02:00
Piotr Fusik b31ae57be1 Make some arrays const. 2017-06-28 20:43:31 +02:00
Greg King 8d5717b57a Small optimization of some cc65-generated loops.
"bne" means also branch-on-not-zero.  Therefore, this optimization doesn't put a compare-to-zero between an increment and a "bne".
2016-05-24 15:52:12 -04:00
Piotr Fusik 8c1f12f06b Fix casting an r-value to char.
For example:
int f(int i, int j) { return (char) (i + 1) == j; }
f(0x1234, 0x35) returned 0.

This bug caused zlib/uncompress return Z_DATA_ERROR on correct input.
2014-09-22 23:47:20 +02:00
Greg King 0390c34e88 Changed multi-line C comments into another style.
The left side doesn't look unbalanced.
2014-06-30 16:51:07 -04:00
Oliver Schmidt 4185caf855 Normalized code. 2014-03-04 01:11:19 +01:00
Oliver Schmidt 85885001b1 Removed (pretty inconsistently used) tab chars from source code base. 2013-05-09 13:57:12 +02:00
uz e6aa00b339 Reorder CF_xxx flags so that they can be used as table index.
git-svn-id: svn://svn.cc65.org/cc65/trunk@5990 b7a2c559-68d2-44c3-8de9-860c34a00d81
2013-03-06 12:53:07 +00:00
uz fa69f31982 Don't emit special code because it doesn't work well with the optimizer.
git-svn-id: svn://svn.cc65.org/cc65/trunk@5689 b7a2c559-68d2-44c3-8de9-860c34a00d81
2012-06-06 21:52:09 +00:00
uz 4a92522c82 In the generated assembly file, add import statements for all zero page
variables known by the runtime. They aren't currently accessed by the compiler
itself but may be useful for inline assembly.


git-svn-id: svn://svn.cc65.org/cc65/trunk@4891 b7a2c559-68d2-44c3-8de9-860c34a00d81
2010-12-29 10:18:29 +00:00
uz 6b3e515573 Reverted part of change 4108 that prevented an optimization step to find
proper replacements. Some other rearrangements for slightly better code.


git-svn-id: svn://svn.cc65.org/cc65/trunk@4640 b7a2c559-68d2-44c3-8de9-860c34a00d81
2010-04-10 11:23:39 +00:00