forked from starkware-libs/cairo-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a86e92b
commit 8e11b8c
Showing
39 changed files
with
1,513 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copies len field elements from src to dst at the given indices. | ||
// I.e., dst = [src[i] for i in indices]. | ||
func copy_indices(dst: felt*, src: felt*, indices: felt*, len: felt) { | ||
struct LoopFrame { | ||
dst: felt*, | ||
indices: felt*, | ||
} | ||
|
||
if (len == 0) { | ||
return (); | ||
} | ||
|
||
%{ vm_enter_scope({'n': ids.len}) %} | ||
tempvar frame = LoopFrame(dst=dst, indices=indices); | ||
|
||
loop: | ||
let frame = [cast(ap - LoopFrame.SIZE, LoopFrame*)]; | ||
assert [frame.dst] = src[[frame.indices]]; | ||
|
||
let continue_copying = [ap]; | ||
// Reserve space for continue_copying. | ||
let next_frame = cast(ap + 1, LoopFrame*); | ||
next_frame.dst = frame.dst + 1, ap++; | ||
next_frame.indices = frame.indices + 1, ap++; | ||
%{ | ||
n -= 1 | ||
ids.continue_copying = 1 if n > 0 else 0 | ||
%} | ||
static_assert next_frame + LoopFrame.SIZE == ap + 1; | ||
jmp loop if continue_copying != 0, ap++; | ||
// Assert that the loop executed len times. | ||
len = cast(next_frame.indices, felt) - cast(indices, felt); | ||
|
||
%{ vm_exit_scope() %} | ||
return (); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from starkware.cairo.common.math import assert_in_range, assert_not_zero | ||
from starkware.cairo.common.pow import pow | ||
|
||
// Returns the ceil value of the log2 of the given value. | ||
// Enforces that 1 <= value <= RANGE_CHECK_BOUND. | ||
func log2_ceil{range_check_ptr}(value: felt) -> felt { | ||
alloc_locals; | ||
assert_not_zero(value); | ||
if (value == 1) { | ||
return 0; | ||
} | ||
|
||
local res; | ||
%{ | ||
from starkware.python.math_utils import log2_ceil | ||
ids.res = log2_ceil(ids.value) | ||
%} | ||
|
||
// Verify that 1 <= 2**(res - 1) < value <= 2**res <= RANGE_CHECK_BOUND. | ||
// The RANGE_CHECK_BOUND bound is required by the `assert_in_range` function. | ||
assert_in_range(res, 1, 128 + 1); | ||
let (lower_bound) = pow(2, res - 1); | ||
let min = lower_bound + 1; | ||
let max = 2 * lower_bound; | ||
assert_in_range(value, min, max + 1); | ||
|
||
return res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.13.2 | ||
0.13.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.