Skip to content

Commit

Permalink
codegen(feat): Optimise single-character MOVE copies.
Browse files Browse the repository at this point in the history
  • Loading branch information
c272 committed May 3, 2024
1 parent 399dd95 commit 76773c8
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 98 deletions.
2 changes: 1 addition & 1 deletion benchmarks/fibonacci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name = "Fibonacci"
source_file = "./examples/algorithms/fibonacci.cobol"
# The 93rd fibonacci number is the largest that can fit within a 64-bit integer.
stdin = "93\n"
iterations = 1000
iterations = 10000
2 changes: 1 addition & 1 deletion benchmarks/fizzbuzz.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "FizzBuzz"
source_file = "./examples/algorithms/fizzbuzz.cobol"
stdin = "100000\n"
iterations = 100
iterations = 1000
2 changes: 1 addition & 1 deletion benchmarks/primality.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "Primality"
source_file = "./examples/algorithms/primality.cobol"
stdin = "50\n10000\n"
iterations = 10
iterations = 100
2 changes: 1 addition & 1 deletion benchmarks/questionmarks.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "QuestionMarks"
source_file = "./examples/algorithms/questionmarks.cobol"
stdin = "THIS2??IS?8A?TEST?STRING?2????3TO??TEST!CONFORMANCY?7??\n"
iterations = 1000
iterations = 10000
2 changes: 1 addition & 1 deletion benchmarks/rot13.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "ROT13"
source_file = "./examples/algorithms/rot13.cobol"
stdin = "LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISCING ELIT. SUSPENDISSE SED NULLA A DIAM DAPIBUS PLACERAT. AENEAN ET MOLLIS FELIS, ET LAOREET SAPIEN. FUSCE A VULPUTATE ODIO. PROIN NON PULVINAR SAPIEN. PROIN MALESUADA IMPERDIET LACINIA. PELLENTESQUE AC ERAT ULTRICIES, PELLENTESQUE ENIM DICTUM, CONSECTETUR ELIT. VESTIBULUM ID EROS PORTA, LOBORTIS EROS AC, CONSEQUAT AUGUE. CRAS BIBENDUM, TURPIS QUIS CURSUS VESTIBULUM, NUNC ELIT DAPIBUS SEM, AT PRETIUM URNA MASSA IMPERDIET DOLOR. SUSPENDISSE SAPIEN METUS, ELEIFEND ACCUMSAN ANTE VEL, LOBORTIS IMPERDIET FELIS. ETIAM PORTTITOR SED URNA QUIS CONGUE. PELLENTESQUE LACINIA, LEO AT CONDIMENTUM RUTRUM, QUAM NULLA PORTA ELIT, EGET BLANDIT LIGULA MAURIS NON ARCU. NULLAM VENENATIS LIBERO MAGNA, AT VESTIBULUM EST EFFICITUR SED. SED TRISTIQUE SOLLICITUDIN ARCU QUIS PHARETRA. MORBI AC EROS ERAT. INTEGER ALIQUET ALIQUET FEUGIAT. NULLAM IACULIS QUIS SAPIEN VENENATIS MOLESTIE. MAECENAS NISI MASSA, SUSCIPIT QUIS INTERDUM TINCIDUNT, GRAVIDA UT EST. NUNC VULPUTATE EST ID MAURIS ULLAMCORPER VARIUS. CRAS IN TORTOR BLANDIT LOREM MATTIS EFFICITUR QUIS QUIS LIBERO. CURABITUR MAGNA MAGNA, PELLENTESQUE VEL ACCUMSAN NEC, LUCTUS SED ELIT. DONEC DICTUM EFFICITUR PURUS ULLAMCORPER MALESUADA. FUSCE ET URNA SAPIEN. NAM NON VOLUTPAT ENIM, CONSEQUAT LOBORTIS MAURIS. DUIS TEMPUS NEQUE AC TINCIDUNT MALESUADA. DUIS GRAVIDA, LOREM QUIS PELLENTESQUE LACINIA, MI MAURIS EGESTAS ARCU, NON PULVINAR DUI NEQUE AT MAURIS. PHASELLUS LOBORTIS, IPSUM UT BIBENDUM ACCUMSAN, NIBH SAPIEN PORTA LIBERO, FACILISIS TRISTIQUE FELIS JUSTO VEL ERAT. DUIS COMMODO, LOREM QUIS TEMPUS MOLESTIE, ORCI LECTUS MATTIS TORTOR, NON DAPIBUS LEO SEM A DOLOR. MAURIS EGET NISL DAPIBUS, FERMENTUM PURUS VITAE, ULTRICES NULLA. MAECENAS TINCIDUNT MI LIBERO, VITAE PLACERAT DUI ELEIFEND NEC. DUIS NON INTERDUM SEM, PORTA BLANDIT LIGULA. NUNC VEHICULA AT LEO AC IMPERDIET. ETIAM GRAVIDA LOREM LEO, PHARETRA FACILISIS EROS VESTIBULUM UT. MORBI VULPUTATE LIGULA MAURIS, AC ULTRICIES MAGNA POSUERE UT. DONEC ACCUMSAN TELLUS IN MAGNA VARIUS POSUERE. FUSCE ID LOBORTIS MASSA. QUISQUE ENIM DOLOR, SCELERISQUE POSUERE TRISTIQUE EGET, CONVALLIS VITAE ORCI. FUSCE NUNC LACUS, INTERDUM SIT AMET TELLUS QUIS, ALIQUAM PRETIUM NISL. NULLA NON JUSTO CONGUE, VESTIBULUM DOLOR NON, IACULIS SAPIEN. SED VOLUTPAT VULPUTATE DIAM AC ACCUMSAN. NULLA INTERDUM LACUS EROS, ID FACILISIS LIGULA HENDRERIT A. CURABITUR ID ALIQUAM ARCU. VESTIBULUM ID LACINIA TELLUS, VEL VARIUS LOREM. DUIS EU NULLA CONGUE, SOLLICITUDIN SEM SED, TEMPOR NISL. UT VITAE DAPIBUS JUSTO. PHASELLUS VENENATIS CONSEQUAT AUCTOR. SED EFFICITUR BIBENDUM DICTUM. VIVAMUS UT LAOREET URNA, NON DIGNISSIM LACUS. DONEC TELLUS ENIM, ULTRICES AC DIGNISSIM ID, GRAVIDA UT NISL. ETIAM VOLUTPAT MAGNA AC URNA SEMPER ULLAMCORPER. SED ALIQUAM LIGULA MAGNA, VITAE TINCIDUNT METUS FAUCIBUS EGET. MORBI POSUERE URNA ORNARE ERAT FINIBUS, SED POSUERE MAURIS PHARETRA. PHASELLUS ET MI DAPIBUS, EFFICITUR MASSA SED, POSUERE TORTOR. ALIQUAM FEUGIAT JUSTO NON CURSUS POSUERE. PROIN EGET DIGNISSIM METUS, VITAE LACINIA NUNC. CURABITUR LUCTUS, EROS AT CONSEQUAT FINIBUS, EROS AUGUE LUCTUS RISUS, ID ACCUMSAN ANTE FELIS UT FELIS. PROIN MATTIS RISUS LACINIA MAGNA RUTRUM, AT EFFICITUR SEM SCELERISQUE. INTEGER VEL HENDRERIT FELIS. UT FAUCIBUS NON SEM NON EFFICITUR. IN HAC HABITASSE PLATEA DICTUMST. MAECENAS CURSUS EFFICITUR ORNARE. NAM EGET SODALES MAURIS. NAM CONVALLIS LAOREET EUISMOD. MORBI SODALES DUI CURSUS ELIT EUISMOD AUCTOR.\n"
iterations = 1000
iterations = 10000
12 changes: 12 additions & 0 deletions crates/compiler/src/compiler/codegen/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub(super) enum CobaltIntrinsic {
PrintInt, // void cb_print_i64(i64)
StrCmp, // i8 cb_strcmp(char*, char*)
StrCpy, // void cb_strcpy(char*, char*, i64, i64, i64, i64, i64, i64)
CharCpy, // void cb_charcpy(char*, char*, i64, i64)
ReadStr, // void cb_readstr(char*, usize)
ReadInt, // i64 cb_readint()
ReadFloat, // f64 cb_readfloat()
Expand Down Expand Up @@ -107,6 +108,7 @@ impl IntrinsicManager {
CobaltIntrinsic::PrintInt => printint_sig(&mut sig),
CobaltIntrinsic::StrCmp => strcmp_sig(&mut sig, module),
CobaltIntrinsic::StrCpy => strcpy_sig(&mut sig, module),
CobaltIntrinsic::CharCpy => charcpy_sig(&mut sig, module),
CobaltIntrinsic::ReadStr => readstr_sig(&mut sig, module),
CobaltIntrinsic::ReadInt => readint_sig(&mut sig),
CobaltIntrinsic::ReadFloat => readfloat_sig(&mut sig),
Expand Down Expand Up @@ -137,6 +139,7 @@ impl IntrinsicManager {
CobaltIntrinsic::PrintInt => "cb_print_i64",
CobaltIntrinsic::StrCmp => "cb_strcmp",
CobaltIntrinsic::StrCpy => "cb_strcpy",
CobaltIntrinsic::CharCpy => "cb_charcpy",
CobaltIntrinsic::ReadStr => "cb_readstr",
CobaltIntrinsic::ReadInt => "cb_readint",
CobaltIntrinsic::ReadFloat => "cb_readfloat",
Expand Down Expand Up @@ -205,6 +208,15 @@ fn strcpy_sig(sig: &mut Signature, module: &mut ObjectModule) {
}
}

/// Generates a function signature for [`CobaltIntrinsic::CharCpy`].
fn charcpy_sig(sig: &mut Signature, module: &mut ObjectModule) {
let ptr_type = module.target_config().pointer_type();
sig.params.push(AbiParam::new(ptr_type)); // src_str
sig.params.push(AbiParam::new(ptr_type)); // dest_str
sig.params.push(AbiParam::new(types::I64)); //src_idx
sig.params.push(AbiParam::new(types::I64)); //dest_idx
}

/// Generates a function signature for [`CobaltIntrinsic::ReadStr`].
fn readstr_sig(sig: &mut Signature, module: &mut ObjectModule) {
let ptr_type = module.target_config().pointer_type();
Expand Down
Loading

0 comments on commit 76773c8

Please sign in to comment.