Comments (4)
I've pushed a fix for this. What is does this is: previously when compiling:
package cal;
actor CastActor() ==> :
my_action: action ==>
var
uint(size=32) a,
uint(size=32) b,
uint(size=64) c,
uint(size=32) d
do
a := 1073741824;
b := 8;
c := a * b;
d := c / 8;
println("d: " + d);
end
end
The generated C is:
static void my_action() {
u32 a;
u32 b;
u64 c;
u32 d;
a = 1073741824;
b = 8;
c = a * b;
d = c / 8;
printf("d: %u\n", d);
}
The generated C now is:
static void my_action() {
u32 a;
u32 b;
u64 c;
u32 d;
a = 1073741824;
b = 8;
c = (u64) a * b;
d = (u32) c / 8;
printf("d: %u\n", d);
}
The output of the compiled C used to be:
d: 0
It now is:
d: 1073741824
Code review for #136 anyone?
from orcc.
Hello Rob,
thats great, have you tested other applications to see if the casting breaks something ?
Cheers,
Endri
On 05 Oct 2015, at 21:31, Rob Stewart [email protected] wrote:
I've pushed a fix for this. What is does this is: previously when compiling:
package cal;
actor CastActor() ==> :
my_action: action ==>
var
uint(size=32) a,
uint(size=32) b,
uint(size=64) c,
uint(size=32) d
do
a := 1073741824;
b := 8;
c := a * b;
d := c / 8;
println("d: " + d);
end
end
The generated C is:static void my_action() {
u32 a;
u32 b;
u64 c;
u32 d;
a = 1073741824;
b = 8;
c = a * b;
d = c / 8;
printf("d: %u\n", d);
}
The generated C now is:static void my_action() {
u32 a;
u32 b;
u64 c;
u32 d;
a = 1073741824;
b = 8;
c = (u64) a * b;
d = (u32) c / 8;
printf("d: %u\n", d);
}
The output of the compiled C used to be:d: 0
It now is:d: 1073741824
Code review for #136 #136 anyone?—
Reply to this email directly or view it on GitHub #135 (comment).
from orcc.
Hi Endri,
Thanks, yes I'll test this with some of our applicaions and the applications in orc-apps. If it all works out, I'll push to orcc/master, rather than cluttering git history with a pull request.
from orcc.
It seems like the theory behind the original problem as well as the proposed fix operate on wrong assumptions about the meaning of C code. In the expression (u64) a * b
, it is not the result of the multiplication that is cast, but rather the operand a
. This is due to the cast operator having a higher precedence than multiplication: https://en.cppreference.com/w/c/language/operator_precedence
Then, because one of the operands is 64 bit and another 32 bit, the latter is expanded to 64 bit by the C compiler, and consequently the multiplication is done on two 64 bit numbers.
Just based on the discussion here, it appears the proposed fix would generate u64 y = (u64) e + f * g
, when all of e
, f
and g
are 32 bit. This would effectively cast only e
to 64 bit while the multiplication of f
and g
would be performed in 32 bit mode. Even modifying the output to actually match the intention of the fix to u64 y = (u64) (e + f * g)
would not help: all the operations would be performed in 32 bit mode then. If you really want to be consistent, you should cast each operand in an operation separately (some contractions are still possible by taking into account C operator precedence).
from orcc.
Related Issues (20)
- Nesting networks: "ClassCastException: ..PortImpl cannot be cast to ...Instance" HOT 7
- HLS VHDL code gen problem: "mem_size => )" HOT 1
- Bug report for C Backend - C compiler error 2143 HOT 3
- getSizeInBits() method in TypeImpl HOT 3
- Supporting more than 64 bit literals HOT 3
- Eclipse plugin doesn't initialize .xdf file when added using New-File menu HOT 3
- Eclipse parser should enforce type safety when adding values to arrays HOT 1
- (C backend) minting 16 or more short's by prefixing `i` creates potentially illegal C code HOT 2
- net.sf.orcc.cal.cal.<type> cannot be resolved to a type. HOT 6
- Mixing of indices of lvalue when using `for` generators in rvalue HOT 2
- inst.getActor() contains no incoming or outgoing port map
- Xtext editor not showing error if action is misspled or missing HOT 1
- xtext lexer warnings
- [C Backend] Fan-out buffer size HOT 4
- Eclipse install issues HOT 2
- [SOLVED] does not appear to work in eclipse 4.7 HOT 2
- [SOLVED] no dialog raised on Set/Update Refinement eclipse 4.7 HOT 1
- [SOLVED] No Actor displayed in Set/Update Refinement dialog in Eclipse 4.3 HOT 1
- which version can work with recent eclipse?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from orcc.