Skip to content

Commit 1419b46

Browse files
committed
[backend/golang] Add Bounds Check Elimination Code
1 parent 4906d92 commit 1419b46

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

_out/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ func (s Item) Vstruct_Validate() bool {
242242
return false
243243
}
244244

245+
_ = s[24]
246+
245247
var __off0 uint64 = 25
246248
var __off1 uint64 = uint64(s[17]) |
247249
uint64(s[18])<<8 |
@@ -318,6 +320,8 @@ func (s Inventory) Vstruct_Validate() bool {
318320
return false
319321
}
320322

323+
_ = s[15]
324+
321325
var __off0 uint64 = 16
322326
var __off1 uint64 = uint64(s[0]) |
323327
uint64(s[1])<<8 |
@@ -423,6 +427,8 @@ func (s Entity) Vstruct_Validate() bool {
423427
return false
424428
}
425429

430+
_ = s[40]
431+
426432
var __off0 uint64 = 41
427433
var __off1 uint64 = uint64(s[25]) |
428434
uint64(s[26])<<8 |

compile/backend/golang/structs.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ func writeStructs(w io.Writer, i *ir.IR) {
105105
fmt.Fprintf(w, "if len(s) < %d {\n", s.DynamicFieldHeadOffsets[len(s.DynamicFieldHeadOffsets)-1])
106106
fmt.Fprintf(w, "return false\n")
107107
fmt.Fprintf(w, "}\n")
108+
if s.DynamicFieldHeadOffsets[len(s.DynamicFieldHeadOffsets)-1] > 0 {
109+
// Add Bounds Check Elimination
110+
fmt.Fprintf(w, "\n_ = s[%d]\n", s.DynamicFieldHeadOffsets[len(s.DynamicFieldHeadOffsets)-1]-1)
111+
}
112+
108113
for i, f := range s.DynamicFieldHeadOffsets {
109114
_ = f
110115
fmt.Fprintf(w, "\nvar __off%d uint64 = ", i)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vstruct",
3-
"version": "1.0.13",
3+
"version": "1.1.0",
44
"description": "Code Generation Based High Speed Data Serialization Tool",
55
"scripts": {
66
"test": "echo \"Error: no test specified\" && exit 1",

0 commit comments

Comments
 (0)