0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-10-10 00:25:06 -04:00
Commit Graph

30 Commits

Author SHA1 Message Date
H. Peter Anvin
c714d66d34 Fixes for JMP|CALL near, RETF, and segment instructions
Some weird things happened when macroizing.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-19 18:55:54 -07:00
H. Peter Anvin
a0396faf3b Fix control/debug register patterns
The control and debug registers are always using the default operand
size. It is probably easiest to just encode it explicitly for now.

Control registers are particularly weird because of the AMD "lock as
REX.R" hack...

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-19 16:26:35 -07:00
H. Peter Anvin
ca50adfb7d BR 3392957: 64-bit K registers allowed in non-64-bit mode
Do not force the operand size for K registers and "ko#"
encodings. This resolves BR 3392957.

Reported-by: ig <glucksmann@avast.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-19 13:39:26 -07:00
H. Peter Anvin
9aecb094a8 insns.dat: use explict macro flags for arithmetic flags
Instead of do more ad hoc hacks in preinsns.pl, add explicit macro
flags for the arithmetic instructions. This also allows folding CMP
back into the standard arithmetic instructions.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-19 12:28:07 -07:00
Maciej Wieczor-Retman
f0efb28d98 assemble: apx: Add NF forbidden flag and fix SBB and ADC
ADC and SBB don't support using the {nf} prefix. They are the only one
in the arithmetic instructions group that are this way.

Add a flag that will warn when an instructions wants to use {nf} but
doesnt' support it.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-19 14:53:04 +02:00
H. Peter Anvin
01cef66b23 insns.dat/preinsns.pl: fix the RORX, SHLX, SHRX, SARX patterns
These are subtle: RORX is only available in immediate shift count
form, whereas SHLX, SHRX and SARX are only available in register shift
count form...

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-13 20:44:53 -07:00
Maciej Wieczor-Retman
e30047b2ff x86: travis: apx: Fix IMUL 0x6B not being able to use EVEX.ZU
64bit and 32bit variant of the IMUL 0x6B instruction can't make use of
the zero-upper bit. It gets assembled normally. With equal operand size
this makes sense since 64 and 32 bit legacy behavior was the same as the
APX ZU one. But the 0x6B IMUL variant uses 8 bit immediate values as the
second operand, hence it should be able to make use of ZU for 32 and 64
bit registers too.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-05 11:05:57 +02:00
Maciej Wieczor-Retman
e91a81d780 x86: preinsns: Fix missing vex.w bits
Looks like the wwflag variable was set for both ww and w1 which caused
some VEX.W bits to not get set. Don't set the wwflag for w0 or w1 cases
in the script.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 08:40:28 +02:00
Maciej Wieczor-Retman
1b9c2f873d x86: Immediate operand longer than byte not possible
Due to ib in the apx arithmetic instruction preprocessed implementation
only byte size immediate operands were possible. Changing ib to i# fixes
the issue.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 08:40:28 +02:00
H. Peter Anvin
f2b6dd6f66 More KMOV pattern fixes
Work even more on KMOV size encodings.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2025-09-02 21:09:20 -07:00
H. Peter Anvin
6f42a3aaf6 (Hopefully) fix kmov and kunpck instructions, disallow "test" for "ktest"
Fix the handling of instruction patterns for KMOV and KUNPCK.
Don't allow K-less versions of KTEST and KORTEST because of
fundmentally different semantics.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-02 18:54:27 -07:00
H. Peter Anvin
c6bb32e9d1 preinsns.pl: don't allow KTEST to be just TEST
The semantics for KTEST are so very different from TEST that it would
be a bad idea to allow the TEST spelling.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-02 18:18:07 -07:00
H. Peter Anvin
49a56ea9ee Add optimization for operand narrowing; tidy up selector handling
Add a optimization frameword for operand narrowing (where the operand
size doesn't matter beyond a certain range because only certain bits
are referenced.)

Add a macro *and* matching facility for dealing with segment selectors, which are
typically rm16/r32/r64, but exactly how that is applied varies
depending on if a datum is read or written.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2024-08-23 02:25:21 -07:00
H. Peter Anvin
2b2f1fc98a More macroizing and sorting of instructions into categories
More work on cleaning up instruction patterns, fixing matchig corner
cases, and tidying up the organization of insns.dat.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2024-08-22 23:22:59 -07:00
H. Peter Anvin
e515dac43f More matching/macrofication work; now passes "make travis"
More matching and macrofication work.
Improve some error and warning messages.
Update some travis tests for better messages and added optimizations.

Fix duplicated warning messages for the same out-of-range value
problem.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2024-08-22 22:07:31 -07:00
H. Peter Anvin
58024b4611 insns: more instruction macroizing/fixups; remote FUTURE tags
Add more instruction macros and fix problems. Adjust some matching
problems.

Remove all FUTURE tags from the instruction list, and add a bunch of
new CPUID tags. Hopefully a small step toward actually getting CPU
feature selection working properly in the future.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-21 11:48:47 -07:00
H. Peter Anvin
75f6f4cdb2 WIP: more matching and template work
Further work on a better matching system. Still a work in progress,
however.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2024-08-20 12:59:07 -07:00
H. Peter Anvin
f114a6276e insns: more macroization and organization
Macroize and update more instruction patterns.

Begin organizing the instructions by functional groups.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-15 22:15:48 -07:00
H. Peter Anvin
8f97af7d71 insns: more macro fun; handle things like RET, RETW, RETD, RETQ
Add macro handling for patterns with a non-suffixed default operand
and alternative suffixed operands.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-15 19:23:33 -07:00
H. Peter Anvin
05f1b6b658 insns: sanitize the handling of "nw" and "osz"; fix more patterns
"nw" now means: 64-bit operand size is the default, o32 is not
permitted in 64-bit mode.

"osz" means: instruction size determined by prefixes, otherwise the
mode default.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-15 17:52:54 -07:00
H. Peter Anvin
fb74d63180 insns: macroize more instructions
Macroize a few more instructions, and add support for a few more types
of common instruction patterns.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-14 23:57:41 -07:00
H. Peter Anvin
8ee33d2734 insns: more macroized instructions and fix preprocessor bugs
Add more macroized instructions, and fix some bugs in the
instruction preprocessor.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-14 21:26:23 -07:00
H. Peter Anvin
557d99d796 insns: more macro goodness
Even better macro support, add match for the BX register.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-14 20:48:18 -07:00
H. Peter Anvin
1b136eb543 insns: use the pre-existing instruction flags handler for preinsns.pl
There is no reason to reinvent the wheel; reusing the existing code
will be cleaner anyway.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-14 16:45:09 -07:00
H. Peter Anvin
3d24dc6fb9 x86/preinsns.pl: use //g matching instead of split+grep
//g matching is a much better way to positively define tokens. Learn
something new every day!

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-12 02:44:54 -07:00
H. Peter Anvin
b205311fa2 x86/preinsns.pl: correctly handle quoted commas
Don't break a string on a quoted comma, for obvious reasons. Allow an
op argument to be quoted in general.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-12 02:06:54 -07:00
H. Peter Anvin
7ecc9c1f9c insns.dat: more macro feature improvements; now can generate shiftX
Add more improvements to the macro features. Now it is possible to
generate the -X versions of the shift instructions as part of the
macroization, which is highly desirable in order to allow them to be
generated using {nf} syntax.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-12 01:32:17 -07:00
H. Peter Anvin
d5f981e035 WIP: insns.dat: further improve macro facility; use for APX and shifts
Work more on the macro facility. Add the ability to kill an
instruction pattern based on expansion (if the token KILL appears.)
Add APX patterns to the arithmetic macro and macroize the shift and
rotate patterns.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-12 00:28:04 -07:00
H. Peter Anvin
4bb1bc8fe6 x86/preinsns.pl: make the macro facility more general
Make the macro facility in preinsns.pl more general, and relying less
on evaluating Perl constructs. This *might* be practical with some
more work, to move to a data file, but wait until we have a better
idea of the needs.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-11 23:12:25 -07:00
H. Peter Anvin
67339f6965 insns: rename addflags.pl to preinsns.pl; use insns.xda for doc
The former addflags.pl now does more general preprocessing, so rename
it from addflags.pl to preinsns.pl.

To generate the instruction list in the documentation, use the
post-preprocessed insns.xda file.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-11 21:34:02 -07:00