diff --git a/src/builtins/bitwise/bitwise.ts b/src/builtins/bitwise/bitwise.ts new file mode 100644 index 0000000..23ff8c2 --- /dev/null +++ b/src/builtins/bitwise/bitwise.ts @@ -0,0 +1,15 @@ +// calculates bitwise 'AND' of given two inputs x and y +function bitwise_and(x: bigint, y: bigint): bigint { + return x & y; +} + +// calculates bitwise 'OR' of given two inputs x and y +function bitwise_or(x: bigint, y: bigint): bigint { + return x | y; +} + +// calculates bitwise 'XOR' of given two inputs x and y +function bitwise_xor(x: bigint, y: bigint): bigint { + return x ^ y; +} + diff --git a/src/tests.ts b/src/tests.ts index 4e6366f..0c4a9cc 100644 --- a/src/tests.ts +++ b/src/tests.ts @@ -95,3 +95,19 @@ function testRunner() { test.finish(); } + +function testBitwiseOperations(): void { + Logger.log(bitwise_operations(BigInt(0), BigInt(0)).toString()); + Logger.log(bitwise_operations(BigInt(31), BigInt(0)).toString()); + Logger.log(bitwise_operations(BigInt(0), BigInt(31)).toString()); + Logger.log(bitwise_operations(BigInt(31), BigInt(31)).toString()); + Logger.log(bitwise_operations(BigInt(31), BigInt(1)).toString()); + Logger.log(bitwise_operations(BigInt(31), BigInt(30)).toString()); + //Expect : + // [0, 0, 0] + // [0, 31, 31] + // [0, 31, 31] + // [31, 0, 31] + // [1, 30, 31] + // [30, 1, 31] +} diff --git a/src/ui/Code.ts b/src/ui/Code.ts index a26932e..943e443 100644 --- a/src/ui/Code.ts +++ b/src/ui/Code.ts @@ -69,6 +69,41 @@ function PEDERSEN(x: number | string, y: number | string): number | string { return pedersen(BigInt(x), BigInt(y)).toString(16); } +/** + * Provides custom function for bitwise 'and' for given two inputs. + * + * @param {number} x - one of the input for 'and' operation + * @param {number} y - the other input for 'and' operation + * @return The bitwise 'and' of two given inputs in bigint form. + * @customfunction + */ +function BITWISE_AND(x: number, y: number): bigint { + return bitwise_and(BigInt(x), BigInt(y)); +} + +/** + * Provides custom function for bitwise 'xor' for given two inputs. + * + * @param {number} x - one of the input for 'xor' operation + * @param {number} y - the other input for 'xor' operation + * @return The bitwise 'xor' of two given inputs in bigint form. + * @customfunction + */ +function BITWISE_XOR(x: number, y: number): bigint { + return bitwise_xor(BigInt(x), BigInt(y)); +} + +/** + * Provides custom function for bitwise 'or' for given two inputs. + * + * @param {number} x - one of the input for 'or' operation + * @param {number} y - the other input for 'or' operation + * @return The bitwise 'or' of two given inputs in bigint form. + * @customfunction + */ +function BITWISE_OR(x: number, y: number): bigint { + return bitwise_or(BigInt(x), BigInt(y)); + function EC_OP( m: number | string, p: AffinePoint, diff --git a/src/vm/vm.ts b/src/vm/vm.ts index 1d48f3d..31be2c8 100644 --- a/src/vm/vm.ts +++ b/src/vm/vm.ts @@ -296,7 +296,6 @@ function runUntilPc(): void { runSheet.getRange(`${executionColumn}2`).setValue(FINAL_FP); runSheet.getRange(`${executionColumn}3`).setValue(FINAL_PC); while (!(pc === FINAL_PC)) { - console.log(i); step(i); i++; pc = runSheet.getRange(`${pcColumn}${i + 1 + 1}`).getValue();