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

320 Commits

Author SHA1 Message Date
Maciej Wieczor-Retman
cbf714d742 travis: apx: OR instruction test cases
Tests similar to other arithmetic instructions.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-11 14:34:40 +02:00
Maciej Wieczor-Retman
55e25b12fe insns: travis: apx: NEG and NOT legacy fix and APX variant
Add test cases and the database entry for the NEG and NOT instructions.

Fix the 0xF7 variants not generating due to a missing hash sign after f6.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-11 14:23:22 +02:00
Maciej Wieczor-Retman
4d0d859dd0 insns: travis: apx: MULX instruction
Add the APX database entry and test cases.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-11 14:17:32 +02:00
Maciej Wieczor-Retman
a3acacc3ad insns: travis: apx: MUL instruction
Add test cases.

Modify what I assume is a typo in the MUL clone of IMUL 0x6B. It should
only use 8bit IMM operand but the preprocessor has i# specified which
would allow other sizes too.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-11 14:17:32 +02:00
Maciej Wieczor-Retman
ed290acf80 insns: travis: apx: APX MOVRS instruction
Add the APX database entry for MOVRS and relevant test cases.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-11 14:17:32 +02:00
H. Peter Anvin
fb54b25f66 insns.dat: fix MOVRS pattern
MOVRS is a pretty basic instruction; it uses the normal operand size
handling.

Fix apx.bin.t accordingly.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-05 18:02:52 -07:00
Maciej Wieczor-Retman
30eb8e2e2a insns: travis: apx: MOVRS instruction
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-05 23:25:42 +02:00
Maciej Wieczor-Retman
beaeb77bce insns: travis: apx: MOVDIR instructions
Add MOVDIR64B and MOVDIRI to the database. Add relevant testcases

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-05 23:25:20 +02:00
Maciej Wieczor-Retman
05a07b7ccf insns: travis: apx: MOVBE instruction
Add the database entry and test cases.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-05 21:44:57 +02:00
Maciej Wieczor-Retman
712095fffe insns: travis: apx: LZCNT instruction
Doesn't yet work with EGPRs.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-05 17:23:29 +02:00
Maciej Wieczor-Retman
ca85c1c3b5 insns: travis: apx: LDTILECFG instruction
Add database entry and test cases.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-05 16:02:58 +02:00
Maciej Wieczor-Retman
3b3a115754 travis: apx: Finish the KMOV test cases
Add remaining APX versions of the KMOV tests (kmovw - kmovq)

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-05 15:19:36 +02:00
Maciej Wieczor-Retman
1054b5aefc x86: Fix handling of the ko# specifier
KMOV opcodes of 0x90 and 0x91 have similar bits set in all size
implementations. .66 and .W1 for 32bit, and .NP and .W1 for 64 bits.

Correct my previous mistake where I swapped the VEX/EVEX.pp values by
accident.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-05 15:17:05 +02:00
Maciej Wieczor-Retman
fca408f86a travis: apx: Remove a TODO comment
The problems got fixed at 3.0rc0.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-05 11:10:38 +02: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
H. Peter Anvin
33262b072a Merge remote-tracking branch 'yongjie/apx.wip' into apx.wip 2025-09-05 01:02:52 -07:00
H. Peter Anvin
9a55314a23 travis: update tests for new or fixed errors/warnings
Some new warnings, some duplicate warnings removed.

The selfref test was broken because of mishandling of $ escaped
symbols; the new set of error messages are far more correct.

With all of this, travis now passes again.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-05 00:59:23 -07:00
H. Peter Anvin
084714737a travis: confirm that crc32 test now produces the correct output
The crc32 test now does produce the correct output one would expect
for running with optimized assembly.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-05 00:45:32 -07:00
H. Peter Anvin
5ddccd6d04 travis: update apx.bin.t
Update the apx.bin.t file, since it now produces the same output as it
does with -DSRC and -DBIN.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-04 23:58:35 -07:00
Maciej Wieczor-Retman
5d1deaffc3 WIP apx: KMOV instructions
Add KMOV APX variants to the database. Add relevant tests.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 23:35:14 +02:00
Maciej Wieczor-Retman
3387f868fd insns: travis: apx: INV instruction
Add INVPCI, INVEPT, INVVPID APX instruction variants to the database and
relevant tests.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 23:29:21 +02:00
Maciej Wieczor-Retman
cb453cba39 insns: travis: apx: INC instruction
Add INC test cases and the database entry.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 13:33:06 +02:00
Maciej Wieczor-Retman
6b137d5212 insns: travis: apx: IMUL instruction test cases and bug fix
Add the test cases for the IMUL instruction.

Fix the 0x6B database bug that used the same bit width of the immediate
operand as the other operands. Make it 8 bit wide, just like in the
legacy instruction.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 13:13:12 +02:00
Yongjie2017
6f3147b4ec add avx 10.2 instructions 2025-09-04 16:33:43 +08:00
Yongjie2017
e56130aeb5 add few missing avx10_1 instructions 2025-09-04 16:32:17 +08:00
Maciej Wieczor-Retman
1ebd820dfc insns: travis: apx: IDIV instruction
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 08:40:28 +02:00
Maciej Wieczor-Retman
d79e4bb93a insns: travis: apx: ENQCMD[S] instructions
Add enqcmd and enqcmds to the database.

Add relevant tests.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 08:40:28 +02:00
Maciej Wieczor-Retman
13b4160ec8 insns: travis: apx: DIV instruction
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 08:40:28 +02:00
Maciej Wieczor-Retman
74867b7750 insns: travis: apx: DEC instruction
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 08:40:28 +02:00
Maciej Wieczor-Retman
ca1228e0dd insns: travis: apx: CRC32 APX, cleanup and tests
Clean up CRC32 with $dq macro and add the APX variants.

Also add tests for legacy and APX variants.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 08:40:28 +02:00
Maciej Wieczor-Retman
bfb82694b7 insns: travis: apx: CMPccXADD instruction
Add CMPccXADD variant to the database with some basic testcases.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 08:40:28 +02:00
Maciej Wieczor-Retman
429f54a391 insns: travis: apx: CMOVcc instruction
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 08:40:28 +02:00
Maciej Wieczor-Retman
276b9d82b8 insns: travis: apx: Add APX extended bitmask instructions
Add APX variants of BLSI, BEXTR, BLSMSK, BLSR, BZHI.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 08:40:28 +02:00
Maciej Wieczor-Retman
75b5a4e1aa insns: travis: apx: ANDN instruction
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 08:40:28 +02:00
Maciej Wieczor-Retman
980238ae27 travis: apx: Tests for already implemted A* APX instructions
The ADD, ADC, ADCX, ADOX, AND instruction testcases.

Part of ADCX tests is commented out because addressing with R16-R31 is
currently bugged without some other mechanism indicating using the APX.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 08:40:28 +02:00
Maciej Wieczor-Retman
dc172d3f82 insns: travis: apx: APX support fo atomic instructions
Add the AOR instruction and use $bwdq macros on the other new atomic
instructions: AADD, AAND and AXOR.

Add tests.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 08:40:28 +02:00
Maciej Wieczor-Retman
89dfdc164c travis: apx: Setup test cases for apx
This json allows assembling the first column in the testcase macro when
updating the apx.bin.t file, and assembling the second column when
running the test.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-04 08:40:28 +02:00
H. Peter Anvin
83534f1f37 Merge remote-tracking branch 'origin/master' into apx.wip
Resolved Conflicts:
	Makefile.in
	Mkfiles/msvc.mak
	Mkfiles/openwcom.mak
	asm/assemble.c
	asm/nasm.c
	asm/parser.c
	doc/Makefile.in
	include/nasm.h
	include/tables.h
	output/legacy.c
	travis/test/br3392531.stderr
	travis/test/br3392716.stderr
	travis/test/org.stderr
	x86/insns.dat

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-25 21:09:15 -07:00
H. Peter Anvin
9f24de1034 parser: improve the "instruction expected" error messages
When throwing one of the "instruction expected" error messages, print
what was encountered instead.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-14 18:43:02 -07:00
H. Peter Anvin
e2ccd5de26 travis: remove obsolete error message about %unmacro
%unmacro now *is* permitted on a macro being expanded; the entire
expansion is strictly performed when the macro is invoked, and the
lifetime issue related to %unmacro and %exitrep has been hacked
around.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-13 13:57:59 -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
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
c9457d42a6 WIP checkpoint: more matching changes, starting to work on patterns
This is a WIP checkpoint; not all tests pass yet.

More matching changes, and hopefully something much closer to what
really is desired now. The number of required patterns is now much
smaller.

However, a lot of *changes* are needed to the patterns.

Since some patterns are repeated all over the place, clean up the
x86/addflags.pl script and make it able to generate macro-based
common patterns; first use being the patterns for the "basic 8"
arithmetic patterns.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-11 21:28:57 -07:00
H. Peter Anvin
bff94fbd39 Major changes to a number of subsystems to improve matching
Work through a number of changes toward making matching a lot saner,
both to reduce the number of patterns to generate for APX but also to
make a number of code patterns simpler.

This replaces a fair number of byte codes.

Improve a number of error messages, especially related to overflows.

Move process_insn() from nasm.c to assemble.c, as it really is the
primary entry point to the assembler module.

Reorder some prefixes. In particular, F2/F3 override 66 when used as a
mandatory prefix, so it makes more sense for them to be closer to the
opcode.

Move a lot more information into struct insn. It is better to have it
in one place; memory consumption is not an issue because struct insn
is transient information.

Get rid of "optimization levels" and replace it with a mask of
flags. That was already halfway done; complete the job.

Replace seg:offset in struct out_data with a struct location. It would
be better to extend this to more places, too.

The ARx and SMx flags are now explicit bitmasks, instead of having a
couple of hard-coded ranges.

Add __func__ to assert or panic messages.

Because of prefix and message changes, a number of travis tests had to
be audited and updated.

Fix a number of instruction patterns which had .128 when they ought to
be .lig. This is no longer a minor issue with the disassembler: for
AVX10, the pattern vector length determines how SAE/RC are encoded,
and there is no valid 128-bit encoding. However, with .lig the 512-bit
encoding can be used.

Separate "o64nw" into two pieces: opsize 64 and "nw" = "REX.w not necessary". The
latter can be included in non-64-bit patterns. "o64" still set REX.W
since that is still the common thing.

New "osz" bytecode: emit an OSP *or* REX.W depending on the current
mode and operand size. Useful for special cases like "nop" where "o64
nop" probably wants to be encoded as "48 90".

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-07 17:13:44 -07:00
H. Peter Anvin
1286a2da4e Tidy up handling of modr/m and compressed immediates
Merge a bunch of common code in the handling of modr/m
generation. Make the handing of compressed disp8 simpler and more
transparent by exporting a the shift factor for the compressed
immediate in ea_data. For the case of no compression, the shift factor
is simply 0; there is no need to distinguish "compressed" from
"uncompressed".

The tidied up version of the disp8 code is simple enough that it makes
more sense to inline it.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-03 16:24:49 -07:00
H. Peter Anvin
973fe19a1b WIP: apx: now can encode most instructions; handle subcases in EVEX
EVEX encoding is really messy, with the 4th register bit in one of
several places depending on which type of register it is. It seems to
work now.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-30 17:03:58 -07:00
H. Peter Anvin
e03b9325e2 parser: tidy up handling of prefixes; allow braced prefix after insn
Clean up the handling of prefixes in general. Allow a set of braced
prefixes to follow the instruction; this is required for things like
{dfv=} but might also be a nicer syntax for things like {rex}.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-24 13:09:36 -07:00
H. Peter Anvin
07cef15235 travis: update the warning message in hle.stderr
Nothing wrong, but the text of the warning message has changed after
subordinating it to another warning.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2023-10-13 20:54:56 -07:00
H. Peter Anvin
73676357de BR 3392906: error out on bad syntax "db 1 2"
NASM would try to "eat the comma token" in db expressions, even for
cases where the token was not a comma. Fix that and error out
properly.

To give better error messages, track where in the input string a token
starts or ends. This information is only valid as long as the input
string is kept, but that is just fine for error messages during
parsing.

Reported-by: Peter Cordes <pcordes@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2023-10-11 12:06:58 -07:00