Skip to content

Commit a409636

Browse files
committed
added spilling
1 parent 8d140c8 commit a409636

File tree

7 files changed

+28
-5
lines changed

7 files changed

+28
-5
lines changed

First_Steps.md

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Parameter | default | possible / typical values | description
6464
--betRatio | 0.2 | 0.1, 0.3 | The share from parameter `--evals`, which are spent for all bets, in per cent (i.e. 0.2 means 20% of --evals will be used for the bet part, and 80% for the final run-part)
6565
--resultDir | ./results | /tmp/myresults | The directory under which `<BRIDGE>/<SYMBOL>` will be created and the result files will be stored
6666
--no-proof | | --no-proof, --proof | [dis\|en]ables the Fiat-Proofing system. It is enabled by default for `fiat`-bridge, disabled for the rest.
67+
--spilling | reversebell | uniform,reversebell | How to bias where to place an operation during the scheduling mutation. 'reversebell' prefers ends (close to the operation that consumes a value), 'uniform' uniformly selects in the possible interval.
6768
--memoryConstraints| none | none, all, out1-arg1 | none: any argN[n] can be read after any outN[n] as been written. That is okay, if all memoy is distinct. 'out1-arg1' specifies that arg1[n] cannnot be read, if out1[n] has been written. It may read arg1[n+m] after out1[n] has been written. Use that if you want to call `mul(r,r,x)` or `sq(a,a)`. all: no argN[n] can be read if any outN[n] has been written. Use that if memory can be overlapping and unaligned.
6869

6970
For more information check `./CryptOpt --help`

completion/_cryptopt

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ _arguments -S -s \
3939
'--memoryConstraints=[Specify any memory contraints. No contraints, all, or out1--arg1 may be aliased]:memorycontraints:->memorycontraintoptions' \
4040
'--uicaarch=[use uiCA estimation instead of running on hardware.]:uiCAConstraints:->uiCAOptions' \
4141
'--objectiveFunction=[use objective Function instead of running on hardware.]:objectiveFunctionConstraints:->objectiveFunctionOptions' \
42+
'--spilling=[use uniform or biased scheduling mutations]:spillingConstraints:->spillingOptions' \
4243
'(-h,--help)'{-h,--help}'[Help]:get help prompt' \
4344
'(--version)'{-v,--version}'[Version]:Version information' \
4445
&& ret=0
@@ -105,6 +106,11 @@ case "$state" in
105106
'length[length of the function (# instructions)]' \
106107
'uiCA[throughput estimation from uiCA. Speicfy arch with --uicaarch]' \
107108
;;
109+
spillingOptions)
110+
_values 'spillingConstraints' \
111+
'reversebell[bias towards ends of interval]' \
112+
'uniform[uniformly at random select from interval]' \
113+
;;
108114
esac
109115

110116

src/helper/argParse.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
MEMORY_CONSTRAINTS_OPTIONS,
3737
ParsedArgsT,
3838
OBJECTIVE_FUNCTION_OPTIONS,
39+
SPILLING,
3940
} from "../types";
4041

4142
const y = await yargs(process.argv.slice(2));
@@ -233,10 +234,17 @@ export const parsedArgs = y
233234
default: "cycles",
234235
string: true,
235236
describe:
236-
"The opjective function which describes which mutation should be kept or discarded. Options: 'cycles' run on hardware, use cycles; stack: size of the used stack slots; length: purely optimise for fewer instructions; uiCA: use uiCA's estimation. Everything but cycles effectively disables monkey-testing becuase the code is not executed.",
237+
"The objective function which describes which mutation should be kept or discarded. Options: 'cycles' run on hardware, use cycles; stack: size of the used stack slots; length: purely optimise for fewer instructions; uiCA: use uiCA's estimation. Everything but cycles effectively disables monkey-testing becuase the code is not executed.",
237238

238239
choices: OBJECTIVE_FUNCTION_OPTIONS,
239240
})
241+
.option("spilling", {
242+
default: "reversebell",
243+
string: true,
244+
describe:
245+
"How to bias where to place an operation during the scheduling mutation. 'reversebell' , 'uniform' uniformly selects in the possible interval.",
246+
choices: SPILLING,
247+
})
240248
.help("help")
241249
.alias("h", "help")
242250
.wrap(Math.min(160, y.terminalWidth()))

src/model/model.class.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export class Model {
245245
return lastRead[0];
246246
}
247247

248-
public static mutatePermutation(): void {
248+
public static mutatePermutation(bias = BIAS.REVERSE_BELL): void {
249249
const m = Model.getInstance();
250250
m.backupbody();
251251

@@ -285,7 +285,7 @@ export class Model {
285285
return this.mutatePermutation();
286286
}
287287

288-
const partner = min + 1 == max ? min : Paul.chooseBetween(max, min, BIAS.REVERSE_BELL);
288+
const partner = min + 1 == max ? min : Paul.chooseBetween(max, min, bias);
289289
if (chosen == partner) {
290290
// would that ever happen ?
291291
return this.mutatePermutation();

src/optimizer/optimizer.class.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
import globals from "@/helper/globals";
3838
import Logger from "@/helper/Logger.class";
3939
import { Model } from "@/model";
40-
import { Paul, sha1Hash } from "@/paul";
40+
import { BIAS, Paul, sha1Hash } from "@/paul";
4141
import { RegisterAllocator } from "@/registerAllocator";
4242
import type { AnalyseResult, OptimizerArgs } from "@/types";
4343

@@ -110,7 +110,7 @@ export class Optimizer {
110110
Logger.log("Mutationalita");
111111
switch (choice) {
112112
case CHOICE.PERMUTE: {
113-
Model.mutatePermutation();
113+
Model.mutatePermutation(this.args.spilling == "uniform" ? BIAS.UNIFORM : BIAS.REVERSE_BELL);
114114
this.revertFunction = () => {
115115
this.numRevert.permutation++;
116116
Model.revertLastMutation();

src/types/CryptOpt.namespace.ts

+6
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ export const OBJECTIVE_FUNCTION_OPTIONS = [
5050
"length", // purely optimise for fewer instructions
5151
"uiCA", // use uiCA's estimation
5252
] as const;
53+
export const SPILLING = [
54+
"reversebell", // default, prefers ends (close to the operation that consumes a value)
55+
"uniform", // 'uniform' uniformly selects in the possible interval.
56+
] as const;
57+
5358
export type MEMORY_CONSTRAINTS_OPTIONS_T = (typeof MEMORY_CONSTRAINTS_OPTIONS)[number];
5459
export type UICA_OPTIONS_T = (typeof UICA_OPTIONS)[number];
5560
export type OBJECTIVE_FUNCTION_OPTIONS_T = (typeof OBJECTIVE_FUNCTION_OPTIONS)[number];
61+
export type SPILLING_T = (typeof SPILLING)[number];
5662

5763
// eslint-disable-next-line @typescript-eslint/no-namespace
5864
export namespace CryptOpt {

src/types/optimizer.types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
FRAME_POINTER_OPTIONS_T,
2222
MEMORY_CONSTRAINTS_OPTIONS_T,
2323
OBJECTIVE_FUNCTION_OPTIONS_T,
24+
SPILLING_T,
2425
UICA_OPTIONS_T,
2526
} from "@/types";
2627

@@ -45,6 +46,7 @@ export type OptimizerArgs = {
4546
memoryConstraints: MEMORY_CONSTRAINTS_OPTIONS_T;
4647
uicaarch: UICA_OPTIONS_T;
4748
objectiveFunction: OBJECTIVE_FUNCTION_OPTIONS_T;
49+
spilling: SPILLING_T;
4850
};
4951
export type ParsedArgsT = OptimizerArgs & {
5052
startFromBestJson: boolean;

0 commit comments

Comments
 (0)