<commit_before>'''Binary arithmetic instructions.'''


from transf import parse
from machine.pentium.common import *


parse.Transfs('''


AddFlags(size, op1, op2, res) =
	![
		<ZeroFlag(size, res)>,
		<NegativeFlag(size, res)>,
		Assign(Bool, <cf>,
			Binary(Or(Bool),
				Binary(And(Bool),<HsbOne(size,op1)>,<HsbOne(size,op2)>),
				Binary(And(Bool),
					<HsbZero(size,res)>,
					Binary(Or(Bool),<HsbOne(size,op1)>,<HsbOne(size,op2)>)
				)
			)
		),
		Assign(Bool, <of>,
			Binary(Or(Bool),
				Binary(And(Bool),
					Binary(And(Bool),<Negative(size,op1)>,<Negative(size,op2)>),
					<NonNegative(size,res)>
				),
				Binary(And(Bool),
					Binary(And(Bool),<NonNegative(size,op1)>,<NonNegative(size,op2)>),
					<Negative(size,res)>
				)
			)
		)
	]

SubFlags(size, op1, op2, res) =
	![
		<ZeroFlag(size, res)>,
		<NegativeFlag(size, res)>,
		Assign(Bool, <cf>,
			Binary(Or(Bool),
				Binary(And(Bool),<HsbZero(size,op1)>,<HsbOne(size,op2)>),
				Binary(And(Bool),
					<HsbZero(size,res)>,
					Binary(Or(Bool),<HsbZero(size,op1)>,<HsbOne(size,op2)>)
				)
			)
		),
		Assign(Bool, <of>,
			Binary(Or(Bool),
				Binary(And(Bool),
					Binary(And(Bool),<NonNegative(size,op1)>,<Negative(size,op2)>),
					<NonNegative(size,res)>
				),
				Binary(And(Bool),
					Binary(And(Bool),<Negative(size,op1)>,<NonNegative(size,op2)>),
					<Negative(size,res)>
				)
			)
		)
	]

AsmAdd(size) =
		[dst, src] -> [
			Assign(type, tmp, dst),
			Assign(type, dst, Binary(Plus(type), dst, src)),
			*<AddFlags(size, !tmp, !src, !dst)>
		]
	where
		type := Word(size) ;
		tmp := temp


asmADDB = AsmAdd(!8)
asmADDW = AsmAdd(!16)
asmADDL = AsmAdd(!32)


AsmADC(size) =
		[dst, src] -> [
			Assign(type, tmp, dst),
			Assign(type, dst,
				Binary(Plus(type),dst,
					Binary(Plus(type),src,
						Cond(<cf>,Lit(type,1),Lit(type,0))))),
			*<AddFlags(size, !tmp, !src, !dst)>
		]
	where
		type := Word(size) ;
		tmp := temp


asmADCB = AsmADC(!8)
asmADCW = AsmADC(!16)
asmADCL = AsmADC(!32)


AsmSub(size) =
		[dst, src] -> [
			Assign(type, tmp, dst),
			Assign(type, dst,
				Binary(Minus(type),dst,
					Binary(Plus(type),src,
						Cond(<cf>,Lit(type,1),Lit(type,0))))),
			*<SubFlags(size, !tmp, !src, !dst)>
		]
	where
		type := Word(size) ;
		tmp := temp

asmSUBB = AsmSub(!8)
asmSUBW = AsmSub(!16)
asmSUBL = AsmSub(!32)


AsmSBB(size) =
		[dst, src] -> [
			Assign(type, tmp, dst),
			Assign(type, dst, Binary(Minus(type), dst, src)),
			*<SubFlags(size, !tmp, !src, !dst)>
		]
	where
		type := Word(size) ;
		tmp := temp

asmSBBB = AsmSBB(!8)
asmSBBW = AsmSBB(!16)
asmSBBL = AsmSBB(!32)<commit_msg>Fix typo.<commit_after>'''Binary arithmetic instructions.'''


from transf import parse
from machine.pentium.common import *


parse.Transfs('''


AddFlags(size, op1, op2, res) =
	![
		<ZeroFlag(size, res)>,
		<NegativeFlag(size, res)>,
		Assign(Bool, <cf>,
			Binary(Or(Bool),
				Binary(And(Bool),<HsbOne(size,op1)>,<HsbOne(size,op2)>),
				Binary(And(Bool),
					<HsbZero(size,res)>,
					Binary(Or(Bool),<HsbOne(size,op1)>,<HsbOne(size,op2)>)
				)
			)
		),
		Assign(Bool, <of>,
			Binary(Or(Bool),
				Binary(And(Bool),
					Binary(And(Bool),<Negative(size,op1)>,<Negative(size,op2)>),
					<NonNegative(size,res)>
				),
				Binary(And(Bool),
					Binary(And(Bool),<NonNegative(size,op1)>,<NonNegative(size,op2)>),
					<Negative(size,res)>
				)
			)
		)
	]

SubFlags(size, op1, op2, res) =
	![
		<ZeroFlag(size, res)>,
		<NegativeFlag(size, res)>,
		Assign(Bool, <cf>,
			Binary(Or(Bool),
				Binary(And(Bool),<HsbZero(size,op1)>,<HsbOne(size,op2)>),
				Binary(And(Bool),
					<HsbZero(size,res)>,
					Binary(Or(Bool),<HsbZero(size,op1)>,<HsbOne(size,op2)>)
				)
			)
		),
		Assign(Bool, <of>,
			Binary(Or(Bool),
				Binary(And(Bool),
					Binary(And(Bool),<NonNegative(size,op1)>,<Negative(size,op2)>),
					<NonNegative(size,res)>
				),
				Binary(And(Bool),
					Binary(And(Bool),<Negative(size,op1)>,<NonNegative(size,op2)>),
					<Negative(size,res)>
				)
			)
		)
	]

AsmAdd(size) =
		[dst, src] -> [
			Assign(type, tmp, dst),
			Assign(type, dst, Binary(Plus(type), dst, src)),
			*<AddFlags(size, !tmp, !src, !dst)>
		]
	where
		type := Word(size) ;
		tmp := temp


asmADDB = AsmAdd(!8)
asmADDW = AsmAdd(!16)
asmADDL = AsmAdd(!32)


AsmADC(size) =
		[dst, src] -> [
			Assign(type, tmp, dst),
			Assign(type, dst,
				Binary(Plus(type),dst,
					Binary(Plus(type),src,
						Cond(<cf>,Lit(type,1),Lit(type,0))))),
			*<AddFlags(size, !tmp, !src, !dst)>
		]
	where
		type := Word(size) ;
		tmp := temp


asmADCB = AsmADC(!8)
asmADCW = AsmADC(!16)
asmADCL = AsmADC(!32)


AsmSub(size) =
		[dst, src] -> [
			Assign(type, tmp, dst),
			Assign(type, dst, Binary(Minus(type), dst, src)),
			*<SubFlags(size, !tmp, !src, !dst)>
		]
	where
		type := Word(size) ;
		tmp := temp

asmSUBB = AsmSub(!8)
asmSUBW = AsmSub(!16)
asmSUBL = AsmSub(!32)


AsmSBB(size) =
		[dst, src] -> [
			Assign(type, tmp, dst),
			Assign(type, dst,
				Binary(Minus(type),dst,
					Binary(Plus(type),src,
						Cond(<cf>,Lit(type,1),Lit(type,0))))),
			*<SubFlags(size, !tmp, !src, !dst)>
		]
	where
		type := Word(size) ;
		tmp := temp

asmSBBB = AsmSBB(!8)
asmSBBW = AsmSBB(!16)
asmSBBL = AsmSBB(!32)
{'fraction_non_alphanumeric': 0.21728252501924558, 'fraction_numerical': 0.016936104695919937, 'mean_word_length': 3.9732057416267943, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '484339', 'n_tokens_mistral': 2673, 'n_tokens_neox': 2225, 'n_words': 326}