<!--
	Assembler Encoding for the Negative Mnemonic
	Version: 1.0.0
	Date Created:  2007-04-06
	Last Modified: 2007-05-25

	Designed for Pentium and higher x86 Processors in 32bit mode protected mode
	Optimized for speed

	Done list:
	o U/S8-256,Boolean
	o EndRegs for all applicable operations
-->
<encoding procfamily="x86" bitdepth="32" proc="P1">
	<!-- ############################################################################################################ -->
	<!-- ############################################################################################################ -->
	<!-- ############################################################################################################ -->
	<!-- Negative Mnemonic -->
	<mnemonic name="Negative" type="Unary" option="Speed">
		<!-- ********************************************************************************************************** -->
		<!-- 8bit values -->
		<codetypeset param0="U/S8">
			<codeset param0="M" total="3" endpipe="V">
				<line code="neg @0" time="&#45;&#45;3" comment="Negate the value" />
			</codeset>

			<codeset param0="R" total="1" endpipe="V" startpipe="U">
				<line code="neg @0" time="&#45;&#45;1" comment="Negate the value" />
			</codeset>
			<codeset param0="R" total="1" endpipe="U" startpipe="V">
				<line code="xor @0, -1" time=" V1" comment="Swap the value's bits" />
				<line code="inc @0"     time="U 1" comment="Increment, essentially negating the value" />
			</codeset>
		</codetypeset>



		<!-- ********************************************************************************************************** -->
		<!-- 16bit values -->
		<codetypeset param0="U/S16">
			<codeset param0="M" total="4" endpipe="V">
				<line code="neg @0" time="&#45;&#45;3+1" comment="Negate the value" />
			</codeset>

			<codeset param0="R" total="2" endpipe="V">
				<line code="neg @0" time="&#45;&#45;1+1" comment="Negate the value" />
			</codeset>
		</codetypeset>



		<!-- ********************************************************************************************************** -->
		<!-- 24bit values -->
		<codetypeset param0="U/S24">
			<codeset param0="M" total="8" totalv="7"
				lostregs="ax,dl" endregs="al=@0.U8[1],ah=@0.U8[2],dl=@0.U8" endpipe="U">
				<line code="mov al, @0.U8[1]" time="U 1" timev=" V1" comment="Get the second byte" />
				<line code="mov dl, @0.U8"    time="U*1"             comment="Get the first byte" />
				<line code="xor al, -1"       time=" V1"             comment="Swap the second byte's bits" />
				<line code="xor dl, -1"       time="U 1"             comment="Swap the first byte's bits" />
				<line code="mov ah, @0.U8[2]" time=" V1"             comment="Get the third byte" />
				<line code="xor ah, -1"       time="U 1"             comment="Swap the third byte's bits" />
				<line code="add dl, 1"        time=" V1"             comment="Increment to negate the first byte" />
				<line code="adc ax, 0"        time="U!1+1"           comment="Add with carry to the second and third byte" />
				<line code="mov @0.U8, dl"    time=" V1"             comment="Store the first byte" />
				<line code="mov @0.U8[1], al" time="U 1"             comment="Store the second byte" />
				<line code="mov @0.U8[2], ah" time="U*1"             comment="Store the third byte" />
			</codeset>

			<codeset param0="R" param0type="U24" total="3" totalv="2" endpipe="U">
				<line code="xor @0.U32, -1"       time="U 1" timev=" V1" comment="Negate the 24bits only" />
				<line code="inc @0.U32"           time="U*1" timev="U 1" comment="Increment to negate" />
				<line code="and @0.U32, 0FFFFFFh" time="U*1"             comment="Clear the high byte" />
			</codeset>
			<codeset param0="R" param0type="S24" total="1" endpipe="U">
				<line code="neg @0.U32" time="&#45;&#45;1" comment="Negate the value" />
			</codeset>
		</codetypeset>



		<!-- ********************************************************************************************************** -->
		<!-- 32bit values -->
		<codetypeset param0="U/S32">
			<codeset param0="M" total="3" endpipe="V">
				<line code="neg @0" time="&#45;&#45;3" comment="Negate the value" />
			</codeset>

			<codeset param0="R" total="1" endpipe="V">
				<line code="neg @0" time="&#45;&#45;1" comment="Negate the value" />
			</codeset>
		</codetypeset>



		<!-- ********************************************************************************************************** -->
		<!-- 48bit values -->
		<codetypeset param0="U/S48">
			<codeset param0="M" total="7" totalv="7"
				lostregs="eax,edx" endregs="eax=@0.U32,dx=@0.U16[2]" endpipe="U">
				<line code="xor edx, edx"      time="U 1"   timev=" V1"   comment="Clear to zero" />
				<line code="mov eax, @0.U32"   time=" V1"   timev="U 1"   comment="Get the low 32 bits" />
				<line code="mov dx, @0.U16[2]" time="U 1+1" timev=" V1+1" comment="Get the high 16 bits" />
				<line code="xor eax, -1"       time=" V1"   timev="U 1"   comment="NOT the low 32 bits" />
				<line code="xor edx, -1"       time="U 1"   timev=" V1"   comment="NOT the high 16 bits" />
				<line code="add eax, 1"        time=" V1"   timev="U 1"   comment="Add 1 to complete the negative" />
				<line code="adc edx, 0"        time="U!1"                 comment="Add with carry to the high 16 bits" />
				<line code="mov @0.U32, eax"   time=" V1"                 comment="Store the low 32 bits" />
				<line code="mov @0.U16[2], dx" time="U 1+1"               comment="Store the high 16 bits" />
			</codeset>

			<codeset param0="R" param0type="U48" total="4" totalv="3" endpipe="U">
				<line code="xor @0.U32, -1"        time="U 1" timev=" V1" comment="NOT the low 32 bits" />
				<line code="xor @0.U32[1], -1"     time=" V1" timev="U 1" comment="NOT the high 32 bits" />
				<line code="add @0.U32, 1"         time="U 1" timev=" V1" comment="Add 1 to complete the negative" />
				<line code="adc @0.U32[1], 0"      time="U!1"             comment="Add with carry to the high 32 bits" />
				<line code="and @0.U32[1], 0FFFFh" time="U*1"             comment="Clear the high 16 bits" />
			</codeset>
			<codeset param0="R" param0type="S48" total="3" totalv="2" endpipe="U">
				<line code="xor @0.U32, -1"        time="U 1" timev=" V1" comment="NOT the low 32 bits" />
				<line code="xor @0.U32[1], -1"     time=" V1" timev="U 1" comment="NOT the high 32 bits" />
				<line code="add @0.U32, 1"         time="U 1" timev=" V1" comment="Add 1 to complete the negative" />
				<line code="adc @0.U32[1], 0"      time="U!1"             comment="Add with carry to the high 32 bits" />
			</codeset>
		</codetypeset>



		<!-- ********************************************************************************************************** -->
		<!-- 64bit values -->
		<codetypeset param0="U/S64">
			<codeset param0="M" total="5" totalv="4"
				lostregs="eax,edx" endregs="eax=@0.U32,edx=@0.U32[1]" endpipe="U">
				<line code="mov eax, @0.U32"    time="U 1" timev=" V1" comment="Get the low 32 bits" />
				<line code="mov edx, @0.U32[1]" time=" V1" timev="U 1" comment="Get the high 32 bits" />
				<line code="xor eax, -1"        time="U 1" timev=" V1" comment="NOT the low 32 bits" />
				<line code="xor edx, -1"        time=" V1" timev="U 1" comment="NOT the high 32 bits" />
				<line code="add eax, 1"         time="U 1" timev=" V1" comment="Add 1 to complete the negative" />
				<line code="adc edx, 0"         time="U!1"             comment="Add with carry to the high 32 bits" />
				<line code="mov @0.U32, eax"    time=" V1"             comment="Store the low dword" />
				<line code="mov @0.U32[1], edx" time="U 1"             comment="Store the high dword" />
			</codeset>

			<codeset param0="R" total="3" totalv="2" endpipe="U">
				<line code="xor @0.U32, -1"    time="U 1" timev=" V1" comment="NOT the low 32 bits" />
				<line code="xor @0.U32[1], -1" time=" V1" timev="U 1" comment="NOT the high 32 bits" />
				<line code="add @0.U32, 1"     time="U 1" timev=" V1" comment="Add 1 to complete the negative" />
				<line code="adc @0.U32[1], 0"  time="U!1"             comment="Add with carry to the high 32 bits" />
			</codeset>
		</codetypeset>



		<!-- ********************************************************************************************************** -->
		<!-- 128bit values -->
		<codetypeset param0="U/S128">
			<codeset param0="M" total="10" totalv="9"
				lostregs="eax,edx" endregs="eax=@0.U32[2],edx=@0.U32[3]" endpipe="U">
				<line code="mov eax, @0.U32"    time="U 1" timev=" V1" comment="Get the low 32 bits" />
				<line code="mov edx, @0.U32[1]" time=" V1" timev="U 1" comment="Get the second 32 bits" />
				<line code="xor eax, -1"        time="U 1" timev=" V1" comment="NOT the low 32 bits" />
				<line code="xor edx, -1"        time=" V1" timev="U 1" comment="NOT the second 32 bits" />
				<line code="add eax, 1"         time="U 1" timev=" V1" comment="Add 1 to complete the negative" />
				<line code="adc edx, 0"         time="U!1"             comment="Add with carry to the second 32 bits" />
				<line code="mov @0.U32, eax"    time=" V1"             comment="Store the low 32 bits" />
				<line code="mov @0.U32[1], edx" time="U 1"             comment="Store the second 32 bits" />

				<line code="mov eax, @0.U32[2]" time=" V1"             comment="Get the third 32 bits" />
				<line code="not eax"            time="&#45;&#45;1"     comment="NOT the third 32 bits" />
				<line code="adc eax, 0"         time="U!1"             comment="Add with carry to the third 32 bits" />
				<line code="mov edx, @0.U32[3]" time=" V1"             comment="Get the high 32 bits" />
				<line code="not edx"            time="&#45;&#45;1"     comment="NOT the high 32 bits" />
				<line code="adc edx, 0"         time="U!1"             comment="Add with carry to the high 32 bits" />
				<line code="mov @0.U32[2], eax" time=" V1"             comment="Store the third 32 bits" />
				<line code="mov @0.U32[3], edx" time="U 1"             comment="Store the high 32 bits" />
			</codeset>

			<codeset param0="R" total="6" totalv="5" endpipe="U">
				<line code="xor @0.U32, -1"    time="U 1" timev=" V1" comment="NOT the low 32 bits" />
				<line code="xor @0.U32[1], -1" time=" V1" timev="U 1" comment="NOT the second 32 bits" />
				<line code="xor @0.U32[2], -1" time="U 1" timev=" V1" comment="NOT the third 32 bits" />
				<line code="xor @0.U32[3], -1" time=" V1" timev="U 1" comment="NOT the high 32 bits" />
				<line code="add @0.U32, 1"     time="U 1" timev=" V1" comment="Add 1 to complete the negative" />
				<line code="adc @0.U32[1], 0"  time="U!1"             comment="Add with carry to the second 32 bits" />
				<line code="adc @0.U32[2], 0"  time="U!1"             comment="Add with carry to the third 32 bits" />
				<line code="adc @0.U32[3], 0"  time="U!1"             comment="Add with carry to the fourth 32 bits" />
			</codeset>
		</codetypeset>



		<!-- ********************************************************************************************************** -->
		<!-- 256bit values -->
		<codetypeset param0="U/S256">
			<codeset param0="M" total="20" totalv="19"
				lostregs="eax,edx" endregs="eax=@0.U32[6],edx=@0.U32[7]" endpipe="U">
				<line code="mov eax, @0.U32"    time="U 1" timev=" V1" comment="Get the low 32 bits" />
				<line code="mov edx, @0.U32[1]" time=" V1" timev="U 1" comment="Get the second 32 bits" />
				<line code="xor eax, -1"        time="U 1" timev=" V1" comment="NOT the low 32 bits" />
				<line code="xor edx, -1"        time=" V1" timev="U 1" comment="NOT the second 32 bits" />
				<line code="add eax, 1"         time="U 1" timev=" V1" comment="Add 1 to complete the negative" />
				<line code="adc edx, 0"         time="U!1"             comment="Add with carry to the second 32 bits" />
				<line code="mov @0.U32, eax"    time=" V1"             comment="Store the low 32 bits" />
				<line code="mov @0.U32[1], edx" time="U 1"             comment="Store the second 32 bits" />

				<line code="mov eax, @0.U32[2]" time=" V1"             comment="Get the third 32 bits" />
				<line code="not eax"            time="&#45;&#45;1"     comment="NOT the third 32 bits" />
				<line code="adc eax, 0"         time="U!1"             comment="Add with carry to the third 32 bits" />
				<line code="mov edx, @0.U32[3]" time=" V1"             comment="Get the fourth 32 bits" />
				<line code="not edx"            time="&#45;&#45;1"     comment="NOT the fourth 32 bits" />
				<line code="adc edx, 0"         time="U!1"             comment="Add with carry to the fourth 32 bits" />
				<line code="mov @0.U32[2], eax" time=" V1"             comment="Store the third 32 bits" />
				<line code="mov @0.U32[3], edx" time="U 1"             comment="Store the fourth 32 bits" />

				<line code="mov eax, @0.U32[4]" time=" V1"             comment="Get the fifth 32 bits" />
				<line code="not eax"            time="&#45;&#45;1"     comment="NOT the fifth 32 bits" />
				<line code="adc eax, 0"         time="U!1"             comment="Add with carry to the fifth 32 bits" />
				<line code="mov edx, @0.U32[5]" time=" V1"             comment="Get the sixth 32 bits" />
				<line code="not edx"            time="&#45;&#45;1"     comment="NOT the sixth 32 bits" />
				<line code="adc edx, 0"         time="U!1"             comment="Add with carry to the sixth 32 bits" />
				<line code="mov @0.U32[4], eax" time=" V1"             comment="Store the fifth 32 bits" />
				<line code="mov @0.U32[5], edx" time="U 1"             comment="Store the sixth 32 bits" />

				<line code="mov eax, @0.U32[6]" time=" V1"             comment="Get the seventh 32 bits" />
				<line code="not eax"            time="&#45;&#45;1"     comment="NOT the seventh 32 bits" />
				<line code="adc eax, 0"         time="U!1"             comment="Add with carry to the seventh 32 bits" />
				<line code="mov edx, @0.U32[7]" time=" V1"             comment="Get the high 32 bits" />
				<line code="not edx"            time="&#45;&#45;1"     comment="NOT the high 32 bits" />
				<line code="adc edx, 0"         time="U!1"             comment="Add with carry to the high 32 bits" />
				<line code="mov @0.U32[6], eax" time=" V1"             comment="Store the seventh 32 bits" />
				<line code="mov @0.U32[7], edx" time="U 1"             comment="Store the high 32 bits" />
			</codeset>

			<codeset param0="R" total="12" totalv="11" endpipe="U">
				<line code="xor @0.U32, -1"    time="U 1" timev=" V1" comment="Swap the low dword's bits" />
				<line code="xor @0.U32[1], -1" time=" V1" timev="U 1" comment="Swap the second dword's bits" />
				<line code="xor @0.U32[2], -1" time="U 1" timev=" V1" comment="Swap the third dword's bits" />
				<line code="xor @0.U32[3], -1" time=" V1" timev="U 1" comment="Swap the fourth dword's bits" />
				<line code="xor @0.U32[4], -1" time="U 1" timev=" V1" comment="Swap the fifth dword's bits" />
				<line code="xor @0.U32[5], -1" time=" V1" timev="U 1" comment="Swap the sixth dword's bits" />
				<line code="xor @0.U32[6], -1" time="U 1" timev=" V1" comment="Swap the seventh dword's bits" />
				<line code="xor @0.U32[7], -1" time=" V1" timev="U 1" comment="Swap the high dword's bits" />

				<line code="add @0.U32, 1"     time="U 1" timev=" V1" comment="Add 1 to complete the negative" />
				<line code="adc @0.U32[1], 0"  time="U!1"             comment="Add with carry to the second 32 bits" />
				<line code="adc @0.U32[2], 0"  time="U!1"             comment="Add with carry to the third 32 bits" />
				<line code="adc @0.U32[3], 0"  time="U!1"             comment="Add with carry to the fourth 32 bits" />
				<line code="adc @0.U32[4], 0"  time="U!1"             comment="Add with carry to the fifth 32 bits" />
				<line code="adc @0.U32[5], 0"  time="U!1"             comment="Add with carry to the sixth 32 bits" />
				<line code="adc @0.U32[6], 0"  time="U!1"             comment="Add with carry to the seventh 32 bits" />
				<line code="adc @0.U32[7], 0"  time="U!1"             comment="Add with carry to the eighth 32 bits" />
			</codeset>
		</codetypeset>



		<!-- ********************************************************************************************************** -->
		<!-- Boolean -->
		<codetypeset param0="Boolean">
			<codeset param0="M,R" total="0" endpipe="-">
				<!-- Do nothing... negating a boolean would cause it to become the same value it was already -->
			</codeset>
		</codetypeset>
	</mnemonic>
</encoding>
