Section 33A. The court on imposing a sentence of commitment to a correctional institution of the commonwealth, a house of correction, or a jail, shall order that the prisoner be deemed to have served a portion of said sentence, such portion to be the number of days spent by the prisoner in confinement prior to such sentence awaiting and during trial.