code wiki / _hdl_build / nx_ad_banner_exceed.nx
nx_ad_banner_exceed.nx source
↩ module page · 51 lines · 2483 B
1// nx_ad_banner_exceed.nx -- LIB: MEASURED S-class exceed primitives for the banner builder. Organ-graded from
2// LIVE EVIDENCE (measures real emitted bytes), never self-scored. Ladder ABSENT<STUB<BUILT<GATED<MEASURED<
3// EXCEEDS. An axis reaches EXCEEDS only when our MEASURED value is strictly better than a CITED incumbent
4// lower-bound (liar-kill in ex_grade_fewer: equal/worse can NEVER be EXCEEDS).
5//
6// CITED incumbent lower-bound (mainstream display-ad creative, e.g. Google Publisher Tag / DoubleClick):
7// loads the ad-tag library = >=1 THIRD-PARTY SCRIPT; pulls creative + impression/viewability beacons =
8// >=1 EXTERNAL FETCH and >=1 TRACKER (MRC viewability / IAB measurement REQUIRE a measurement script ->
9// tracking implies third-party JS). So incumbent third_party_js>=1, external_fetch>=1, tracker>=1.
10// These are architecture lower-bounds (not fabricated counts); our 0s are MEASURED on the real bytes.
11// Composes nx_ad_serve (as_len). license_tier: ORIGINAL
12import "nx_ad_serve.nx"
13import "nx_syscalls.nx"
14
15const LV_ABSENT: i64 = 0
16const LV_STUB: i64 = 1
17const LV_BUILT: i64 = 2
18const LV_GATED: i64 = 3
19const LV_MEASURED: i64 = 4
20const LV_EXCEEDS: i64 = 5
21
22// count non-overlapping occurrences of needle in hay[0..n].
23func ex_count(hay: *u8, n: i64, needle: *u8) -> i64 {
24 let nl: i64 = as_len(needle)
25 if nl == 0 { return 0 }
26 var c: i64 = 0; var i: i64 = 0
27 while i + nl <= n {
28 var k: i64 = 0; var mt: i64 = 1
29 while k < nl { if hay[i+k] != needle[k] { mt = 0; k = nl } else { k = k + 1 } }
30 if mt == 1 { c = c + 1; i = i + nl } else { i = i + 1 }
31 }
32 return c
33}
34// external-fetch vectors (src= attrs + CSS url(http...)).
35func ex_external_fetch(b: *u8, n: i64) -> i64 { return ex_count(b, n, "src=" as *u8) + ex_count(b, n, "url(http" as *u8) }
36// known third-party tracker tokens.
37func ex_tracker(b: *u8, n: i64) -> i64 {
38 var c: i64 = 0
39 c = c + ex_count(b, n, "doubleclick" as *u8)
40 c = c + ex_count(b, n, "google-analytics" as *u8)
41 c = c + ex_count(b, n, "googletagmanager" as *u8)
42 c = c + ex_count(b, n, "facebook.net" as *u8)
43 c = c + ex_count(b, n, "gtag(" as *u8)
44 c = c + ex_count(b, n, "/pixel" as *u8)
45 return c
46}
47// grade a "fewer-is-better" axis vs a cited incumbent lower-bound. EXCEEDS ONLY when strictly fewer (liar-kill).
48func ex_grade_fewer(nishi: i64, incumbent: i64) -> i64 {
49 if nishi < incumbent { return LV_EXCEEDS }
50 return LV_MEASURED
51}