- read-only, write-only and read-write memory mapped I/O - 3 Updates
- Rudolph, the red-nosed reindeer - 4 Updates
- "Metaclasses: Thoughts on generative C++" 2017-07-26 by Herb Sutter - 4 Updates
- Here is my political thoughts - 1 Update
- "Death to C, ++" - 2 Updates
- "Metaclasses: Thoughts on generative C++" 2017-07-26 by Herb Sutter - 1 Update
- Equivalent unary operators for BSF and BSR - 1 Update
legalize+jeeves@mail.xmission.com (Richard): Aug 02 02:38AM [Please do not mail me a copy of your followup] jt@toerring.de (Jens Thoms Toerring) spake the secret code >I've played around with this bit but get a problem when I >try to do e.g, >ReadWriteRegister<uint16_t, 0x1000> rwr; Yeah, I had similar problems and my test code made it compile, but as I look on it now, it wasn't representative of the use case. I can certainly do it with the address held at runtime, but in most embedded environments the memory map doesn't change because you're using physical addresses, not addresses obtained at runtime. My goal is to find something that is as idiomatic as the following C code (Game Boy Advance is my reference platform): #include "toolbox.h" int main() { DISPCNT = DCNT_MODE3 | DCNT_BG2; m3_plot( 120, 80, RGB15(31, 0, 0) ); // or CLR_RED m3_plot( 136, 80, RGB15( 0,31, 0) ); // or CLR_LIME m3_plot( 120, 96, RGB15( 0, 0,31) ); // or CLR_BLUE while (1); return 0; } Refer to the memory-mapped IO registers summarized here: <http://problemkaputt.de/gbatek.htm#gbaiomap> There are read/write, read-only and write-only registers on the GBA. The C libraries used by most coders don't prevent you from mistakenly reading a write-only register, etc. Refer to "tonclib" tutorial for snippet above: <http://www.coranac.com/tonc/text/first.htm#sec-second> What I like about this snippet: - any GBA programmer is going to understand what is happening to the DISPCNT register here. - The "m3_plot" routine is easily inferred as "(display) mode 3 pixel plot" based on the arguments and the face that DISPCNT is put into mode 3. Again, this is going to be understandable if you understand GBA display hardware. - Computing the value assigned to DISPCNT results in very efficient code (simply store fixed constant value at a fixed constand address) - RGB15 macro results in efficient constants passed into m3_plot. What I dislike about this snippet: - It relies on macros with all their pitfalls - No guard against mistakes. What if I use the wrong bitfield macros (e.g. macros intended for the values of a different register) for DISPCNT register? DISPCNT is read/write, but other registers are read-only or write-only. What if I use them incorrectly? - RGB15 macro can't alert me when I use arguments that are out of range. I think this tonclib library is a good starting point, but I want to explore ways in which the zero overhead abstraction of C++ can allow us to do better at finding coding mistakes at compile-time, assist us in unit testing our code, all without giving up the efficiency of the resulting code that we can already get from tonclib. Gcc is kept current for the GBA, so we aren't held back by older compilers. <https://sourceforge.net/projects/devkitadv/files/> -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Terminals Wiki <http://terminals-wiki.org> The Computer Graphics Museum <http://computergraphicsmuseum.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
legalize+jeeves@mail.xmission.com (Richard): Aug 02 08:54PM [Please do not mail me a copy of your followup] This seems to do the trick better. I'm not a fan of having to sprinkle the reinterpret_cast's in there, but at least they are encapsulated inside the implementation. #include <cstdint> namespace RegisterModel { typedef uint64_t addr_t; template <typename T, addr_t const address> struct ReadOnlyRegister { operator T() const { return *reinterpret_cast<volatile T const *>(address); } T operator=(T) = delete; }; template <typename T, addr_t const address> struct WriteOnlyRegister { operator T() const = delete; void operator=(T value) { *reinterpret_cast<volatile T *>(address) = value; } }; template <typename T, addr_t const address> struct ReadWriteRegister { operator T() const { return *reinterpret_cast<volatile T const *>(address); } void operator=(T value) { *reinterpret_cast<volatile T *>(address) = value; } }; } namespace { using namespace std; using namespace RegisterModel; ReadWriteRegister<uint32_t, 0x04000000U> DISPCNT; } It's also a little ugly that I now need to declare RegisterModel::addr_t as the type of an integer big enough to hold an address in the target platform. In the GBA, this is a std::uint32_t but if I'm compiling unit test code on Windows this might be std::uint64_t. Still, it solves the compiler complaining about the constraints on the pointer argument to the template while giving me an address known at compile time. Going back to the tonclib example I posted earlier, we could get more safety for the DISPCNT register in one of a couple ways. We could view DISPCNT = DCNT_MODE3 | DCNT_BG2; as constructing a constexpr expression on the right that produces some explicit type representing valid values of the DISPCNT register, say DisplayControl, and write an assignment operator for values of these types: struct DisplayControl { // standard enum bit flags style class implementation }; struct DisplayControlRegister : public ReadWriteRegister<uint32_t, 0x04000000U> { DisplayControl operator=(DisplayControl value); }; DisplayControlRegister DISPCNT; Now I'm protected against assigning invalid values into the display control register. Another approach is to model the individual fields in the display control register as getter/setter functions on DisplayControlRegister. However, that would likely involve read/modify/write cycles for the individual chunks and wouldn't be as efficient as the C style code above. The nature of this register is that it is generally configured once wholesale at game startup. For other registers, getter/setter methods might be more reasonable if you are changing the individual fields at different times. Knowing which is best involves more understanding of idiomatic GBA programming. -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Terminals Wiki <http://terminals-wiki.org> The Computer Graphics Museum <http://computergraphicsmuseum.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
red floyd <dont.bother@its.invalid>: Aug 02 04:13PM -0700 On 8/2/2017 1:54 PM, Richard wrote: > std::uint64_t. Still, it solves the compiler complaining about the > constraints on the pointer argument to the template while giving me > an address known at compile time. What about uaddr_t? I know it's probably not ISO standard, but I *THINK* it's POSIX.... |
"Öö Tiib" <ootiib@hot.ee>: Aug 01 11:43PM -0700 > > > ? An account is not needed to run those. > > No. Why to run those? I won't. > Well, you did say you "like to try stuff." That was not meant to imply that I download arbitrary code from internet and compile and run it. > 2009. Now the only way is via the command line > interface. I'm happy to help anyone get started > with it. Yes, but how can anyone know that there have been no online tools since 2009? Nothing says that anywhere. To reduce your work of helping you could try to make it easier to understand from your page what steps one is expected to take for to get some C++ data serialized and deserialized. See examples that I gave. https://capnproto.org/cxx.html http://www.boost.org/doc/libs/1_64_0/libs/serialization/doc/index.html From those it is immediately obvious what one is expected to do. > You can clone or download the code and build it. > On my slowest machine, it takes less than 3 seconds > to build. Ok, thanks. |
scott@slp53.sl.home (Scott Lurndal): Aug 02 12:26PM >any of my employers, past or present, would countenance putting their >private information out on a 3rd party's web site. Which would stop this >cold. I concur. We use Apache Thrift for interlanguage RPC. From a company perspective, on-line code generation is a non-starter, even leaving aside the security implications. |
woodbrian77@gmail.com: Aug 02 10:41AM -0700 On Wednesday, August 2, 2017 at 7:27:01 AM UTC-5, Scott Lurndal wrote: > >private information out on a 3rd party's web site. Which would stop this > >cold. > I concur. We use Apache Thrift for interlanguage RPC. The C++ Middleware Writer is a form of message oriented middleware. > From a company > perspective, on-line code generation is a non-starter, even leaving aside > the security implications. Companies can buy a license if they want to. Brian Ebenezer Enterprises http://webEbenezer.net |
woodbrian77@gmail.com: Aug 02 02:19PM -0700 > > >cold. > > I concur. We use Apache Thrift for interlanguage RPC. > The C++ Middleware Writer is a form of message oriented middleware. Konstantin, the guy who developed the benchmarks has updated the repo recently. Now I'm able to get past the build problem with capnproto, but am hitting a build problem with Thrift -- it can't find openssl/err.h. Shouldn't cmake check for that? I also tried building the benchmark project on Trueos/ FreeBSD, but hit a build problem with Boost. Have I mentioned that the C++ Middleware Writer minimizes the amount of code that you have to download/build/maintain/etc? Brian Ebenezer Enterprises - In G-d we trust. http://webEbenezer.net |
legalize+jeeves@mail.xmission.com (Richard): Aug 02 02:17AM [Please do not mail me a copy of your followup] "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> spake the secret code >[...] >I hope Herb's thing doesn't >enforce that: usually people find the virtual inheritance cost unacceptable. Since it's a library you can define your own idea of the requirements of an interface or whatever you want to call it. Personally, I would stick to interface being a pure abstract base class and what you describe above is simply a base class, so 'base_class' derives from 'interface'. The advantage of what Herb is proposing is that these choices -- does 'interface' for our team mean abstract base class? -- are left up to you based on what libraries you consume and/or write. His proposed metaclasses give you this general mechanism without requiring the language to impose a particular interpretation on you as a user of the language and if you're not using any of this stuff, you're not paying for it. However, if this mechanism makes it into the language then I see the standard library evolving to encompass a tried-and-tested library of such standard metaclasses and I would not be surprised if the thing named 'interface' ends up being a pure abstract base class and not a combination of pure virtual methods and base class methods. -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Terminals Wiki <http://terminals-wiki.org> The Computer Graphics Museum <http://computergraphicsmuseum.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Aug 02 10:36AM +0200 On 02.08.2017 04:17, Richard wrote: > such standard metaclasses and I would not be surprised if the thing > named 'interface' ends up being a pure abstract base class and not a > combination of pure virtual methods and base class methods. I think you misunderstood me. In Eiffel, as I recall, an interface can be adorned with preconditions and postconditions on methods. This is also possible in C++, though not as a language feature: it must be done as wrappers. There was a DBC proposal once, to get core language support (including maybe syntax). It stranded. With Java you're restricted to a silly semantics-less notion of interface. It would be sad to have that imposed on C++. Cheers!, - Alf |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Aug 02 03:55PM +0200 On 02.08.2017 14:57, Stefan Ram wrote: > This is one example. Java offers several similar > possibilities by other means, like abstract classes > (to hide the implementation method »negateImpl«). Looks like things have changed. In Java 7 the language spec said "Every method declaration in the body of an interface is implicitly abstract, so its body is always represented by a semicolon, not a block". But Java 8 introduced the `default` mechanism. I wasn't aware of that. It's discussed in <url: https://stackoverflow.com/questions/31578427/what-is-the-purpose-of-the-default-keyword-in-java>. Thanks for that feedback! Cheers!, - Alf |
legalize+jeeves@mail.xmission.com (Richard): Aug 02 08:34PM [Please do not mail me a copy of your followup] "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> spake the secret code >In Eiffel, as I recall, an interface can be adorned with preconditions >and postconditions on methods. Uh... if you want to impose precondition and postcondition verificatino you can do that right now with existing mechanisms. This seems unrelated to metaclasses, although I suppose you could use metaclasses to generate the post/precondition validating boiler plate. That's all metaclasses are doing: give you a better way of doing boiler plate than external tools (Qt's moc, COM's IDL) or macros. >With Java you're restricted to a silly semantics-less notion of >interface. It would be sad to have that imposed on C++. Have you watched the video? There is no "imposition" being discussed. -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Terminals Wiki <http://terminals-wiki.org> The Computer Graphics Museum <http://computergraphicsmuseum.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
rami18 <coco@coco.com>: Aug 02 02:10PM -0400 Hello.... Read this: Here is my political thoughts: Communism and hard socialism use Class Struggle, even with violence, as a tool, but this is not like a consistent system, because it is like a state of hate against more intelligent people, or more rich people.. and this being lack of honesty and lack of confidence. This is why you have seen me attacking this problem of Class Struggle, this is a matter of great importance, this is why i have tried to prove that all is not black and white, and this is why tolerance must apply here, but i have tried to prove also that this tolerance i am talking about is inferred from empirical moral as a constrain that enhance optimization, that means that enhance performance and reliability that includes security. Elevated consciousness.. To reach this level it would be necessary to optimize more and i have defined optimization as being performance and reliability, what allowed me to reach an elevated consciousness is that I have been in contact with philosophy and i have done mathematics and i have done operational research and i have done computer science and i have done also politics and so on. This is what makes you become an elevated consciousness, and when you reach this elevated consciousness, you begin to feel rich, it is like wealth, I can like affirm that i am rich in this elevated consciousness, but is it an elevated consciousness? I affirm it because I am able in reality to compare myself to presidents and so on. And in doing so, i am like convinced that I have reached an elevated consciousness. Here is my abstracted political model at first, i have first attacked the problem of Class Struggle of nazism and communism and after that i have showed you what it has to be world wide.. please read all the following to understand my abstracted view that is more correct: Hitler was a national socialist, and since he was also a socialist, the nature of his socialism was violent, so he has applied the tool of Class Struggle with violence against jews , because jews were superior with there intelligence etc. , and since he was a nationalist, his Class Struggle with violence against jews was also a racial Struggle with violence against jews. But read what follows to understand my thoughts: About the essence of communism and the essence of nazism Communism starts from an observation that humans are not equal from the point of view of money and intelligence performance and memory performance and speech and language articulation performance etc. then it says that to give more equal chances, we must use the tool of Class Struggle even if it uses violence. Nazism is national socialism that applies the tool of Class Struggle to fight jews, because jews are superior with there intelligence and money. Now the view of national socialism of nazism and communism is a narrow view, because even of we are high intelligence , we can be not high performance of memory or/and we can be not high performance of speech and language articulation and we can have more risk to construct and to operate and to make successful our private companies etc. so this means that even if we are high intelligence , we can still suffer more, so this tells us that all is not black and white, so from the this point of view , we can not apply Class Struggle of communism and nazism easily, because all is not black and white as i have explained, other than that allowing the rich to be rich , is because we want richness to maximize performance and reliability and security and we want richness because the one that wants to become rich can have more risk and suffers more as i have explained, but to be more fair , we have to be more helpful to the weakest members among us, and we have to be a correct social system. About discrimination and hate.. If you are still immature you will say that i am a white arab, so you will say that you can not be confident with arabs, so you will start to discriminate.. that's an inferior thinking, you have to be able to see the big picture, that means you have to be aware of the economic model of today, you will say that Donald Trump is protectionism, but Donald Trump is aware of the constrains , so he knows about the advantages of Fordism, and he knows also that we are trying to play the game of Fordism by giving the necessary wages to others to be able to buy your products and services, this is not socialism, this is part of thinking bigger in economy, the old way of thinking of racism and hate is the easy and simplistic way of thinking, we know about it , but we have to be smarter and be convinced of the game of today, protectionism must be smart, today we can not be protectionism by hating and discriminating stupidly, because arabs have to be learned how to think the advantages of Fordism and how to think Adam Smith's specialization Theory, this is part of the game of today, also having a great number of people inside the society , like is having USA, is an economic advantage that avoids extremism of the past , by avoiding extremist protectionism, so all in all you understand me more.. and related to what i am saying , i have also said: So you hear for example that: Justice must constrain happiness and responsability must constrain justice, that's not the language of love.. because that's not a correct view, because we are constrained by empirical moral that says that a kind of tolerance over responsability plays the role of an heuristic that optimizes our economic system and our social system, like when we are applying a kind of tolerance over arab immigrants that are useful to the economic system and to the social system, so usefulness is the key point also that optimizes the system and that constrain the system to be a kind of tolerance over responsbility by not saying that arab immigrants are not as beautiful as white europeans and be discrimination with them, that's not the language of love, because the language of love is also optimization that mandate a kind of tolerance over responsability, this is the same when i say that optimization is the language of love also , because we must know how to be compassion and respect and love towards arabs and africans to attract consumers and to higher consumer confidence index, also democracy is subjected to a constrain of financial and banks institutions that have there rating methodology that take into account the Political Risk factor and the economic conditions, this is a counter-power that creates more quality and more world stability because we have to optimize our economic systems and by being responsable by being also responsable governance, other than that compassion and respect can be virility and they are like mandatory for the system, because compassion and respect gets us more organized because neglecting compassion and respect cause violence and extremism that make our society unstable and less optimized , so tuning compassion and respect right with social services and medical services and with educational services and with help to the people to avoid violence and extremism is also more stability and more power , so this compassion and respect is virility. So as you see optimization is the language of love. What is the essence of organization ? Those are the questions that we ask in courses of philosophy. Now i have to be smartness and rationality and logic to answer this question. Smartness is an important requirement that fulfill this goal. And you have to learn how to think Sir and Madam.. So how can we attack this problem ? When you start thinking it is like also abstracting to the essentials to be able to simplify our thinking.. So this process of abstraction needs also my smartness to decompose efficiently... Smartness is also a fast process that finds fast the shortest path to the solution or that finds the solution to the problem.. So my smartness will answer like this: Look at our essence, we are a composition of consciousness and physical body.. But we can try to say that we are guided by the process of survival of fittest.. But this is not good abstraction.. We have to be smartness.. So why do we need to organize ? You will say that we have to be organized because of the process survival of the fittest.. But this is a narrow view.. Because it is a definition that is pejorative and not efficient.. Because of the following question: Why we need to survive better ? It is because of our weaknesses. But i say that it is still not a correct answer , because it is too much abstraction that lacks efficiency. Because our weaknesses need to be organized by optimization. This is the magical word, it is optimization. Why do we optimize ? to be more powerful and more reliability and correctness. You will ask a question such as: Is optimization: reliability and correctness ? My answer: When you are not reliable and/or correctness you are less efficient, so efficiency is also reliability and correctness. This is why i have abstracted the essence of organization to the process of optimization. But that's lacking Abstraction. Because we have to look at the composition of optimization. Optimization is performance and reliability. So that the essence of organization is the composition of optimization that is performance and reliability. So the essence of optimization is not only performance , but it is reliability. And that's also efficient morality, and efficient morality is Liberty and Liberty is efficient morality. So now my answer is not finished: Because the optimization is constrained.. Because corruption of morality is related to optimization.. So how can we measure corruption of morality ? What is corruption of morality ? This is an interesting subject.. It's like abstracting, you have to decompose and compose.. You can say for example what are the causes of corruption of morality? You can say what is the consequences of corruption ? You can define efficiently morality to be able to know about corruption. So if you define morality you will define it as a composition of: Guidance of moral, and a priori pure moral and empirical moral. And now you see that the difficulty is how to set the reference to be able to measure corruption of morality with it. What is the reference of morality ? The reference must be optimization that knows how to be optimization. I mean that optimization can not set itself as being performance alone. And optimization can not set itself to be extreme justice that lacks optimization, like ignoring the optimization by the "heuristic" of "tolerance" that optimizes the economic system and the social system. And optimization must be an effort to maintain stableness and reliability of the system, that means reliability of the system, this is related to security, and security is also related to compassion and love and respect, because neglecting compassion , love and respect do cause extremism and violence that hurt the system. How optimization must be this effort ? because discipline and progress are inherent to Liberty, so you have to enforce them efficiently and wisely by the hard way, that means by laws and by the soft way that i talked about.. So all in all the schema seems to be more clear and seems to indicate to us more what is corruption of morality, and it indicate to us what is the essence of organization.. I was thinking more, and here is my new thinking: Determinism easy for us to set the truth and sets the way of logic, and this truth and way of logic must be computed by our brain to create a consistent system that is efficient morality that is optimization that is performance and reliability. So there is some truth that hurts and some truth that is efficient morality that is optimization that we call tolerable or good, so the essence of truth is based on our essence that is our consciousness of space-time and the determinism of our empirical and physical world, and about the essence of logical consistency of the system, you can understand it by example like this: About the consistency of the system We call it consistency of the system.. When the system is: If A is smaller than B And B is smaller than C And if B is medium The system above doesn't allow to say that: A is smaller than B Because if you say that , it is as you are saying that A is smaller than B only, so that's a contradiction that hurts consistency of the system. And The system above doesn't allow to say that: B is smaller than C Because if you say that , it is as you are saying that B is smaller than C only, so that's a contradiction that hurts consistency of the system. So the system has to be consistent, so the system force you to say all at the same time: A is smaller than B B is smaller than C B is medium So that to be strict and clear to not create any contradiction. And about the essence of measure.. Philosophy is like mathematics.. Now what is the essence of measure ? I think that the reference is the consciousness of space-time as i have explained, adjoined with the senses of measure that we have, such as the sense of orientation and the sense of measuring space and saying that this is bigger than this etc. those ingrediants permit us to measure, i will ask for example, what is a point (in geometry) ? to understand a point we must map it to our consciousness of space-time as i have explained, so this is rooted on the physical empirical world, even if we are using our senses of measure, so this is why i have explained that mathematical logic and the mathematical Set theory for example are also rooted on the physical and empirical world , but the space-time can be relative or general, relativeness permit also to measure the truth , but this seems to create some contradictions in the system, this has been showed in my writing and explanation of my previous post of what is the essence of love and what is love, but i have showed that this can be resolved by using the reference of the general morality of the society as the reference that permits to measure and that must be enforced by laws and police. The essence of the Truth What is a Truth ? what is the essence of the Truth ? That's an important question.. Philosophy is like mathematics, because Philosophy must be based on efficient morality and efficient morality is optimization and optimization is performance and reliability. So if you look at mathematical logic.. What is mathematical logic ? Mathematical logic is also being conscious and feeling the space-time.. Here is why: Now I will give my explanation of what is consciousness... I hope that in my previous messages you have understood my explanation of how the consciousness of time is generated by our brain, I have said that the brain has a sense of direction that makes it possible to say that one object is left or on the right and back or front etc., and the brain is also able to see space in 3 dimensions with the sense of the gaze for example, that is to say to give coordinates as cartesian or polar in three dimensions to objects in the space of reality, and also the brain by means of the sense of touch and the eye is capable of the sense of the measurement of the magnitudes in the space of reality, these are ingredients of the brain which gives birth to the consciousness of time, for consciousness of time means that for two objects that follow each other, we are able to feel the existence in space of the back of the first object (by |
SG <s.gesemann@gmail.com>: Aug 02 06:27AM -0700 On Tuesday, July 18, 2017 at 7:34:48 PM UTC+2, Lynn McGuire wrote: > But, if one cannot walk the tightrope then one should find something > else to do in life. After all, working on the high wire is not for > everyone. Hmm, that analogy makes me wonder. Generally one assumes that safety comes with other downsides. Sticking with that analogy, a bridge would be a safer way to cross a canyon than a tight rope. But you might not be able to afford building one (higher cost = higher runtime or memory overhead). The analogy of bridge vs tight rope does kind of fit for languages that protect you better than C and C++ but intrinsically incur costs due to design choices. It's not a secret that programs in interpreted languages or even statically compiled languages such as Java are at a disadvantage compared to C++ since they make it difficult to avoid pointer-heavy data structes. Every variable in Python is a reference. Every variable of a non-primitive type in Java is a reference. Composing an object out of subobjects in Java doesn't give you a single chunk of memory but a tree of objects linked by those kinds of references. The cost is bad memory layout and potential cache misses. In addition you usually have a garbage or cycle collector of some sort which does have its own trade-offs. But I don't think this analogy of a bridge fits with respect to Rust. Rust would be like a tight rope that's safer than a normal tight rope but still as cheap (or almost as cheap) as the normal one. Even if you are good at walking on a tight rope and only very rarely loose your balance by accident, why wouldn't you pick the safer one unless you don't value your life? That's the whole point about Rust's existence! * fearless concurrency * memory safety without garbage collection * zero-overhead abstractions Frankly, I don't understand the opposition. I've programmed in C and C++ for over 10 years. Yes, I care about performance. That's why I switched to C++. And yes, I care about the three things I listed above. C++ got that "zero-overhead principle" down. But its story w.r.t. memory safety and data race freedom is lacking. Sure, there are efforts in C++ (static checking for guideline adherence) but to be honest, I'm not holding my breath. I start believing Stroustrup and Herb Sutter when I get ahold of a working static analyzer and annotated standard library that prevents use-after-free errors at compile-time. Yes, effective use of C++ makes leaking resources by accident pretty hard. That's cool. Thank you RAII. But we still deal with things like references, non-owning pointers, iterators etc that might be invalidated earlier than expected—even in "modern C++". Sure, you could replace some of that with a std::weak_ptr that is smart enough to figure out if the pointee is gone. But that's IMHO an undesirable performance regression. Wouldn't it be cool if the compiler could verify for you that non-owning pointers are never going to be invalid if the program actually compiles? So, before you dismiss Rust based on preconceived notions along the lines of "higher overhead" or "not close enough to the metal", you should probably stop and consider taking a closer look at Rust. No, I don't buy into the idea that only incompetent programmers make mistates. That's just nonsense. my two cents, SG |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Aug 02 05:14PM +0100 On 02/08/2017 14:27, SG wrote: > Every variable of a non-primitive type in Java is a reference. Pointer not reference. /Flibble |
ram@zedat.fu-berlin.de (Stefan Ram): Aug 02 12:57PM >support (including maybe syntax). It stranded. >With Java you're restricted to a silly semantics-less notion of >interface. It would be sad to have that imposed on C++. Do you want to say that in Java one cannot write wrappers at least as one can do in C++? I am not sure whether I understood your requirements, but here's a Java program that prints »-22«: The interface Negate defines some conditions for an implementation via assertations in a wrapper. The class NegateImpl then provides the implementation and the client Main calls it via a method that does the assertations. interface Negate { /** Returns the negative of its argument. @param arg a number between -2000000000 and 2000000000. @return the negative of arg */ default int negate( final int arg ) { assert arg <= 2000000000; assert arg >= -2000000000; final int result = negateImpl( arg ); assert result + arg == 0; return result; } /** Returns the negative of its argument. @param arg a number between -2000000000 and 2000000000. @return the negative of arg */ int negateImpl( int arg ); } class NegateImpl implements Negate { public int negateImpl( final int arg ) { return -arg; }} public final class Main { public static void main( final java.lang.String[] args ) { final Negate negate = new NegateImpl(); java.lang.System.out.println( negate.negate( 22 )); }} This is one example. Java offers several similar possibilities by other means, like abstract classes (to hide the implementation method »negateImpl«). |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Aug 01 09:16PM -0400 On 8/1/2017 2:47 PM, Rick C. Hodgin wrote: > 100M iterations, and my algorithm gave 2.927. > BSR = 53.2M function calls per second > Mine = 34.2M function calls per second For 8-bit values, this standard loop optimizes to about 10% better performance than my first algorithm: int result; // If the value's non-zero, return bit position (if any) if (v != 0) { // Iterate through each bit for (result = 7; result >= 0; result--, v <<= 1) { // Is this bit on? if ((v & 0x80) != 0) return(result); // Yes } // If we get here, no set bit was found } return(-1); When extended out to processing full 32-bits, this algorithm targets about 50% the speed of native BSR, and is the best solution I've been able to create, which is a register-optimized version reducing the score above from 1.879 to 1.772. In using the function you specified for _BitScanReverse() in Visual Studio 2015 produced an identical result to the non-register- optimized BSR function. It reveals use of BSR: 91: int result; 92: 93: _BitScanReverse((DWORD*)&lnResult, v); 00A11061 0F BD 44 24 08 bsr eax,dword ptr [esp+8] 00A11066 89 04 24 mov dword ptr [esp],eax 94: return(result); Thank you, Rick C. Hodgin |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment