Commits

Boolsheet  committed 3609071

Slightly improved the performance of the AND, OR, and XOR functions.

  • Participants
  • Parent commits 3ecc36d

Comments (0)

Files changed (1)

 ]]
 --[[
 
-	Some functions that do bitwise operations in pure lua.
-	They assume unsigned 32-bit integers for all parameters.
-
-	AND, OR and XOR are unrolled into one big statement because it seems to be
-	one of the faster ways to do this operation. This probably depends on how
-	Lua was compiled and on what system it is running on.
+	AND, OR, XOR, NOT, shift and rotate bitwise operations in pure lua.
+	They assume unsigned 32-bit integers for all parameters. The functions
+	with the suffix '8' expect unsigned 8-bit integers.
 
 	Setting the global variable BIT_USE_LOOKUP_TABLES to true before loading
 	this script activates the lookup table generation.
 	bit_lua.band(int1, int2, int3, ...)
 	bit_lua.bor(int1, int2, int3, ...)
 	bit_lua.bxor(int1, int2, int3, ...)
+	bit_lua.bnot(int)
+	bit_lua.band8(byte1, byte2, byte3, ...)
+	bit_lua.bor8(byte1, byte2, byte3, ...)
 	bit_lua.bxor8(byte1, byte2, byte3, ...)
-	bit_lua.bnot(int)
 	bit_lua.bnot8(byte)
 	bit_lua.lshift(int, by)
 	bit_lua.rshift(int, by)
 	POT_LUT[i] = 2^i
 end
 
-local band, bor, bxor, bxor8
+local band, bor, bxor
+local band8, bor8, bxor8
 
 local bit_lua = {}
 
 
 band = function(int1, int2, int3, ...)
-	int2 =
-	((int1%0x00000002>=0x00000001 and int2%0x00000002>=0x00000001 and 0x00000001) or 0)+
-	((int1%0x00000004>=0x00000002 and int2%0x00000004>=0x00000002 and 0x00000002) or 0)+
-	((int1%0x00000008>=0x00000004 and int2%0x00000008>=0x00000004 and 0x00000004) or 0)+
-	((int1%0x00000010>=0x00000008 and int2%0x00000010>=0x00000008 and 0x00000008) or 0)+
-	((int1%0x00000020>=0x00000010 and int2%0x00000020>=0x00000010 and 0x00000010) or 0)+
-	((int1%0x00000040>=0x00000020 and int2%0x00000040>=0x00000020 and 0x00000020) or 0)+
-	((int1%0x00000080>=0x00000040 and int2%0x00000080>=0x00000040 and 0x00000040) or 0)+
-	((int1%0x00000100>=0x00000080 and int2%0x00000100>=0x00000080 and 0x00000080) or 0)+
-	((int1%0x00000200>=0x00000100 and int2%0x00000200>=0x00000100 and 0x00000100) or 0)+
-	((int1%0x00000400>=0x00000200 and int2%0x00000400>=0x00000200 and 0x00000200) or 0)+
-	((int1%0x00000800>=0x00000400 and int2%0x00000800>=0x00000400 and 0x00000400) or 0)+
-	((int1%0x00001000>=0x00000800 and int2%0x00001000>=0x00000800 and 0x00000800) or 0)+
-	((int1%0x00002000>=0x00001000 and int2%0x00002000>=0x00001000 and 0x00001000) or 0)+
-	((int1%0x00004000>=0x00002000 and int2%0x00004000>=0x00002000 and 0x00002000) or 0)+
-	((int1%0x00008000>=0x00004000 and int2%0x00008000>=0x00004000 and 0x00004000) or 0)+
-	((int1%0x00010000>=0x00008000 and int2%0x00010000>=0x00008000 and 0x00008000) or 0)+
-	((int1%0x00020000>=0x00010000 and int2%0x00020000>=0x00010000 and 0x00010000) or 0)+
-	((int1%0x00040000>=0x00020000 and int2%0x00040000>=0x00020000 and 0x00020000) or 0)+
-	((int1%0x00080000>=0x00040000 and int2%0x00080000>=0x00040000 and 0x00040000) or 0)+
-	((int1%0x00100000>=0x00080000 and int2%0x00100000>=0x00080000 and 0x00080000) or 0)+
-	((int1%0x00200000>=0x00100000 and int2%0x00200000>=0x00100000 and 0x00100000) or 0)+
-	((int1%0x00400000>=0x00200000 and int2%0x00400000>=0x00200000 and 0x00200000) or 0)+
-	((int1%0x00800000>=0x00400000 and int2%0x00800000>=0x00400000 and 0x00400000) or 0)+
-	((int1%0x01000000>=0x00800000 and int2%0x01000000>=0x00800000 and 0x00800000) or 0)+
-	((int1%0x02000000>=0x01000000 and int2%0x02000000>=0x01000000 and 0x01000000) or 0)+
-	((int1%0x04000000>=0x02000000 and int2%0x04000000>=0x02000000 and 0x02000000) or 0)+
-	((int1%0x08000000>=0x04000000 and int2%0x08000000>=0x04000000 and 0x04000000) or 0)+
-	((int1%0x10000000>=0x08000000 and int2%0x10000000>=0x08000000 and 0x08000000) or 0)+
-	((int1%0x20000000>=0x10000000 and int2%0x20000000>=0x10000000 and 0x10000000) or 0)+
-	((int1%0x40000000>=0x20000000 and int2%0x40000000>=0x20000000 and 0x20000000) or 0)+
-	((int1%0x80000000>=0x40000000 and int2%0x80000000>=0x40000000 and 0x40000000) or 0)+
-	((int1>=0x80000000 and int2>=0x80000000 and 0x80000000) or 0)
+	local int = 0
+
+	if int1 % 0x00000002 >= 0x00000001 and int2 % 0x00000002 >= 0x00000001 then   int = int + 0x00000001   end
+	if int1 % 0x00000004 >= 0x00000002 and int2 % 0x00000004 >= 0x00000002 then   int = int + 0x00000002   end
+	if int1 % 0x00000008 >= 0x00000004 and int2 % 0x00000008 >= 0x00000004 then   int = int + 0x00000004   end
+	if int1 % 0x00000010 >= 0x00000008 and int2 % 0x00000010 >= 0x00000008 then   int = int + 0x00000008   end
+	if int1 % 0x00000020 >= 0x00000010 and int2 % 0x00000020 >= 0x00000010 then   int = int + 0x00000010   end
+	if int1 % 0x00000040 >= 0x00000020 and int2 % 0x00000040 >= 0x00000020 then   int = int + 0x00000020   end
+	if int1 % 0x00000080 >= 0x00000040 and int2 % 0x00000080 >= 0x00000040 then   int = int + 0x00000040   end
+	if int1 % 0x00000100 >= 0x00000080 and int2 % 0x00000100 >= 0x00000080 then   int = int + 0x00000080   end
+	if int1 % 0x00000200 >= 0x00000100 and int2 % 0x00000200 >= 0x00000100 then   int = int + 0x00000100   end
+	if int1 % 0x00000400 >= 0x00000200 and int2 % 0x00000400 >= 0x00000200 then   int = int + 0x00000200   end
+	if int1 % 0x00000800 >= 0x00000400 and int2 % 0x00000800 >= 0x00000400 then   int = int + 0x00000400   end
+	if int1 % 0x00001000 >= 0x00000800 and int2 % 0x00001000 >= 0x00000800 then   int = int + 0x00000800   end
+	if int1 % 0x00002000 >= 0x00001000 and int2 % 0x00002000 >= 0x00001000 then   int = int + 0x00001000   end
+	if int1 % 0x00004000 >= 0x00002000 and int2 % 0x00004000 >= 0x00002000 then   int = int + 0x00002000   end
+	if int1 % 0x00008000 >= 0x00004000 and int2 % 0x00008000 >= 0x00004000 then   int = int + 0x00004000   end
+	if int1 % 0x00010000 >= 0x00008000 and int2 % 0x00010000 >= 0x00008000 then   int = int + 0x00008000   end
+	if int1 % 0x00020000 >= 0x00010000 and int2 % 0x00020000 >= 0x00010000 then   int = int + 0x00010000   end
+	if int1 % 0x00040000 >= 0x00020000 and int2 % 0x00040000 >= 0x00020000 then   int = int + 0x00020000   end
+	if int1 % 0x00080000 >= 0x00040000 and int2 % 0x00080000 >= 0x00040000 then   int = int + 0x00040000   end
+	if int1 % 0x00100000 >= 0x00080000 and int2 % 0x00100000 >= 0x00080000 then   int = int + 0x00080000   end
+	if int1 % 0x00200000 >= 0x00100000 and int2 % 0x00200000 >= 0x00100000 then   int = int + 0x00100000   end
+	if int1 % 0x00400000 >= 0x00200000 and int2 % 0x00400000 >= 0x00200000 then   int = int + 0x00200000   end
+	if int1 % 0x00800000 >= 0x00400000 and int2 % 0x00800000 >= 0x00400000 then   int = int + 0x00400000   end
+	if int1 % 0x01000000 >= 0x00800000 and int2 % 0x01000000 >= 0x00800000 then   int = int + 0x00800000   end
+	if int1 % 0x02000000 >= 0x01000000 and int2 % 0x02000000 >= 0x01000000 then   int = int + 0x01000000   end
+	if int1 % 0x04000000 >= 0x02000000 and int2 % 0x04000000 >= 0x02000000 then   int = int + 0x02000000   end
+	if int1 % 0x08000000 >= 0x04000000 and int2 % 0x08000000 >= 0x04000000 then   int = int + 0x04000000   end
+	if int1 % 0x10000000 >= 0x08000000 and int2 % 0x10000000 >= 0x08000000 then   int = int + 0x08000000   end
+	if int1 % 0x20000000 >= 0x10000000 and int2 % 0x20000000 >= 0x10000000 then   int = int + 0x10000000   end
+	if int1 % 0x40000000 >= 0x20000000 and int2 % 0x40000000 >= 0x20000000 then   int = int + 0x20000000   end
+	if int1 % 0x80000000 >= 0x40000000 and int2 % 0x80000000 >= 0x40000000 then   int = int + 0x40000000   end
+	if int1              >= 0x80000000 and int2              >= 0x80000000 then   int = int + 0x80000000   end
 
 	if not int3 then
-		return int2
+		return int
 	end
 
-	return band(int2, int3, ...)
+	return band(int, int3, ...)
 end
 
 
 bor = function(int1, int2, int3, ...)
-	int2 =
-	(((int1%0x00000002>=0x00000001 or (int2%0x00000002>=0x00000001)) and 0x00000001) or 0)+
-	(((int1%0x00000004>=0x00000002 or (int2%0x00000004>=0x00000002)) and 0x00000002) or 0)+
-	(((int1%0x00000008>=0x00000004 or (int2%0x00000008>=0x00000004)) and 0x00000004) or 0)+
-	(((int1%0x00000010>=0x00000008 or (int2%0x00000010>=0x00000008)) and 0x00000008) or 0)+
-	(((int1%0x00000020>=0x00000010 or (int2%0x00000020>=0x00000010)) and 0x00000010) or 0)+
-	(((int1%0x00000040>=0x00000020 or (int2%0x00000040>=0x00000020)) and 0x00000020) or 0)+
-	(((int1%0x00000080>=0x00000040 or (int2%0x00000080>=0x00000040)) and 0x00000040) or 0)+
-	(((int1%0x00000100>=0x00000080 or (int2%0x00000100>=0x00000080)) and 0x00000080) or 0)+
-	(((int1%0x00000200>=0x00000100 or (int2%0x00000200>=0x00000100)) and 0x00000100) or 0)+
-	(((int1%0x00000400>=0x00000200 or (int2%0x00000400>=0x00000200)) and 0x00000200) or 0)+
-	(((int1%0x00000800>=0x00000400 or (int2%0x00000800>=0x00000400)) and 0x00000400) or 0)+
-	(((int1%0x00001000>=0x00000800 or (int2%0x00001000>=0x00000800)) and 0x00000800) or 0)+
-	(((int1%0x00002000>=0x00001000 or (int2%0x00002000>=0x00001000)) and 0x00001000) or 0)+
-	(((int1%0x00004000>=0x00002000 or (int2%0x00004000>=0x00002000)) and 0x00002000) or 0)+
-	(((int1%0x00008000>=0x00004000 or (int2%0x00008000>=0x00004000)) and 0x00004000) or 0)+
-	(((int1%0x00010000>=0x00008000 or (int2%0x00010000>=0x00008000)) and 0x00008000) or 0)+
-	(((int1%0x00020000>=0x00010000 or (int2%0x00020000>=0x00010000)) and 0x00010000) or 0)+
-	(((int1%0x00040000>=0x00020000 or (int2%0x00040000>=0x00020000)) and 0x00020000) or 0)+
-	(((int1%0x00080000>=0x00040000 or (int2%0x00080000>=0x00040000)) and 0x00040000) or 0)+
-	(((int1%0x00100000>=0x00080000 or (int2%0x00100000>=0x00080000)) and 0x00080000) or 0)+
-	(((int1%0x00200000>=0x00100000 or (int2%0x00200000>=0x00100000)) and 0x00100000) or 0)+
-	(((int1%0x00400000>=0x00200000 or (int2%0x00400000>=0x00200000)) and 0x00200000) or 0)+
-	(((int1%0x00800000>=0x00400000 or (int2%0x00800000>=0x00400000)) and 0x00400000) or 0)+
-	(((int1%0x01000000>=0x00800000 or (int2%0x01000000>=0x00800000)) and 0x00800000) or 0)+
-	(((int1%0x02000000>=0x01000000 or (int2%0x02000000>=0x01000000)) and 0x01000000) or 0)+
-	(((int1%0x04000000>=0x02000000 or (int2%0x04000000>=0x02000000)) and 0x02000000) or 0)+
-	(((int1%0x08000000>=0x04000000 or (int2%0x08000000>=0x04000000)) and 0x04000000) or 0)+
-	(((int1%0x10000000>=0x08000000 or (int2%0x10000000>=0x08000000)) and 0x08000000) or 0)+
-	(((int1%0x20000000>=0x10000000 or (int2%0x20000000>=0x10000000)) and 0x10000000) or 0)+
-	(((int1%0x40000000>=0x20000000 or (int2%0x40000000>=0x20000000)) and 0x20000000) or 0)+
-	(((int1%0x80000000>=0x40000000 or (int2%0x80000000>=0x40000000)) and 0x40000000) or 0)+
-	(((int1>=0x80000000 or (int2>=0x80000000)) and 0x80000000) or 0)
+	local int = 0
+
+	if int1 % 0x00000002 >= 0x00000001 or int2 % 0x00000002 >= 0x00000001 then   int = int + 0x00000001   end
+	if int1 % 0x00000004 >= 0x00000002 or int2 % 0x00000004 >= 0x00000002 then   int = int + 0x00000002   end
+	if int1 % 0x00000008 >= 0x00000004 or int2 % 0x00000008 >= 0x00000004 then   int = int + 0x00000004   end
+	if int1 % 0x00000010 >= 0x00000008 or int2 % 0x00000010 >= 0x00000008 then   int = int + 0x00000008   end
+	if int1 % 0x00000020 >= 0x00000010 or int2 % 0x00000020 >= 0x00000010 then   int = int + 0x00000010   end
+	if int1 % 0x00000040 >= 0x00000020 or int2 % 0x00000040 >= 0x00000020 then   int = int + 0x00000020   end
+	if int1 % 0x00000080 >= 0x00000040 or int2 % 0x00000080 >= 0x00000040 then   int = int + 0x00000040   end
+	if int1 % 0x00000100 >= 0x00000080 or int2 % 0x00000100 >= 0x00000080 then   int = int + 0x00000080   end
+	if int1 % 0x00000200 >= 0x00000100 or int2 % 0x00000200 >= 0x00000100 then   int = int + 0x00000100   end
+	if int1 % 0x00000400 >= 0x00000200 or int2 % 0x00000400 >= 0x00000200 then   int = int + 0x00000200   end
+	if int1 % 0x00000800 >= 0x00000400 or int2 % 0x00000800 >= 0x00000400 then   int = int + 0x00000400   end
+	if int1 % 0x00001000 >= 0x00000800 or int2 % 0x00001000 >= 0x00000800 then   int = int + 0x00000800   end
+	if int1 % 0x00002000 >= 0x00001000 or int2 % 0x00002000 >= 0x00001000 then   int = int + 0x00001000   end
+	if int1 % 0x00004000 >= 0x00002000 or int2 % 0x00004000 >= 0x00002000 then   int = int + 0x00002000   end
+	if int1 % 0x00008000 >= 0x00004000 or int2 % 0x00008000 >= 0x00004000 then   int = int + 0x00004000   end
+	if int1 % 0x00010000 >= 0x00008000 or int2 % 0x00010000 >= 0x00008000 then   int = int + 0x00008000   end
+	if int1 % 0x00020000 >= 0x00010000 or int2 % 0x00020000 >= 0x00010000 then   int = int + 0x00010000   end
+	if int1 % 0x00040000 >= 0x00020000 or int2 % 0x00040000 >= 0x00020000 then   int = int + 0x00020000   end
+	if int1 % 0x00080000 >= 0x00040000 or int2 % 0x00080000 >= 0x00040000 then   int = int + 0x00040000   end
+	if int1 % 0x00100000 >= 0x00080000 or int2 % 0x00100000 >= 0x00080000 then   int = int + 0x00080000   end
+	if int1 % 0x00200000 >= 0x00100000 or int2 % 0x00200000 >= 0x00100000 then   int = int + 0x00100000   end
+	if int1 % 0x00400000 >= 0x00200000 or int2 % 0x00400000 >= 0x00200000 then   int = int + 0x00200000   end
+	if int1 % 0x00800000 >= 0x00400000 or int2 % 0x00800000 >= 0x00400000 then   int = int + 0x00400000   end
+	if int1 % 0x01000000 >= 0x00800000 or int2 % 0x01000000 >= 0x00800000 then   int = int + 0x00800000   end
+	if int1 % 0x02000000 >= 0x01000000 or int2 % 0x02000000 >= 0x01000000 then   int = int + 0x01000000   end
+	if int1 % 0x04000000 >= 0x02000000 or int2 % 0x04000000 >= 0x02000000 then   int = int + 0x02000000   end
+	if int1 % 0x08000000 >= 0x04000000 or int2 % 0x08000000 >= 0x04000000 then   int = int + 0x04000000   end
+	if int1 % 0x10000000 >= 0x08000000 or int2 % 0x10000000 >= 0x08000000 then   int = int + 0x08000000   end
+	if int1 % 0x20000000 >= 0x10000000 or int2 % 0x20000000 >= 0x10000000 then   int = int + 0x10000000   end
+	if int1 % 0x40000000 >= 0x20000000 or int2 % 0x40000000 >= 0x20000000 then   int = int + 0x20000000   end
+	if int1 % 0x80000000 >= 0x40000000 or int2 % 0x80000000 >= 0x40000000 then   int = int + 0x40000000   end
+	if int1              >= 0x80000000 or int2              >= 0x80000000 then   int = int + 0x80000000   end
 
 	if not int3 then
-		return int2
+		return int
 	end
 
-	return bor(int2, int3, ...)
+	return bor(int, int3, ...)
 end
 
 
 bxor = function(int1, int2, int3, ...)
-	int2 =
-	((int1%0x00000002>=0x00000001 ~= (int2%0x00000002>=0x00000001) and 0x00000001) or 0)+
-	((int1%0x00000004>=0x00000002 ~= (int2%0x00000004>=0x00000002) and 0x00000002) or 0)+
-	((int1%0x00000008>=0x00000004 ~= (int2%0x00000008>=0x00000004) and 0x00000004) or 0)+
-	((int1%0x00000010>=0x00000008 ~= (int2%0x00000010>=0x00000008) and 0x00000008) or 0)+
-	((int1%0x00000020>=0x00000010 ~= (int2%0x00000020>=0x00000010) and 0x00000010) or 0)+
-	((int1%0x00000040>=0x00000020 ~= (int2%0x00000040>=0x00000020) and 0x00000020) or 0)+
-	((int1%0x00000080>=0x00000040 ~= (int2%0x00000080>=0x00000040) and 0x00000040) or 0)+
-	((int1%0x00000100>=0x00000080 ~= (int2%0x00000100>=0x00000080) and 0x00000080) or 0)+
-	((int1%0x00000200>=0x00000100 ~= (int2%0x00000200>=0x00000100) and 0x00000100) or 0)+
-	((int1%0x00000400>=0x00000200 ~= (int2%0x00000400>=0x00000200) and 0x00000200) or 0)+
-	((int1%0x00000800>=0x00000400 ~= (int2%0x00000800>=0x00000400) and 0x00000400) or 0)+
-	((int1%0x00001000>=0x00000800 ~= (int2%0x00001000>=0x00000800) and 0x00000800) or 0)+
-	((int1%0x00002000>=0x00001000 ~= (int2%0x00002000>=0x00001000) and 0x00001000) or 0)+
-	((int1%0x00004000>=0x00002000 ~= (int2%0x00004000>=0x00002000) and 0x00002000) or 0)+
-	((int1%0x00008000>=0x00004000 ~= (int2%0x00008000>=0x00004000) and 0x00004000) or 0)+
-	((int1%0x00010000>=0x00008000 ~= (int2%0x00010000>=0x00008000) and 0x00008000) or 0)+
-	((int1%0x00020000>=0x00010000 ~= (int2%0x00020000>=0x00010000) and 0x00010000) or 0)+
-	((int1%0x00040000>=0x00020000 ~= (int2%0x00040000>=0x00020000) and 0x00020000) or 0)+
-	((int1%0x00080000>=0x00040000 ~= (int2%0x00080000>=0x00040000) and 0x00040000) or 0)+
-	((int1%0x00100000>=0x00080000 ~= (int2%0x00100000>=0x00080000) and 0x00080000) or 0)+
-	((int1%0x00200000>=0x00100000 ~= (int2%0x00200000>=0x00100000) and 0x00100000) or 0)+
-	((int1%0x00400000>=0x00200000 ~= (int2%0x00400000>=0x00200000) and 0x00200000) or 0)+
-	((int1%0x00800000>=0x00400000 ~= (int2%0x00800000>=0x00400000) and 0x00400000) or 0)+
-	((int1%0x01000000>=0x00800000 ~= (int2%0x01000000>=0x00800000) and 0x00800000) or 0)+
-	((int1%0x02000000>=0x01000000 ~= (int2%0x02000000>=0x01000000) and 0x01000000) or 0)+
-	((int1%0x04000000>=0x02000000 ~= (int2%0x04000000>=0x02000000) and 0x02000000) or 0)+
-	((int1%0x08000000>=0x04000000 ~= (int2%0x08000000>=0x04000000) and 0x04000000) or 0)+
-	((int1%0x10000000>=0x08000000 ~= (int2%0x10000000>=0x08000000) and 0x08000000) or 0)+
-	((int1%0x20000000>=0x10000000 ~= (int2%0x20000000>=0x10000000) and 0x10000000) or 0)+
-	((int1%0x40000000>=0x20000000 ~= (int2%0x40000000>=0x20000000) and 0x20000000) or 0)+
-	((int1%0x80000000>=0x40000000 ~= (int2%0x80000000>=0x40000000) and 0x40000000) or 0)+
-	((int1>=0x80000000 ~= (int2>=0x80000000) and 0x80000000) or 0)
+	local int = 0
+
+	if (int1 % 0x00000002 >= 0x00000001) ~= (int2 % 0x00000002 >= 0x00000001) then   int = int + 0x00000001   end
+	if (int1 % 0x00000004 >= 0x00000002) ~= (int2 % 0x00000004 >= 0x00000002) then   int = int + 0x00000002   end
+	if (int1 % 0x00000008 >= 0x00000004) ~= (int2 % 0x00000008 >= 0x00000004) then   int = int + 0x00000004   end
+	if (int1 % 0x00000010 >= 0x00000008) ~= (int2 % 0x00000010 >= 0x00000008) then   int = int + 0x00000008   end
+	if (int1 % 0x00000020 >= 0x00000010) ~= (int2 % 0x00000020 >= 0x00000010) then   int = int + 0x00000010   end
+	if (int1 % 0x00000040 >= 0x00000020) ~= (int2 % 0x00000040 >= 0x00000020) then   int = int + 0x00000020   end
+	if (int1 % 0x00000080 >= 0x00000040) ~= (int2 % 0x00000080 >= 0x00000040) then   int = int + 0x00000040   end
+	if (int1 % 0x00000100 >= 0x00000080) ~= (int2 % 0x00000100 >= 0x00000080) then   int = int + 0x00000080   end
+	if (int1 % 0x00000200 >= 0x00000100) ~= (int2 % 0x00000200 >= 0x00000100) then   int = int + 0x00000100   end
+	if (int1 % 0x00000400 >= 0x00000200) ~= (int2 % 0x00000400 >= 0x00000200) then   int = int + 0x00000200   end
+	if (int1 % 0x00000800 >= 0x00000400) ~= (int2 % 0x00000800 >= 0x00000400) then   int = int + 0x00000400   end
+	if (int1 % 0x00001000 >= 0x00000800) ~= (int2 % 0x00001000 >= 0x00000800) then   int = int + 0x00000800   end
+	if (int1 % 0x00002000 >= 0x00001000) ~= (int2 % 0x00002000 >= 0x00001000) then   int = int + 0x00001000   end
+	if (int1 % 0x00004000 >= 0x00002000) ~= (int2 % 0x00004000 >= 0x00002000) then   int = int + 0x00002000   end
+	if (int1 % 0x00008000 >= 0x00004000) ~= (int2 % 0x00008000 >= 0x00004000) then   int = int + 0x00004000   end
+	if (int1 % 0x00010000 >= 0x00008000) ~= (int2 % 0x00010000 >= 0x00008000) then   int = int + 0x00008000   end
+	if (int1 % 0x00020000 >= 0x00010000) ~= (int2 % 0x00020000 >= 0x00010000) then   int = int + 0x00010000   end
+	if (int1 % 0x00040000 >= 0x00020000) ~= (int2 % 0x00040000 >= 0x00020000) then   int = int + 0x00020000   end
+	if (int1 % 0x00080000 >= 0x00040000) ~= (int2 % 0x00080000 >= 0x00040000) then   int = int + 0x00040000   end
+	if (int1 % 0x00100000 >= 0x00080000) ~= (int2 % 0x00100000 >= 0x00080000) then   int = int + 0x00080000   end
+	if (int1 % 0x00200000 >= 0x00100000) ~= (int2 % 0x00200000 >= 0x00100000) then   int = int + 0x00100000   end
+	if (int1 % 0x00400000 >= 0x00200000) ~= (int2 % 0x00400000 >= 0x00200000) then   int = int + 0x00200000   end
+	if (int1 % 0x00800000 >= 0x00400000) ~= (int2 % 0x00800000 >= 0x00400000) then   int = int + 0x00400000   end
+	if (int1 % 0x01000000 >= 0x00800000) ~= (int2 % 0x01000000 >= 0x00800000) then   int = int + 0x00800000   end
+	if (int1 % 0x02000000 >= 0x01000000) ~= (int2 % 0x02000000 >= 0x01000000) then   int = int + 0x01000000   end
+	if (int1 % 0x04000000 >= 0x02000000) ~= (int2 % 0x04000000 >= 0x02000000) then   int = int + 0x02000000   end
+	if (int1 % 0x08000000 >= 0x04000000) ~= (int2 % 0x08000000 >= 0x04000000) then   int = int + 0x04000000   end
+	if (int1 % 0x10000000 >= 0x08000000) ~= (int2 % 0x10000000 >= 0x08000000) then   int = int + 0x08000000   end
+	if (int1 % 0x20000000 >= 0x10000000) ~= (int2 % 0x20000000 >= 0x10000000) then   int = int + 0x10000000   end
+	if (int1 % 0x40000000 >= 0x20000000) ~= (int2 % 0x40000000 >= 0x20000000) then   int = int + 0x20000000   end
+	if (int1 % 0x80000000 >= 0x40000000) ~= (int2 % 0x80000000 >= 0x40000000) then   int = int + 0x40000000   end
+	if (int1              >= 0x80000000) ~= (int2              >= 0x80000000) then   int = int + 0x80000000   end
 
 	if not int3 then
-		return int2
+		return int
 	end
 
-	return bxor(int2, int3, ...)
+	return bxor(int, int3, ...)
+end
+
+band8 = function(byte1, byte2, byte3, ...)
+	local byte = 0
+
+	if byte1 % 0x02 >= 0x01 and byte2 % 0x02 >= 0x01 then   byte = byte + 0x01   end
+	if byte1 % 0x04 >= 0x02 and byte2 % 0x04 >= 0x02 then   byte = byte + 0x02   end
+	if byte1 % 0x08 >= 0x04 and byte2 % 0x08 >= 0x04 then   byte = byte + 0x04   end
+	if byte1 % 0x10 >= 0x08 and byte2 % 0x10 >= 0x08 then   byte = byte + 0x08   end
+	if byte1 % 0x20 >= 0x10 and byte2 % 0x20 >= 0x10 then   byte = byte + 0x10   end
+	if byte1 % 0x40 >= 0x20 and byte2 % 0x40 >= 0x20 then   byte = byte + 0x20   end
+	if byte1 % 0x80 >= 0x40 and byte2 % 0x80 >= 0x40 then   byte = byte + 0x40   end
+	if byte1        >= 0x80 and byte2        >= 0x80 then   byte = byte + 0x80   end
+
+	if not byte3 then
+		return byte
+	end
+
+	return band8(byte, byte3, ...)
+end
+
+bor8 = function(byte1, byte2, byte3, ...)
+	local byte = 0
+
+	if byte1 % 0x02 >= 0x01 or byte2 % 0x02 >= 0x01 then   byte = byte + 0x01   end
+	if byte1 % 0x04 >= 0x02 or byte2 % 0x04 >= 0x02 then   byte = byte + 0x02   end
+	if byte1 % 0x08 >= 0x04 or byte2 % 0x08 >= 0x04 then   byte = byte + 0x04   end
+	if byte1 % 0x10 >= 0x08 or byte2 % 0x10 >= 0x08 then   byte = byte + 0x08   end
+	if byte1 % 0x20 >= 0x10 or byte2 % 0x20 >= 0x10 then   byte = byte + 0x10   end
+	if byte1 % 0x40 >= 0x20 or byte2 % 0x40 >= 0x20 then   byte = byte + 0x20   end
+	if byte1 % 0x80 >= 0x40 or byte2 % 0x80 >= 0x40 then   byte = byte + 0x40   end
+	if byte1        >= 0x80 or byte2        >= 0x80 then   byte = byte + 0x80   end
+
+	if not byte3 then
+		return byte
+	end
+
+	return bor8(byte, byte3, ...)
 end
 
 bxor8 = function(byte1, byte2, byte3, ...)
-	byte2 =
-	((byte1%0x02==0x01 ~= (byte2%0x02==0x01) and 0x01) or 0)+
-	((byte1%0x04>=0x02 ~= (byte2%0x04>=0x02) and 0x02) or 0)+
-	((byte1%0x08>=0x04 ~= (byte2%0x08>=0x04) and 0x04) or 0)+
-	((byte1%0x10>=0x08 ~= (byte2%0x10>=0x08) and 0x08) or 0)+
-	((byte1%0x20>=0x10 ~= (byte2%0x20>=0x10) and 0x10) or 0)+
-	((byte1%0x40>=0x20 ~= (byte2%0x40>=0x20) and 0x20) or 0)+
-	((byte1%0x80>=0x40 ~= (byte2%0x80>=0x40) and 0x40) or 0)+
-	((byte1>=0x80 ~= (byte2>=0x80) and 0x80) or 0)
+	local byte, b1, b2 = 0
+
+	if (byte1 % 0x02 >= 0x01) ~= (byte2 % 0x02 >= 0x01) then   byte = byte + 0x01   end
+	if (byte1 % 0x04 >= 0x02) ~= (byte2 % 0x04 >= 0x02) then   byte = byte + 0x02   end
+	if (byte1 % 0x08 >= 0x04) ~= (byte2 % 0x08 >= 0x04) then   byte = byte + 0x04   end
+	if (byte1 % 0x10 >= 0x08) ~= (byte2 % 0x10 >= 0x08) then   byte = byte + 0x08   end
+	if (byte1 % 0x20 >= 0x10) ~= (byte2 % 0x20 >= 0x10) then   byte = byte + 0x10   end
+	if (byte1 % 0x40 >= 0x20) ~= (byte2 % 0x40 >= 0x20) then   byte = byte + 0x20   end
+	if (byte1 % 0x80 >= 0x40) ~= (byte2 % 0x80 >= 0x40) then   byte = byte + 0x40   end
+	if (byte1        >= 0x80) ~= (byte2        >= 0x80) then   byte = byte + 0x80   end
 
 	if not byte3 then
-		return byte2
+		return byte
 	end
 
-	return bxor8(byte2, byte3, ...)
+	return bxor8(byte, byte3, ...)
 end
 
 
 		AND_LT[b1], OR_LT[b1], XOR_LT[b1] = {}, {}, {}
 
 		for b2 = 0, 255 do
-			AND_LT[b1][b2] = band(b1, b2)
-			OR_LT[b1][b2] = bor(b1, b2)
-			XOR_LT[b1][b2] = bxor(b1, b2)
+			AND_LT[b1][b2] = band8(b1, b2)
+			OR_LT[b1][b2] = bor8(b1, b2)
+			XOR_LT[b1][b2] = bxor8(b1, b2)
 		end
 	end
 
 bit_lua.band = band
 bit_lua.bor = bor
 bit_lua.bxor = bxor
+
+bit_lua.band8 = band8
+bit_lua.bor8 = bor8
 bit_lua.bxor8 = bxor8
 
 
-
 bit_lua.bnot = function(int)
 	return 4294967295 - int
 end