Skip to content

Commit

Permalink
optimisations of memory cell
Browse files Browse the repository at this point in the history
  • Loading branch information
StringNick committed Jun 3, 2024
1 parent c83d840 commit 55fe50a
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 118 deletions.
4 changes: 2 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ pub fn build(b: *std.Build) void {
.target = target,
.optimize = optimize,
.link_libc = true,
.omit_frame_pointer = if (optimize == .ReleaseFast) true else false,
.strip = true,
.omit_frame_pointer = if (optimize == .ReleaseFast) false else false,
.strip = false,
});
// Add dependency modules to the executable.
for (deps) |mod| exe.root_module.addImport(
Expand Down
11 changes: 3 additions & 8 deletions src/hint_processor/math_hints.zig
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,10 @@ pub fn unsignedDivRem(
if (div.isZero() or div.cmp(&divPrimeByBound(b)).compare(.gt)) return HintError.OutOfValidRange;
} else if (div.isZero()) return HintError.OutOfValidRange;

const qr = try (field_helper.divRem(u256, value.toU256(), div.toU256()) catch MathError.DividedByZero);
const q, const r = try (field_helper.divRem(u256, value.toU256(), div.toU256()) catch MathError.DividedByZero);

try hint_utils.insertValueFromVarName(allocator, "r", MaybeRelocatable.fromInt(u256, qr[1]), vm, ids_data, ap_tracking);
try hint_utils.insertValueFromVarName(allocator, "q", MaybeRelocatable.fromInt(u256, qr[0]), vm, ids_data, ap_tracking);
}

fn cmpFn(context: void, a: struct { u256, u64 }, b: struct { u256, u64 }) bool {
_ = context; // autofix
return a[0] > b[0];
try hint_utils.insertValueFromVarName(allocator, "r", MaybeRelocatable.fromInt(u256, r), vm, ids_data, ap_tracking);
try hint_utils.insertValueFromVarName(allocator, "q", MaybeRelocatable.fromInt(u256, q), vm, ids_data, ap_tracking);
}

// Implements hint:from starkware.cairo.common.math_utils import assert_integer
Expand Down
4 changes: 1 addition & 3 deletions src/integration_tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ pub fn main() !void {

var ok_count: usize = 0;
var fail_count: usize = 0;
var progress = std.Progress{
.dont_print_on_dumb = true,
};
var progress = std.Progress{};
const root_node = progress.start("Test", cairo_programs.len);
const have_tty = progress.terminal != null and
(progress.supports_ansi_escape_codes or progress.is_windows_terminal);
Expand Down
2 changes: 1 addition & 1 deletion src/vm/builtins/builtin_runner/range_check.zig
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pub const RangeCheckBuiltinRunner = struct {
return null;

for (rc_segment.items) |cell| {
var cellFelt = cell.?.maybe_relocatable.intoFelt() catch null;
var cellFelt = cell.getValue().?.intoFelt() catch null;
const cellBytes = cellFelt.?.toBytesLe();
var j: usize = 0;
while (j < 32) : (j += 2) {
Expand Down
8 changes: 4 additions & 4 deletions src/vm/core.zig
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,12 @@ pub const CairoVM = struct {
pub fn verifyAutoDeductions(self: *const Self, allocator: Allocator) !void {
for (self.builtin_runners.items) |*builtin| {
const segment_index = builtin.base();
const segment = self.segments.memory.data.items[segment_index];
for (segment.items, 0..) |value, offset| {
if (value) |v| {

for (self.segments.memory.data.items[segment_index].items, 0..) |value, offset| {
if (value.getValue()) |v| {
const addr = Relocatable.init(@intCast(segment_index), offset);
const deduced_memory_cell = try builtin.deduceMemoryCell(allocator, addr, self.segments.memory) orelse continue;
if (!deduced_memory_cell.eq(v.maybe_relocatable)) {
if (!deduced_memory_cell.eq(v)) {
return CairoVMError.InconsistentAutoDeduction;
}
}
Expand Down
Loading

0 comments on commit 55fe50a

Please sign in to comment.