Commit graph

38 commits

Author SHA1 Message Date
cinap_lenrek fc412aef3d 6c: extern registers must be considered used on return
the peephole optimizer would remove stores to extern
register before a return statement as it would think
they are only set, but not used.
2021-11-17 01:23:57 +00:00
cinap_lenrek 4fd09def0f kencc: revert back to "set but not used"
The change to "assignment not used" breaks symmetry with
"used and not set" and removes the reference to the
specific warning mentioned in /sys/doc/comp.ms.

Also, the patch was half-assed as that it left some typos
in like "used an not set", which this change also fixed.
2021-06-26 13:16:36 +00:00
Noam Preil 1a09421f7d kencc: clarify warning for unused assignments 2021-06-21 03:29:58 +00:00
cinap_lenrek 9de5aac7a2 5c, 6c, 7c, 8c, kc, qc, vc: use explicit gmove(... , nn) in cgen() for result of OAS*, OPREINC, OPOSTINC
The expression value of the assignment operation was
returned implicitely by relying on regalloc() on the
right hand side "nod" borrowing the register from nn.

But this only works if nn is a register.

In case of 6c, it can also be a ONAME from a .safe
rathole returned by regsalloc().

This change adds explicit gmove() calls to assign the
expression value. Note that gmove() checks if source
and destination are the same register so it wont emit
redundant move operations in the common case.

The same is applied also to OPREINC and OPOSTINC operations.
2021-03-13 13:56:40 +01:00
Ori Bernstein d52d7bc121 Backed out changeset 2737b9af622b
not what I wanted to commit.
2020-04-25 10:57:17 -07:00
Ori Bernstein 2de164c51d fix typos in time calculation
the results of the time calculation were garbled -- and
apparently negative on my system when testing, so the
test passed when it shouldn't have.
2020-04-25 10:43:39 -07:00
cinap_lenrek 34a1b1bb22 ?c: fix Bconv() misusage of strncat() 2020-04-19 04:33:07 +02:00
cinap_lenrek e6634fbd0c 6c: conserve registers for floating point operations
for floating point operations, reuse the return register
on the right hand side if it has higher complex number
than the left hand side to conserve registers.

this makes the following code compile, that was previously
run out of floating point register:

float
f(float r[15])
{
	return (r[0] + (r[1] * (r[2] + r[3] * (r[4] + r[5] * (r[6] + r[7] * (r[8] + r[9] * (r[10] + r[11] * (r[12] + r[13] * r[14]))))))));
}

the downside is that this produces extra move operations.
2020-04-19 01:25:35 +02:00
cinap_lenrek 49c159b50f 6c: remove mystery sys.c file 2020-04-11 05:19:11 +02:00
cinap_lenrek 1b8a569417 cc, ?[acl]: fix gethunk() and move common memory allocator code to cc/compat
for gethunk() to work, all allocators have to use it,
including allocations done by libc thru malloc(),
so the fake allocation functions are mandatory for
everyone.

to avoid duplication the code is moved to cc/compat
and prototypes provided in new cc/compat.h header.
2020-04-11 05:03:49 +02:00
cinap_lenrek 4cffc04364 8c, 6c: LEA x, R; MOV (R), R -> MOV x, R 2019-06-24 19:38:46 +02:00
cinap_lenrek 345714dd56 8c, 6c: avoid allocating index registers when we don't have to
when a operation receives a chain of OINDEX nodes as its operands,
each indexing step used to allocate a new index register. this
is wastefull an can result in running out of fixed registers on 386
for code such as: x = a[a[a[a[i]]]].

instead we attempt to reuse the destination register of the operation
as the index register if it is not otherwise referenced. this results
in the index chain to use a single register for index and result and
leaves registers free to be used for something usefull instead.

for 6c, try to avoid R13 as well as BP index base register.
2019-06-24 19:36:01 +02:00
cinap_lenrek 63191949b9 cc: remove nullwarn() from OCAST codegen, zap void casts
implicit casts would cause spurious "result of operation not used"
warnings such as ape's stdio putc() macro.

make (void) casts non-ops when the casted expression has no
side effects. this avoid spurious warning with ape's assert()
macro.
2019-06-19 23:50:33 +02:00
cinap_lenrek 3bb5168c6f 8c, 6c: fix INDEX node #reg calculation 2019-06-18 13:28:15 +02:00
cinap_lenrek 97a2f14b1c [5678vq]c: fix .safe node type for *FUNC() = *FUNC() sugen 2019-05-01 08:55:24 +02:00
spew 3d0ebdc439 6c, 8c: Fix nocast cast bug which prevents address arithmetic from being computed at compile time 2018-05-28 19:38:33 -04:00
spew 1ddf581f8c cc: fix result of operation not used warning for void casts 2018-05-24 19:31:55 -04:00
cinap_lenrek c67d0c699f 6c: reverse register allocation order to avoid having to spill AX,DX and CX
allocating AX,CX,DX last improves 64-bit multiplication-add
chains like a*b + c*d as the multiplication does not need to save
and restore AX and DX registers in most cases. reserving CX for
shifts also helps.
2017-01-08 17:41:10 +01:00
cinap_lenrek 19dc7c2097 6c, 8c: fix "DI botch" evacuating DI/SI/CX registers to ".save" variables 2017-01-02 05:49:18 +01:00
cinap_lenrek d41ca0d32c 6c: subsitute floating point registers eleminating MOVSD and MOVSS instructions in peephole pass 2016-08-14 18:52:18 +02:00
cinap_lenrek a00b6bdbfa 8c, 6c: native ROL (cyclic shift) instruction support, improve peephole optimizers
introduce rolor() function to subsitute (a << c) | (a >> (bits(a) - c))
with (a <<< c) where <<< is cyclic rotation and c is constant.
this almost doubles the speed of chacha encryption of 386 and amd64.

the peephole optimizer used to stop when it hit a shift or rol
instruction when attempting to eleminate moves by register
substitution. but we do not have to as long as the shift count
operand is not CX (which cannot be substituted) and CX is not
a subject for substitution.
2016-06-09 23:12:46 +02:00
cinap_lenrek 5cdabc5eb1 ?c: track ../cc/cc.h dependency and rebuild cc.a$O as neccesary 2016-06-09 23:03:30 +02:00
cinap_lenrek 2d59b15c39 5c/6c/8c/vc: import various changes from charles forsyth
- cover more cases that have no side effects
- ensure function has complex FNX
- pull operators out of OFUNC level
- rewrite OSTRUCT lhs to avoid all side-effects, use regalloc() instead of regret()
2015-10-06 06:20:01 +02:00
cinap_lenrek ec51877698 6c: remove 6c/vlrt.c file 2015-10-04 22:12:16 +02:00
cinap_lenrek bfd0cb0db4 cc/6c: fix return type of mixed asop expressions, preserve type for moves so fixed<->float conversions work correctly 2015-10-04 20:02:58 +02:00
cinap_lenrek f5f9ecdcfa 6c: MOVL xxx, r; MOVLQZX r, r -> MOVL xxx, r
eleminate MOVLQXZ instructions after MOVL as MOVL implicitely
zero extends the result.
2015-03-17 16:12:01 +01:00
cinap_lenrek 7cdc13accc 6c: fix missing memset in Bconv() 2015-03-01 05:33:41 +01:00
cinap_lenrek 0037c93433 6c: eleminate more MOV instructions
convert:

x = B || W
MOVxLZX a, r; MOVxQZX r, b -> MOVxQZX a, r; MOVQ r, b
MOVxLSX a, r; MOVxQSX r, r -> MOVxQSX a, r; MOVQ r, r

the MOVQ can then be eleminated by copy propagation.

improve subprop() by accepting other mov and lea
instructions as the source op.
2015-02-18 23:34:33 +01:00
cinap_lenrek 03feba8cc1 [125678kqv][cl]: fix sprint() and strcpy() buffer overflows 2015-02-17 22:13:35 +01:00
cinap_lenrek decc7ec518 6c/8c: eleminate moves by swaping source and destination operands in peephole pass 2014-09-24 20:45:16 +02:00
cinap_lenrek bc306a5a63 8c, 6c: generate enam.c file, just like 5c 2014-08-07 21:35:52 +02:00
Aram Hăvărneanu bf0d5c8abb 6a, 6c, 6l: fix copy propagation
Without an explicit signal for a truncation, copy propagation will
sometimes propagate a 32-bit truncation and end up overwriting uses of
the original 64-bit value.

This was independently discovered and fixed in Go. See:
	http://golang.org/issue/1315
	https://codereview.appspot.com/6002043/

Thanks Charles Forsyth for tips and advice.
2014-05-30 12:28:01 +02:00
cinap_lenrek 391198888a 8c, 6c: fix peephole bug for eleminating CMPL $0,R after shift
the shift instructions does not change the zero flag
when the shift count is 0, so we cannot remove the
compare instruction in this case.

this fixes oggdec under 386.
2014-04-28 22:53:50 +02:00
cinap_lenrek cde97a4d5f 6c, 8c: optimize away CMPL/CMPQ reg, $0 instruction in peephole pass
when the previous instruction sets the zero flag,
we can remove the CMPL/CMPQ instruction.
this removes compares for zero/non zero tests only.
it only looks at the previous non-nop instruction
to see if it sets our compare value register.
2014-03-29 19:44:04 +01:00
cinap_lenrek 393dfd1ced 8c, 6c: fix mulgen botch error for handling multiplication by zero constant 2014-03-21 19:05:17 +01:00
cinap_lenrek 03ae4fa162 6c: fix 32bit pointer truncation (from patch/6c-sugen-types)
1. Go group spotted that a slightly-obscured pointer move was done by AMOVL not AMOVQ.
2. Inspecting the code further, I noticed that other pointer types were set to TLONG not TIND,
   causing similar truncation of pointers to 32 bits.
2013-02-28 19:23:54 +01:00
cinap_lenrek 3ba213a9d7 6c: extern register fix (import from patch/6c-extreg)
to make it easy to use normal libraries (such as libdraw, libsec, and libmp)
with the kernel, which uses extern register, don't stray into the external
register set when allocating values to registers.
2012-09-18 18:18:43 +02:00
cinap_lenrek 4f33c88a51 import updated compilers from sources 2012-07-30 19:11:16 +02:00