C++ Logo

std-proposals

Advanced search

Re: Fwd: Proposal for improving the C/C++ language, to get higher performance

From: Wesley Oliver <wesley.olis_at_[hidden]>
Date: Mon, 18 Jan 2021 16:56:31 +0200
Hi,

The example for the second which I forgot would be as follows:
I see that formatting of 2 got messed up, so I have hoisted it and move the
code example to the same section to keep the flow simple.

Kind Regards,

Wesley Oliver


On Mon, Jan 18, 2021 at 4:26 PM Wesley Oliver <wesley.olis_at_[hidden]> wrote:

> Hi,
>
> Well the realm of change to high level language, which can express
> solution in, that the compiler will then convert
> with optimization and things to low level instructions or and intermediate
> language.
>
> So with my suggestion one is an alternative I feel more readable way to
> work with bits and bitmap pages, which the language could expose a high
> level syntax and the compiler
> would then convert to the low level verbose more complex interpretation.
>
> So the one with this would be language suggested improvement, in which a
> compiler would then have to obviously implement support for in that
> language version.
> Additional Native Ptr BitMap Flags bit position to int or ptr, value and
> visa versa visa for languages and CPU
>
> https://docs.google.com/document/d/1VlxUG9Cvp3YPRyF_CdCkGeGgRyGA0GDp3miDJElAbT4/edit
>
> Then the other idea of mine for break, continue, skip with label that can
> be used in the language with slight improved scope, would be another c/C++,
> javascript language specification improvement,
> in which the compiler would then have to be upgrade to get support for.
> The compiler with difficult will be able to re-wrok code to this level, in
> my mind, as my solutions would be greatly different and
> the power of the human brain is lot more powerfully, inverting a solution
> to a problem because it faster written in different way with 4 levels of
> looping, and other complex logic, the compiler is going to have a hard time
> pattern match that.
>
> That why I have suggested the improvement to break, continue, addition of
> skip that each take a parameter int or label to simplify things, in which
> myself as the human can write very different solutions to problems that the
> compiler can simply compile to existing instructions in different solution.
> Later on the compilers could look at improving this to automatically detect
> many various patterns, which become more complex for it to do and will take
> time, as those patterns need proof that don't change the behavior of code.
> So first of would be the improvement of the languages to enable us to write
> more efficient code, that could be directly at statement level translated
> to instructions or intermediate language, which is much easier to implement.
>
> Later one could then look at if any existing compiler optimization and how
> many of them current may or mayn't be able to translate code into such
> optimal solutions in instructions that us humans can do and be really
> creative about.
>
> The idea I have submitted to the language commit for javascript, as well I
> do C and then C++ and guess eventually java will follow, because of the
> performance and freedom to new solutions that can be written with the
> language changes, that the compilers can directly translate to
> instructions, with out optermizations.
>

----------------------
* 2: This is basically the idea of improving the efficiency of code
execution, which compilers could do if there can determine which statements
they can running in parallel or asynchronously. *

>

> async {conditiona statement, bounds check statement, boundscheck statment}
> or
> {conditiona statement, bounds check statement, boundscheck statment} ,
> same as {conditiona statement & bounds check statement & boundscheck
> statment}
> What the compiler would do and later cpu enhancement for instructions that
> the compiler could take advantage of is the following.
> The the statment is backwards compatible and will run in sequential order
> from right to left if not support or lack of registers.
>
> Compiler will try and load the evaluation of these statements in different
> register, in other words 6 register, that a hybrid instruction could
> execute maybe SIMD on all, but actually <,>,===, 1== type combination of
> statements, maybe later more.
> Actually later more with different way of design a processor in my mind.
>
> By having this language improvement, we see how much more code speed up as
> basically load store and compares for each of these statements could be
> reduce to since clock cycle version 3X3 = 9 clock cycles.
>
> We may want to think about the syntax, as they may be other later
> variation that can be asynced, so maybe want to not implied the allowed
> parameters, just use bracket to say the section
> can be async and the compiler will handle it. may want different key word
> that async like masync which means micro processor async work in the chip
> wiring.
>
> I do think that what one could look at doing to improve the speed of
> processor from my Engineering VHDL brack ground is the following.
> New architecture that is backwards compatible, that reduces load and
> stores, by directly coupling the instruction for operation between
> registered directly to
> a selection bus instead. so one has a data store stack, with up to 20 X
> 64bit or more require lanes to the instruction logic.
> Instructions execute on bus/bitwidth/granularity, posslbe support SIMD if
> less 64bit for same instruction. each instruction specifies a one the
> selector buses.
> This would mean there are no load an store operation into register, that
> are permantely connected to the datastore.
> operations can typically run on any selector bus combinations input1,
> input2, result to the datastore out of the 20 it can select from.
> This is equivalent of giving a processor like 20 register to operate with.
> To improve things further, the 20 X 64bit datastore, has hit counter such
> keeps the most used data in memory, so if someone only gets operated on 1
> per every 12 cycles,
> then that item will be loaded into the lowest data register. out of the 20
> and will be evicted the most. There could be optimal predictor loader, that
> load maybe 4 datastore register
> such that there is no stalling the cpu and data is available for next
> operation so those load statement are not seen.
>
> They could introduce groups of data store selector buses, based on stats
> of many programs, such they have many more say 100 eventually directly
> operation, with no common bus,
> to improve performance, and also allow for async, parallel computation on
> the datastore as long as there are not select bus instruction conflicts.
>
> I hope that this helps you better understand the level at which I work and
> the levels just like Microsoft got intel got cpu makers to implement so do
> improve things.
> The same is what I am going for here, what I need in a language that would
> allow me to write improved faster code, that later the cpu and compilers
> would almost directly
>

function match(string str) {

string match = "matchme";

int countMatch = 0;
for( int i = 0; true; i++;)
{
  label-continue; // start executing code from here, if you where nearer
the javascript specific as of current, else required inline function and
use return
inline function(...) {
  int j = 0;
  while(true) {
    if (
     masync{str[i] != match[j] & i < str.length & j < matchstr.length}
     ) {
    continue label-continue; // or you use return, with the inline function
   }
  }
countMatch++ ;
}// inlineline function using return.
return count;
}

or

function match(string str) {

  string match = "matchme";

  int countMatch = 0;

   for( int i = 0; true; i++;)
  {
   match( countMatch, str, match);
  }
  return count;
}

 label-continue; // start executing code from here, if you where nearer the
javascript specific as of current, else required inline function and use
return
inline function match(int& countMatch , string& str, string& match) {
  int j = 0;
  while(true) {
    if (
     masync{str[i] != match[j] & i < str.length & j < matchstr.length}
     ) {
      return;
   }
  }
countMatch++ ;
}

---------------------------

>
>
> *1. *Currently C/C++ falls flat on this because it just goto statement in
> the background, the language specification hasn't taken into account the
> looping logic for loops, that need to be taken into account.
> So c++ behaviour is not desirable, therefore would like to suggest
> improvements to match that of javascript and also include the short comings
> of javascript, labels any where finer grained control and
> the ability to chain break;continue, break; statement, to get the desired
> behaviour different for loop existing on ones way out.
>
>
> https://es.discourse.group/t/achive-higher-performent-solutions-with-greater-high-level-control-of-break-num-label-continue-skip-equivalent-of-low-level-goto-with-block-chain-of-statments/619
>
> Achive Higher performent solutions with Greater high level control of
> break(num/label), continue(-), skip(-), equivalent of low level 'goto' ,
> with block chain of statments
> <https://es.discourse.group/t/achive-higher-performent-solutions-with-greater-high-level-control-of-break-num-label-continue-skip-equivalent-of-low-level-goto-with-block-chain-of-statments/619>
>
> Continue to push the boundaries of performance that javascript solution to
> problems can deliver in a high-level language, that only be achieved in
> more tedious assemble, low level c/C++ will get you.
>
> The proposal is to improve the flow control statements in Loops e.g for,
> while, do, which allows for better-optermized solutions to problems,
> avoiding some tricks, to do the same, which slight would defeat the
> purpose, as tricks come with hidden cpu cycle overhears.
> I will provide examples of solution that should generate more optimize
> assembly code and have faster run times for early kick out solution, where
> there can be less boiler plat to handle early kickout and positive cases.
>
> Propose that with in a since function block scope, to keep it simple at
> first, later it could possible be expanded to indefinite level, however,
> that would result in language become too complex.
>
> Proposal 1:
> Allow changing of break, continue, skip in sequence, to control multiple
> loops and not just the most inner loop, from with in the most inner loop.
> e.g
>
> for(let i = 0; i < 10; i++) {for(let j =0;j<10;j++) {
> console.log(i + ":" + j+",");
> if (j ==5) {
> break;
> continue;
> }
> }console.log("Tail assume correct count increments or similar code");
> }
> output: 1:1,1:2,1:3,1:4,1:5,2:1,2:2,2:3,2:4,2:5,....
>
> Proposal 2:
> Block skip operator, which allows for a section of code to totally be
> skip, such that a solution can have multiple manual typed sections, where
> not all may apply to the current iteration evaluation, so want them to be
> skipped. This could be achieved with map of functions to be call based on a
> condition, but this adds additional complexity and low-level code
> generation. This is my mind would allow process to better skip instructions
> and branch predict, than over head of function calling may have, but
> probably with compiler optermizations results in the same optermization of
> code block of all if statements for skips instruction being hoisted, and
> then it running the blocks.
>
> for (let i = 0; i < 10; i++)
> {
> {
> skip;
> console.log("First Block,");
> }
> {
> console.log("Second Block,");
> }
> }output: Second Block,Second Block,Second Block,Second Block,Second Block,Second Block,...
>
> Proposal 3:
> Allow parametrized version of a break, continue, skip that take either an
> integer or label to control the exit of multiple neasted loops. The integer
> version say how many loops to skip, not present current loop, if larger
> than 0, it will skip, break or continue until that many times until the
> count has decrease to 0.
> e.g number
>
> for (let i = 0; i < 5; i++) {
> for (let j = 0; j < 5; i++) {
> for (let j = 0; j < 5; i++) {
>
> console.log("K");
> break(3);
> }
> }
> }
> output: K
>
> e.g label
>
> :label-first-loop:for (let i = 0; i < 5; i++) {
> :label-second-loop
> for (let j = 0; j < 5; i++) {
> :label-third-loop
> for (let j = 0; j < 5; i++) {
>
> console.log("K");
> break(label-first-loop);
>
> label-first-block: {...}
> label-second-block: {....}
> label-third-block: {....}
> }
> }
> }
> output: K
>
> By doing this one can write much better solutions, like the following
> below:
>
> function johnMary(str) {
>
> const strJohn = "John"; // may not have null terminating as also check as literal charater.
> const strMary = "Mary";
> const strWasley = "Wasley";
>
> //str += '\u0000';
>
> let countJohn = 0;
> let countMary = str.length;
> let countWasley = 0;
>
> for(let i = 0; i < str.length; i++) {
>
> (function() { // or lamda.
>
> if (str[i] !== strJohn[0]) { // asumption of no empty strings, which incertain langauges are represented by \0\0 incase of other end condition optermization.
> return; //skip, basically goto end of parent block of brace code, this would allow for code after this doing a second string comparision to execute.
> // skip, break, continue should be parametised, which take in a number e.g skip(2), will skip to blocks.
> //*** alternative to return would be skip, which allows us not to use a anonmas function wrapper and overhead.***
> }
>
> let end = i + strJohn.length;
>
> // In javascript it looks like one is quite luck, as the comparison of arr[-1] == arr[-1] => undefined === is false, so there is no additioanl evaluation.
> // So I guess on needs check what happens in the arr access, but I am sure each access will be check string bounds anyways, so the only improvement here would be acess with null string terninator.
> // to get a speed up as one would have in c++, so I am guessing depending on the back altought the v8 is back by c++, could get a mabye not get one less if check.
> // typically if the input string 'str' is null terminated '\0' then this block of code wouldn't be needed.ONe see speed up of one less up front if statment, no branch prediction needed, typically only
> // when get near end of the string there would be a penalty for additional loop, increment, condition, if-break. for the posibly 90% of evaluations, improve branch prediction.
> // versus assignment, condition-execute.
>
> // if (end > str.length) {
> // end = str.length;
> // }
>
> for (let j = 1, k = i + 1; k < end; j++, k++) {
>
> console.log(str[k] + ":" + strJohn[j]); // check iterations here for tetsing.
> if (str[k] !== strJohn[j])
> return; // break;contiunue in sequence, or continue(2), in some circumstances, however, not if want futher cod eto run that is a results of positive match in other skip blocks.
> }
>
> countJohn++;
>
> })();
>
> // Code that would typiclaly execute after the skip statment.
> //*** */:label-skip-alternative-matching-logic ***
> {
> end = Math.min(i + strMary.length, str.length);
>
> for (let j = 0, k = i; k < end; j++, k++) {
>
> const ch = str[k];
>
> if (ch !== strMary[j]) {
> countMary--; // Many additional subtractions operations at a low level are required, can also result in greater mistakes and complicated code as assume all are matches, which for this case you can do.
> break;
> }
> }
> }
>
> {
> end = Math.min(i + strWasley.length, str.length);
>
> for (let j = 0, k = i; k < end; j++, k++) {
>
> const ch = str[k];
>
> if (ch !== strWasley[j]) {
> countWasley--; //unessary computation, bnut require undoing computation, wasited cycles. 2X, also requires negative variables.
> break;
> }
> }
>
> countWasley++; // nessary sucessull computation.
> // if we get out the loop we would like to assume positive, but in this case,
> // we have to countWasley
> }
> }
>
> console.log("John:" + countJohn);
> console.log("Mary:" + countMary);
> console.log("Wasley:" + countWasley);
>
> return countJohn === countMary && countMary === countWasley;
> }console.log(johnMary("John"));console.log(johnMary("John&Mary&Wasley\0"));
>
> Reply
>
> - created
> 1d
> - last reply
> <https://es.discourse.group/t/achive-higher-performent-solutions-with-greater-high-level-control-of-break-num-label-continue-skip-equivalent-of-low-level-goto-with-block-chain-of-statments/619/3>
>
> <https://es.discourse.group/t/achive-higher-performent-solutions-with-greater-high-level-control-of-break-num-label-continue-skip-equivalent-of-low-level-goto-with-block-chain-of-statments/619/3>
> 18h
> - 2replies
> - 33views
> - 2users
> -
>
>
> <https://es.discourse.group/t/achive-higher-performent-solutions-with-greater-high-level-control-of-break-num-label-continue-skip-equivalent-of-low-level-goto-with-block-chain-of-statments/619/3>
> <https://es.discourse.group/u/aclaymore>
> aclaymore <https://es.discourse.group/u/aclaymore>
> 18h
> <https://es.discourse.group/t/achive-higher-performent-solutions-with-greater-high-level-control-of-break-num-label-continue-skip-equivalent-of-low-level-goto-with-block-chain-of-statments/619/2>
>
> If I am following correctly these are all already possible with labels.
>
> Proposal 1:
>
> outerLoop: for (let i = 0; i < 10; i++) {
> for (let j = 0; j < 10; j++) {
> console.log(i + ":" + j + ",");
> if (j == 5) {
> continue outerLoop;
> }
> }
> }
>
> Proposal 2:
>
> console.log('1');
> test: {
> console.log('2');
> break test;
> console.log(`this won't run`);
> }console.log('3');
>
> Proposal 3:
>
> outerLoop: for (let i = 0; i < 5; i++) {
> for (let j = 0; j < 5; i++) {
> for (let j = 0; j < 5; i++) {
> console.log("K");
> break outerLoop;
> }
> }
> }
>
> Reply
>





>
> <https://es.discourse.group/u/wesley_olis>
> wesley_olis <https://es.discourse.group/u/wesley_olis>
> 1m
> <https://es.discourse.group/t/achive-higher-performent-solutions-with-greater-high-level-control-of-break-num-label-continue-skip-equivalent-of-low-level-goto-with-block-chain-of-statments/619/3>
>
> Hi,
>
> thank you for sharing that, was not where of that, because c/c++
> specification labels are limited as I pulled the specification to be within
> block scope, as there are limitation of using goto can be used.
>
> After testing this is my problem with the code and specification, which
> limits what is possible
> never the less, this is already good to know, as in c continue is
> equivalent of goto, has not properly been integrated with for loop control
> like javascript has, however, still feel there is room for improvement,
> which gives us the correct ganulaity of control.
> c++ breaking or goto the mostouter will have your program running
> indefinitely. as is different in meaning.
>
> labelled object literal is great because break as if this was an early
> return function, but without having to nest an anonymous functions
>
> 1.
>
> continue with a label, performs breaks and the last loop is a
> continuous behaviour, one still wants granularity of control here, because
> could have global scope variables, in which break, break, continue
> behaviour is not desired.
> 2.
>
> break in a loop, stops execution and skips the final conditional
> check, incremental step as per normal.
> 3.
>
> labels must be anywhere in the loop or outside section as long it now
> across function bounderies, obviously continue has the constraint of above
> the previous loop start. can't break to label brace section from outside
> the block scope.
>
> 4.skip, is required because break is basically only to parent block
> section label or an object literal bracet block, which allow for finer
> grain control.
>
> 1. Chaning of break and continue statements, such that different
> behaviour of exiting multiple neasted loops can be achieved, so get program
> behaviour that one desires. continue 3 loops, out may not be want ones
> wants, with have more global variables.
>
> mostLoop: for (let i = 0; i < 5; i++) {
> console.log("SkipContinue");
> /* breakHere:{
> console.log("breakHere");
> }*/
> console.log("runCOntinue");
> outerLoop: for (let j = 0; console.log("outerCondition") || j < 5; j++, console.log("outerLoopPosRepeatStep")) {
>
> console.log("outerinnerbefore");
>
> innerLoop: for (let k = 0; console.log("innerCondition") || k < 5; k++, console.log("innerLoopPosRepeatStep")) {
> console.log("K" + i + ":" + j + ":" + k);// continue innerLoop;
> //continue outerLoop;
> //break outerLoop;
> break mostLoop;
> console.log("SkipK");
> }
> console.log("outerinnerpost");
> }
> }
>
> test1: {
> console.log("test1");
> break test2
> console.log("test1postbreak");
> }
>
> test2: {
> console.log("test2")
> }
>
>
>
>
> The idea, I have to help the compiler and the writer determine which
> statements, is the following:
>
> aenhance the execution of with the new knowlagde I have given them.
>
> Kind Regards,
>
> Wesley Oliver
>
>
>
> On Mon, Jan 18, 2021 at 11:31 AM Peter Sommerlad (C++) <
> peter.cpp_at_[hidden]> wrote:
>
>> Dear Wesley,
>>
>> I have a hard time to understand what you are actually suggesting.
>>
>> Please prepare a Tony-Table to show before/after what code would look
>> like with your proposal.
>>
>> From a gut feeling, I think you are trying to change stuff in the
>> language, that is in the realm of compiler optimizers.
>>
>> Regards
>> Peter.
>>
>> Wesley Oliver via Std-Proposals wrote on 17.01.21 13:52:
>> >
>> >
>> > Hi,
>> >
>> > I would like to propose an improvement to the C and well c++ language,
>> > because I believe it should be available in both languages that would
>> > allow us to write more performant code in a Higher Level language
>> > without having to write assemble level or low-level c with assemble.
>> >
>> > I have proposed typically something similar to javascript, however,
>> this
>> > applies to all languages
>> > c, c++ as limitation of all them, goto doesn't hit the mark, comes up a
>> > little short.
>> > In c, c++ inline would probably get one near there with compiler
>> > optermizations, but it is still not a great way to write code.
>> >
>> > I would like to allow loops structures, to do what I describe below,
>> but
>> > basically the same applies for c/c++, however, one would be using
>> > explicit function inlining.
>> >
>> > Typically I am sure that there would be many solutions of comparison,
>> > where we would be able to start taking advantage of this to improve the
>> > speed of algorithms,
>> > which currently high level languages basically limit.
>> >
>> >
>> https://es.discourse.group/t/achive-higher-performent-solutions-with-greater-high-level-control-of-break-num-label-continue-skip-equivalent-of-low-level-goto-with-block-chain-of-statments/619
>> >
>> > https://sites.google.com/site/wiprogamming/Home/developer-blog
>> >
>> > 07 April 2020 - Additional Native Ptr BitMap Flags bit position to int
>> > or ptr, value and visa versa visa for languages and CPU
>> > <
>> https://docs.google.com/document/d/1VlxUG9Cvp3YPRyF_CdCkGeGgRyGA0GDp3miDJElAbT4/edit?usp=sharing>
>>
>> >
>> >
>> > Also thinking about it stepping a pointer onwards and de-referencing to
>> > access the value, I think could also have special optimization, to look
>> > at making this one operation stepAndLoadValue, but I would have go and
>> > check the instruction set of various process, but definitely benefit
>> > from that
>> > I have go check them out and arm instruction set.
>> > may need a char^ like in delphi, but means variable acts like a
>> pointer,
>> > however, pair with its dereferenced version, possibly lazy evaluated.
>> > That would save me from have to have to variables here to reduce the
>> > double dereferencing, it's simpler to work with a variable
>> > that have both accessible, thinking maybe look like an iterator, first,
>> > second. concept, to keep backwards compatibility with operators.
>> > the wrapping class could then just simplify things and reduce require
>> > number of variables for optimal performance.
>> >
>> > Overall this reduce the number of if statements and things and allows
>> > for faster branch prediction.
>> > Typicaly have string which are null terminated, is much faster as
>> > reduces all underlying checks. well at least other languages,
>> > c is not doing that but still, wanting the most performant code.
>> >
>> > *Example:
>> > *
>> > function match(char* str) {
>> >
>> > char* matchme = "matchme\0";
>> >
>> > let countMatch = 0;
>> >
>> > for(char* ch = str, char chd = ch*;chd != '\0';ch++, chd = *ch)
>> > {
>> > // could make this an inline function.
>> >
>> > char* chs = str, char chds = chs*;
>> > char* mech = matchme, char mechd = *mech ;
>> > while(true) { // sure that by now compiler optermized, could just
>> > say loop
>> > if (chds != mechd) {
>> > if(mechd == '\0') {
>> > break;
>> > continue; // kicks out of the loop and skip the rest of the
>> > parent look code, for a case that fail, in the case of successfully
>> > match, then countMatch++ will execute.
>> > }
>> > }
>> > mech++; mechd = * mech; chs++; chds = *chs ;
>> > }
>> > countMatch++;
>> > }
>> > }
>> >
>> >
>> > Kind Regards,
>> >
>> > Wesley Oliver
>> >
>> >
>> >
>> > --
>> > ----
>> > GitHub:https://github.com/wesleyolis
>> > LinkedIn:
>> https://www.linkedin.com/in/wesley-walter-anton-oliver-85466613b/
>> > Blog/Website:https://sites.google.com/site/wiprogamming/Home
>> > Skype: wezley_oliver
>> > MSN messenger: wesley.olis_at_[hidden] <mailto:wesley.olis_at_[hidden]>
>> >
>> > <
>> http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
>>
>> > Virus-free. www.avg.com
>> > <
>> http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
>>
>> >
>> >
>> > <#m_-1762488501658346478_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>> >
>> >
>> > --
>> > ----
>> > GitHub:https://github.com/wesleyolis
>> > LinkedIn:
>> https://www.linkedin.com/in/wesley-walter-anton-oliver-85466613b/
>> > Blog/Website:https://sites.google.com/site/wiprogamming/Home
>> > Skype: wezley_oliver
>> > MSN messenger: wesley.olis_at_[hidden] <mailto:wesley.olis_at_[hidden]>
>> >
>> >
>>
>>
>> --
>> Peter Sommerlad
>>
>> Better Software: Consulting, Training, Reviews
>> Modern, Safe & Agile C++
>>
>> peter.cpp_at_[hidden]
>> +41 79 432 23 32
>>
>
>
> --
> ----
> GitHub:https://github.com/wesleyolis
> LinkedIn:https://www.linkedin.com/in/wesley-walter-anton-oliver-85466613b/
> Blog/Website:https://sites.google.com/site/wiprogamming/Home
> Skype: wezley_oliver
> MSN messenger: wesley.olis_at_[hidden]
>


-- 
----
GitHub:https://github.com/wesleyolis
LinkedIn:https://www.linkedin.com/in/wesley-walter-anton-oliver-85466613b/
Blog/Website:https://sites.google.com/site/wiprogamming/Home
Skype: wezley_oliver
MSN messenger: wesley.olis_at_[hidden]

Received on 2021-01-18 08:56:47