-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathITCHv41.rl
More file actions
146 lines (130 loc) · 3.58 KB
/
ITCHv41.rl
File metadata and controls
146 lines (130 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
%%{
machine ITCHv41;
write data;
# Common fields for both Ordered Executed message types
nanoseconds = any{4} >{ nanos = __builtin_bswap32(*(const uint32_t*)(p)); };
orderExecutedShares4 = any{4} >{ shares = __builtin_bswap32(*(const uint32_t*)(p)); };
orderExecutedMatchNum8 = any{8} >{ matchNum = __builtin_bswap64(*(const uint64_t*)(p)); };
orderExecutedRefNum8 = any{8} >{ refNum = __builtin_bswap64(*(const uint64_t*)(p)); };
orderExecutedCommon = orderExecutedRefNum8
orderExecutedShares4
orderExecutedMatchNum8;
# 4.5.1 Order Executed Message
orderExecuted = 'E' %{ type = 1; }
nanoseconds
orderExecutedCommon;
# 4.5.2 Order Executed With Price Message
orderExecutedPrintable1 = 'Y' %{ printable = true; }
| 'N' %{ printable = false; };
orderExecutedPrice4 = any{4} >{ price = __builtin_bswap32(*(const uint32_t*)(p)); };
orderExecutedWithPrice = 'C' %{ type = 2; }
nanoseconds
orderExecutedCommon
orderExecutedPrintable1
orderExecutedPrice4;
}%%
// define a function pointer type that matches the STG calling convention
typedef void (*HsCall)(int64_t*, int64_t*, int64_t*, int64_t, int64_t, int64_t, int64_t,
int64_t, int64_t, int64_t*, float, float, float, float, double, double);
extern void
ITCHv41_run(
int64_t* restrict baseReg,
int64_t* restrict sp,
int64_t* restrict hp,
const uint8_t* restrict buffer, // R1
int64_t length, // R2
int64_t r3,
int64_t r4,
int64_t r5,
int64_t r6,
int64_t* restrict spLim,
float f1,
float f2,
float f3,
float f4,
double d1,
double d2)
{
%% main := orderExecuted | orderExecutedWithPrice;
int cs;
%% write init;
const uint8_t* p = buffer;
const uint8_t* pe = &buffer[length];
// create undefined variables, clang will emit these as a llvm undef literal
const int64_t iUndef;
const float fUndef;
const double dUndef;
uint32_t type;
uint32_t nanos;
uint32_t shares;
uint32_t price;
uint64_t matchNum;
uint64_t refNum;
bool printable;
%% write exec;
const HsCall fun = (HsCall)sp[0];
// the machine has completed
if (cs == ITCHv41_first_final)
{
return fun(
baseReg,
sp, // updated_stack,
hp,
type,
nanos,
shares,
price,
matchNum,
refNum,
spLim,
fUndef,
fUndef,
fUndef,
fUndef,
dUndef,
dUndef);
}
else if (cs == ITCHv41_error)
{
return fun(
baseReg,
sp, // updated_stack,
hp,
-1,
iUndef,
iUndef,
iUndef,
iUndef,
iUndef,
spLim,
fUndef,
fUndef,
fUndef,
fUndef,
dUndef,
dUndef);
}
else
{
return fun(
baseReg,
sp, // updated_stack,
hp,
-2,
iUndef,
iUndef,
iUndef,
iUndef,
iUndef,
spLim,
fUndef,
fUndef,
fUndef,
fUndef,
dUndef,
dUndef);
}
}